|
| 1 | +#!/bin/bash -ex |
| 2 | +RUST_BRANCH=fortanixvme-2023-05-07-alpha |
| 3 | +RUST_SGX_BRANCH=fortanixvme-2023-05-07-alpha |
| 4 | +MODE=test |
| 5 | +WORKDIR=~/CI |
| 6 | + |
| 7 | +if [ ! -d "${WORKDIR}" ]; then |
| 8 | + WORKDIR=$(mktemp -d /tmp/fortanixvme-ci-XXX) |
| 9 | +fi |
| 10 | + |
| 11 | +cd ${WORKDIR} |
| 12 | + |
| 13 | +echo 'Update tools' |
| 14 | +# TODO make sure rust-sgx branch compiles with latest nightly |
| 15 | +#rustup update nightly |
| 16 | +#rustup default nightly |
| 17 | +rustup install nightly-2023-05-07 |
| 18 | +rustup default nightly-2023-05-07 |
| 19 | + |
| 20 | +echo 'Fetching fortanixvme tools' |
| 21 | +if [ -d "./rust-sgx" ]; then |
| 22 | + pushd rust-sgx |
| 23 | + git reset |
| 24 | + git checkout ${RUST_SGX_BRANCH} |
| 25 | + git fetch |
| 26 | + git pull |
| 27 | + popd |
| 28 | +else |
| 29 | + git clone https://github.com/fortanix/rust-sgx.git -b ${RUST_SGX_BRANCH} |
| 30 | +fi |
| 31 | + |
| 32 | +echo 'Building fortanixvme tools' |
| 33 | +pushd rust-sgx/fortanix-vme/ |
| 34 | +cargo build --workspace --exclude dcap-provider |
| 35 | +popd |
| 36 | + |
| 37 | +echo 'Installing fortanixvme tools' |
| 38 | +# clean up exiting tools |
| 39 | +rm -f ~/.cargo/bin/ftxvme-elf2eif || true |
| 40 | +rm -f ~/.cargo/bin/ftxvme-runner || true |
| 41 | +rm -f ~/.cargo/bin/ftxvme-runner-cargo || true |
| 42 | + |
| 43 | +# Set up tools |
| 44 | +ln -fs ${WORKDIR}/rust-sgx/target/debug/ftxvme-elf2eif ~/.cargo/bin/ftxvme-elf2eif |
| 45 | +ln -fs ${WORKDIR}/rust-sgx/target/debug/ftxvme-runner ~/.cargo/bin/ftxvme-runner |
| 46 | +ln -fs ${WORKDIR}/rust-sgx/target/debug/ftxvme-runner-cargo ~/.cargo/bin/ftxvme-runner-cargo |
| 47 | + |
| 48 | +# Specify cargo runner for fortanixvme target |
| 49 | +touch ~/.cargo/config |
| 50 | +sed -i '/ftxvme/d;/fortanixvme/d' ~/.cargo/config |
| 51 | +echo >> ~/.cargo/config -e '[target.x86_64-unknown-linux-fortanixvme]\nrunner = ["ftxvme-runner-cargo", "--verbose"]' |
| 52 | + |
| 53 | +echo 'Fetching Rust compiler' |
| 54 | +if [ -d "./rust" ]; then |
| 55 | + pushd rust |
| 56 | + git reset |
| 57 | + git checkout ${RUST_BRANCH} |
| 58 | + git fetch |
| 59 | + git pull |
| 60 | + # https://github.com/rust-lang/rust/issues/72104 |
| 61 | + git submodule foreach --recursive git reset |
| 62 | + git submodule update --init --recursive |
| 63 | + git submodule foreach --recursive git fetch --depth=2147483647 origin '+refs/heads/*:refs/remotes/origin/*' |
| 64 | + popd |
| 65 | +else |
| 66 | + git clone https://github.com/fortanix/rust.git -b ${RUST_BRANCH} |
| 67 | + pushd rust |
| 68 | + git submodule update --init --recursive |
| 69 | + popd |
| 70 | +fi |
| 71 | + |
| 72 | +echo 'Installing musl toolchain' |
| 73 | +musl_dir="${WORKDIR}/musl-toolchain" |
| 74 | +mkdir -p ${musl_dir} |
| 75 | + |
| 76 | +pushd rust |
| 77 | +if [ -z "$(ls -A ${musl_dir})" ]; then |
| 78 | + # musl-toolchain installation directory is empty, install it |
| 79 | + CFLAGS="-Wa,-mrelax-relocations=no -Wa,--compress-debug-sections=none -Wl,--compress-debug-sections=none" \ |
| 80 | + CXXFLAGS="-Wa,-mrelax-relocations=no -Wa,--compress-debug-sections=none -Wl,--compress-debug-sections=none" \ |
| 81 | + REPLACE_CC=0 \ |
| 82 | + INSTALL_DIR=${musl_dir} \ |
| 83 | + bash ./src/ci/docker/scripts/musl-toolchain.sh x86_64 |
| 84 | +fi |
| 85 | + |
| 86 | +if [ ! -f "config.toml" ]; then |
| 87 | + # Warning: when you want to build `lld` as well, you can add `--enable-lld`, but currently it fails when LLVM is |
| 88 | + # downloaded from ci instead of rebuild. It can be resolved by removing `--set llvm.download-ci-llvm=true` |
| 89 | + # This version of llvm is too old to be downloaded. We'll need to compile it ourselves. |
| 90 | + # We also need an older version of `cargo` that doesn't add unknown flags when it calls `rustc` |
| 91 | + ./configure \ |
| 92 | + --target=x86_64-unknown-linux-fortanixvme,x86_64-unknown-linux-fortanixvme \ |
| 93 | + --musl-root-fortanixvme=${musl_dir}/x86_64-linux-musl/ \ |
| 94 | + --set target.x86_64-unknown-linux-fortanixvme.crt-static=true \ |
| 95 | + --set install.prefix=${workdir}/rust/toolchain \ |
| 96 | + --set llvm.targets=X86 \ |
| 97 | + --set llvm.download-ci-llvm=false \ |
| 98 | + --set rust.verbose-tests=true \ |
| 99 | + --enable-extended \ |
| 100 | + --tools=cargo |
| 101 | +fi |
| 102 | + |
| 103 | +# Newer binutils broke things on some vms/distros (i.e., linking against |
| 104 | +# unknown relocs disabled by the following flag), so we need to go out of our |
| 105 | +# way to produce "super compatible" binaries. |
| 106 | +# |
| 107 | +# See: https://github.com/rust-lang/rust/issues/34978 |
| 108 | +# And: https://github.com/rust-lang/rust/issues/59411 |
| 109 | +export CFLAGS_x86_64_unknown_linux_fortanixvme="-Wa,-mrelax-relocations=no -Wa,--compress-debug-sections=none \ |
| 110 | + -Wl,--compress-debug-sections=none" |
| 111 | +export CC_x86_64_unknown_linux_fortanixvme=${musl_dir}/bin/x86_64-linux-musl-gcc |
| 112 | +export CXX_x86_64_unknown_linux_fortanixvme=${musl_dir}/bin/x86_64-linux-musl-g++ |
| 113 | +export LD_x86_64_unknown_linux_fortanixvme=${musl_dir}/bin/x86_64-linux-musl-ld |
| 114 | + |
| 115 | +if [ "${MODE}" == "test" ]; then |
| 116 | + RUST_TEST_THREADS=1 nice -n 19 ionice -c idle ./x.py test --stage=1 --target=x86_64-unknown-linux-fortanixvme library/std --host='' --no-doc --exclude src/tools/linkchecker ${testname} |
| 117 | +else |
| 118 | + nice -n 19 ionice -c idle python3 ./x.py build |
| 119 | + |
| 120 | + source $HOME/.cargo/env |
| 121 | + rustup uninstall fortanixvme |
| 122 | + rustup toolchain link fortanixvme build/x86_64-unknown-linux-gnu/stage2 |
| 123 | + app_dir=$(mktemp -d /tmp/app-XXX) |
| 124 | + pushd ${app_dir} |
| 125 | + cargo +fortanixvme new my_app |
| 126 | + pushd my_app |
| 127 | + cargo +fortanixvme run --target x86_64-unknown-linux-fortanixvme |
| 128 | + popd |
| 129 | + popd |
| 130 | +fi |
| 131 | + |
| 132 | +popd |
0 commit comments