From 014d83688355b4e5837c172cd27f68593c3ac5a9 Mon Sep 17 00:00:00 2001 From: YX Cao Date: Thu, 29 Aug 2024 06:31:06 -0700 Subject: [PATCH] Fix and update CI (#367) - Change to use GitHub Action to install cargo-next. - Fix new nightly lints about cfg. - Add script to run CI tests locally. --- .github/workflows/test.yml | 8 +++++- ci.sh | 16 +++++------ ci_local.sh | 41 ++++++++++++++++++++++++++++ ci_tools.sh | 42 +---------------------------- mbedtls-platform-support/Cargo.toml | 6 +++++ mbedtls-sys/Cargo.toml | 7 +++++ mbedtls/Cargo.toml | 11 +++++++- 7 files changed, 80 insertions(+), 51 deletions(-) create mode 100755 ci_local.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a0e156847..d3bfce37d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -86,6 +86,12 @@ jobs: toolchain: ${{ matrix.rust }} targets: ${{ matrix.target }} + - name: Install cargo-nextest + uses: taiki-e/install-action@v2 + with: + tool: nextest@0.9.52 + checksum: true + - name: Run tests run: | # Set LIBCLANG_PATH for bindgen to access clang library under windows-2019 @@ -96,7 +102,7 @@ jobs: ./ci_tools.sh ./ci.sh env: - TRAVIS_RUST_VERSION: ${{ matrix.rust }} + RUST_VERSION: ${{ matrix.rust }} TARGET: ${{ matrix.target }} MATRIX_OS: ${{ matrix.os }} ZLIB_INSTALLED: ${{ matrix.target == 'x86_64-unknown-linux-gnu' && 'true' || '' }} diff --git a/ci.sh b/ci.sh index f1f7d6439..e0dce1d93 100755 --- a/ci.sh +++ b/ci.sh @@ -4,8 +4,8 @@ cd "$(dirname "$0")" repo_root=$(readlink -f $(dirname "${BASH_SOURCE[0]}")) -if [ -z $TRAVIS_RUST_VERSION ]; then - echo "Expected TRAVIS_RUST_VERSION to be set in env" +if [ -z $RUST_VERSION ]; then + echo "Expected RUST_VERSION to be set in env" exit 1 fi @@ -17,11 +17,11 @@ export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=/tmp/aarch64-linux-musl-cr export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUNNER=qemu-aarch64 cd "${repo_root}/mbedtls" -case "$TRAVIS_RUST_VERSION" in +case "$RUST_VERSION" in stable|beta|nightly) # Install the rust toolchain - rustup default $TRAVIS_RUST_VERSION - rustup target add --toolchain $TRAVIS_RUST_VERSION $TARGET + rustup default $RUST_VERSION + rustup target add --toolchain $RUST_VERSION $TARGET printenv for FEAT in "" "x509," "ssl,"; do @@ -44,7 +44,7 @@ case "$TRAVIS_RUST_VERSION" in cargo nextest run --no-default-features --features "$FEAT"no_std_deps --target $TARGET fi else - cargo +$TRAVIS_RUST_VERSION test --no-run --features "$FEAT" --target=$TARGET + cargo +$RUST_VERSION test --no-run --features "$FEAT" --target=$TARGET fi done @@ -71,8 +71,8 @@ case "$TRAVIS_RUST_VERSION" in fi ;; *) - # Default case: If TRAVIS_RUST_VERSION does not match any of the above - echo "Unknown version $TRAVIS_RUST_VERSION" + # Default case: If RUST_VERSION does not match any of the above + echo "Unknown version $RUST_VERSION" exit 1 ;; esac diff --git a/ci_local.sh b/ci_local.sh new file mode 100755 index 000000000..d4cd9b1b7 --- /dev/null +++ b/ci_local.sh @@ -0,0 +1,41 @@ +#!/bin/bash +set -e +cd "$(dirname "$0")" + +# This script needs cargo-binstall installed +# Please check: https://github.com/cargo-bins/cargo-binstall + +cargo binstall cargo-nextest@0.9.52 --secure + +./ci_tools.sh + +# Array containing the configurations (rust and target) +# Please comment out other options if you do not want to test them +configs=( + "stable|x86_64-unknown-linux-gnu" + "stable|x86_64-fortanix-unknown-sgx" + "stable|aarch64-unknown-linux-musl" + "nightly|x86_64-unknown-linux-gnu" + "beta|x86_64-unknown-linux-gnu" +) + +# Path to the script to run +given_script="./ci.sh" + +# Iterate over each configuration +for config in "${configs[@]}"; do + # Split the configuration into rust and target using IFS (Internal Field Separator) + IFS='|' read -r rust target <<< "$config" + echo "Running $given_script with RUST_VERSION=$rust and TARGET=$target" + + # Export the variables to be used in the given script + export RUST_VERSION=$rust + export TARGET=$target + + # Run the given script with the set environment variables + $given_script + + echo "Finished running $given_script with RUST_VERSION=$rust and TARGET=$target" +done + + diff --git a/ci_tools.sh b/ci_tools.sh index b74b41624..d9d728ac2 100755 --- a/ci_tools.sh +++ b/ci_tools.sh @@ -15,7 +15,7 @@ check_sha512() { Linux) sha512sum -c <<< "$hash *$file" ;; - Darwin) + Darwin*) shasum -a 512 -c <<< "$hash *$file" ;; MINGW64_NT-*) @@ -28,25 +28,6 @@ check_sha512() { esac } -# function for downloading pre-built `cargo-nextest` on various platforms -download_cargo_nextest() { - local platform="$1" - local cargo_nextest_hash="$2" - local url="$3" - echo "Check if need to download pre-built $platform 'cargo-nextest'" - if ! check_sha512 "${cargo_nextest_hash}" "${CARGO_HOME:-$HOME/.cargo}/bin/cargo-nextest"; then - case $platform in - MINGW64-*) - curl -LsSf "$url" -o temp.zip && unzip -d "${CARGO_HOME:-$HOME/.cargo}/bin" temp.zip && rm temp.zip - ;; - *) - curl -LsSf "$url" | tar zxf - -C "${CARGO_HOME:-$HOME/.cargo}/bin" - ;; - esac - check_sha512 "${cargo_nextest_hash}" "${CARGO_HOME:-$HOME/.cargo}/bin/cargo-nextest" - fi -} - aarch64_cross_toolchain_hash=c8ee0e7fd58f5ec6811e3cec5fcdd8fc47cb2b49fb50e9d7717696ddb69c812547b5f389558f62dfbf9db7d6ad808a5a515cc466b8ea3e9ab3daeb20ba1adf33 # save to directory that will be cached aarch64_cross_toolchain_save_path=${repo_root}/target/aarch64-linux-musl-cross.tgz @@ -59,24 +40,3 @@ if [ "$TARGET" == "aarch64-unknown-linux-musl" ]; then tar -xf ${aarch64_cross_toolchain_save_path} -C /tmp; fi -# download pre-built `cargo-nextest` -kernel=$(uname) -architecture=$(uname -m) -case "$kernel-$architecture" in - Linux-x86_64 | Linux-amd64) - download_cargo_nextest "amd64" "d22ce5799f3056807fd0cd8223a290c7153a5f084d5ab931fce755c2cabd33f79c0f75542eb724fe07a7ca083f415ec1f84edc46584b06df43d97a0ff91018da" "https://get.nexte.st/0.9.52/linux" - ;; - Linux-arm64) - download_cargo_nextest "arm64" "cff3297c84560de8693e7f887fcf6cf33ab0036e27a9debf2b0a0832094555335f34dc30d0f9d1128ce8472dcb4594a3cf33be2357b19dcc94269b58090cc1a9" "https://get.nexte.st/0.9.52/linux-arm" - ;; - Darwin-x86_64) - download_cargo_nextest "Darwin-amd64" "0bb8b77ce019de3d06ee6b7382d830ed67309f187781e0de3866a0635879b494c7db48d55eee7553cfaa0bfca59abd8f8540a6d81ed703f06f9c81514d20073d" "https://get.nexte.st/0.9.52/mac" - ;; - MINGW64_NT-*-x86_64) - download_cargo_nextest "MINGW64-amd64" "3ffd504a4ef0b4b5e988457e6c525e62bd030d46b8f303f1c4e83a9a8ba89aef34bb239e23f391d1dddb75bea6ff074499153b2c71b06338a05d74916408de9c" "https://get.nexte.st/0.9.52/windows" - ;; - *) - echo "Unknown platform '$kernel-$architecture'" - exit 1 - ;; -esac diff --git a/mbedtls-platform-support/Cargo.toml b/mbedtls-platform-support/Cargo.toml index 68f3748c3..fe5a962ba 100644 --- a/mbedtls-platform-support/Cargo.toml +++ b/mbedtls-platform-support/Cargo.toml @@ -44,3 +44,9 @@ custom_gmtime_r = ["mbedtls-sys-auto/custom_gmtime_r", "chrono"] custom_time = ["mbedtls-sys-auto/custom_time", "chrono"] force_aesni_support = ["mbedtls-sys-auto/custom_has_support","mbedtls-sys-auto/aes_alt", "aesni"] aesni = ["mbedtls-sys-auto/aesni"] + +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = [ + 'cfg(sys_threading_component, values("custom"))', + 'cfg(sys_time_component, values("custom"))', +] } diff --git a/mbedtls-sys/Cargo.toml b/mbedtls-sys/Cargo.toml index 1dd386db2..852afddda 100644 --- a/mbedtls-sys/Cargo.toml +++ b/mbedtls-sys/Cargo.toml @@ -72,3 +72,10 @@ custom_time = ["time"] custom_gmtime_r = ["time"] # deprecated features, these don't do anything anymore, can be removed on major version bump pthread = ["threading"] + +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = [ + 'cfg(std_component, values("fs"))', + 'cfg(threading_component, values("pthread"))', + 'cfg(time_component, values("custom", "libc"))', +] } diff --git a/mbedtls/Cargo.toml b/mbedtls/Cargo.toml index 512eb3d7d..61b3068bd 100644 --- a/mbedtls/Cargo.toml +++ b/mbedtls/Cargo.toml @@ -150,4 +150,13 @@ harness = false [[bench]] name = "cipher" -harness = false \ No newline at end of file +harness = false + +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = [ + 'cfg(nightly)', + 'cfg(sys_threading_component, values("custom"))', + 'cfg(sys_time_component, values("custom"))', + 'cfg(sys_std_component, values("entropy", "net"))', + 'cfg(time_component, values("custom", "libc"))', +] }