Skip to content

symcheck: Make target a positional argument #968

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,26 @@ symcheck=(cargo run -p symbol-check --release)
[[ "$target" = "wasm"* ]] && symcheck+=(--features wasm)
symcheck+=(-- build-and-check)

"${symcheck[@]}" -p compiler_builtins --target "$target"
"${symcheck[@]}" -p compiler_builtins --target "$target" --release
"${symcheck[@]}" -p compiler_builtins --target "$target" --features c
"${symcheck[@]}" -p compiler_builtins --target "$target" --features c --release
"${symcheck[@]}" -p compiler_builtins --target "$target" --features no-asm
"${symcheck[@]}" -p compiler_builtins --target "$target" --features no-asm --release
"${symcheck[@]}" -p compiler_builtins --target "$target" --features no-f16-f128
"${symcheck[@]}" -p compiler_builtins --target "$target" --features no-f16-f128 --release
"${symcheck[@]}" "$target" -- -p compiler_builtins
"${symcheck[@]}" "$target" -- -p compiler_builtins --release
"${symcheck[@]}" "$target" -- -p compiler_builtins --features c
"${symcheck[@]}" "$target" -- -p compiler_builtins --features c --release
"${symcheck[@]}" "$target" -- -p compiler_builtins --features no-asm
"${symcheck[@]}" "$target" -- -p compiler_builtins --features no-asm --release
"${symcheck[@]}" "$target" -- -p compiler_builtins --features no-f16-f128
"${symcheck[@]}" "$target" -- -p compiler_builtins --features no-f16-f128 --release

run_intrinsics_test() {
args=(
--target "$target" --verbose \
--manifest-path builtins-test-intrinsics/Cargo.toml
)
args+=( "$@" )
build_args=(--verbose --manifest-path builtins-test-intrinsics/Cargo.toml)
build_args+=("$@")

# symcheck also checks the results of builtins-test-intrinsics
"${symcheck[@]}" "${args[@]}"
"${symcheck[@]}" "$target" -- "${build_args[@]}"

# FIXME: we get access violations on Windows, our entrypoint may need to
# be tweaked.
if [ "${BUILD_ONLY:-}" != "1" ] && ! [[ "$target" = *"windows"* ]]; then
cargo run "${args[@]}"
cargo run --target "$target" "${build_args[@]}"
fi
}

Expand Down
66 changes: 45 additions & 21 deletions crates/symbol-check/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ const CHECK_EXTENSIONS: &[Option<&str>] = &[Some("rlib"), Some("a"), Some("exe")

const USAGE: &str = "Usage:

symbol-check build-and-check CARGO_ARGS ...
symbol-check build-and-check [TARGET] -- CARGO_BUILD_ARGS ...

Cargo will get invoked with `CARGO_ARGS` and all output
Cargo will get invoked with `CARGO_ARGS` and the specified target. All output
`compiler_builtins*.rlib` files will be checked.

If TARGET is not specified, the host target is used.
";

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

match &args_ref[1..] {
["build-and-check", "--target", target, args @ ..] if !args.is_empty() => {
run_build_and_check(Some(target), args);
["build-and-check", target, "--", args @ ..] if !args.is_empty() => {
check_cargo_args(args);
run_build_and_check(target, args);
}
["build-and-check", args @ ..] if !args.is_empty() => {
run_build_and_check(None, args);
["build-and-check", "--", args @ ..] if !args.is_empty() => {
check_cargo_args(args);
run_build_and_check(&host_target(), args);
}
_ => {
println!("{USAGE}");
Expand All @@ -43,7 +47,18 @@ fn main() {
}
}

fn run_build_and_check(target: Option<&str>, args: &[&str]) {
/// Make sure `--target` isn't passed to avoid confusion (since it should be proivded only once,
/// positionally).
fn check_cargo_args(args: &[&str]) {
for arg in args {
assert!(
!arg.contains("--target"),
"target must be passed positionally. {USAGE}"
);
}
}

fn run_build_and_check(target: &str, args: &[&str]) {
let paths = exec_cargo_with_args(target, args);
for path in paths {
println!("Checking {}", path.display());
Expand All @@ -70,17 +85,16 @@ fn host_target() -> String {

/// Run `cargo build` with the provided additional arguments, collecting the list of created
/// libraries.
fn exec_cargo_with_args(target: Option<&str>, args: &[&str]) -> Vec<PathBuf> {
let mut host = String::new();
let target = target.unwrap_or_else(|| {
host = host_target();
host.as_str()
});

fn exec_cargo_with_args(target: &str, args: &[&str]) -> Vec<PathBuf> {
let mut cmd = Command::new("cargo");
cmd.args(["build", "--target", target, "--message-format=json"])
.args(args)
.stdout(Stdio::piped());
cmd.args([
"build",
"--target",
target,
"--message-format=json-diagnostic-rendered-ansi",
])
.args(args)
.stdout(Stdio::piped());

println!("running: {cmd:?}");
let mut child = cmd.spawn().expect("failed to launch Cargo");
Expand All @@ -91,11 +105,21 @@ fn exec_cargo_with_args(target: Option<&str>, args: &[&str]) -> Vec<PathBuf> {

for line in reader.lines() {
let line = line.expect("failed to read line");
println!("{line}"); // tee to stdout

// Select only steps that create files
let j: Value = serde_json::from_str(&line).expect("failed to deserialize");
if j["reason"] != "compiler-artifact" {
let reason = &j["reason"];

// Forward output that is meant to be user-facing
if reason == "compiler-message" {
println!("{}", j["message"]["rendered"].as_str().unwrap());
} else if reason == "build-finished" {
println!("build finshed. success: {}", j["success"]);
} else if reason == "build-script-executed" {
let pretty = serde_json::to_string_pretty(&j).unwrap();
println!("build script output: {pretty}",);
}

// Only interested in the artifact list now
if reason != "compiler-artifact" {
continue;
}

Expand Down