diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 33db9c9207..45850ebe08 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -34,21 +34,52 @@ jobs: containerImage: immunant/c2rust:ubuntu-bionic-latest container: $[ variables['containerImage'] ] steps: + + # rust was installed for the `docker` user, not the user azure creates + # but cargo and rustup can be controlled via $CARGO_HOME and $RUSTUP_HOME. + # NOTE: $HOME is not set correctly for the azure user; don't rely on it. + + - script: | + export PATH="/home/docker/.cargo/bin:$PATH" + export RUSTUP_HOME=/home/docker/.rustup + export CARGO_HOME=$AGENT_TEMPDIRECTORY/.cargo + ./scripts/run_ci_checks.sh fmt + cargo fmt --check + displayName: 'cargo fmt --check' + + - script: | + export PATH="/home/docker/.cargo/bin:$PATH" + export RUSTUP_HOME=/home/docker/.rustup + export CARGO_HOME=$AGENT_TEMPDIRECTORY/.cargo + ./scripts/run_ci_checks.sh check + displayName: 'cargo check' + + - script: | + export PATH="/home/docker/.cargo/bin:$PATH" + export RUSTUP_HOME=/home/docker/.rustup + export CARGO_HOME=$AGENT_TEMPDIRECTORY/.cargo + ./scripts/run_ci_checks.sh doc + displayName: 'cargo doc' + - script: | - # rust was installed for the `docker` user, not the user azure creates - # but cargo and rustup can be controlled via $CARGO_HOME and $RUSTUP_HOME. - # NOTE: $HOME is not set correctly for the azure user; don't rely on it. export PATH="/home/docker/.cargo/bin:$PATH" export RUSTUP_HOME=/home/docker/.rustup export CARGO_HOME=$AGENT_TEMPDIRECTORY/.cargo - cargo build --release - displayName: 'Fast build against host clang/LLVM' + ./scripts/run_ci_checks.sh build + displayName: 'cargo build against host clang/LLVM (fast build)' - script: | export PATH="/home/docker/.cargo/bin:$PATH" export RUSTUP_HOME=/home/docker/.rustup export CARGO_HOME=$AGENT_TEMPDIRECTORY/.cargo - python3 ./scripts/test_translator.py ./tests + ./scripts/run_ci_checks.sh test + displayName: 'cargo test' + + - script: | + export PATH="/home/docker/.cargo/bin:$PATH" + export RUSTUP_HOME=/home/docker/.rustup + export CARGO_HOME=$AGENT_TEMPDIRECTORY/.cargo + ./scripts/run_ci_checks.sh test-translator displayName: 'Test translator (fast build)' - job: Darwin @@ -73,8 +104,29 @@ jobs: - script: | export LLVM_CONFIG_PATH=$(brew --prefix llvm)/bin/llvm-config - cargo build --release - displayName: 'Fast build against host clang/LLVM' + ./scripts/run_ci_checks.sh fmt + displayName: 'cargo fmt --check' + + - script: | + export LLVM_CONFIG_PATH=$(brew --prefix llvm)/bin/llvm-config + ./scripts/run_ci_checks.sh check + displayName: 'cargo check' + + - script: | + export LLVM_CONFIG_PATH=$(brew --prefix llvm)/bin/llvm-config + ./scripts/run_ci_checks.sh doc + displayName: 'cargo doc' + + - script: | + export LLVM_CONFIG_PATH=$(brew --prefix llvm)/bin/llvm-config + ./scripts/run_ci_checks.sh build + displayName: 'cargo build against host clang/LLVM (fast build)' - - script: python3 ./scripts/test_translator.py ./tests + - script: | + export LLVM_CONFIG_PATH=$(brew --prefix llvm)/bin/llvm-config + ./scripts/run_ci_checks.sh test + displayName: 'cargo test' + + - script: | + ./scripts/run_ci_checks.sh test-translator displayName: 'Test translator (fast build)' diff --git a/scripts/pdg.sh b/scripts/pdg.sh index 392ad97e13..55fdf90a28 100755 --- a/scripts/pdg.sh +++ b/scripts/pdg.sh @@ -43,6 +43,7 @@ main() { local metadata="${CWD}/${test_dir}/metadata.bc" (cd "${test_dir}" + unset RUSTFLAGS # transpiled code has tons of warnings; don't allow `-D warnings` export RUST_BACKTRACE=1 export INSTRUMENT_BACKEND=log export INSTRUMENT_OUTPUT=log.bc diff --git a/scripts/provision_mac.sh b/scripts/provision_mac.sh index d6c1e64958..2991577fe4 100755 --- a/scripts/provision_mac.sh +++ b/scripts/provision_mac.sh @@ -21,7 +21,8 @@ export HOMEBREW_NO_AUTO_UPDATE=1 # NOTE: Pin LLVM to a known good version since new releases # tend not to be backwards compatible -hb_packages=(python cmake ninja gpg llvm) +# `bash` needed b/c macOS ships with bash 3, which doesn't support arrays properly +hb_packages=(python cmake ninja gpg llvm bash) for item in "${hb_packages[@]}"; do brew info "${item}" | grep 'Not installed' > /dev/null && brew install "${item}" done diff --git a/scripts/run_ci_checks.sh b/scripts/run_ci_checks.sh new file mode 100755 index 0000000000..9d3bf46912 --- /dev/null +++ b/scripts/run_ci_checks.sh @@ -0,0 +1,61 @@ +#!/usr/bin/env bash + +set -euox pipefail + +# Run the same checks that are run in CI in `azure-pipelines.yml`. + +# Deny all warnings, including in documentation. +export RUSTFLAGS="-D warnings" +export RUSTDOCFLAGS="-D warnings" + +fmt() { + cargo fmt --check +} + +# Soon to be superceded by the commented out `cargo clippy` below. +# This is different from `cargo build` +# as this uses `--all-features` to check everything. +check() { + cargo check --tests --all-features + # cargo clippy --tests --all-features +} + +doc() { + cargo doc --all-features --document-private-items --no-deps +} + +# At this point, we could unset `RUSTFLAGS` and `RUSTDOCFLAGS`, +# as we've already checked all the code, +# but doing so and then re-compiling would flush the caches, +# so we leave them until we're done compiling. + +# Don't build with `--all-features` as `--all-features` includes `--features llvm-static`, +# which we don't want to test here (it doesn't work out of the box on Arch and Fedora; +# see https://github.com/immunant/c2rust/issues/500). +build() { + cargo build --release +} + +test() { + cargo test --release --exclude c2rust-analyze --workspace +} + +# `test_translatory.py` compiles translated code, +# which has tons of warnings. +# `RUSTFLAGS="-D warnings"` would be inherited by that, +# causing tons of errors, so unset that. +test-translator() { + unset RUSTFLAGS + ./scripts/test_translator.py tests/ +} + +all() { + fmt + check + doc + build + test + test-translator +} + +"${1:-all}"