rust-lang / rustc_codegen_cranelift

Cranelift based backend for rustc
Apache License 2.0
1.52k stars 94 forks source link

`faster-hex` v0.8.0 fails to build #1404

Closed Shnatsel closed 4 months ago

Shnatsel commented 8 months ago

The error is:

error[E0425]: cannot find function `vectorization_support_no_cache_x86` in this scope
  --> /home/shnatsel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/faster-hex-0.8.0/src/lib.rs:63:28
   |
63 |         let val = unsafe { vectorization_support_no_cache_x86() };
   |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

The signature of the missing function is:

// We enable xsave so it can inline the _xgetbv call.
#[target_feature(enable = "xsave")]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cold]
unsafe fn vectorization_support_no_cache_x86() -> Vectorization {

or see it in context here: https://github.com/nervosnetwork/faster-hex/blob/856aba7b141a5fe16113fae110d535065882f25a/src/lib.rs#L72-L76

rustc version:

rustc 1.75.0-nightly (31bc7e2c4 2023-10-30)
binary: rustc
commit-hash: 31bc7e2c47e82798a392c770611975a6883132c8
commit-date: 2023-10-30
host: x86_64-unknown-linux-gnu
release: 1.75.0-nightly
LLVM version: 17.0.3

This issue blocks the compilation of anything that depends on gix, the Git implementation in Rust. That includes cargo itself, numerous Cargo plugins (cargo audit, cargo deny, cargo-semver-checks, cargo edit, cargo release, cargo vet, etc) and other tools such as starship, bacon, onefetch, etc.

bjorn3 commented 8 months ago

This is the problem: https://github.com/nervosnetwork/faster-hex/blob/7ae3424144e578fe9023be8f2c11268d8cf15e16/src/lib.rs#L76 cfg(target_feature = "...") will always be false for cg_clif currently as I haven't implemented CodegenBackend::target_features yet. It looks like faster-hex 0.8.1 has removed this condition, so updating to that version would be a workaround. Shouldn't be too hard to implement CodegenBackend::target_features based the target features specified in the target spec though at least.

Shnatsel commented 8 months ago

Indeed, I can confirm that upgrading to 0.8.1 fixes the issue. And using the cranelift backend cuts the debug build time by 40% for cargo audit :tada:

bjorn3 commented 4 months ago

As of https://github.com/rust-lang/rustc_codegen_cranelift/commit/45d8c121ba02c825379b655d8dd74e1843e98d62 SSE is now reported as enabled on x86_64 by cg_clif.