-
Notifications
You must be signed in to change notification settings - Fork 718
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
Support for wasm32-wasi #1568
Support for wasm32-wasi #1568
Conversation
just kindly fwd: @dynamite-bud said this doesn't work #1043 (comment) WASI_SDK_PATH=/(...)/wasi/wasi-sdk cargo build --target wasm32-wasi 1.71.0-nightly 2.90 4.88G 14:24:35 100%
Compiling ring v0.17.0-not-released-yet (/(...)/ring)
error: no rules expected the token `unsafe`
--> src/arithmetic/bigint/bn_mul_mont_fallback.rs:26:5
|
26 | unsafe fn bn_mul_mont(
| ^^^^^^ no rules expected this token in macro call
|
::: src/prefixed.rs:1:1
|
1 | macro_rules! prefixed_extern {
| ---------------------------- when calling this macro
|
note: while trying to match `fn`
--> src/prefixed.rs:6:22
|
6 | $vis:vis fn $name:ident ( $( $arg_pat:ident : $arg_ty:ty ),* $(,)? )
| ^^
warning: unused macro definition: `prefixed_export`
--> src/prefixed.rs:44:14
|
44 | macro_rules! prefixed_export {
| ^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_macros)]` on by default
warning: unused imports: `Limb`, `MODULUS_MAX_LIMBS`, `N0`, `limbs_from_mont_in_place`, `limbs_mul`
--> src/arithmetic/bigint/bn_mul_mont_fallback.rs:22:13
|
22 | use super::{limbs_from_mont_in_place, limbs_mul, Limb, MODULUS_MAX_LIMBS, N0};
| ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^ ^^
|
= note: `#[warn(unused_imports)]` on by default
warning: unused import: `crate::c`
--> src/arithmetic/bigint/bn_mul_mont_fallback.rs:23:5
|
23 | use crate::c;
| ^^^^^^^^
warning: `ring` (lib) generated 3 warnings
error: could not compile `ring` (lib) due to previous error; 3 warnings emitted |
It works with
And the wasi tests in the CI also succeed. |
@@ -47,7 +47,7 @@ fn digest_misc() { | |||
} | |||
|
|||
// wasm_bindgen doesn't build this correctly. | |||
#[cfg(not(target_arch = "wsam32"))] | |||
#[cfg(not(target_arch = "wasm32"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing out the typo. I fixed this the right way in PR #1647, so you can remove this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I will, Thanks for the review.
&std::env::var("WASI_SDK_PATH").expect("missing environment variable: WASI_SDK_PATH"); | ||
c.compiler(format!("{}/bin/clang", wasi_sdk_path).as_str()); | ||
c.archiver(format!("{}/bin/llvm-ar", wasi_sdk_path).as_str()); | ||
c.flag(format!("--sysroot={}/share/wasi-sysroot", wasi_sdk_path).as_str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like these changes belong in cc-rs. We traditionally avoid doing this kind of discovery. I suggest we remove this change from this PR.
target: ${{ matrix.target }} | ||
toolchain: ${{ matrix.rust_channel }} | ||
|
||
- name: Install wasi-sdk |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic ideally belongs in install-build-tools.sh. The idea is that anybody can run mk/install-build-tools.sh --target=wasm32-wasi
and the necessary tools installed. Then CI can use mk/install-build-tools.sh
too, and then peoples' local build environment matches CI (more or less).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I install the wasi-sdk with the install-build-tools.sh
script, where would you place the install files? On linux you would typically place them in /opt/wasi-sdk
but I'm not sure it I can assume that.
@@ -464,6 +464,69 @@ jobs: | |||
# TODO: Do this check on Windows too. | |||
- run: mk/check-symbol-prefixes.sh --target=${{ matrix.target }} | |||
|
|||
# The wasm32-wasi targets have a different set of feature sets. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not understand this comment about feature sets, and thus I don't understand why the wasi target needs its own build matrix.
You should consider supporting Support for WASI using Without supporting pre-compiled files, it doesn't require any changes to the build scripts, nor messing with environment variables. |
run: | | ||
export WASI_URL=$(curl -s https://api.github.com/repos/WebAssembly/wasi-sdk/releases/latest | jq -r '.assets[] | select(.name | contains("linux.tar.gz")) | .browser_download_url') | ||
wget -O ./wasi-sdk-linux.tar.gz $WASI_URL | ||
mkdir wasi-sdk |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, why do we need the WASI SDK? If you look at the existing wasm32 targets, we manage to build them with standard clang, and I don't see anything WASI-specific here besides the rand.rs, which doesn't add any new C stuff. Maybe we can get rid of this SDK dependency by treating the -wasi
target just like the -unknown-unknown
target?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be even better, as it could run in web browsers without additional modules.
Thanks a lot for taking this on. I wasn't entirely sure how to do this. |
This PR adds support for the wasm32-wasi target.
To get the CI working, i had to use the dtolnay/rust-toolchain@stable action. The toolchain only seems to work when it is installed with rustup, see a similar issue here: https://bugs.archlinux.org/task/75269.
Currently the clippy and audit CI runs are failing. I didn't include them in this PR because I thought it would make it more difficult to see the actual changes. If I should include the clippy and audit changes, please let me know.
I agree to license my contributions to each file under the terms given at the top of each file I changed.