Skip to content

Commit

Permalink
ci: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Taowyoo committed Sep 9, 2023
1 parent e78944e commit a785156
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 130 deletions.
41 changes: 27 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ jobs:
target: x86_64-unknown-linux-gnu
os: ubuntu-20.04
- rust: stable
target: aarch64-unknown-linux-musl
target: x86_64-fortanix-unknown-sgx
os: ubuntu-20.04
- rust: stable
target: x86_64-fortanix-unknown-sgx
target: x86_64-pc-windows-msvc
os: windows-latest
- rust: stable
target: aarch64-unknown-linux-musl
os: ubuntu-20.04
- rust: stable
target: x86_64-apple-darwin
os: macos-latest
- rust: beta
target: x86_64-unknown-linux-gnu
os: ubuntu-20.04
- rust: nightly
target: x86_64-unknown-linux-gnu
os: ubuntu-20.04
- rust: stable
target: x86_64-apple-darwin
os: macos-latest
- rust: stable
target: x86_64-pc-windows-msvc
os: windows-latest

runs-on: ${{ matrix.os }}

Expand All @@ -57,21 +57,34 @@ jobs:
sudo apt-get update
sudo apt-get install -y qemu-user
- name: Setup Rust toolchain
uses: actions-rs/toolchain@v1
# python version is read from .python-version
- name: Setup python
uses: actions/setup-python@v4
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
override: true
cache: 'pip'
cache-dependency-path: |
mbedtls-sys/vendor/scripts/basic.requirements.txt
mbedtls-sys/vendor/scripts/driver.requirements.txt
- name: Install python dependencies
run: python3 -m pip install -r mbedtls-sys/vendor/scripts/basic.requirements.txt

- name: Cache Dependencies
uses: Swatinem/rust-cache@988c164c3d0e93c4dbab36aaf5bbeb77425b2894
with:
key: ${{ matrix.rust }}

- name: Setup Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
override: true

- name: Run tests
run: |
./ct.sh
./ci_tools.sh
./ci.sh
env:
TRAVIS_RUST_VERSION: ${{ matrix.rust }}
TARGET: ${{ matrix.target }}
Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.8.10
56 changes: 56 additions & 0 deletions ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash
set -ex
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"
exit 1
fi

python3 -m pip install -r ./mbedtls-sys/vendor/scripts/basic.requirements.txt

# Test logic start from here
export CFLAGS_x86_64_fortanix_unknown_sgx="-isystem/usr/include/x86_64-linux-gnu -mlvi-hardening -mllvm -x86-experimental-lvi-inline-asm-hardening"
export CC_x86_64_fortanix_unknown_sgx=clang-11
export CC_aarch64_unknown_linux_musl=/tmp/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=/tmp/target/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUNNER=qemu-aarch64

cd "${repo_root}/mbedtls"
case "$TRAVIS_RUST_VERSION" in
stable|beta|nightly)
# Install the rust toolchain
rustup default $TRAVIS_RUST_VERSION
rustup target add --toolchain $TRAVIS_RUST_VERSION $TARGET
printenv

# The SGX target cannot be run under test like a ELF binary
if [ "$TARGET" != "x86_64-fortanix-unknown-sgx" ]; then
# make sure that explicitly providing the default target works
cargo nextest run --target $TARGET --release
cargo nextest run --features dsa --target $TARGET
cargo nextest run --features async-rt,tls13 --target $TARGET

# If AES-NI is supported, test the feature
if [ -n "$AES_NI_SUPPORT" ]; then
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
fi
;;
*)
# Default case: If TRAVIS_RUST_VERSION does not match any of the above
echo "Unknown version $TRAVIS_RUST_VERSION"
exit 1
;;
esac
77 changes: 13 additions & 64 deletions ct.sh → ci_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
set -ex
cd "$(dirname "$0")"

if [ -z $TRAVIS_RUST_VERSION ]; then
echo "Expected TRAVIS_RUST_VERSION to be set in env"
exit 1
fi
repo_root=$(readlink -f $(dirname "${BASH_SOURCE[0]}"))

# Setup dependencies and tools

Expand All @@ -31,22 +28,6 @@ check_sha512() {
esac
}

aarch64_cross_toolchain_hash=c8ee0e7fd58f5ec6811e3cec5fcdd8fc47cb2b49fb50e9d7717696ddb69c812547b5f389558f62dfbf9db7d6ad808a5a515cc466b8ea3e9ab3daeb20ba1adf33
# save to directory that will be cached
aarch64_cross_toolchain_save_path=/tmp/aarch64-linux-musl-cross.tgz
if [ "$TARGET" == "aarch64-unknown-linux-musl" ]; then
if ! check_sha512 ${aarch64_cross_toolchain_hash} ${aarch64_cross_toolchain_save_path}; then
wget https://more.musl.cc/10-20210301/x86_64-linux-musl/aarch64-linux-musl-cross.tgz -O ${aarch64_cross_toolchain_save_path}
check_sha512 ${aarch64_cross_toolchain_hash} ${aarch64_cross_toolchain_save_path}
fi
tar -xf ${aarch64_cross_toolchain_save_path} -C /tmp;
fi

# According to `mbedtls-sys/vendor/README.md`, need to install needed pkgs
python3 -m venv venv
source venv/bin/activate || source venv/Scripts/activate
python3 -m pip install -r ./mbedtls-sys/vendor/scripts/basic.requirements.txt

# function for downloading pre-built `cargo-nextest` on various platforms
download_cargo_nextest() {
local platform="$1"
Expand All @@ -65,6 +46,18 @@ download_cargo_nextest() {
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
if [ "$TARGET" == "aarch64-unknown-linux-musl" ]; then
if ! check_sha512 ${aarch64_cross_toolchain_hash} ${aarch64_cross_toolchain_save_path}; then
wget https://more.musl.cc/10-20210301/x86_64-linux-musl/aarch64-linux-musl-cross.tgz -O ${aarch64_cross_toolchain_save_path}
check_sha512 ${aarch64_cross_toolchain_hash} ${aarch64_cross_toolchain_save_path}
fi
tar -xf ${aarch64_cross_toolchain_save_path} -C /tmp;
fi

# download pre-built `cargo-nextest`
kernel=$(uname)
architecture=$(uname -m)
Expand All @@ -86,47 +79,3 @@ case "$kernel-$architecture" in
exit 1
;;
esac

# Test logic start from here
export CFLAGS_x86_64_fortanix_unknown_sgx="-isystem/usr/include/x86_64-linux-gnu -mlvi-hardening -mllvm -x86-experimental-lvi-inline-asm-hardening"
export CC_x86_64_fortanix_unknown_sgx=clang-11
export CC_aarch64_unknown_linux_musl=/tmp/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=/tmp/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUNNER=qemu-aarch64

cd "./mbedtls"
case "$TRAVIS_RUST_VERSION" in
stable|beta|nightly)
# Install the rust toolchain
rustup default $TRAVIS_RUST_VERSION
rustup target add --toolchain $TRAVIS_RUST_VERSION $TARGET
printenv

# The SGX target cannot be run under test like a ELF binary
if [ "$TARGET" != "x86_64-fortanix-unknown-sgx" ]; then
# make sure that explicitly providing the default target works
cargo nextest run --target $TARGET --release
cargo nextest run --features dsa --target $TARGET
cargo nextest run --features async-rt,tls13 --target $TARGET

# If AES-NI is supported, test the feature
if [ -n "$AES_NI_SUPPORT" ]; then
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
fi
;;
*)
# Default case: If TRAVIS_RUST_VERSION does not match any of the above
echo "Unknown version $TRAVIS_RUST_VERSION"
exit 1
;;
esac
52 changes: 0 additions & 52 deletions ct_locally.sh

This file was deleted.

0 comments on commit a785156

Please sign in to comment.