Conditional test compilation with target_feature and target_arch

Hello,

I have a lib crate with a that provide a conditionally compiled function with the following attributes:

#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "sse4.2")]
pub unsafe fn foo() { 
    ...use of some sse4.2 intrinsics....
}

The library provides integration tests.
The foo()is tested in a tests/test.rs
Is it possible to add the target_arch and target_feature at crate test level? Or at least to test function level?
Test of foo is importing mycrate-sys::foo, use static slice for assertion comparison, etc...
I don't want to add the target_arch and target_feature for each symbol and use and mod that is in the test.rs and even if i do that I have an

error attribute should be applied to a function

when write this:

#[target_feature(enable = "sse4.2")]
use mycrate-sys::foo;

Thank you :slight_smile:

I don't know about crate level, but you can executable wise with rustc flags or RUSTFLAGS.

I mixed it all up.
Here is what's I do to fix this:

Functions that used sse4.2 intrinsics

#[cfg(target_arch = "x86_64")]
#[cfg(target_feature = "sse4.2")]
pub unsafe fn foo() { 
    ...use of some sse4.2 intrinsics....
}

then in test crate that test all functions that used sse4.2 intrinsics:

#![cfg(target_arch = "x86_64")]
#![cfg(target_feature = "sse4.2")]
use mycrate-sys::foo;

Then I pass -C target-feature=+sse4.2 and it's ok!

Thanks for the help

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.