Skip to content

__getrandom_v03_custom Not Preventing wasm-bindgen Import on wasm32-unknown-unknown with Internet Computer #633

Closed as not planned

Description

@e274426380

Description
Hi, I'm encountering an issue where defining __getrandom_v03_custom as per the documentation (https://docs.rs/getrandom/0.3.2/getrandom/#opt-in-backends) does not prevent wasm-bindgen from being imported when targeting wasm32-unknown-unknown for deployment on the Internet Computer (IC). Despite disabling default features and enabling the custom backend via --cfg getrandom_backend="custom", the resulting WASM file still contains __wbindgen_describe imports, causing deployment failures on IC.

Expected Behavior
According to the documentation, defining __getrandom_v03_custom and enabling the custom backend should override the default wasm_js backend, avoiding the dependency on wasm-bindgen and its associated imports (e.g., __wbindgen_describe).

Actual Behavior
Even with the custom function defined and the configuration applied, wasm-bindgen is still linked into the final WASM binary, as verified by wasm-objdump -x. This leads to deployment errors on the Internet Computer, which does not support wasm-bindgen imports.

According to my query, the dependency chain is: burn -> rand -> getrandom

[package]
name = "burn_price_backend"
version = "0.1.0"
edition = "2021"

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

[dependencies]
candid = "0.10"
ic-cdk = "0.16"
ic-cdk-macros = "0.13"
bincode = "1.3.3"
burn = { git = "https://github.com/burn-rs/burn", default-features = false, features = ["std", "ndarray", "autodiff"] }
serde = { version = "1.0", features = ["derive"] }
getrandom = { version = "0.3.2", default-features = false }

.cargo/config.toml

[build]
rustflags = ["--cfg", "getrandom_backend=\"custom\""]
target = "wasm32-unknown-unknown"

This is my code repository:
https://github.com/e274426380/burn_price

Activity

  1. newpavlov commented on Mar 21, 2025

    @newpavlov
    Member

    You should find a crate which enables the wasm_js feature for getrandom in your dependency tree and ask its authors to not do that (or patch the dep). Unfortunately, configuration flags can not influence dependency resolution, so by enabling the wasm_js feature wasm-bindgen gets compiled as part of your project.

  2. newpavlov commented on Mar 21, 2025

    @newpavlov
    Member

    We will add a stronger warning for wasm_js (see #633). Since it's a downstream issue, we can not do much here, so I will close this issue.

  3. e274426380 commented on Mar 24, 2025

    @e274426380
    Author

    We will add a stronger warning for wasm_js (see #633). Since it's a downstream issue, we can not do much here, so I will close this issue.

    But as far as I know, the getrandom project using version 0.2.9 works fine on Internet Computer.
    And use this configuration:
    features = [“custom”]
    https://github.com/smallstepman/ic-mnist

  4. newpavlov commented on Mar 24, 2025

    @newpavlov
    Member

    It does not matter. As far as I understand, you have a problematic crate in your dependency tree which enables the wasm_js feature for getrandom v0.3. We can not do anything about it on our side.

  5. dhardy commented on Sep 22, 2025

    @dhardy
    Member

    Is this issue reproducible today? The code linked above no longer exists.

  6. e274426380 commented on Sep 22, 2025

    @e274426380
    Author

    Is this issue reproducible today? The code linked above no longer exists.

    I'm using the burn framework. After contacting the author of burn to modify the dependencies, the issue was resolved.

  7. newpavlov commented on Sep 22, 2025

    @newpavlov
    Member

    It was resolved by not enabling the wasm_js feature in the dependency, correct? We would like to check whether enabling the feature still results in the same problem (see #726), i.e. whether having wasm-bindgen/js-sys in dependency tree without calling any code from them breaks your build.

  8. e274426380 commented on Sep 22, 2025

    @e274426380
    Author

    It was resolved by not enabling the wasm_js feature in the dependency, correct? We would like to check whether enabling the feature still results in the same problem (see #726), i.e. whether having wasm-bindgen/js-sys in dependency tree without calling any code from them breaks your build.

    No, upon checking, I found that the other party hadn't enabled the wasm option, forcing the use of the default getrandom configuration, which caused this error. I contacted the burn framework author and had them support my use of wasm, so the issue has now been resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions