From 053ce3b9b6d49f176b30672e703944afe40466c1 Mon Sep 17 00:00:00 2001 From: YX Cao Date: Thu, 2 Nov 2023 12:02:03 -0700 Subject: [PATCH] Fix macos build (#333) * Allow name-mangling for the mbedtls_free, mbedtls_calloc and mbedtls_ssl_flush_output functions According to the discussion in https://github.com/rust-lang/rust-bindgen/issues/1221#issuecomment-442950753, the \u{1} is a hint to LLVM to avoid name-mangling but this might be required on some platforms to link against the right name, e.g. on macOS. * Add macOS test in CI * tests: add missing nextest config * build: bump ver --------- Co-authored-by: Tobias Naumann --- .config/nextest.toml | 118 +++++++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 3 + Cargo.lock | 2 +- ci.sh | 3 + mbedtls-sys/build/cmake.rs | 2 + mbedtls/Cargo.toml | 2 +- mbedtls/src/alloc.rs | 4 +- 7 files changed, 130 insertions(+), 4 deletions(-) create mode 100644 .config/nextest.toml diff --git a/.config/nextest.toml b/.config/nextest.toml new file mode 100644 index 000000000..56b29c45f --- /dev/null +++ b/.config/nextest.toml @@ -0,0 +1,118 @@ +# This is based on the default config used by nextest. It is embedded in the binary at +# build time. It may be used as a template for .config/nextest.toml. + +[store] +# The directory under the workspace root at which nextest-related files are +# written. Profile-specific storage is currently written to dir/. +dir = "target/nextest" + +[test-groups] +serial-integration = { max-threads = 1 } + +# This section defines the default nextest profile. Custom profiles are layered +# on top of the default profile. +[profile.default] +# "retries" defines the number of times a test should be retried. If set to a +# non-zero value, tests that succeed on a subsequent attempt will be marked as +# non-flaky. Can be overridden through the `--retries` option. +# Examples +# * retries = 3 +# * retries = { backoff = "fixed", count = 2, delay = "1s" } +# * retries = { backoff = "exponential", count = 10, delay = "1s", jitter = true, max-delay = "10s" } +retries = 0 + +# The number of threads to run tests with. Supported values are either an integer or +# the string "num-cpus". Can be overridden through the `--test-threads` option. +test-threads = "num-cpus" + +# The number of threads required for each test. This is generally used in overrides to +# mark certain tests as heavier than others. However, it can also be set as a global parameter. +threads-required = 1 + +# Show these test statuses in the output. +# +# The possible values this can take are: +# * none: no output +# * fail: show failed (including exec-failed) tests +# * retry: show flaky and retried tests +# * slow: show slow tests +# * pass: show passed tests +# * skip: show skipped tests (most useful for CI) +# * all: all of the above +# +# Each value includes all the values above it; for example, "slow" includes +# failed and retried tests. +# +# Can be overridden through the `--status-level` flag. +status-level = "pass" + +# Similar to status-level, show these test statuses at the end of the run. +final-status-level = "flaky" + +# "failure-output" defines when standard output and standard error for failing tests are produced. +# Accepted values are +# * "immediate": output failures as soon as they happen +# * "final": output failures at the end of the test run +# * "immediate-final": output failures as soon as they happen and at the end of +# the test run; combination of "immediate" and "final" +# * "never": don't output failures at all +# +# For large test suites and CI it is generally useful to use "immediate-final". +# +# Can be overridden through the `--failure-output` option. +failure-output = "immediate" + +# "success-output" controls production of standard output and standard error on success. This should +# generally be set to "never". +success-output = "never" + +# Cancel the test run on the first failure. For CI runs, consider setting this +# to false. +fail-fast = true + +# Treat a test that takes longer than the configured 'period' as slow, and print a message. +# See for more information. +# +# Optional: specify the parameter 'terminate-after' with a non-zero integer, +# which will cause slow tests to be terminated after the specified number of +# periods have passed. +# Example: slow-timeout = { period = "60s", terminate-after = 2 } +slow-timeout = { period = "60s" } + +# Treat a test as leaky if after the process is shut down, standard output and standard error +# aren't closed within this duration. +# +# This usually happens in case of a test that creates a child process and lets it inherit those +# handles, but doesn't clean the child process up (especially when it fails). +# +# See for more information. +leak-timeout = "100ms" + +[profile.default.junit] +# Output a JUnit report into the given file inside 'store.dir/'. +# If unspecified, JUnit is not written out. + +# path = "junit.xml" + +# The name of the top-level "report" element in JUnit report. If aggregating +# reports across different test runs, it may be useful to provide separate names +# for each report. +report-name = "nextest-run" + +# Whether standard output and standard error for passing tests should be stored in the JUnit report. +# Output is stored in the and elements of the element. +store-success-output = false + +# Whether standard output and standard error for failing tests should be stored in the JUnit report. +# Output is stored in the and elements of the element. +# +# Note that if a description can be extracted from the output, it is always stored in the +# element. +store-failure-output = true + +[[profile.default.overrides]] +# `is_probably_prime` test heavily use rdrand, sometimes the VM where test is running has shortage on it +filter = 'test(is_probably_prime)' +retries = { backoff = "exponential", count = 6, delay = "1s", jitter = true } +test-group = 'serial-integration' + diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1f571c846..01ed2688b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -54,6 +54,9 @@ jobs: - rust: nightly target: x86_64-unknown-linux-gnu os: ubuntu-20.04 + - rust: stable + target: x86_64-apple-darwin + os: macos-latest runs-on: ${{ matrix.os }} diff --git a/Cargo.lock b/Cargo.lock index fe0ada21a..f04014112 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -485,7 +485,7 @@ checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" [[package]] name = "mbedtls" -version = "0.12.0-alpha.1" +version = "0.12.0-alpha.2" dependencies = [ "async-stream", "bit-vec", diff --git a/ci.sh b/ci.sh index 500177e09..739fb0aaa 100755 --- a/ci.sh +++ b/ci.sh @@ -43,6 +43,9 @@ case "$TRAVIS_RUST_VERSION" in cargo nextest run --no-default-features --features "$FEAT"no_std_deps,rdrand,time --target $TARGET cargo nextest run --no-default-features --features "$FEAT"no_std_deps --target $TARGET fi + if [ "$TARGET" == "x86_64-apple-darwin" ]; then + cargo nextest run --no-default-features --features no_std_deps --target $TARGET + fi else cargo +$TRAVIS_RUST_VERSION test --no-run --features "$FEAT" --target=$TARGET diff --git a/mbedtls-sys/build/cmake.rs b/mbedtls-sys/build/cmake.rs index 808527cc3..bc82e501b 100644 --- a/mbedtls-sys/build/cmake.rs +++ b/mbedtls-sys/build/cmake.rs @@ -19,6 +19,8 @@ impl super::BuildConfig { .define("ENABLE_TESTING", "OFF") // This is turn off on windows by default .define("GEN_FILES", "ON") + // Prefer unix-style over Apple-style Python3 on macOS, required for the Github Actions CI + .define("Python3_FIND_FRAMEWORK", "LAST") .build_target("install"); for cflag in &self.cflags { cmk.cflag(cflag); diff --git a/mbedtls/Cargo.toml b/mbedtls/Cargo.toml index a65c5f99d..4d119a989 100644 --- a/mbedtls/Cargo.toml +++ b/mbedtls/Cargo.toml @@ -2,7 +2,7 @@ name = "mbedtls" # We jumped from v0.9 to v0.12 because v0.10 and v0.11 were based on mbedtls 3.X, which # we decided not to support. -version = "0.12.0-alpha.1" +version = "0.12.0-alpha.2" authors = ["Jethro Beekman "] build = "build.rs" edition = "2018" diff --git a/mbedtls/src/alloc.rs b/mbedtls/src/alloc.rs index 8a73835eb..ef8bc74ab 100644 --- a/mbedtls/src/alloc.rs +++ b/mbedtls/src/alloc.rs @@ -16,9 +16,9 @@ use core::ptr::NonNull; use mbedtls_sys::types::raw_types::c_void; extern "C" { - #[link_name = concat!("\u{1}forward_mbedtls_free_", env!("RUST_MBEDTLS_METADATA_HASH"))] + #[link_name = concat!("forward_mbedtls_free_", env!("RUST_MBEDTLS_METADATA_HASH"))] pub(crate) fn mbedtls_free(n: *mut mbedtls_sys::types::raw_types::c_void); - #[link_name = concat!("\u{1}forward_mbedtls_calloc_", env!("RUST_MBEDTLS_METADATA_HASH"))] + #[link_name = concat!("forward_mbedtls_calloc_", env!("RUST_MBEDTLS_METADATA_HASH"))] pub(crate) fn mbedtls_calloc( n: mbedtls_sys::types::size_t, size: mbedtls_sys::types::size_t,