Skip to content

Commit

Permalink
Add rust-toolchain file instead of always using stable. (#2408)
Browse files Browse the repository at this point in the history
Cherry-pick from master of 463a663 and
8a02d35, except that the toolchain is set to
1.40.0 instead of stable.

---

Add rust-toolchain file instead of always using stable.

Currently our release branches always use the stable toolchain,
just like master. Unfortunately a new stable has the ability
to break the build, since it brings new clippy and rustfmt and we enforce
clean clippy and formatting in the builds.

With this change, we now let rustup read the toolchain from
the rust-toolchain file instead of forcing it to use latest stable.
The expectation is that when we create release branches, we'll freeze
the toolchain version to the latest Rust release at the time.

For the Windows ARM32 builds, since we use a custom toolchain
instead of rustup, the toolchain version is part of the download URL.

---

Fix handling of toolchain-specific Windows ARM32 compiler.

- Ensure that compiler zip and expanded directory are resolved relative to
  the repo root, not current directory.

  This is needed because the azureiotedge-diagnostics build script changes
  the current directory when it switches from building amd64 to arm32.

- Ensure that compiler zip and expanded directory contain the toolchain name.

  Previously the existing expanded directory would be used regardless of
  which toolchain zip was expanded to create it.

  This is also needed because the build agent is shared for older branches that
  do not use the toolchain file, so their zip and expanded directories
  must not conflict.
  • Loading branch information
arsing authored Jan 28, 2020
1 parent e468d03 commit 2676621
Show file tree
Hide file tree
Showing 18 changed files with 145 additions and 237 deletions.
16 changes: 9 additions & 7 deletions builds/checkin/edgelet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,25 @@ jobs:
echo "##vso[task.setvariable variable=IOTEDGE_HOMEDIR;]/tmp"
echo "##vso[task.setvariable variable=CARGO;]${CARGO_HOME:-"$HOME/.cargo"}/bin/cargo"
displayName: Set env variables
- script: edgelet/build/linux/install.sh -t "${RUST_TOOLCHAIN}"
- script: |
echo "$RUST_TOOLCHAIN" > rust-toolchain
displayName: Override Rust toolchain
workingDirectory: edgelet
env:
RUST_TOOLCHAIN: $(rust.toolchain)
- script: edgelet/build/linux/install.sh
displayName: Install Rust
- script: |
curl -L https://github.com/mozilla/grcov/releases/download/v0.5.1/grcov-linux-x86_64.tar.bz2 | tar jxf -
curl -L https://raw.github.com/eriwen/lcov-to-cobertura-xml/8c55cd11f80a21e7e46f20f8c81fcde0bf11f5e5/lcov_cobertura/lcov_cobertura.py -o lcov_cobertura.py
workingDirectory: edgelet
displayName: Install code coverage tools
- script: $CARGO "+${RUST_TOOLCHAIN}" build --verbose
- script: $CARGO build --verbose
displayName: Build
workingDirectory: edgelet
env:
RUST_TOOLCHAIN: $(rust.toolchain)
- script: $CARGO "+${RUST_TOOLCHAIN}" test --verbose
- script: $CARGO test --verbose
displayName: Test
workingDirectory: edgelet
env:
RUST_TOOLCHAIN: $(rust.toolchain)
- script: |
zip -0 target/ccov.zip `find ./target \( -name "*.gc*" \) -print`
./grcov target/ccov.zip -s . -t lcov --llvm --branch --ignore-not-existing --ignore-dir "/*" --ignore-dir "*docker-rs*" > target/lcov.info
Expand Down
4 changes: 2 additions & 2 deletions builds/ci/edgelet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ jobs:
displayName: armv7-unknown-linux-gnueabihf build
inputs:
filePath: edgelet/build/linux/cross.sh
arguments: --toolchain armv7-unknown-linux-gnueabihf --release true
arguments: --target armv7-unknown-linux-gnueabihf --release true
- task: Bash@3
displayName: armv7-unknown-linux-gnueabihf test
inputs:
filePath: edgelet/build/linux/cross-test.sh
arguments: --toolchain armv7-unknown-linux-gnueabihf --release true
arguments: --target armv7-unknown-linux-gnueabihf --release true

################################################################################
- job: windows_amd64
Expand Down
12 changes: 3 additions & 9 deletions edgelet/build/linux/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ BUILD_REPOSITORY_LOCALPATH=${BUILD_REPOSITORY_LOCALPATH:-$DIR/../../..}
PROJECT_ROOT=${BUILD_REPOSITORY_LOCALPATH}/edgelet
SCRIPT_NAME=$(basename "$0")
CARGO="${CARGO_HOME:-"$HOME/.cargo"}/bin/cargo"
TOOLCHAIN="stable-x86_64-unknown-linux-gnu"
RELEASE=

###############################################################################
Expand All @@ -28,7 +27,6 @@ usage()
echo ""
echo "options"
echo " -h, --help Print this help and exit."
echo " -t, --toolchain Toolchain (default: stable-x86_64-unknown-linux-gnu)"
echo " -r, --release Release build? (flag, default: false)"
exit 1;
}
Expand All @@ -42,16 +40,12 @@ process_args()
for arg in "$@"
do
if [ $save_next_arg -eq 1 ]; then
TOOLCHAIN="$arg"
save_next_arg=0
elif [ $save_next_arg -eq 2 ]; then
RELEASE="true"
save_next_arg=0
else
case "$arg" in
"-h" | "--help" ) usage;;
"-t" | "--toolchain" ) save_next_arg=1;;
"-r" | "--release" ) save_next_arg=2;;
"-r" | "--release" ) save_next_arg=1;;
* ) usage;;
esac
fi
Expand Down Expand Up @@ -79,7 +73,7 @@ incremental = false
EOF

if [[ -z ${RELEASE} ]]; then
cd "$PROJECT_ROOT" && $CARGO "+$TOOLCHAIN" build --all
cd "$PROJECT_ROOT" && $CARGO build --all
else
cd "$PROJECT_ROOT" && $CARGO "+$TOOLCHAIN" build --all --release
cd "$PROJECT_ROOT" && $CARGO build --all --release
fi
40 changes: 13 additions & 27 deletions edgelet/build/linux/clippy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ DIR=$(cd "$(dirname "$0")" && pwd)
BUILD_REPOSITORY_LOCALPATH=${BUILD_REPOSITORY_LOCALPATH:-$DIR/../../..}
PROJECT_ROOT=${BUILD_REPOSITORY_LOCALPATH}/edgelet
SCRIPT_NAME=$(basename "$0")
TOOLCHAIN='stable'
RUSTUP="${CARGO_HOME:-"$HOME/.cargo"}/bin/rustup"
CARGO="${CARGO_HOME:-"$HOME/.cargo"}/bin/cargo"

Expand All @@ -37,41 +36,28 @@ function print_help_and_exit()
exit 1
}

function run_clippy()
{
echo "Running clippy..."
(cd $PROJECT_ROOT && $CARGO "+$TOOLCHAIN" clippy --all)
(cd $PROJECT_ROOT && $CARGO "+$TOOLCHAIN" clippy --all --tests)
(cd $PROJECT_ROOT && $CARGO "+$TOOLCHAIN" clippy --all --examples)
}

###############################################################################
# Obtain and validate the options supported by this script
###############################################################################
function process_args()
{
save_next_arg=0
for arg in "$@"
do
if [ $save_next_arg -eq 1 ]; then
save_next_arg=0
else
case "$arg" in
"-h" | "--help" ) usage;;
* ) usage;;
esac
fi
case "$arg" in
"-h" | "--help" ) usage;;
* ) usage;;
esac
done
}

process_args "$@"

if [[ $USE_DOCKER -eq 1 ]]; then
run_clippy_via_docker
else
echo "Installing $TOOLCHAIN toolchain"
$RUSTUP install "$TOOLCHAIN"
echo "Installing clippy..."
$RUSTUP component add clippy "--toolchain=$TOOLCHAIN"
run_clippy
fi
cd $PROJECT_ROOT

echo "Installing clippy..."
$RUSTUP component add clippy

echo "Running clippy..."
$CARGO clippy --all
$CARGO clippy --all --tests
$CARGO clippy --all --examples
62 changes: 0 additions & 62 deletions edgelet/build/linux/coverage.sh

This file was deleted.

12 changes: 6 additions & 6 deletions edgelet/build/linux/cross-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ DIR=$(cd "$(dirname "$0")" && pwd)
BUILD_REPOSITORY_LOCALPATH=${BUILD_REPOSITORY_LOCALPATH:-$DIR/../../..}
PROJECT_ROOT=${BUILD_REPOSITORY_LOCALPATH}/edgelet
SCRIPT_NAME=$(basename "$0")
TOOLCHAIN="armv7-unknown-linux-gnueabihf"
TARGET="armv7-unknown-linux-gnueabihf"
RELEASE=

###############################################################################
Expand All @@ -27,7 +27,7 @@ usage()
echo ""
echo "options"
echo " -h, --help Print this help and exit."
echo " -t, --toolchain Toolchain (default: stable-x86_64-unknown-linux-gnu)"
echo " -t, --target Target architecture"
echo " -r, --release Release build? (flag, default: false)"
exit 1;
}
Expand All @@ -41,15 +41,15 @@ process_args()
for arg in "$@"
do
if [ $save_next_arg -eq 1 ]; then
TOOLCHAIN="$arg"
TARGET="$arg"
save_next_arg=0
elif [ $save_next_arg -eq 2 ]; then
RELEASE="true"
save_next_arg=0
else
case "$arg" in
"-h" | "--help" ) usage;;
"-t" | "--toolchain" ) save_next_arg=1;;
"-t" | "--target" ) save_next_arg=1;;
"-r" | "--release" ) save_next_arg=2;;
* ) usage;;
esac
Expand All @@ -60,7 +60,7 @@ process_args()
process_args "$@"

if [[ -z ${RELEASE} ]]; then
cd "$PROJECT_ROOT" && IOTEDGE_HOMEDIR=/tmp cross test --all --target "$TOOLCHAIN"
cd "$PROJECT_ROOT" && IOTEDGE_HOMEDIR=/tmp cross test --all --target "$TARGET"
else
cd "$PROJECT_ROOT" && IOTEDGE_HOMEDIR=/tmp cross test --all --release --target "$TOOLCHAIN"
cd "$PROJECT_ROOT" && IOTEDGE_HOMEDIR=/tmp cross test --all --release --target "$TARGET"
fi
12 changes: 6 additions & 6 deletions edgelet/build/linux/cross.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ DIR=$(cd "$(dirname "$0")" && pwd)
BUILD_REPOSITORY_LOCALPATH=${BUILD_REPOSITORY_LOCALPATH:-$DIR/../../..}
PROJECT_ROOT=${BUILD_REPOSITORY_LOCALPATH}/edgelet
SCRIPT_NAME=$(basename "$0")
TOOLCHAIN="armv7-unknown-linux-gnueabihf"
TARGET="armv7-unknown-linux-gnueabihf"
RELEASE=

###############################################################################
Expand All @@ -27,7 +27,7 @@ usage()
echo ""
echo "options"
echo " -h, --help Print this help and exit."
echo " -t, --toolchain Toolchain (default: stable-x86_64-unknown-linux-gnu)"
echo " -t, --target Target architecture"
echo " -r, --release Release build? (flag, default: false)"
exit 1;
}
Expand All @@ -41,15 +41,15 @@ process_args()
for arg in "$@"
do
if [ $save_next_arg -eq 1 ]; then
TOOLCHAIN="$arg"
TARGET="$arg"
save_next_arg=0
elif [ $save_next_arg -eq 2 ]; then
RELEASE="true"
save_next_arg=0
else
case "$arg" in
"-h" | "--help" ) usage;;
"-t" | "--toolchain" ) save_next_arg=1;;
"-t" | "--target" ) save_next_arg=1;;
"-r" | "--release" ) save_next_arg=2;;
* ) usage;;
esac
Expand All @@ -60,7 +60,7 @@ process_args()
process_args "$@"

if [[ -z ${RELEASE} ]]; then
cd "$PROJECT_ROOT" && cross build --all --target "$TOOLCHAIN"
cd "$PROJECT_ROOT" && cross build --all --target "$TARGET"
else
cd "$PROJECT_ROOT" && cross build --all --release --target "$TOOLCHAIN"
cd "$PROJECT_ROOT" && cross build --all --release --target "$TARGET"
fi
8 changes: 4 additions & 4 deletions edgelet/build/linux/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ process_args()

process_args "$@"

cd $PROJECT_ROOT

echo "Installing rustfmt"
echo "$RUSTUP component add rustfmt-preview"
$RUSTUP component add rustfmt-preview
$RUSTUP component add rustfmt

echo "Running cargo fmt"
echo "cd $PROJECT_ROOT && $CARGO fmt --all -- --check"
cd $PROJECT_ROOT && $CARGO fmt --all -- --check
$CARGO fmt --all -- --check
Loading

0 comments on commit 2676621

Please sign in to comment.