Skip to content

Commit 0643c3b

Browse files
authored
Rollup merge of #128841 - lqd:rustc-args, r=onur-ozkan
bootstrap: don't use rustflags for `--rustc-args` r? `@onur-ozkan` This is going to require a bit of context. #47558 has added `--rustc-args` to `./x test` to allow passing flags when building `compiletest` tests. It was made specifically because using `RUSTFLAGS` would rebuild the compiler/stdlib, which would in turn require the flag you want to build tests with to successfully bootstrap. #113178 made the request that it also works for other tests and doctests. This is not trivial to support across the board for `library`/`compiler` unit-tests/doctests and across stages. This issue was closed in #113948 by using `RUSTFLAGS`, seemingly incorrectly since #123489 fixed that part to make it work. Unfortunately #123489/#113948 have regressed the goals of `--rustc-args`: - now we can't use rustc args that don't bootstrap, to run the UI tests: we can't test incomplete features. The new trait solver doesn't bootstrap, in-progress borrowck/polonius changes don't bootstrap, some other features are similarly incomplete, etc. - using the flag now rebuilds everything from scratch: stage0 stdlib, stage1 compiler, stage1 stdlib. You don't need to re-do all this to compile UI tests, you only need the latter to run stdlib tests with a new flag, etc. This happens for contributors, but also on CI today. (Not to mention that in doing that it will rebuild things with flags that are not meant to be used, e.g. stdlib cfgs that don't exist in the compiler; or you could also imagine that this silently enables flags that were not meant to be enabled in this way). Since then, bd71c71 has started using it to test a stdlib feature, relying on the fact that it now rebuilds everything. So #125011 also regressed CI times more than necessary because it rebuilds everything instead of just stage 1 stdlib. It's not easy for me to know how to properly fix #113178 in bootstrap, but #113948/#123489 are not it since they regress the initial intent. I'd think bootstrap would have to know from the list of test targets that are passed that the `library` or `compiler` paths that are passed could require rebuilding these crates with different rustflags, probably also depending on stages. Therefore I would not be able to fix it, and will just try in this PR to unregress the situation to unblock the initial use-case. It seems miri now also uses `./x miri --rustc-args` in this incorrect meaning to rebuild the `library` paths they support to run with the new args. I've not made any bootstrap changes related to `./x miri` in this PR, so `--rustc-args` wouldn't work there anymore. I'd assume this would need to use rustflags again but I don't know how to make that work properly in bootstrap, hence opening as draft, so you can tell me how to do that. I assume we don't want to break their use-case again now that it exists, even though there are ways to use `./x test` to do exactly that. `RUSTFLAGS_NOT_BOOTSTRAP=flag ./x test library/std` is a way to run unit tests with a new flag without rebuilding everything, while with #123489 there is no way anymore to run tests with a flag that doesn't bootstrap. --- edit: after review, this PR: - renames `./x test --rustc-args` to `./x test --compiletest-rustc-args` as it only applies there, and cannot use rustflags for this purpose. - fixes the regression that using these args rebuilt everything from scratch - speeds up some CI jobs via the above point - removes `./x miri --rustc-args` as only library tests are supported, needs to rebuild libstd, and `./x miri --compiletest-rustc-args` wouldn't work since compiletests are not supported.
2 parents 37b9567 + 2abfa35 commit 0643c3b

File tree

11 files changed

+24
-34
lines changed

11 files changed

+24
-34
lines changed

compiler/rustc_codegen_gcc/build_system/src/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ fn asm_tests(env: &Env, args: &TestArg) -> Result<(), String> {
552552
&"--stage",
553553
&"0",
554554
&"tests/assembly/asm",
555-
&"--rustc-args",
555+
&"--compiletest-rustc-args",
556556
&rustc_args,
557557
],
558558
Some(&rust_dir),
@@ -1020,7 +1020,7 @@ where
10201020
&"--stage",
10211021
&"0",
10221022
&format!("tests/{}", test_type),
1023-
&"--rustc-args",
1023+
&"--compiletest-rustc-args",
10241024
&rustc_args,
10251025
],
10261026
Some(&rust_path),

src/bootstrap/src/core/build_steps/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1817,7 +1817,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
18171817

18181818
let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
18191819
flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
1820-
flags.extend(builder.config.cmd.rustc_args().iter().map(|s| s.to_string()));
1820+
flags.extend(builder.config.cmd.compiletest_rustc_args().iter().map(|s| s.to_string()));
18211821

18221822
if suite != "mir-opt" {
18231823
if let Some(linker) = builder.linker(target) {

src/bootstrap/src/core/builder.rs

-5
Original file line numberDiff line numberDiff line change
@@ -2226,11 +2226,6 @@ impl<'a> Builder<'a> {
22262226
rustdocflags.arg("--cfg=parallel_compiler");
22272227
}
22282228

2229-
// Pass the value of `--rustc-args` from test command. If it's not a test command, this won't set anything.
2230-
self.config.cmd.rustc_args().iter().for_each(|v| {
2231-
rustflags.arg(v);
2232-
});
2233-
22342229
Cargo {
22352230
command: cargo,
22362231
compiler,

src/bootstrap/src/core/builder/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ mod dist {
633633
config.paths = vec!["library/std".into()];
634634
config.cmd = Subcommand::Test {
635635
test_args: vec![],
636-
rustc_args: vec![],
636+
compiletest_rustc_args: vec![],
637637
no_fail_fast: false,
638638
no_doc: true,
639639
doc: false,
@@ -704,7 +704,7 @@ mod dist {
704704
let mut config = configure(&["A-A"], &["A-A"]);
705705
config.cmd = Subcommand::Test {
706706
test_args: vec![],
707-
rustc_args: vec![],
707+
compiletest_rustc_args: vec![],
708708
no_fail_fast: false,
709709
doc: true,
710710
no_doc: false,

src/bootstrap/src/core/config/flags.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,9 @@ pub enum Subcommand {
357357
/// extra arguments to be passed for the test tool being used
358358
/// (e.g. libtest, compiletest or rustdoc)
359359
test_args: Vec<String>,
360-
/// extra options to pass the compiler when running tests
360+
/// extra options to pass the compiler when running compiletest tests
361361
#[arg(long, value_name = "ARGS", allow_hyphen_values(true))]
362-
rustc_args: Vec<String>,
362+
compiletest_rustc_args: Vec<String>,
363363
#[arg(long)]
364364
/// do not run doc tests
365365
no_doc: bool,
@@ -402,9 +402,6 @@ pub enum Subcommand {
402402
/// extra arguments to be passed for the test tool being used
403403
/// (e.g. libtest, compiletest or rustdoc)
404404
test_args: Vec<String>,
405-
/// extra options to pass the compiler when running tests
406-
#[arg(long, value_name = "ARGS", allow_hyphen_values(true))]
407-
rustc_args: Vec<String>,
408405
#[arg(long)]
409406
/// do not run doc tests
410407
no_doc: bool,
@@ -509,10 +506,10 @@ impl Subcommand {
509506
}
510507
}
511508

512-
pub fn rustc_args(&self) -> Vec<&str> {
509+
pub fn compiletest_rustc_args(&self) -> Vec<&str> {
513510
match *self {
514-
Subcommand::Test { ref rustc_args, .. } | Subcommand::Miri { ref rustc_args, .. } => {
515-
rustc_args.iter().flat_map(|s| s.split_whitespace()).collect()
511+
Subcommand::Test { ref compiletest_rustc_args, .. } => {
512+
compiletest_rustc_args.iter().flat_map(|s| s.split_whitespace()).collect()
516513
}
517514
_ => vec![],
518515
}

src/bootstrap/src/utils/change_tracker.rs

+5
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
225225
severity: ChangeSeverity::Info,
226226
summary: "New option `llvm.libzstd` to control whether llvm is built with zstd support.",
227227
},
228+
ChangeInfo {
229+
change_id: 128841,
230+
severity: ChangeSeverity::Warning,
231+
summary: "./x test --rustc-args was renamed to --compiletest-rustc-args as it only applies there. ./x miri --rustc-args was also removed.",
232+
},
228233
];

src/ci/docker/scripts/x86_64-gnu-llvm.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ if [[ -z "${PR_CI_JOB}" ]]; then
1818
# compiler, and is sensitive to the addition of new flags.
1919
../x.py --stage 1 test tests/ui-fulldeps
2020

21-
# The tests are run a second time with the size optimizations enabled.
22-
../x.py --stage 1 test library/std library/alloc library/core \
23-
--rustc-args "--cfg feature=\"optimize_for_size\""
21+
# Rebuild the stdlib with the size optimizations enabled and run tests again.
22+
RUSTFLAGS_NOT_BOOTSTRAP="--cfg feature=\"optimize_for_size\"" ../x.py --stage 1 test \
23+
library/std library/alloc library/core
2424
fi
2525

2626
# NOTE: intentionally uses all of `x.py`, `x`, and `x.ps1` to make sure they all work on Linux.

src/etc/completions/x.py.fish

+1-2
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ complete -c x.py -n "__fish_seen_subcommand_from doc" -l enable-bolt-settings -d
266266
complete -c x.py -n "__fish_seen_subcommand_from doc" -l skip-stage0-validation -d 'Skip stage0 compiler validation'
267267
complete -c x.py -n "__fish_seen_subcommand_from doc" -s h -l help -d 'Print help (see more with \'--help\')'
268268
complete -c x.py -n "__fish_seen_subcommand_from test" -l test-args -d 'extra arguments to be passed for the test tool being used (e.g. libtest, compiletest or rustdoc)' -r
269-
complete -c x.py -n "__fish_seen_subcommand_from test" -l rustc-args -d 'extra options to pass the compiler when running tests' -r
269+
complete -c x.py -n "__fish_seen_subcommand_from test" -l compiletest-rustc-args -d 'extra options to pass the compiler when running compiletest tests' -r
270270
complete -c x.py -n "__fish_seen_subcommand_from test" -l extra-checks -d 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell)' -r
271271
complete -c x.py -n "__fish_seen_subcommand_from test" -l compare-mode -d 'mode describing what file the actual ui output will be compared to' -r
272272
complete -c x.py -n "__fish_seen_subcommand_from test" -l pass -d 'force {check,build,run}-pass tests to this mode' -r
@@ -313,7 +313,6 @@ complete -c x.py -n "__fish_seen_subcommand_from test" -l enable-bolt-settings -
313313
complete -c x.py -n "__fish_seen_subcommand_from test" -l skip-stage0-validation -d 'Skip stage0 compiler validation'
314314
complete -c x.py -n "__fish_seen_subcommand_from test" -s h -l help -d 'Print help (see more with \'--help\')'
315315
complete -c x.py -n "__fish_seen_subcommand_from miri" -l test-args -d 'extra arguments to be passed for the test tool being used (e.g. libtest, compiletest or rustdoc)' -r
316-
complete -c x.py -n "__fish_seen_subcommand_from miri" -l rustc-args -d 'extra options to pass the compiler when running tests' -r
317316
complete -c x.py -n "__fish_seen_subcommand_from miri" -l config -d 'TOML configuration file for build' -r -F
318317
complete -c x.py -n "__fish_seen_subcommand_from miri" -l build-dir -d 'Build directory, overrides `build.build-dir` in `config.toml`' -r -f -a "(__fish_complete_directories)"
319318
complete -c x.py -n "__fish_seen_subcommand_from miri" -l build -d 'build target of the stage0 compiler' -r -f

src/etc/completions/x.py.ps1

+1-2
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ Register-ArgumentCompleter -Native -CommandName 'x.py' -ScriptBlock {
338338
}
339339
'x.py;test' {
340340
[CompletionResult]::new('--test-args', 'test-args', [CompletionResultType]::ParameterName, 'extra arguments to be passed for the test tool being used (e.g. libtest, compiletest or rustdoc)')
341-
[CompletionResult]::new('--rustc-args', 'rustc-args', [CompletionResultType]::ParameterName, 'extra options to pass the compiler when running tests')
341+
[CompletionResult]::new('--compiletest-rustc-args', 'compiletest-rustc-args', [CompletionResultType]::ParameterName, 'extra options to pass the compiler when running compiletest tests')
342342
[CompletionResult]::new('--extra-checks', 'extra-checks', [CompletionResultType]::ParameterName, 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell)')
343343
[CompletionResult]::new('--compare-mode', 'compare-mode', [CompletionResultType]::ParameterName, 'mode describing what file the actual ui output will be compared to')
344344
[CompletionResult]::new('--pass', 'pass', [CompletionResultType]::ParameterName, 'force {check,build,run}-pass tests to this mode')
@@ -392,7 +392,6 @@ Register-ArgumentCompleter -Native -CommandName 'x.py' -ScriptBlock {
392392
}
393393
'x.py;miri' {
394394
[CompletionResult]::new('--test-args', 'test-args', [CompletionResultType]::ParameterName, 'extra arguments to be passed for the test tool being used (e.g. libtest, compiletest or rustdoc)')
395-
[CompletionResult]::new('--rustc-args', 'rustc-args', [CompletionResultType]::ParameterName, 'extra options to pass the compiler when running tests')
396395
[CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'TOML configuration file for build')
397396
[CompletionResult]::new('--build-dir', 'build-dir', [CompletionResultType]::ParameterName, 'Build directory, overrides `build.build-dir` in `config.toml`')
398397
[CompletionResult]::new('--build', 'build', [CompletionResultType]::ParameterName, 'build target of the stage0 compiler')

src/etc/completions/x.py.sh

+3-7
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,7 @@ _x.py() {
13001300
return 0
13011301
;;
13021302
x.py__miri)
1303-
opts="-v -i -j -h --no-fail-fast --test-args --rustc-args --no-doc --doc --verbose --incremental --config --build-dir --build --host --target --exclude --skip --include-default-paths --rustc-error-format --on-fail --dry-run --dump-bootstrap-shims --stage --keep-stage --keep-stage-std --src --jobs --warnings --error-format --json-output --color --bypass-bootstrap-lock --llvm-skip-rebuild --rust-profile-generate --rust-profile-use --llvm-profile-use --llvm-profile-generate --enable-bolt-settings --skip-stage0-validation --reproducible-artifact --set --help [PATHS]... [ARGS]..."
1303+
opts="-v -i -j -h --no-fail-fast --test-args --no-doc --doc --verbose --incremental --config --build-dir --build --host --target --exclude --skip --include-default-paths --rustc-error-format --on-fail --dry-run --dump-bootstrap-shims --stage --keep-stage --keep-stage-std --src --jobs --warnings --error-format --json-output --color --bypass-bootstrap-lock --llvm-skip-rebuild --rust-profile-generate --rust-profile-use --llvm-profile-use --llvm-profile-generate --enable-bolt-settings --skip-stage0-validation --reproducible-artifact --set --help [PATHS]... [ARGS]..."
13041304
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
13051305
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
13061306
return 0
@@ -1310,10 +1310,6 @@ _x.py() {
13101310
COMPREPLY=($(compgen -f "${cur}"))
13111311
return 0
13121312
;;
1313-
--rustc-args)
1314-
COMPREPLY=($(compgen -f "${cur}"))
1315-
return 0
1316-
;;
13171313
--config)
13181314
COMPREPLY=($(compgen -f "${cur}"))
13191315
return 0
@@ -1862,7 +1858,7 @@ _x.py() {
18621858
return 0
18631859
;;
18641860
x.py__test)
1865-
opts="-v -i -j -h --no-fail-fast --test-args --rustc-args --no-doc --doc --bless --extra-checks --force-rerun --only-modified --compare-mode --pass --run --rustfix-coverage --verbose --incremental --config --build-dir --build --host --target --exclude --skip --include-default-paths --rustc-error-format --on-fail --dry-run --dump-bootstrap-shims --stage --keep-stage --keep-stage-std --src --jobs --warnings --error-format --json-output --color --bypass-bootstrap-lock --llvm-skip-rebuild --rust-profile-generate --rust-profile-use --llvm-profile-use --llvm-profile-generate --enable-bolt-settings --skip-stage0-validation --reproducible-artifact --set --help [PATHS]... [ARGS]..."
1861+
opts="-v -i -j -h --no-fail-fast --test-args --compiletest-rustc-args --no-doc --doc --bless --extra-checks --force-rerun --only-modified --compare-mode --pass --run --rustfix-coverage --verbose --incremental --config --build-dir --build --host --target --exclude --skip --include-default-paths --rustc-error-format --on-fail --dry-run --dump-bootstrap-shims --stage --keep-stage --keep-stage-std --src --jobs --warnings --error-format --json-output --color --bypass-bootstrap-lock --llvm-skip-rebuild --rust-profile-generate --rust-profile-use --llvm-profile-use --llvm-profile-generate --enable-bolt-settings --skip-stage0-validation --reproducible-artifact --set --help [PATHS]... [ARGS]..."
18661862
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
18671863
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
18681864
return 0
@@ -1872,7 +1868,7 @@ _x.py() {
18721868
COMPREPLY=($(compgen -f "${cur}"))
18731869
return 0
18741870
;;
1875-
--rustc-args)
1871+
--compiletest-rustc-args)
18761872
COMPREPLY=($(compgen -f "${cur}"))
18771873
return 0
18781874
;;

src/etc/completions/x.py.zsh

+1-2
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ _arguments "${_arguments_options[@]}" \
337337
(test)
338338
_arguments "${_arguments_options[@]}" \
339339
'*--test-args=[extra arguments to be passed for the test tool being used (e.g. libtest, compiletest or rustdoc)]:ARGS: ' \
340-
'*--rustc-args=[extra options to pass the compiler when running tests]:ARGS: ' \
340+
'*--compiletest-rustc-args=[extra options to pass the compiler when running compiletest tests]:ARGS: ' \
341341
'--extra-checks=[comma-separated list of other files types to check (accepts py, py\:lint, py\:fmt, shell)]:EXTRA_CHECKS: ' \
342342
'--compare-mode=[mode describing what file the actual ui output will be compared to]:COMPARE MODE: ' \
343343
'--pass=[force {check,build,run}-pass tests to this mode]:check | build | run: ' \
@@ -393,7 +393,6 @@ _arguments "${_arguments_options[@]}" \
393393
(miri)
394394
_arguments "${_arguments_options[@]}" \
395395
'*--test-args=[extra arguments to be passed for the test tool being used (e.g. libtest, compiletest or rustdoc)]:ARGS: ' \
396-
'*--rustc-args=[extra options to pass the compiler when running tests]:ARGS: ' \
397396
'--config=[TOML configuration file for build]:FILE:_files' \
398397
'--build-dir=[Build directory, overrides \`build.build-dir\` in \`config.toml\`]:DIR:_files -/' \
399398
'--build=[build target of the stage0 compiler]:BUILD:( )' \

0 commit comments

Comments
 (0)