Skip to content

Commit cced03b

Browse files
committed
Auto merge of rust-lang#157007 - Kobzol:reject-invalid-backend, r=jieyouxu
Reject invalid codegen backends on CI The way we set codegen backends in CI jobs contained several bugs. 1) We didn't check if the specified codegen backend is valid. That can be useful in forks, but not on our CI, there it should be a loud error. 2) The codegen backends were specified with weird quoting that was (I think) producing invalid backends. 3) The specified backends in `RUST_CONFIGURE_ARGS` were being overridden due to `run.sh` setting codegen backends based on the `CODEGEN_BACKENDS` environment variable (see rust-lang#156989). This PR should fix all of these. After doing some CI runs on this PR, I realized that setting `CODEGEN_BACKENDS` from within the Dockerfile doesn't work, because we use `docker run --env CODEGEN_BACKENDS`, and that will unset the inner env even if the same env is not actually configured in the environment from where `docker run` is executed (sigh). So instead I decided to pass the env variables from `jobs.yml`. It's not really pretty, but it is a solution that should work with the current structure.
2 parents 8c1d720 + 69bb710 commit cced03b

5 files changed

Lines changed: 23 additions & 18 deletions

File tree

src/bootstrap/src/core/config/toml/rust.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! This module defines the `Rust` struct, which represents the `[rust]` table
22
//! in the `bootstrap.toml` configuration file.
33
4+
use build_helper::ci::CiEnv;
45
use serde::{Deserialize, Deserializer};
56

67
use crate::core::config::toml::TomlConfig;
@@ -422,6 +423,11 @@ pub(crate) fn parse_codegen_backends(
422423
)
423424
}
424425
if !BUILTIN_CODEGEN_BACKENDS.contains(&backend.as_str()) {
426+
if CiEnv::is_rust_lang_managed_ci_job() {
427+
eprintln!("Unknown codegen backend {backend}");
428+
exit!(1);
429+
}
430+
425431
println!(
426432
"HELP: '{backend}' for '{section}.codegen-backends' might fail. \
427433
List of known codegen backends: {BUILTIN_CODEGEN_BACKENDS:?}"

src/ci/docker/host-x86_64/x86_64-gnu-gcc-core-tests/Dockerfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# This Dockerfile builds sysroot crates with the GCC backend and then run libcore tests
2-
# with it.
1+
# This Dockerfile builds sysroot crates with the GCC backend and then runs
2+
# libcore tests with the GCC backend.
33

44
FROM ubuntu:22.04
55

@@ -40,8 +40,7 @@ ENV RUST_CONFIGURE_ARGS="--build=x86_64-unknown-linux-gnu \
4040
--enable-sanitizers \
4141
--enable-profiler \
4242
--enable-compiler-docs \
43-
--set llvm.libzstd=true \
44-
--set rust.codegen-backends=[\\\"gcc\\\"]"
43+
--set llvm.libzstd=true"
4544
ENV SCRIPT="python3 ../x.py \
4645
--stage 1 \
4746
test library/coretests \

src/ci/docker/host-x86_64/x86_64-gnu-gcc/Dockerfile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# This Dockerfile builds sysroot with the LLVM backendsthen run tests with the
2-
# GCC backend.
1+
# This Dockerfile builds sysroot with the LLVM backend and then runs tests
2+
# with the GCC backend.
33

44
FROM ubuntu:22.04
55

@@ -39,8 +39,7 @@ ENV RUST_CONFIGURE_ARGS="--build=x86_64-unknown-linux-gnu \
3939
--enable-sanitizers \
4040
--enable-profiler \
4141
--enable-compiler-docs \
42-
--set llvm.libzstd=true \
43-
--set rust.codegen-backends=[\\\"llvm\\\",\\\"gcc\\\"]"
42+
--set llvm.libzstd=true"
4443
ENV SCRIPT="python3 ../x.py \
4544
--stage 2 \
4645
test tests \
@@ -52,5 +51,4 @@ ENV SCRIPT="python3 ../x.py \
5251
--skip tests/rustdoc-js \
5352
--skip tests/rustdoc-js-std \
5453
--skip tests/rustdoc-json \
55-
--skip tests/rustdoc-ui \
56-
--set rust.codegen-backends=[\\\"llvm\\\",\\\"gcc\\\"]"
54+
--skip tests/rustdoc-ui"

src/ci/github-actions/jobs.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,13 @@ pr:
144144
<<: *job-linux-4c
145145
- name: x86_64-gnu-gcc
146146
doc_url: https://rustc-dev-guide.rust-lang.org/tests/codegen-backend-tests/cg_gcc.html
147+
env:
148+
CODEGEN_BACKENDS: llvm,gcc
147149
<<: *job-linux-4c
148150
- name: x86_64-gnu-gcc-core-tests
149151
doc_url: https://rustc-dev-guide.rust-lang.org/tests/codegen-backend-tests/cg_gcc.html
152+
env:
153+
CODEGEN_BACKENDS: gcc
150154
<<: *job-linux-4c
151155

152156
# Jobs that run when you perform a try build (@bors try)
@@ -361,14 +365,6 @@ auto:
361365
continue_on_error: true
362366
<<: *job-linux-4c
363367

364-
- name: x86_64-gnu-gcc
365-
doc_url: https://rustc-dev-guide.rust-lang.org/tests/codegen-backend-tests/cg_gcc.html
366-
<<: *job-linux-4c
367-
368-
- name: x86_64-gnu-gcc-core-tests
369-
doc_url: https://rustc-dev-guide.rust-lang.org/tests/codegen-backend-tests/cg_gcc.html
370-
<<: *job-linux-4c
371-
372368
# This job ensures commits landing on nightly still pass the full
373369
# test suite on the stable channel. There are some UI tests that
374370
# depend on the channel being built (for example if they include the

src/ci/run.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ if [ "$FORCE_CI_RUSTC" == "" ]; then
5858
DISABLE_CI_RUSTC_IF_INCOMPATIBLE=1
5959
fi
6060

61+
if [[ "$RUST_CONFIGURE_ARGS" == *"rust.codegen-backends"* ]]; then
62+
echo "error: Please specify codegen backends using the CODEGEN_BACKENDS environment variable, \
63+
not via RUST_CONFIGURE_ARGS."
64+
exit 1
65+
fi
66+
6167
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set build.print-step-timings --enable-verbose-tests"
6268
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set build.metrics"
6369
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-verbose-configure"

0 commit comments

Comments
 (0)