File tree 2 files changed +42
-22
lines changed
2 files changed +42
-22
lines changed Original file line number Diff line number Diff line change @@ -599,29 +599,32 @@ impl BuildOutput {
599
599
}
600
600
"rustc-link-arg-bin" => {
601
601
if extra_link_arg {
602
- let parts = value. splitn ( 2 , "=" ) . collect :: < Vec < _ > > ( ) ;
603
- if parts. len ( ) == 2 {
604
- let bin_name = parts[ 0 ] . to_string ( ) ;
605
- if !targets
606
- . iter ( )
607
- . any ( |target| target. is_bin ( ) && target. name ( ) == bin_name)
608
- {
609
- bail ! (
610
- "invalid instruction `cargo:{}` from {}\n \
611
- The package {} does not have a bin target with the name `{}`.",
612
- key,
613
- whence,
614
- pkg_descr,
615
- bin_name
616
- ) ;
617
- }
618
- linker_args. push ( ( LinkType :: SingleBin ( bin_name) , parts[ 1 ] . to_string ( ) ) ) ;
619
- } else {
620
- warnings. push ( format ! (
621
- "cargo:{} has invalid syntax: expected `cargo:{}=BIN=ARG`" ,
622
- key, key
623
- ) ) ;
602
+ let mut parts = value. splitn ( 2 , '=' ) ;
603
+ let bin_name = parts. next ( ) . unwrap ( ) . to_string ( ) ;
604
+ let arg = parts. next ( ) . ok_or_else ( || {
605
+ anyhow:: format_err!(
606
+ "invalid instruction `cargo:{}={}` from {}\n \
607
+ The instruction should have the form cargo:{}=BIN=ARG",
608
+ key,
609
+ value,
610
+ whence,
611
+ key
612
+ )
613
+ } ) ?;
614
+ if !targets
615
+ . iter ( )
616
+ . any ( |target| target. is_bin ( ) && target. name ( ) == bin_name)
617
+ {
618
+ bail ! (
619
+ "invalid instruction `cargo:{}` from {}\n \
620
+ The package {} does not have a bin target with the name `{}`.",
621
+ key,
622
+ whence,
623
+ pkg_descr,
624
+ bin_name
625
+ ) ;
624
626
}
627
+ linker_args. push ( ( LinkType :: SingleBin ( bin_name) , arg. to_string ( ) ) ) ;
625
628
} else {
626
629
warnings. push ( format ! ( "cargo:{} requires -Zextra-link-arg flag" , key) ) ;
627
630
}
Original file line number Diff line number Diff line change @@ -162,6 +162,23 @@ The package foo v0.0.1 ([ROOT]/foo) does not have a bin target.
162
162
[COMPILING] foo [..]
163
163
error: invalid instruction `cargo:rustc-link-arg-bin` from build script of `foo v0.0.1 ([ROOT]/foo)`
164
164
The package foo v0.0.1 ([ROOT]/foo) does not have a bin target with the name `abc`.
165
+ " ,
166
+ )
167
+ . run ( ) ;
168
+
169
+ p. change_file (
170
+ "build.rs" ,
171
+ r#"fn main() { println!("cargo:rustc-link-arg-bin=abc"); }"# ,
172
+ ) ;
173
+
174
+ p. cargo ( "check -Zextra-link-arg" )
175
+ . masquerade_as_nightly_cargo ( )
176
+ . with_status ( 101 )
177
+ . with_stderr (
178
+ "\
179
+ [COMPILING] foo [..]
180
+ error: invalid instruction `cargo:rustc-link-arg-bin=abc` from build script of `foo v0.0.1 ([ROOT]/foo)`
181
+ The instruction should have the form cargo:rustc-link-arg-bin=BIN=ARG
165
182
" ,
166
183
)
167
184
. run ( ) ;
You can’t perform that action at this time.
0 commit comments