Remove cupid dependency and env-override-no-avx CI run

This commit is contained in:
sayantn
2025-04-15 05:57:45 +05:30
committed by Amanieu d'Antras
parent f6fbd665a0
commit cc6855e1e9
7 changed files with 3 additions and 182 deletions
-15
View File
@@ -35,20 +35,6 @@ jobs:
run: rustup update nightly --no-self-update && rustup default nightly
- run: cargo test --manifest-path crates/stdarch-verify/Cargo.toml
env_override:
name: Env Override
needs: [style]
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update nightly --no-self-update && rustup default nightly
- run: RUST_STD_DETECT_UNSTABLE=avx cargo test --features=std_detect_env_override --manifest-path crates/std_detect/Cargo.toml env_override_no_avx
shell: bash
test:
needs: [style]
name: Test
@@ -243,7 +229,6 @@ jobs:
needs:
- docs
- verify
- env_override
- test
- build-std-detect
runs-on: ubuntu-latest
-4
View File
@@ -44,12 +44,8 @@ case ${TARGET} in
mips-* | mipsel-*)
export RUSTFLAGS="${RUSTFLAGS} -C llvm-args=-fast-isel=false"
;;
# Some of our test dependencies use the deprecated `gcc` crates which is
# missing a fix from https://github.com/alexcrichton/cc-rs/pull/627. Apply
# the workaround manually here.
armv7-*eabihf | thumbv7-*eabihf)
export RUSTFLAGS="${RUSTFLAGS} -Ctarget-feature=+neon"
export TARGET_CFLAGS="-mfpu=vfpv3-d16"
;;
# Some of our test dependencies use the deprecated `gcc` crates which
# doesn't detect RISC-V compilers automatically, so do it manually here.
@@ -31,14 +31,10 @@ alloc = { version = "1.0.0", optional = true, package = "rustc-std-workspace-all
[target.'cfg(not(windows))'.dependencies]
libc = { version = "0.2.0", optional = true, default-features = false }
[dev-dependencies]
cupid = "0.6.0"
[features]
default = [ "std_detect_dlsym_getauxval", "std_detect_file_io" ]
std_detect_file_io = [ "libc" ]
std_detect_dlsym_getauxval = [ "libc" ]
std_detect_env_override = [ "libc" ]
rustc-dep-of-std = [
"core",
"compiler_builtins",
+1 -2
View File
@@ -52,8 +52,7 @@ crate from working on applications in which `std` is not available.
* All `x86`/`x86_64` targets are supported on all platforms by querying the
`cpuid` instruction directly for the features supported by the hardware and
the operating system. `std_detect` assumes that the binary is an user-space
application. If you need raw support for querying `cpuid`, consider using the
[`cupid`](https://crates.io/crates/cupid) crate.
application.
* Linux/Android:
* `arm{32, 64}`, `mips{32,64}{,el}`, `powerpc{32,64}{,le}`, `loongarch64`, `s390x`:
@@ -121,65 +121,12 @@ fn initialize(&self, value: usize) -> usize {
}
}
cfg_if::cfg_if! {
if #[cfg(feature = "std_detect_env_override")] {
#[inline]
fn disable_features(disable: &[u8], value: &mut Initializer) {
if let Ok(disable) = core::str::from_utf8(disable) {
for v in disable.split(" ") {
let _ = super::Feature::from_str(v).map(|v| value.unset(v as u32));
}
}
}
#[inline]
fn initialize(mut value: Initializer) -> Initializer {
use core::ffi::CStr;
const RUST_STD_DETECT_UNSTABLE: &CStr = c"RUST_STD_DETECT_UNSTABLE";
cfg_if::cfg_if! {
if #[cfg(windows)] {
use alloc::vec;
#[link(name = "kernel32")]
unsafe extern "system" {
fn GetEnvironmentVariableA(name: *const u8, buffer: *mut u8, size: u32) -> u32;
}
let len = unsafe { GetEnvironmentVariableA(RUST_STD_DETECT_UNSTABLE.as_ptr().cast::<u8>(), core::ptr::null_mut(), 0) };
if len > 0 {
// +1 to include the null terminator.
let mut env = vec![0; len as usize + 1];
let len = unsafe { GetEnvironmentVariableA(RUST_STD_DETECT_UNSTABLE.as_ptr().cast::<u8>(), env.as_mut_ptr(), len + 1) };
if len > 0 {
disable_features(&env[..len as usize], &mut value);
}
}
} else {
let env = unsafe {
libc::getenv(RUST_STD_DETECT_UNSTABLE.as_ptr())
};
if !env.is_null() {
let len = unsafe { libc::strlen(env) };
let env = unsafe { core::slice::from_raw_parts(env as *const u8, len) };
disable_features(env, &mut value);
}
}
}
do_initialize(value);
value
}
} else {
#[inline]
fn initialize(value: Initializer) -> Initializer {
do_initialize(value);
value
}
}
}
#[inline]
fn do_initialize(value: Initializer) {
fn initialize(value: Initializer) -> Initializer {
CACHE[0].initialize((value.0) as usize & Cache::MASK);
CACHE[1].initialize((value.0 >> Cache::CAPACITY) as usize & Cache::MASK);
CACHE[2].initialize((value.0 >> (2 * Cache::CAPACITY)) as usize & Cache::MASK);
value
}
// We only have to detect features once, and it's fairly costly, so hint to LLVM
@@ -204,10 +151,6 @@ fn detect_and_initialize() -> Initializer {
///
/// It uses the `Feature` variant to index into this variable as a bitset. If
/// the bit is set, the feature is enabled, and otherwise it is disabled.
///
/// If the feature `std_detect_env_override` is enabled looks for the env
/// variable `RUST_STD_DETECT_UNSTABLE` and uses its content to disable
/// Features that would had been otherwise detected.
#[inline]
pub(crate) fn test(bit: u32) -> bool {
let (relative_bit, idx) = if bit < Cache::CAPACITY {
@@ -168,13 +168,6 @@ pub(crate) fn to_str(self) -> &'static str {
Feature::_last => unreachable!(),
}
}
#[cfg(feature = "std_detect_env_override")]
pub(crate) fn from_str(s: &str) -> Result<Feature, ()> {
match s {
$($feature_lit => Ok(Feature::$feature),)*
_ => Err(())
}
}
}
/// Each function performs run-time feature detection for a single
@@ -10,7 +10,6 @@
movrs_target_feature
)]
extern crate cupid;
#[macro_use]
extern crate std_detect;
@@ -109,96 +108,6 @@ fn dump() {
println!("amx-movrs: {:?}", is_x86_feature_detected!("amx-movrs"));
}
#[cfg(feature = "std_detect_env_override")]
#[test]
fn env_override_no_avx() {
if let Ok(disable) = std::env::var("RUST_STD_DETECT_UNSTABLE") {
let information = cupid::master().unwrap();
for d in disable.split(" ") {
match d {
"avx" => {
if information.avx() {
assert_ne!(is_x86_feature_detected!("avx"), information.avx())
}
}
"avx2" => {
if information.avx2() {
assert_ne!(is_x86_feature_detected!("avx2"), information.avx2())
}
}
_ => {}
}
}
}
}
#[test]
fn compare_with_cupid() {
let information = cupid::master().unwrap();
assert_eq!(is_x86_feature_detected!("aes"), information.aesni());
assert_eq!(
is_x86_feature_detected!("pclmulqdq"),
information.pclmulqdq()
);
assert_eq!(is_x86_feature_detected!("rdrand"), information.rdrand());
assert_eq!(is_x86_feature_detected!("rdseed"), information.rdseed());
assert_eq!(is_x86_feature_detected!("tsc"), information.tsc());
assert_eq!(is_x86_feature_detected!("sse"), information.sse());
assert_eq!(is_x86_feature_detected!("sse2"), information.sse2());
assert_eq!(is_x86_feature_detected!("sse3"), information.sse3());
assert_eq!(is_x86_feature_detected!("ssse3"), information.ssse3());
assert_eq!(is_x86_feature_detected!("sse4.1"), information.sse4_1());
assert_eq!(is_x86_feature_detected!("sse4.2"), information.sse4_2());
assert_eq!(is_x86_feature_detected!("sse4a"), information.sse4a());
assert_eq!(is_x86_feature_detected!("sha"), information.sha());
assert_eq!(is_x86_feature_detected!("f16c"), information.f16c());
assert_eq!(is_x86_feature_detected!("avx"), information.avx());
assert_eq!(is_x86_feature_detected!("avx2"), information.avx2());
assert_eq!(is_x86_feature_detected!("avx512f"), information.avx512f());
assert_eq!(is_x86_feature_detected!("avx512cd"), information.avx512cd());
assert_eq!(is_x86_feature_detected!("avx512er"), information.avx512er());
assert_eq!(is_x86_feature_detected!("avx512pf"), information.avx512pf());
assert_eq!(is_x86_feature_detected!("avx512bw"), information.avx512bw());
assert_eq!(is_x86_feature_detected!("avx512dq"), information.avx512dq());
assert_eq!(is_x86_feature_detected!("avx512vl"), information.avx512vl());
assert_eq!(
is_x86_feature_detected!("avx512ifma"),
information.avx512_ifma()
);
assert_eq!(
is_x86_feature_detected!("avx512vbmi"),
information.avx512_vbmi()
);
assert_eq!(
is_x86_feature_detected!("avx512vpopcntdq"),
information.avx512_vpopcntdq()
);
assert_eq!(is_x86_feature_detected!("fma"), information.fma());
assert_eq!(is_x86_feature_detected!("bmi1"), information.bmi1());
assert_eq!(is_x86_feature_detected!("bmi2"), information.bmi2());
assert_eq!(is_x86_feature_detected!("popcnt"), information.popcnt());
assert_eq!(is_x86_feature_detected!("abm"), information.lzcnt());
assert_eq!(is_x86_feature_detected!("tbm"), information.tbm());
assert_eq!(is_x86_feature_detected!("lzcnt"), information.lzcnt());
assert_eq!(is_x86_feature_detected!("xsave"), information.xsave());
assert_eq!(is_x86_feature_detected!("xsaveopt"), information.xsaveopt());
assert_eq!(
is_x86_feature_detected!("xsavec"),
information.xsavec_and_xrstor()
);
assert_eq!(
is_x86_feature_detected!("xsaves"),
information.xsaves_xrstors_and_ia32_xss()
);
assert_eq!(
is_x86_feature_detected!("cmpxchg16b"),
information.cmpxchg16b(),
);
assert_eq!(is_x86_feature_detected!("adx"), information.adx(),);
assert_eq!(is_x86_feature_detected!("rtm"), information.rtm(),);
assert_eq!(is_x86_feature_detected!("movbe"), information.movbe(),);
}
#[test]
#[allow(deprecated)]
fn x86_deprecated() {