Skip to content

Commit 8b4868e

Browse files
celinvaloli-obk
authored andcommitted
Add custom toolchain section
I also made it a bit easier to override our scripts toolchain
1 parent dd70d31 commit 8b4868e

File tree

3 files changed

+72
-21
lines changed

3 files changed

+72
-21
lines changed

.github/scripts/run_own_tests.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
#!/usr/bin/env bash
22
# Execute our own set of tests using a local `compiletest` tool based on `ui_test`.
3+
# This will run cargo under the repository path and, by default, will run the toolchain
4+
# specified in the `rust-toolchain.toml` file.
35
set -e
46
set -u
57

68
# Where we will store the SMIR tools (Optional).
79
TOOLS_BIN="${TOOLS_BIN:-"/tmp/smir/bin"}"
810
# Assume we are inside SMIR repository
911
SMIR_PATH=$(git rev-parse --show-toplevel)
12+
REPO_TOOLCHAIN=$(rustup show active-toolchain | (read toolchain _; echo $toolchain))
13+
TOOLCHAIN="${TOOLCHAIN:-${REPO_TOOLCHAIN}}"
1014
export RUST_BACKTRACE=1
1115

1216
# Build stable_mir tools
1317
function build_smir_tools() {
14-
pushd "${SMIR_PATH}"
15-
cargo +nightly build -Z unstable-options --out-dir "${TOOLS_BIN}"
18+
echo "#### Build tools. Toolchain: ${TOOLCHAIN}"
19+
cargo +${TOOLCHAIN} build -Z unstable-options --out-dir "${TOOLS_BIN}"
1620
export PATH="${TOOLS_BIN}":"${PATH}"
1721
}
1822

@@ -37,5 +41,6 @@ function run_tests() {
3741
done
3842
}
3943

44+
pushd "${SMIR_PATH}" > /dev/null
4045
build_smir_tools
4146
run_tests

.github/scripts/run_rustc_tests.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ TOOLS_BIN="${TOOLS_BIN:-"/tmp/smir/bin"}"
1919
# Assume we are inside SMIR repository
2020
SMIR_PATH=$(git rev-parse --show-toplevel)
2121

22+
# Set the toolchain to be used in this script
23+
REPO_TOOLCHAIN=$(rustup show active-toolchain | (read toolchain _; echo $toolchain))
24+
TOOLCHAIN="${TOOLCHAIN:-${REPO_TOOLCHAIN}}"
25+
2226
# Build stable_mir tools
2327
function build_smir_tools() {
2428
pushd "${SMIR_PATH}"
25-
cargo +nightly build -Z unstable-options --out-dir "${TOOLS_BIN}"
29+
cargo +${TOOLCHAIN} build -Z unstable-options --out-dir "${TOOLS_BIN}"
2630
export PATH="${TOOLS_BIN}":"${PATH}"
2731
}
2832

@@ -32,7 +36,7 @@ function setup_rustc_repo() {
3236
mkdir -p "$(dirname ${RUST_REPO})"
3337
git clone -b master https://github.com/rust-lang/rust.git "${RUST_REPO}"
3438
pushd "${RUST_REPO}"
35-
commit="$(rustc +nightly -vV | awk '/^commit-hash/ { print $2 }')"
39+
commit="$(rustc +${TOOLCHAIN} -vV | awk '/^commit-hash/ { print $2 }')"
3640
git checkout ${commit}
3741
git submodule init -- "${RUST_REPO}/library/stdarch"
3842
git submodule update
@@ -56,9 +60,9 @@ function run_tests() {
5660
#"pretty pretty" -- 2 failing tests
5761
)
5862

59-
SYSROOT=$(rustc +nightly --print sysroot)
63+
SYSROOT=$(rustc +${TOOLCHAIN} --print sysroot)
6064
PY_PATH=$(type -P python3)
61-
HOST=$(rustc +nightly -vV | awk '/^host/ { print $2 }')
65+
HOST=$(rustc +${TOOLCHAIN} -vV | awk '/^host/ { print $2 }')
6266
FILE_CHECK="$(which FileCheck-12 || which FileCheck-13 || which FileCheck-14)"
6367

6468
for suite_cfg in "${SUITES[@]}"; do
@@ -68,7 +72,7 @@ function run_tests() {
6872
mode=${suite_pair[1]}
6973

7074
echo "#### Running suite: ${suite} mode: ${mode}"
71-
cargo +nightly run -p compiletest -- \
75+
cargo +${TOOLCHAIN} run -p compiletest -- \
7276
--compile-lib-path="${SYSROOT}/lib" \
7377
--run-lib-path="${SYSROOT}/lib"\
7478
--python="${PY_PATH}" \

dev/README.md

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
1-
# Development documentation
1+
# Developer documentation
22

33
This folder contains some documentation useful for the development of Stable MIR
44

5-
## Toolchain versions
6-
7-
Our CI currently run a nightly job that build and run our test suites against the latest nightly toolchain.
8-
This repository also contains a .toolchain file that specifies to use `nightly` channel.
9-
10-
However, if you already have the nightly toolchain installed, this will not update the toolchain to
11-
the latest nightly.
12-
You need to explicitly do that.
13-
14-
If you see some errors while compiling our tools, please ensure you have the latest nightly.
15-
You might also want to check [our nightly runs](https://github.com/rust-lang/project-stable-mir/actions/workflows/nightly.yml?query=branch%3Amain) to ensure they are not currently broken.
16-
If so, you can check what was the last successful nightly run, and use its nightly version.
17-
185
## Tools
196

207
We currently have two different tools that is used to help with testing StableMIR
@@ -77,3 +64,58 @@ We have a few different test suites for Stable MIR:
7764
These tests are run using `--smir-fixme`.
7865
- `sanity-checks`: Small examples that exercise some specific construct.
7966
These tests succeed if compilation and all smir checks succeed.
67+
68+
## Toolchain versions
69+
70+
Our CI currently run a nightly job that build and run our test suites against the latest nightly toolchain.
71+
This repository also contains a .toolchain file that specifies to use `nightly` channel.
72+
73+
However, if you already have the nightly toolchain installed, this will not update the toolchain to
74+
the latest nightly.
75+
You need to explicitly do that.
76+
77+
If you see some errors while compiling our tools, please ensure you have the latest nightly.
78+
You might also want to check [our nightly runs](https://github. com/rust-lang/project-stable-mir/actions/workflows/nightly.yml?query=branch%2Amain) to ensure they are not currently broken.
79+
If so, you can check what was the last successful nightly run, and use its nightly version.
80+
81+
### Custom toolchain
82+
83+
In order to run the tools and test suites using a local copy of `rustc`, do the following:
84+
1. Build stage 2 of the compiler.
85+
See [`rustc` build guide](https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html) for more details. E.g.:
86+
```shell
87+
git clone https://github.com/rust-lang/rust.git
88+
cd rust
89+
git checkout ${COMMIT_ID:?"Missing rustc commit id"}
90+
./configure --enable-extended --tools=src,rustfmt,cargo --enable-debug --set=llvm.download-ci-llvm=true
91+
./x.py build -i --stage 2
92+
```
93+
94+
2. Create a custom toolchain:
95+
```shell
96+
# This will create a toolchain named "local"
97+
# Set the TARGET variable, e.g.: x86_64-unknown-linux-gnu
98+
rustup toolchain link local build/${TARGET}/stage2
99+
cp build/${TARGET}/stage2-tools-bin/* build/${TARGET}/stage2/bin/
100+
```
101+
3. Override the current toolchain in your `project-stable-mir` repository.
102+
```shell
103+
cd ${SMIR_FOLDER}
104+
rustup override set local
105+
cargo clean
106+
cargo build
107+
```
108+
109+
By default, the build scripts will use the active toolchain for the project folder.
110+
If you run step 3, the scripts should already pick up the local toolchain.
111+
Additionally, you can also set the rust toolchain by setting the TOOLCHAIN environment variable.
112+
E.g.:
113+
```shell
114+
# Clean old build
115+
cargo clean
116+
117+
# Run test with local toolchain
118+
TOOLCHAIN=local ./.github/scripts/run_own_tests.sh
119+
```
120+
121+
Note: To remove the override created on step 3, run `rustup override unset` in the same folder.

0 commit comments

Comments
 (0)