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

Getting C-defined intrinsics into a project that uses the stable compiler doesn't work because of all the #![feature] checks #562

Open
adamnovak opened this issue Dec 6, 2023 · 2 comments

Comments

@adamnovak
Copy link

As noted in #561, I am working on a Rust project that builds C code and is suffering from a missing intrinsic. Luckily, I am building for wasm32-wasi, and I have a C compiler with its own libcompiler-rt implementation for my target platform.

The README for this project says that in that case, I can drop this into my Cargo.toml to use the C library implementations in my project:

[dependencies.compiler_builtins]
git = "https://github.com/rust-lang/compiler-builtins"
features = ["c"]

But this doesn't work at all. I get a bunch of errors about the crate using #![feature].

error[E0554]: `#![feature]` may not be used on the stable release channel
 --> /Users/anovak/.cargo/git/checkouts/compiler-builtins-79341f926ffc30b3/2731a48/src/lib.rs:2:38
  |
2 | #![cfg_attr(not(feature = "no-asm"), feature(asm))]
  |                                      ^^^^^^^^^^^^

error[E0554]: `#![feature]` may not be used on the stable release channel
 --> /Users/anovak/.cargo/git/checkouts/compiler-builtins-79341f926ffc30b3/2731a48/src/lib.rs:3:1
  |
3 | #![feature(abi_unadjusted)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0554]: `#![feature]` may not be used on the stable release channel
 --> /Users/anovak/.cargo/git/checkouts/compiler-builtins-79341f926ffc30b3/2731a48/src/lib.rs:4:38
  |
4 | #![cfg_attr(not(feature = "no-asm"), feature(global_asm))]
  |                                      ^^^^^^^^^^^^^^^^^^^

If I remove the git line and use whatever release Cargo finds for me, I get the same error. It looks like the #![feature] logic has been in the codebase for years, and there isn't actually a version of the crate available for the stable Rust compiler.

Which leaves me confused as to how, when I don't edit Cargo.toml, the file /Users/anovak/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/wasm32-wasi/lib/libcompiler_builtins-a0294efb55e060eb.rlib is getting into my build. How was the library built to be part of the stable-aarch64-apple-darwin Rust toolchain if the library can't build on the stable Rust compiler?

And how do I convince the stable Rust compiler to be able to link with C code that needs intrinsics from my C compiler's compiler-rt library?

@Amanieu
Copy link
Member

Amanieu commented Dec 8, 2023

compiler-builtins is an internal implementation detail of Rust and is not intended for use as a normal dependency. It is meant to be built as part of the standard library (which is exempt from feature restrictions since it comes from the same Rust version as the compiler), not as a normal Cargo dependency.

The compiler-builtins from rustup already has the "c" feature enabled. The problem is that our build.rs does not include these function on WASM targets. If you look at build.rs you will see we do have them on AArch64 and MIPS64 targets, perhaps you could try copying that for WASM targets as well?

To actually test this, you will need a nightly compiler and a checkout of compiler-rt from which the C files can be compiled.

Once you have confirmed that this fixes the issue, you can submit a PR here, and then another PR to rust-lang/rust to update the compiler-builtins version in the standard library.

@bjorn3
Copy link
Member

bjorn3 commented Dec 8, 2023

I believe wasm32-unknown-unknown is intended to be free from C code. Wasm32-wasi can enable it though. Wasi-libc is already written in C anyway.

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

3 participants