From b4e0bccf8a15d9e989b03c364e2f4c8b27288b0d Mon Sep 17 00:00:00 2001 From: Yuxiang Cao Date: Fri, 8 Sep 2023 14:33:42 -0700 Subject: [PATCH] fix msvc build --- ct.sh | 10 +++++----- mbedtls-platform-support/src/self_test.rs | 21 ++++++++++----------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/ct.sh b/ct.sh index a22bc383f..2290d6f15 100755 --- a/ct.sh +++ b/ct.sh @@ -104,6 +104,11 @@ case "$TRAVIS_RUST_VERSION" in # The SGX target cannot be run under test like a ELF binary if [ "$TARGET" != "x86_64-fortanix-unknown-sgx" ]; then + # no_std tests only are able to run on x86 platform + if [ "$TARGET" == "x86_64-unknown-linux-gnu" ] || [ "$TARGET" == "x86_64-apple-darwin" ] || [[ "$TARGET" =~ ^x86_64-pc-windows- ]]; then + cargo nextest run --no-default-features --features no_std_deps,rdrand,time --target $TARGET + cargo nextest run --no-default-features --features no_std_deps --target $TARGET + fi # make sure that explicitly providing the default target works cargo nextest run --target $TARGET --release cargo nextest run --features dsa --target $TARGET @@ -114,11 +119,6 @@ case "$TRAVIS_RUST_VERSION" in cargo nextest run --features force_aesni_support,tls13 --target $TARGET fi - # no_std tests only are able to run on x86 platform - if [ "$TARGET" == "x86_64-unknown-linux-gnu" ] || [ "$TARGET" == "x86_64-apple-darwin" ] || [[ "$TARGET" =~ ^x86_64-pc-windows- ]]; then - cargo nextest run --no-default-features --features no_std_deps,rdrand,time --target $TARGET - cargo nextest run --no-default-features --features no_std_deps --target $TARGET - fi else cargo +$TRAVIS_RUST_VERSION test --no-run --target=$TARGET cargo +$TRAVIS_RUST_VERSION test --no-default-features --features dsa,force_aesni_support,mpi_force_c_code,rdrand,std,time,tls13 --no-run --target=$TARGET diff --git a/mbedtls-platform-support/src/self_test.rs b/mbedtls-platform-support/src/self_test.rs index 73ec11123..35febb024 100644 --- a/mbedtls-platform-support/src/self_test.rs +++ b/mbedtls-platform-support/src/self_test.rs @@ -40,18 +40,17 @@ cfg_if::cfg_if! { } } } -cfg_if::cfg_if! { - if #[cfg(any(not(feature = "std"), target_env = "sgx"))] { - #[allow(non_upper_case_globals)] - static mut rand_f: Option c_int> = None; - // needs to be pub for global visiblity - #[doc(hidden)] - #[no_mangle] - pub unsafe extern "C" fn rand() -> c_int { - rand_f.expect("Called self-test rand without enabling self-test")() - } - } +#[cfg(any(not(feature = "std"), target_env = "sgx"))] +#[allow(non_upper_case_globals)] +static mut rand_f: Option c_int> = None; + +// needs to be pub for global visiblity +#[cfg(all(any(not(feature = "std"), target_env = "sgx"), not(target_env = "msvc")))] +#[doc(hidden)] +#[no_mangle] +pub unsafe extern "C" fn rand() -> c_int { + rand_f.expect("Called self-test rand without enabling self-test")() } /// Set callback functions to enable the MbedTLS self tests.