forked from fortanix/rust-mbedtls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ct.sh
executable file
·118 lines (105 loc) · 4.96 KB
/
ct.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
set -ex
cd "$(dirname "$0")"
if [ -z $TRAVIS_RUST_VERSION ]; then
echo "Expected TRAVIS_RUST_VERSION to be set in env"
exit 1
fi
# checks if a file has a specific sha512 hash, compatible for Linux and macOS
check_sha512() {
local hash="$1"
local file="$2"
local platform=$(uname)
case $platform in
Linux)
sha512sum -c <<< "$hash *$file"
;;
Darwin)
shasum -a 512 -c <<< "$hash *$file"
;;
*)
echo "Unsupported platform '$platfom'"
exit 1
;;
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
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
# Setup dependencies and tools
# According to `mbedtls-sys/vendor/README.md`, need to install needed pkgs
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"
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
curl -LsSf "$url" | tar zxf - -C "${CARGO_HOME:-$HOME/.cargo}/bin"
check_sha512 "${cargo_nextest_hash}" "${CARGO_HOME:-$HOME/.cargo}/bin/cargo-nextest"
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"
;;
*)
echo "Unknown platform '$kernel-$architecture'"
exit 1
;;
esac
# Test logic start from here
cd "./mbedtls"
if [ "$TRAVIS_RUST_VERSION" == "stable" ] || [ "$TRAVIS_RUST_VERSION" == "beta" ] || [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then
# 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" ]; 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,rdrand --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 --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
else
echo "Unknown version $TRAVIS_RUST_VERSION"
exit 1
fi