@@ -18,10 +18,12 @@ const CHECK_EXTENSIONS: &[Option<&str>] = &[Some("rlib"), Some("a"), Some("exe")
1818
1919const USAGE : & str = "Usage:
2020
21- symbol-check build-and-check CARGO_ARGS ...
21+ symbol-check build-and-check [TARGET] -- CARGO_BUILD_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
2729fn 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