Skip to content
New issue

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

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

Already on GitHub? # to your account

Imports from "env" getting into Wasm artifact #2345

Closed
bakaq opened this issue Feb 9, 2025 · 6 comments
Closed

Imports from "env" getting into Wasm artifact #2345

bakaq opened this issue Feb 9, 2025 · 6 comments

Comments

@bakaq
Copy link

bakaq commented Feb 9, 2025

Found in mthom/scryer-prolog#2819.

Compiling any crate with dependencies on ring (with wasm32_unknown_unknown_js feature) to wasm32-unknown-unknown leaves 2 functions imported from "env". wasm-tools print artifact.wasm | grep '"env"' gives:

  (import "env" "ring_core_0_17_8_bn_from_montgomery_in_place" (func $ring_core_0_17_8_bn_from_montgomery_in_place (;17;) (type 18)))
  (import "env" "ring_core_0_17_8_limbs_mul_add_limb" (func $ring_core_0_17_8_limbs_mul_add_limb (;18;) (type 11)))

I found both functions in the code. The problem seems to be that it links with an assembly version if it exists, and with the current #[cfg] attributes it seems to think that wasm32 has an assembly implementation of both of these. Adding a target_arch = "wasm32" term to the relevant attributes seems to fix this.

I have no idea why this isn't caught by CI.

@briansmith
Copy link
Owner

This is a symptom of not linking the C code, as these functions are defined in C. This might be because you are using an old version of wasm_bindgen? Or maybe we are using too old of a wasm_bindgen in CI and if we upgraded ours then we'd have the same issue?

@briansmith
Copy link
Owner

Which version of Rust are and which version of wasm-bindgen are you using? Could you try different versions and report back?

@bakaq
Copy link
Author

bakaq commented Feb 9, 2025

Using Rust 1.80.1 and wasm-bindgen 0.2.92. I tried 0.2.100 too and same problem.

@briansmith
Copy link
Owner

Did you set TARGET_CC to a wasm32-capable compiler?

@bakaq
Copy link
Author

bakaq commented Feb 9, 2025

Ok, I tried inside a docker container and it works fine actually. It seems that this is an issue with my distro being weird. Sorry for the noise and thank you for the guidance.

@bakaq bakaq closed this as completed Feb 9, 2025
@briansmith
Copy link
Owner

Thanks for reporting back!

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

No branches or pull requests

2 participants