Skip to content

Commit 113c2b3

Browse files
committed
symcheck: Make target a positional argument
This makes it more obvious what we intend to check rather than looking for `--target`.
1 parent 245c676 commit 113c2b3

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

ci/run.sh

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,26 @@ symcheck=(cargo run -p symbol-check --release)
5454
[[ "$target" = "wasm"* ]] && symcheck+=(--features wasm)
5555
symcheck+=(-- build-and-check)
5656

57-
"${symcheck[@]}" -p compiler_builtins --target "$target"
58-
"${symcheck[@]}" -p compiler_builtins --target "$target" --release
59-
"${symcheck[@]}" -p compiler_builtins --target "$target" --features c
60-
"${symcheck[@]}" -p compiler_builtins --target "$target" --features c --release
61-
"${symcheck[@]}" -p compiler_builtins --target "$target" --features no-asm
62-
"${symcheck[@]}" -p compiler_builtins --target "$target" --features no-asm --release
63-
"${symcheck[@]}" -p compiler_builtins --target "$target" --features no-f16-f128
64-
"${symcheck[@]}" -p compiler_builtins --target "$target" --features no-f16-f128 --release
57+
"${symcheck[@]}" "$target" -- -p compiler_builtins
58+
"${symcheck[@]}" "$target" -- -p compiler_builtins --release
59+
"${symcheck[@]}" "$target" -- -p compiler_builtins --features c
60+
"${symcheck[@]}" "$target" -- -p compiler_builtins --features c --release
61+
"${symcheck[@]}" "$target" -- -p compiler_builtins --features no-asm
62+
"${symcheck[@]}" "$target" -- -p compiler_builtins --features no-asm --release
63+
"${symcheck[@]}" "$target" -- -p compiler_builtins --features no-f16-f128
64+
"${symcheck[@]}" "$target" -- -p compiler_builtins --features no-f16-f128 --release
6565

6666
run_intrinsics_test() {
67-
args=(
68-
--target "$target" --verbose \
69-
--manifest-path builtins-test-intrinsics/Cargo.toml
70-
)
71-
args+=( "$@" )
67+
cargo_args=(--verbose --manifest-path builtins-test-intrinsics/Cargo.toml)
68+
cargo_args+=("$@")
7269

7370
# symcheck also checks the results of builtins-test-intrinsics
74-
"${symcheck[@]}" "${args[@]}"
71+
"${symcheck[@]}" "$target" -- "${cargo_args[@]}"
7572

7673
# FIXME: we get access violations on Windows, our entrypoint may need to
7774
# be tweaked.
7875
if [ "${BUILD_ONLY:-}" != "1" ] && ! [[ "$target" = *"windows"* ]]; then
79-
cargo run "${args[@]}"
76+
cargo run --target "$target" "${cargo_args[@]}"
8077
fi
8178
}
8279

crates/symbol-check/src/main.rs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ const CHECK_EXTENSIONS: &[Option<&str>] = &[Some("rlib"), Some("a"), Some("exe")
1818

1919
const USAGE: &str = "Usage:
2020
21-
symbol-check build-and-check CARGO_ARGS ...
21+
symbol-check build-and-check [TARGET] -- CARGO_ARGS ...
2222
23-
Cargo will get invoked with `CARGO_ARGS` and all output
23+
Cargo will get invoked with `CARGO_ARGS` and the specified target. All output
2424
`compiler_builtins*.rlib` files will be checked.
25+
26+
If TARGET is not specified, the host target is used.
2527
";
2628

2729
fn main() {
@@ -30,11 +32,13 @@ fn main() {
3032
let args_ref = args.iter().map(String::as_str).collect::<Vec<_>>();
3133

3234
match &args_ref[1..] {
33-
["build-and-check", "--target", target, args @ ..] if !args.is_empty() => {
34-
run_build_and_check(Some(target), args);
35+
["build-and-check", target, "--", args @ ..] if !args.is_empty() => {
36+
check_cargo_args(args);
37+
run_build_and_check(target, args);
3538
}
36-
["build-and-check", args @ ..] if !args.is_empty() => {
37-
run_build_and_check(None, args);
39+
["build-and-check", "--", args @ ..] if !args.is_empty() => {
40+
check_cargo_args(args);
41+
run_build_and_check(&host_target(), args);
3842
}
3943
_ => {
4044
println!("{USAGE}");
@@ -43,7 +47,18 @@ fn main() {
4347
}
4448
}
4549

46-
fn run_build_and_check(target: Option<&str>, args: &[&str]) {
50+
/// Make sure `--target` isn't passed to avoid confusion (since it should be proivded only once,
51+
/// positionally).
52+
fn check_cargo_args(args: &[&str]) {
53+
for arg in args {
54+
assert!(
55+
!arg.contains("--target"),
56+
"target must be passed positionally. {USAGE}"
57+
);
58+
}
59+
}
60+
61+
fn run_build_and_check(target: &str, args: &[&str]) {
4762
let paths = exec_cargo_with_args(target, args);
4863
for path in paths {
4964
println!("Checking {}", path.display());
@@ -70,13 +85,7 @@ fn host_target() -> String {
7085

7186
/// Run `cargo build` with the provided additional arguments, collecting the list of created
7287
/// libraries.
73-
fn exec_cargo_with_args(target: Option<&str>, args: &[&str]) -> Vec<PathBuf> {
74-
let mut host = String::new();
75-
let target = target.unwrap_or_else(|| {
76-
host = host_target();
77-
host.as_str()
78-
});
79-
88+
fn exec_cargo_with_args(target: &str, args: &[&str]) -> Vec<PathBuf> {
8089
let mut cmd = Command::new("cargo");
8190
cmd.args(["build", "--target", target, "--message-format=json"])
8291
.args(args)

0 commit comments

Comments
 (0)