Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebAssembly build error #622

Closed
baoyachi opened this issue Apr 11, 2024 · 9 comments
Closed

WebAssembly build error #622

baoyachi opened this issue Apr 11, 2024 · 9 comments

Comments

@baoyachi
Copy link

build log:

➜  rust-demo git:(master) wasm-pack build --target bundler                           
[INFO]: 🎯  Checking for the Wasm target...
[INFO]: πŸŒ€  Compiling to Wasm...
   Compiling cc v1.0.90
   Compiling version_check v0.9.4
   Compiling libc v0.2.153
   Compiling cfg-if v1.0.0
   Compiling once_cell v1.19.0
   Compiling zerocopy v0.7.32
   Compiling chumsky v1.0.0-alpha.7
   Compiling allocator-api2 v0.2.16
   Compiling unicode-ident v1.0.12
   Compiling demo v0.1.0 (~/rust-demo)
   Compiling ahash v0.8.11
   Compiling psm v0.1.21
   Compiling stacker v0.1.15
   Compiling hashbrown v0.14.3
error: failed to build archive: 'wasm32.o': section too large

The following warnings were emitted during compilation:

warning: [email protected]: warning: /Library/Developer/CommandLineTools/usr/bin/ranlib: archive library: ~/rust-demo/target/wasm32-unknown-unknown/release/build/psm-e7819be911e6050d/out/libpsm_s.a the table of contents is empty (no object file members in the library define global symbols)

error: could not compile `psm` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
Error: Compiling your crate to WebAssembly failed
Caused by: Compiling your crate to WebAssembly failed
Caused by: failed to execute `cargo build`: exited with exit status: 101
  full command: cd "~/rust-demo" && "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown"
➜  rust-demo git:(master)
  • Cargo.toml file
[package]
name = "demo"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
chumsky = "1.0.0-alpha.6"
@zesterer
Copy link
Owner

zesterer commented Apr 11, 2024

It's difficult to determine what's going on here, but this line

error: failed to build archive: 'wasm32.o': section too large

Implies that perhaps too much code was being generated (although I'm not sure why that would be the case). Are you compiling with optimisations enabled?

@baoyachi
Copy link
Author

It's difficult to determine what's going on here, but this line

error: failed to build archive: 'wasm32.o': section too large

Implies that perhaps too much code was being generated (although I'm not sure why that would be the case). Are you compiling with optimisations enabled?

I just use command:wasm-pack build --target bundler

@zesterer
Copy link
Owner

This seems much more likely to be an issue with wasm-pack than chumsky, I'd recommend asking on the relevant GitHub repo instead.

@toadslop
Copy link

toadslop commented May 8, 2024

Try building in release and see if the issue persists. In a project that I was working on, I found that the debug build included type information that was larger than some limitation in the wasm parser. When I built in release mode, that type information wasn't included, and so it worked. Its obviously not ideal, but at least its a workaround until a final solution is implemented.

@zesterer
Copy link
Owner

An alternative there might be to just skip including that debug information:

[profile.dev]
debug = false

Obviously this is very non-ideal. I can't think of a good way to strip that information for specifically chumsky code though. You can declare crate-specific debug settings, but since chumsky is basically all generic code, it'll get inlined at the use site and probably won't be counted as code for chumsky-the-crate any longer.

@jccampagne
Copy link

jccampagne commented Jun 6, 2024

I had a similar issue on a different project. Installing LLVM from brew and making sure brew's LLVM was called (by updating PATH) instead of using Xcode's worked for me.

~ % clang --version       
Apple clang version 15.0.0 (clang-1500.3.9.4)
Target: arm64-apple-darwin23.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

versus:

~ % export PATH=/opt/homebrew/Cellar/llvm/18.1.6/bin/:$PATH                             
~ % clang --version                                        
Homebrew clang version 18.1.6
Target: arm64-apple-darwin23.5.0
Thread model: posix
InstalledDir: /opt/homebrew/Cellar/llvm/18.1.6/bin

@baoyachi
Copy link
Author

baoyachi commented Jul 8, 2024

The reason for this error is caused by the stacker library,
Have you considered replacing the stacker library

@zesterer
Copy link
Owner

zesterer commented Jul 8, 2024

stacker is behind an optional feature flag, disabling that feature flag will remove the dependency and associated functionality. It's non-essential for chumsky, so this should be possible.

@baoyachi
Copy link
Author

baoyachi commented Jul 8, 2024

Yeh, It can be resolved through the following dependencies

  • Cargo.toml file
[package]
name = "demo"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
chumsky = { version = "1.0.0-alpha.6", features = ["std"], default-features = false }

@baoyachi baoyachi closed this as completed Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants