@@ -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_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,14 +47,14 @@ fn main() {
4347 }
4448}
4549
46- fn run_build_and_check ( target : Option < & str > , args : & [ & str ] ) {
47- let paths = exec_cargo_with_args ( target , args ) ;
48- for path in paths {
49- println ! ( "Checking {}" , path . display ( ) ) ;
50- let archive = Archive :: from_path ( & path ) ;
51-
52- verify_no_duplicates ( & archive ) ;
53- verify_core_symbols ( & archive ) ;
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+ ) ;
5458 }
5559}
5660
@@ -68,15 +72,20 @@ fn host_target() -> String {
6872 . to_owned ( )
6973}
7074
75+ fn run_build_and_check ( target : & str , args : & [ & str ] ) {
76+ let paths = exec_cargo_with_args ( target, args) ;
77+ for path in paths {
78+ println ! ( "Checking {}" , path. display( ) ) ;
79+ let archive = Archive :: from_path ( & path) ;
80+
81+ verify_no_duplicates ( & archive) ;
82+ verify_core_symbols ( & archive) ;
83+ }
84+ }
85+
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