From 21362149343b5eecb968f2aa506725d2a27fb6ff Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 16 Nov 2017 11:23:56 +0100 Subject: [PATCH] add support for no_std --- library/stdarch/Cargo.toml | 1 + library/stdarch/ci/run.sh | 3 +++ library/stdarch/src/lib.rs | 4 ++++ library/stdarch/src/x86/mod.rs | 11 +++++++++++ library/stdarch/src/x86/runtime.rs | 1 + library/stdarch/src/x86/sse.rs | 2 +- library/stdarch/src/x86/sse2.rs | 4 ++-- 7 files changed, 23 insertions(+), 3 deletions(-) diff --git a/library/stdarch/Cargo.toml b/library/stdarch/Cargo.toml index a4d67f84bed5..874f9d4f08e3 100644 --- a/library/stdarch/Cargo.toml +++ b/library/stdarch/Cargo.toml @@ -32,3 +32,4 @@ cupid = "0.3" [features] strict = [] +std = [] \ No newline at end of file diff --git a/library/stdarch/ci/run.sh b/library/stdarch/ci/run.sh index c8b41e9c78ad..f4d3382cb07b 100755 --- a/library/stdarch/ci/run.sh +++ b/library/stdarch/ci/run.sh @@ -19,3 +19,6 @@ echo "RUSTFLAGS=${RUSTFLAGS}" cargo test --target $TARGET --features "strict" cargo test --release --target $TARGET --features "strict" + +cargo test --target $TARGET --features "strict,std" +cargo test --release --target $TARGET --features "strict,std" diff --git a/library/stdarch/src/lib.rs b/library/stdarch/src/lib.rs index b8670c8d5231..ed18b00d3f07 100644 --- a/library/stdarch/src/lib.rs +++ b/library/stdarch/src/lib.rs @@ -128,6 +128,10 @@ cast_possible_truncation, cast_precision_loss, shadow_reuse, cyclomatic_complexity, similar_names, doc_markdown, many_single_char_names))] +#![cfg_attr(not(feature = "std"), no_std)] + +#[cfg(not(feature = "std"))] +extern crate core as std; #[cfg(test)] extern crate stdsimd_test; diff --git a/library/stdarch/src/x86/mod.rs b/library/stdarch/src/x86/mod.rs index ba84f9d89093..96011521abe6 100644 --- a/library/stdarch/src/x86/mod.rs +++ b/library/stdarch/src/x86/mod.rs @@ -41,3 +41,14 @@ mod abm; mod bmi; mod bmi2; mod tbm; + +#[allow(non_camel_case_types)] +#[cfg(not(feature = "std"))] +#[repr(u8)] +pub enum c_void { + #[doc(hidden)] __variant1, + #[doc(hidden)] __variant2, +} + +#[cfg(feature = "std")] +use std::os::raw::c_void; diff --git a/library/stdarch/src/x86/runtime.rs b/library/stdarch/src/x86/runtime.rs index 4b7e3aa56e4f..1549c4f7a359 100644 --- a/library/stdarch/src/x86/runtime.rs +++ b/library/stdarch/src/x86/runtime.rs @@ -283,6 +283,7 @@ pub fn __unstable_detect_feature(x: __Feature) -> bool { #[cfg(test)] mod tests { + #[cfg(feature = "std")] #[test] fn runtime_detection_x86_nocapture() { println!("sse: {:?}", cfg_feature_enabled!("sse")); diff --git a/library/stdarch/src/x86/sse.rs b/library/stdarch/src/x86/sse.rs index 49e10efdd132..2d1be6d1348d 100644 --- a/library/stdarch/src/x86/sse.rs +++ b/library/stdarch/src/x86/sse.rs @@ -3,7 +3,7 @@ use simd_llvm::simd_shuffle4; use v128::*; use v64::f32x2; -use std::os::raw::c_void; +use super::c_void; use std::mem; use std::ptr; diff --git a/library/stdarch/src/x86/sse2.rs b/library/stdarch/src/x86/sse2.rs index d1832f2b34d7..75e6ac58cef2 100644 --- a/library/stdarch/src/x86/sse2.rs +++ b/library/stdarch/src/x86/sse2.rs @@ -4,7 +4,7 @@ use stdsimd_test::assert_instr; use std::mem; -use std::os::raw::c_void; +use super::c_void; use std::ptr; use simd_llvm::{simd_cast, simd_shuffle16, simd_shuffle2, simd_shuffle4, @@ -2242,7 +2242,7 @@ extern "C" { #[cfg(test)] mod tests { - use std::os::raw::c_void; + use super::c_void; use stdsimd_test::simd_test; use test::black_box; // Used to inhibit constant-folding.