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

Building for target different than current OS one #1217

Closed
ranile opened this issue Jan 16, 2022 · 4 comments
Closed

Building for target different than current OS one #1217

ranile opened this issue Jan 16, 2022 · 4 comments

Comments

@ranile
Copy link

ranile commented Jan 16, 2022

I'm trying to build a project for wasm32-unknown-unknown but failing at it because there is no target added. I do not understand how I can add the target.

$ ~/path/to/rustc_codegen_cranelift/build/cargo-clif -V
cargo 1.59.0-nightly (fcef61230 2021-12-17)

$ cargo -V
cargo 1.59.0-nightly (fcef61230 2021-12-17)

$ ~/code/cranelift-playgroud/rustc_codegen_cranelift/build/cargo-clif build
    Finished dev [unoptimized + debuginfo] target(s) in 42.26s

$ ~/code/cranelift-playgroud/rustc_codegen_cranelift/build/cargo-clif build --target wasm32-unknown-unknown
  error[E0463]: can't find crate for `core`
  |
  = note: the `wasm32-unknown-unknown` target may not be installed
  = help: consider downloading the target with `rustup target add wasm32-unknown-unknown`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

# set cargo to use nightly installed by `rustc_codegen_cranelift/y.rs`

$ ~/.cargo/bin/cargo -V
cargo 1.59.0-nightly (fcef61230 2021-12-17)

$ ~/.cargo/bin/cargo build --target wasm32-unknown-unknown
    Finished dev [unoptimized + debuginfo] target(s) in 42.47s
Complete output (with errors)
$ ~/code/cranelift-playgroud/rustc_codegen_cranelift/build/cargo-clif -V
cargo 1.59.0-nightly (fcef61230 2021-12-17)

$ ~/code/cranelift-playgroud/rustc_codegen_cranelift/build/cargo-clif build
   Compiling proc-macro2 v1.0.36
   Compiling unicode-xid v0.2.2
   Compiling syn v1.0.85
   Compiling serde_derive v1.0.133
   Compiling log v0.4.14
   Compiling wasm-bindgen-shared v0.2.78
   Compiling serde v1.0.133
   Compiling cfg-if v1.0.0
   Compiling lazy_static v1.4.0
   Compiling bumpalo v3.9.1
   Compiling ryu v1.0.9
   Compiling serde_json v1.0.75
   Compiling itoa v1.0.1
   Compiling wasm-bindgen v0.2.78
   Compiling version_check v0.9.4
   Compiling percent-encoding v2.1.0
   Compiling matches v0.1.9
   Compiling autocfg v1.0.1
   Compiling fnv v1.0.7
   Compiling itoa v0.4.8
   Compiling anymap2 v0.13.0
   Compiling slab v0.4.5
   Compiling hashbrown v0.11.2
   Compiling boolinator v2.4.0
   Compiling scoped-tls-hkt v0.1.2
   Compiling form_urlencoded v1.0.1
   Compiling proc-macro-error-attr v1.0.4
   Compiling proc-macro-error v1.0.4
   Compiling indexmap v1.8.0
   Compiling quote v1.0.14
   Compiling wasm-bindgen-backend v0.2.78
   Compiling wasm-bindgen-macro-support v0.2.78
   Compiling wasm-bindgen-macro v0.2.78
   Compiling thiserror-impl v1.0.30
   Compiling yew-macro v0.19.3 (https://github.com/yewstack/yew/#62e3194d)
   Compiling thiserror v1.0.30
   Compiling bincode v1.3.3
   Compiling serde_urlencoded v0.7.0
   Compiling js-sys v0.3.55
   Compiling console_error_panic_hook v0.1.7
   Compiling web-sys v0.3.55
   Compiling serde-wasm-bindgen v0.3.1
   Compiling gloo-utils v0.1.2
   Compiling gloo-events v0.1.1
   Compiling gloo-console v0.2.1
   Compiling gloo-render v0.1.0
   Compiling gloo-dialogs v0.1.0
   Compiling gloo-timers v0.2.2
   Compiling gloo-storage v0.2.0
   Compiling gloo-history v0.1.0
   Compiling gloo-file v0.2.0
   Compiling gloo-worker v0.1.0
   Compiling gloo v0.6.0
   Compiling yew v0.19.3 (https://github.com/yewstack/yew/#62e3194d)
   Compiling yew-test-app v0.1.0 (/home/hamza/code/cranelift-playgroud/yew-test-app)
    Finished dev [unoptimized + debuginfo] target(s) in 42.26s

$ ~/code/cranelift-playgroud/rustc_codegen_cranelift/build/cargo-clif build --target wasm32-unknown-unknown
   Compiling ryu v1.0.9
   Compiling itoa v1.0.1
   Compiling cfg-if v1.0.0
   Compiling matches v0.1.9
   Compiling percent-encoding v2.1.0
   Compiling itoa v0.4.8
   Compiling fnv v1.0.7
   Compiling anymap2 v0.13.0
error[E0463]: can't find crate for `core`
  |
  = note: the `wasm32-unknown-unknown` target may not be installed
  = help: consider downloading the target with `rustup target add wasm32-unknown-unknown`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

error[E0463]: can't find crate for `compiler_builtins`

error: cannot find attribute `test` in this scope
   --> /home/hamza/.cargo/registry/src/github.com-1ecc6299db9ec823/matches-0.1.9/lib.rs:120:3
    |
120 | #[test]
    |   ^^^^

error: cannot find macro `panic` in this scope
   --> /home/hamza/.cargo/registry/src/github.com-1ecc6299db9ec823/matches-0.1.9/lib.rs:65:22
    |
65  |               ref e => panic!("assertion failed: `{:?}` does not match `{}`", e, stringify!($($pattern)+)),
    |                        ^^^^^
...
124 | /     assert_matches!(foo, Some(bar) if
125 | |         matches!(bar.as_bytes()[0], b'+' | b'-') &&
126 | |         matches!(bar.as_bytes()[1], b'0'...b'9')
127 | |     );
    | |_____- in this macro invocation
    |
    = note: this error originates in the macro `assert_matches` (in Nightly builds, run with -Z macro-backtrace for more info)

error: cannot find attribute `test` in this scope
   --> /home/hamza/.cargo/registry/src/github.com-1ecc6299db9ec823/matches-0.1.9/lib.rs:111:3
    |
111 | #[test]
    |   ^^^^

# error continues ...

$ ~/.cargo/bin/cargo -V
cargo 1.58.0 (7f08ace4f 2021-11-24)

$ ~/.cargo/bin/cargo build
   Compiling proc-macro2 v1.0.36
   Compiling unicode-xid v0.2.2
   Compiling syn v1.0.85
   Compiling serde_derive v1.0.133
   Compiling log v0.4.14
   Compiling serde v1.0.133
   Compiling wasm-bindgen-shared v0.2.78
   Compiling cfg-if v1.0.0
   Compiling lazy_static v1.4.0
   Compiling bumpalo v3.9.1
   Compiling serde_json v1.0.75
   Compiling ryu v1.0.9
   Compiling itoa v1.0.1
   Compiling wasm-bindgen v0.2.78
   Compiling version_check v0.9.4
   Compiling percent-encoding v2.1.0
   Compiling matches v0.1.9
   Compiling fnv v1.0.7
   Compiling autocfg v1.0.1
   Compiling itoa v0.4.8
   Compiling slab v0.4.5
   Compiling anymap2 v0.13.0
   Compiling hashbrown v0.11.2
   Compiling boolinator v2.4.0
   Compiling scoped-tls-hkt v0.1.2
   Compiling form_urlencoded v1.0.1
   Compiling proc-macro-error-attr v1.0.4
   Compiling proc-macro-error v1.0.4
   Compiling indexmap v1.8.0
   Compiling quote v1.0.14
   Compiling wasm-bindgen-backend v0.2.78
   Compiling wasm-bindgen-macro-support v0.2.78
   Compiling thiserror-impl v1.0.30
   Compiling yew-macro v0.19.3 (https://github.com/yewstack/yew/#62e3194d)
   Compiling wasm-bindgen-macro v0.2.78
   Compiling thiserror v1.0.30
   Compiling bincode v1.3.3
   Compiling serde_urlencoded v0.7.0
   Compiling js-sys v0.3.55
   Compiling console_error_panic_hook v0.1.7
   Compiling web-sys v0.3.55
   Compiling serde-wasm-bindgen v0.3.1
   Compiling gloo-utils v0.1.2
   Compiling gloo-events v0.1.1
   Compiling gloo-console v0.2.1
   Compiling gloo-dialogs v0.1.0
   Compiling gloo-render v0.1.0
   Compiling gloo-timers v0.2.2
   Compiling gloo-storage v0.2.0
   Compiling gloo-history v0.1.0
   Compiling gloo-file v0.2.0
   Compiling gloo-worker v0.1.0
   Compiling gloo v0.6.0
   Compiling yew v0.19.3 (https://github.com/yewstack/yew/#62e3194d)
   Compiling yew-test-app v0.1.0 (/home/hamza/code/cranelift-playgroud/yew-test-app)
    Finished dev [unoptimized + debuginfo] target(s) in 40.98s

$ ~/.cargo/bin/cargo build --target wasm32-unknown-unknown
   Compiling ryu v1.0.9
   Compiling itoa v1.0.1
   Compiling cfg-if v1.0.0
   Compiling matches v0.1.9
   Compiling percent-encoding v2.1.0
   Compiling fnv v1.0.7
   Compiling itoa v0.4.8
   Compiling anymap2 v0.13.0
   Compiling slab v0.4.5
   Compiling hashbrown v0.11.2
   Compiling scoped-tls-hkt v0.1.2
   Compiling serde v1.0.133
   Compiling serde_json v1.0.75
   Compiling wasm-bindgen v0.2.78
   Compiling form_urlencoded v1.0.1
   Compiling indexmap v1.8.0
   Compiling thiserror v1.0.30
   Compiling bincode v1.3.3
   Compiling serde_urlencoded v0.7.0
   Compiling js-sys v0.3.55
   Compiling console_error_panic_hook v0.1.7
   Compiling web-sys v0.3.55
   Compiling serde-wasm-bindgen v0.3.1
   Compiling wasm-bindgen-futures v0.4.28
   Compiling gloo-utils v0.1.2
   Compiling gloo-events v0.1.1
   Compiling gloo-console v0.2.1
   Compiling gloo-dialogs v0.1.0
   Compiling gloo-render v0.1.0
   Compiling gloo-timers v0.2.2
   Compiling gloo-storage v0.2.0
   Compiling gloo-worker v0.1.0
   Compiling gloo-file v0.2.0
   Compiling gloo-history v0.1.0
   Compiling gloo v0.6.0
   Compiling yew v0.19.3 (https://github.com/yewstack/yew/#62e3194d)
   Compiling yew-test-app v0.1.0 (/home/hamza/code/cranelift-playgroud/yew-test-app)
    Finished dev [unoptimized + debuginfo] target(s) in 24.27s

# -------------------

$  rustup show
Default host: x86_64-unknown-linux-gnu
rustup home:  /home/hamza/.rustup

installed toolchains
--------------------

stable-x86_64-unknown-linux-gnu (default)
nightly-2021-12-30-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu
1.56-x86_64-unknown-linux-gnu

installed targets for active toolchain
--------------------------------------

wasm32-unknown-unknown
x86_64-unknown-linux-gnu

active toolchain
----------------

stable-x86_64-unknown-linux-gnu (default)
rustc 1.58.0 (02072b482 2022-01-11)

# set cargo to use nightly installed by `rustc_codegen_cranelift/y.rs`

$ ~/.cargo/bin/cargo -V
cargo 1.59.0-nightly (fcef61230 2021-12-17)

$ ~/.cargo/bin/cargo build --target wasm32-unknown-unknown
   Compiling proc-macro2 v1.0.36
   Compiling unicode-xid v0.2.2
   Compiling syn v1.0.85
   Compiling serde_derive v1.0.133
   Compiling wasm-bindgen-shared v0.2.78
   Compiling serde v1.0.133
   Compiling log v0.4.14
   Compiling lazy_static v1.4.0
   Compiling cfg-if v1.0.0
   Compiling bumpalo v3.9.1
   Compiling serde_json v1.0.75
   Compiling ryu v1.0.9
   Compiling wasm-bindgen v0.2.78
   Compiling itoa v1.0.1
   Compiling version_check v0.9.4
   Compiling matches v0.1.9
   Compiling percent-encoding v2.1.0
   Compiling autocfg v1.0.1
   Compiling itoa v0.4.8
   Compiling fnv v1.0.7
   Compiling slab v0.4.5
   Compiling anymap2 v0.13.0
   Compiling hashbrown v0.11.2
   Compiling boolinator v2.4.0
   Compiling scoped-tls-hkt v0.1.2
   Compiling form_urlencoded v1.0.1
   Compiling proc-macro-error-attr v1.0.4
   Compiling proc-macro-error v1.0.4
   Compiling indexmap v1.8.0
   Compiling quote v1.0.14
   Compiling wasm-bindgen-backend v0.2.78
   Compiling wasm-bindgen-macro-support v0.2.78
   Compiling thiserror-impl v1.0.30
   Compiling yew-macro v0.19.3 (https://github.com/yewstack/yew/#62e3194d)
   Compiling wasm-bindgen-macro v0.2.78
   Compiling thiserror v1.0.30
   Compiling bincode v1.3.3
   Compiling serde_urlencoded v0.7.0
   Compiling js-sys v0.3.55
   Compiling console_error_panic_hook v0.1.7
   Compiling web-sys v0.3.55
   Compiling serde-wasm-bindgen v0.3.1
   Compiling wasm-bindgen-futures v0.4.28
   Compiling gloo-utils v0.1.2
   Compiling gloo-events v0.1.1
   Compiling gloo-console v0.2.1
   Compiling gloo-render v0.1.0
   Compiling gloo-dialogs v0.1.0
   Compiling gloo-timers v0.2.2
   Compiling gloo-storage v0.2.0
   Compiling gloo-worker v0.1.0
   Compiling gloo-history v0.1.0
   Compiling gloo-file v0.2.0
   Compiling gloo v0.6.0
   Compiling yew v0.19.3 (https://github.com/yewstack/yew/#62e3194d)
   Compiling yew-test-app v0.1.0 (/home/hamza/code/cranelift-playgroud/yew-test-app)
    Finished dev [unoptimized + debuginfo] target(s) in 42.47s

This works when I use with cargo installed via rustup but not with cranelift one. Any help would be appriciated

@bjorn3
Copy link
Member

bjorn3 commented Jan 16, 2022

Cranelift doesn't yet have a wasm backend, so it can't compile for wasm32-unknown-unknown. See bytecodealliance/wasmtime#2566. You will have to use the default llvm backend of rustc for now.

For all supported targets (x86_64 and aarch64 at the moment) this can be done by setting https://github.com/bjorn3/rustc_codegen_cranelift/blob/8f02c4e2ee4a5e86bc14a3fe4d1bee9c3f2fc253/config.txt#L11 and rebuilding cg_clif.

@ranile
Copy link
Author

ranile commented Jan 16, 2022

@bjorn3, I'm not building cranelift for wasm32-unknown-unknown. I have obtained a binary of rustc_codegen_cranelift built on x86_64-unknown-linux-gnu that I'm using to build another project for wasm32-unknown-unknown using cranelift. Not sure how those are related.

@bjorn3
Copy link
Member

bjorn3 commented Jan 16, 2022

If you want to build a project for a target using cranelift, cranelift needs to have a backend for this target. So building a project or wasm using cranelift requires that cranelift has a wasm backend which it doesn't yet.

@ranile
Copy link
Author

ranile commented Jan 16, 2022

Oh, that's unfortunate. Guess we got to deal with it the way it is now...

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

2 participants