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

My project broke with the latest versions of wasm-pack and wasm-bindgen #3376

Closed
Swolebrain opened this issue Mar 30, 2023 · 6 comments
Closed
Labels

Comments

@Swolebrain
Copy link

Swolebrain commented Mar 30, 2023

Summary

Without making any code changes, only having updated my deps, my wasm project no longer works. None of my Rust functions that are decorated with the #[wasm_bindgen] annotation are being exported to JS any more. They don't show up in my generated .js file and their declarations don't show up inside my .d.ts file either.

Can someone please tell me if there's a new flag I need to use in order for these functions not to be tree-shaken or something? Perhaps set the sideEffects property to true?

I can't post the source code because it's for work, but literally nothing changed and now the generated code inside /pkg doesn't have any of the stuff i want to convert with wasm-bindgen.

Additional Details

I saw something that seemed related in a PR in rust-wasm (1224).

I for the life of me cannot find documentation on how to set this sideEffects property to true.

@Liamolucko
Copy link
Collaborator

I doubt that sideEffects is the problem. It was previously false, and rustwasm/wasm-pack#1224 effectively set it to be partially true, so any problems caused by it not being true should have been there in the previous version of wasm-pack too.

Was it specifically the latest version of wasm-pack that caused the problem, or did you update both wasm-bindgen and wasm-pack at the same time and aren't sure?

Also, although you can't share any code, can you give some basic info about the setup you're using? Specifically, which --target you're passing to wasm-pack and whether you're using a bundler, and if so which one it is.

@Swolebrain
Copy link
Author

Swolebrain commented Mar 30, 2023

I updated both wasm-pack and wasm-bindgen at the same time so I'm not sure. This is the actual build command:

wasm-pack build --target web --out-name mypackage_wasm --mode no-install

The compilation target is wasm32-unknown-unknown and this is in .cargo/config.toml:

[target.wasm32-unknown-unknown]
linker = "x86_64-unknown-linux-gnu-clang"
rustflags = [
    "-C", "link-arg=-target",
    "-C", "link-arg=wasm32-unknown-unknown",
    "-C", "link-arg=-fuse-ld=lld",
    "-C", "link-arg=-nostartfiles",
]

@Liamolucko
Copy link
Collaborator

The thing that's jumping out to me there is --mode no-install - I think you might be running into rustwasm/wasm-pack#1247. wasm-pack v0.11.0 crashes when trying to use a locally installed version of wasm-opt, which I suspect you might be using considering that you've disabled downloading it.

If that's the issue, wasm-pack will be throwing an error something along the lines of 'wasm-opt does not exist'. Downgrading to wasm-pack v0.10.3 should fix it, or removing the local wasm-opt and letting wasm-pack download it, which still works.

@Swolebrain
Copy link
Author

Swolebrain commented Apr 18, 2023

Okay Thanks a lot for your help, that is promising. Indeed, a prior step in my build process is to install wasm-bindgen-cli locally into the build box.

Below is the output of the wasm-pack step. It's not quite like that other issue you linked to. It says it's skipping wams-opt. Is there a way to force it not to skip wasm-opt? What is wasm-opt? If it's being skipped and not crashing, could that still be the source of the issue?

+ wasm-pack build --target web --out-name mypackate_wasm --scope amzn --mode no-install
[INFO] : Checking for the Wasm target...
[INFO] : Compiling to Wasm...
   Compiling proc-macro2 v1.0.56
   Compiling quote v1.0.26
   Compiling unicode-ident v1.0.8
   Compiling syn v1.0.109
   Compiling cfg-if v1.0.0
   Compiling libc v0.2.141
   Compiling autocfg v1.1.0
   Compiling log v0.4.17
   Compiling memchr v2.5.0
   Compiling serde_derive v1.0.159
   Compiling ident_case v1.0.1
   Compiling fnv v1.0.7
   Compiling strsim v0.10.0
   Compiling once_cell v1.17.1
   Compiling io-lifetimes v1.0.10
   Compiling parking_lot_core v0.9.7
   Compiling either v1.8.1
   Compiling crunchy v0.2.2
   Compiling rustix v0.37.11
   Compiling scopeguard v1.1.0
   Compiling smallvec v1.10.0
   Compiling tiny-keccak v2.0.2
   Compiling hashbrown v0.12.3
   Compiling serde v1.0.159
   Compiling linux-raw-sys v0.3.1
   Compiling version_check v0.9.4
   Compiling regex-syntax v0.6.29
   Compiling bitflags v1.3.2
   Compiling siphasher v0.3.10
   Compiling precomputed-hash v0.1.1
   Compiling new_debug_unreachable v1.0.4
   Compiling bit-vec v0.6.3
   Compiling serde_json v1.0.95
   Compiling fixedbitset v0.4.2
   Compiling unicode-xid v0.2.4
   Compiling ryu v1.0.13
   Compiling itoa v1.0.6
   Compiling pico-args v0.4.2
   Compiling tinyvec_macros v0.1.1
   Compiling thiserror v1.0.40
   Compiling wasm-bindgen-shared v0.2.84
   Compiling itertools v0.10.5
   Compiling diff v0.1.13
   Compiling phf_shared v0.10.0
   Compiling bit-set v0.5.3
   Compiling tinyvec v1.6.0
   Compiling semver v1.0.17
   Compiling percent-encoding v2.2.0
   Compiling unicode-bidi v0.3.13
   Compiling bumpalo v3.12.0
   Compiling ena v0.14.2
   Compiling form_urlencoded v1.1.0
   Compiling rustc_lexer v0.1.0
   Compiling ipnet v2.7.2
   Compiling lazy_static v1.4.0
   Compiling indexmap v1.9.3
   Compiling lock_api v0.4.9
   Compiling proc-macro-error-attr v1.0.4
   Compiling proc-macro-error v1.0.4
   Compiling os_str_bytes v6.5.0
   Compiling heck v0.4.1
   Compiling wasm-bindgen v0.2.84
   Compiling anyhow v1.0.70
   Compiling termcolor v1.2.0
   Compiling unicode-segmentation v1.10.1
   Compiling aho-corasick v0.7.20
   Compiling arrayvec v0.5.2
   Compiling atty v0.2.14
   Compiling json v0.12.4
   Compiling typed-arena v2.0.2
   Compiling clap_lex v0.2.4
   Compiling amzn-waterford-rust v1.1.4424
   Compiling textwrap v0.16.0
   Compiling Inflector v0.11.4
   Compiling syn v2.0.13
   Compiling pretty v0.11.3
   Compiling petgraph v0.6.3
   Compiling unicode-normalization v0.1.22
   Compiling idna v0.3.0
   Compiling dirs-sys-next v0.1.2
   Compiling dirs-next v2.0.0
   Compiling term v0.7.0
   Compiling parking_lot v0.12.1
   Compiling url v2.3.1
   Compiling regex v1.7.3
   Compiling string_cache v0.8.7
   Compiling ascii-canvas v3.0.0
   Compiling thiserror-impl v1.0.40
   Compiling lalrpop-util v0.19.9
   Compiling is-terminal v0.4.7
   Compiling lalrpop v0.19.9
   Compiling darling_core v0.14.4
   Compiling darling_core v0.13.4
   Compiling wasm-bindgen-backend v0.2.84
   Compiling derive_arbitrary v1.3.0
   Compiling clap_derive v3.2.18
   Compiling ts-rs-macros v6.2.0
   Compiling wasm-bindgen-macro-support v0.2.84
   Compiling arbitrary v1.3.0
   Compiling wasm-bindgen-macro v0.2.84
   Compiling darling_macro v0.14.4
   Compiling ts-rs v6.2.1
   Compiling darling_macro v0.13.4
   Compiling darling v0.14.4
   Compiling serde_with_macros v2.3.2
   Compiling darling v0.13.4
   Compiling serde_with_macros v1.5.2
   Compiling clap v3.2.23
   Compiling console_error_panic_hook v0.1.7
   Compiling toml v0.5.11
   Compiling cargo-lock v8.0.3
   Compiling serde_with v2.3.2
   Compiling serde_with v1.14.0
   ....
[optimized]     Finished release  target(s) in 51.31s
[INFO] : License key is set in Cargo.toml but no LICENSE file(s) were found; Please add the LICENSE file(s) to your project directory
[INFO] : Skipping wasm-opt as no downloading was requested
[INFO] : Optional field missing from Cargo.toml: 'repository'. This is not necessary, but recommended
[INFO] : :-) Done in 51.53s
[INFO] : :-) Your wasm pkg is ready to publish at /local/p4clients/pkgbuild-IEPza/workspace/src/______/pkg.
[WARN] : :-) [6] Couldn't resolve host name (Could not resolve host: crates.io)

@Swolebrain
Copy link
Author

I think you're right that this has to do with the --no-install flag though.

@Swolebrain
Copy link
Author

Alright this is resolved, my company's internal build tools stopped passing a flag to CLang that it needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants