Skip to content

Commit afc3d1e

Browse files
committed
Remove cupid dependency and env-override-no-avx CI run
1 parent ea51964 commit afc3d1e

File tree

7 files changed

+3
-179
lines changed

7 files changed

+3
-179
lines changed

.github/workflows/main.yml

-15
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,6 @@ jobs:
3535
run: rustup update nightly --no-self-update && rustup default nightly
3636
- run: cargo test --manifest-path crates/stdarch-verify/Cargo.toml
3737

38-
env_override:
39-
name: Env Override
40-
needs: [style]
41-
runs-on: ${{ matrix.os }}
42-
strategy:
43-
matrix:
44-
os: [ubuntu-latest, windows-latest]
45-
steps:
46-
- uses: actions/checkout@v4
47-
- name: Install Rust
48-
run: rustup update nightly --no-self-update && rustup default nightly
49-
- run: RUST_STD_DETECT_UNSTABLE=avx cargo test --features=std_detect_env_override --manifest-path crates/std_detect/Cargo.toml env_override_no_avx
50-
shell: bash
51-
5238
test:
5339
needs: [style]
5440
name: Test
@@ -271,7 +257,6 @@ jobs:
271257
needs:
272258
- docs
273259
- verify
274-
- env_override
275260
- test
276261
- build-std-detect
277262
runs-on: ubuntu-latest

ci/run.sh

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ case ${TARGET} in
4949
# the workaround manually here.
5050
armv7-*eabihf | thumbv7-*eabihf)
5151
export RUSTFLAGS="${RUSTFLAGS} -Ctarget-feature=+neon"
52-
export TARGET_CFLAGS="-mfpu=vfpv3-d16"
5352
;;
5453
# Some of our test dependencies use the deprecated `gcc` crates which
5554
# doesn't detect RISC-V compilers automatically, so do it manually here.

crates/std_detect/Cargo.toml

-4
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,10 @@ alloc = { version = "1.0.0", optional = true, package = "rustc-std-workspace-all
3131
[target.'cfg(not(windows))'.dependencies]
3232
libc = { version = "0.2.0", optional = true, default-features = false }
3333

34-
[dev-dependencies]
35-
cupid = "0.6.0"
36-
3734
[features]
3835
default = [ "std_detect_dlsym_getauxval", "std_detect_file_io" ]
3936
std_detect_file_io = [ "libc" ]
4037
std_detect_dlsym_getauxval = [ "libc" ]
41-
std_detect_env_override = [ "libc" ]
4238
rustc-dep-of-std = [
4339
"core",
4440
"compiler_builtins",

crates/std_detect/README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ crate from working on applications in which `std` is not available.
5252
* All `x86`/`x86_64` targets are supported on all platforms by querying the
5353
`cpuid` instruction directly for the features supported by the hardware and
5454
the operating system. `std_detect` assumes that the binary is an user-space
55-
application. If you need raw support for querying `cpuid`, consider using the
56-
[`cupid`](https://crates.io/crates/cupid) crate.
55+
application.
5756

5857
* Linux/Android:
5958
* `arm{32, 64}`, `mips{32,64}{,el}`, `powerpc{32,64}{,le}`, `riscv{32,64}`, `loongarch64`, `s390x`:

crates/std_detect/src/detect/cache.rs

+2-59
Original file line numberDiff line numberDiff line change
@@ -121,65 +121,12 @@ impl Cache {
121121
}
122122
}
123123

124-
cfg_if::cfg_if! {
125-
if #[cfg(feature = "std_detect_env_override")] {
126-
#[inline]
127-
fn disable_features(disable: &[u8], value: &mut Initializer) {
128-
if let Ok(disable) = core::str::from_utf8(disable) {
129-
for v in disable.split(" ") {
130-
let _ = super::Feature::from_str(v).map(|v| value.unset(v as u32));
131-
}
132-
}
133-
}
134-
135-
#[inline]
136-
fn initialize(mut value: Initializer) -> Initializer {
137-
use core::ffi::CStr;
138-
const RUST_STD_DETECT_UNSTABLE: &CStr = c"RUST_STD_DETECT_UNSTABLE";
139-
cfg_if::cfg_if! {
140-
if #[cfg(windows)] {
141-
use alloc::vec;
142-
#[link(name = "kernel32")]
143-
unsafe extern "system" {
144-
fn GetEnvironmentVariableA(name: *const u8, buffer: *mut u8, size: u32) -> u32;
145-
}
146-
let len = unsafe { GetEnvironmentVariableA(RUST_STD_DETECT_UNSTABLE.as_ptr().cast::<u8>(), core::ptr::null_mut(), 0) };
147-
if len > 0 {
148-
// +1 to include the null terminator.
149-
let mut env = vec![0; len as usize + 1];
150-
let len = unsafe { GetEnvironmentVariableA(RUST_STD_DETECT_UNSTABLE.as_ptr().cast::<u8>(), env.as_mut_ptr(), len + 1) };
151-
if len > 0 {
152-
disable_features(&env[..len as usize], &mut value);
153-
}
154-
}
155-
} else {
156-
let env = unsafe {
157-
libc::getenv(RUST_STD_DETECT_UNSTABLE.as_ptr())
158-
};
159-
if !env.is_null() {
160-
let len = unsafe { libc::strlen(env) };
161-
let env = unsafe { core::slice::from_raw_parts(env as *const u8, len) };
162-
disable_features(env, &mut value);
163-
}
164-
}
165-
}
166-
do_initialize(value);
167-
value
168-
}
169-
} else {
170-
#[inline]
171-
fn initialize(value: Initializer) -> Initializer {
172-
do_initialize(value);
173-
value
174-
}
175-
}
176-
}
177-
178124
#[inline]
179-
fn do_initialize(value: Initializer) {
125+
fn initialize(value: Initializer) -> Initializer {
180126
CACHE[0].initialize((value.0) as usize & Cache::MASK);
181127
CACHE[1].initialize((value.0 >> Cache::CAPACITY) as usize & Cache::MASK);
182128
CACHE[2].initialize((value.0 >> (2 * Cache::CAPACITY)) as usize & Cache::MASK);
129+
value
183130
}
184131

185132
// 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 {
204151
///
205152
/// It uses the `Feature` variant to index into this variable as a bitset. If
206153
/// the bit is set, the feature is enabled, and otherwise it is disabled.
207-
///
208-
/// If the feature `std_detect_env_override` is enabled looks for the env
209-
/// variable `RUST_STD_DETECT_UNSTABLE` and uses its content to disable
210-
/// Features that would had been otherwise detected.
211154
#[inline]
212155
pub(crate) fn test(bit: u32) -> bool {
213156
let (relative_bit, idx) = if bit < Cache::CAPACITY {

crates/std_detect/src/detect/macros.rs

-7
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,6 @@ macro_rules! features {
168168
Feature::_last => unreachable!(),
169169
}
170170
}
171-
#[cfg(feature = "std_detect_env_override")]
172-
pub(crate) fn from_str(s: &str) -> Result<Feature, ()> {
173-
match s {
174-
$($feature_lit => Ok(Feature::$feature),)*
175-
_ => Err(())
176-
}
177-
}
178171
}
179172

180173
/// Each function performs run-time feature detection for a single

crates/std_detect/tests/x86-specific.rs

-91
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
movrs_target_feature
1111
)]
1212

13-
extern crate cupid;
1413
#[macro_use]
1514
extern crate std_detect;
1615

@@ -109,96 +108,6 @@ fn dump() {
109108
println!("amx-movrs: {:?}", is_x86_feature_detected!("amx-movrs"));
110109
}
111110

112-
#[cfg(feature = "std_detect_env_override")]
113-
#[test]
114-
fn env_override_no_avx() {
115-
if let Ok(disable) = std::env::var("RUST_STD_DETECT_UNSTABLE") {
116-
let information = cupid::master().unwrap();
117-
for d in disable.split(" ") {
118-
match d {
119-
"avx" => {
120-
if information.avx() {
121-
assert_ne!(is_x86_feature_detected!("avx"), information.avx())
122-
}
123-
}
124-
"avx2" => {
125-
if information.avx2() {
126-
assert_ne!(is_x86_feature_detected!("avx2"), information.avx2())
127-
}
128-
}
129-
_ => {}
130-
}
131-
}
132-
}
133-
}
134-
135-
#[test]
136-
fn compare_with_cupid() {
137-
let information = cupid::master().unwrap();
138-
assert_eq!(is_x86_feature_detected!("aes"), information.aesni());
139-
assert_eq!(
140-
is_x86_feature_detected!("pclmulqdq"),
141-
information.pclmulqdq()
142-
);
143-
assert_eq!(is_x86_feature_detected!("rdrand"), information.rdrand());
144-
assert_eq!(is_x86_feature_detected!("rdseed"), information.rdseed());
145-
assert_eq!(is_x86_feature_detected!("tsc"), information.tsc());
146-
assert_eq!(is_x86_feature_detected!("sse"), information.sse());
147-
assert_eq!(is_x86_feature_detected!("sse2"), information.sse2());
148-
assert_eq!(is_x86_feature_detected!("sse3"), information.sse3());
149-
assert_eq!(is_x86_feature_detected!("ssse3"), information.ssse3());
150-
assert_eq!(is_x86_feature_detected!("sse4.1"), information.sse4_1());
151-
assert_eq!(is_x86_feature_detected!("sse4.2"), information.sse4_2());
152-
assert_eq!(is_x86_feature_detected!("sse4a"), information.sse4a());
153-
assert_eq!(is_x86_feature_detected!("sha"), information.sha());
154-
assert_eq!(is_x86_feature_detected!("f16c"), information.f16c());
155-
assert_eq!(is_x86_feature_detected!("avx"), information.avx());
156-
assert_eq!(is_x86_feature_detected!("avx2"), information.avx2());
157-
assert_eq!(is_x86_feature_detected!("avx512f"), information.avx512f());
158-
assert_eq!(is_x86_feature_detected!("avx512cd"), information.avx512cd());
159-
assert_eq!(is_x86_feature_detected!("avx512er"), information.avx512er());
160-
assert_eq!(is_x86_feature_detected!("avx512pf"), information.avx512pf());
161-
assert_eq!(is_x86_feature_detected!("avx512bw"), information.avx512bw());
162-
assert_eq!(is_x86_feature_detected!("avx512dq"), information.avx512dq());
163-
assert_eq!(is_x86_feature_detected!("avx512vl"), information.avx512vl());
164-
assert_eq!(
165-
is_x86_feature_detected!("avx512ifma"),
166-
information.avx512_ifma()
167-
);
168-
assert_eq!(
169-
is_x86_feature_detected!("avx512vbmi"),
170-
information.avx512_vbmi()
171-
);
172-
assert_eq!(
173-
is_x86_feature_detected!("avx512vpopcntdq"),
174-
information.avx512_vpopcntdq()
175-
);
176-
assert_eq!(is_x86_feature_detected!("fma"), information.fma());
177-
assert_eq!(is_x86_feature_detected!("bmi1"), information.bmi1());
178-
assert_eq!(is_x86_feature_detected!("bmi2"), information.bmi2());
179-
assert_eq!(is_x86_feature_detected!("popcnt"), information.popcnt());
180-
assert_eq!(is_x86_feature_detected!("abm"), information.lzcnt());
181-
assert_eq!(is_x86_feature_detected!("tbm"), information.tbm());
182-
assert_eq!(is_x86_feature_detected!("lzcnt"), information.lzcnt());
183-
assert_eq!(is_x86_feature_detected!("xsave"), information.xsave());
184-
assert_eq!(is_x86_feature_detected!("xsaveopt"), information.xsaveopt());
185-
assert_eq!(
186-
is_x86_feature_detected!("xsavec"),
187-
information.xsavec_and_xrstor()
188-
);
189-
assert_eq!(
190-
is_x86_feature_detected!("xsaves"),
191-
information.xsaves_xrstors_and_ia32_xss()
192-
);
193-
assert_eq!(
194-
is_x86_feature_detected!("cmpxchg16b"),
195-
information.cmpxchg16b(),
196-
);
197-
assert_eq!(is_x86_feature_detected!("adx"), information.adx(),);
198-
assert_eq!(is_x86_feature_detected!("rtm"), information.rtm(),);
199-
assert_eq!(is_x86_feature_detected!("movbe"), information.movbe(),);
200-
}
201-
202111
#[test]
203112
#[allow(deprecated)]
204113
fn x86_deprecated() {

0 commit comments

Comments
 (0)