@@ -29,19 +29,19 @@ pub struct CompileAndLinkFlags {
29
29
/// Enum containing all the considered return value from the script
30
30
#[ derive( Debug , Clone , PartialEq , Eq ) ]
31
31
pub enum BuildScriptOutput {
32
- /// cargo:rustc-link-lib
32
+ /// cargo:: rustc-link-lib
33
33
LinkLib ( String ) ,
34
- /// cargo:rustc-link-search
34
+ /// cargo:: rustc-link-search
35
35
LinkSearch ( String ) ,
36
- /// cargo:rustc-cfg
36
+ /// cargo:: rustc-cfg
37
37
Cfg ( String ) ,
38
- /// cargo:rustc-flags
38
+ /// cargo:: rustc-flags
39
39
Flags ( String ) ,
40
- /// cargo:rustc-link-arg
40
+ /// cargo:: rustc-link-arg
41
41
LinkArg ( String ) ,
42
- /// cargo:rustc-env
42
+ /// cargo:: rustc-env
43
43
Env ( String ) ,
44
- /// cargo:VAR=VALUE
44
+ /// cargo:: VAR=VALUE
45
45
DepEnv ( String ) ,
46
46
}
47
47
@@ -50,7 +50,7 @@ impl BuildScriptOutput {
50
50
///
51
51
/// Examples
52
52
/// ```rust
53
- /// assert_eq!(BuildScriptOutput::new("cargo:rustc-link-lib=lib"), Some(BuildScriptOutput::LinkLib("lib".to_owned())));
53
+ /// assert_eq!(BuildScriptOutput::new("cargo:: rustc-link-lib=lib"), Some(BuildScriptOutput::LinkLib("lib".to_owned())));
54
54
/// ```
55
55
fn new ( line : & str ) -> Option < BuildScriptOutput > {
56
56
let split = line. splitn ( 2 , '=' ) . collect :: < Vec < _ > > ( ) ;
@@ -59,13 +59,18 @@ impl BuildScriptOutput {
59
59
return None ;
60
60
}
61
61
let param = split[ 1 ] . trim ( ) . to_owned ( ) ;
62
- let key_split = split[ 0 ] . splitn ( 2 , ':' ) . collect :: < Vec < _ > > ( ) ;
63
- if key_split. len ( ) <= 1 || key_split[ 0 ] != "cargo" {
64
- // Not a cargo directive.
65
- return None ;
66
- }
62
+ let cargo_instruction_name = {
63
+ if split[ 0 ] . starts_with ( "cargo::" ) {
64
+ & split[ 0 ] [ 7 ..]
65
+ } else if split[ 0 ] . starts_with ( "cargo:" ) {
66
+ & split[ 0 ] [ 6 ..]
67
+ } else {
68
+ // Not a cargo directive.
69
+ return None ;
70
+ }
71
+ } ;
67
72
68
- match key_split [ 1 ] {
73
+ match cargo_instruction_name {
69
74
"rustc-link-lib" => Some ( BuildScriptOutput :: LinkLib ( param) ) ,
70
75
"rustc-link-search" => Some ( BuildScriptOutput :: LinkSearch ( param) ) ,
71
76
"rustc-cfg" => Some ( BuildScriptOutput :: Cfg ( param) ) ,
@@ -82,20 +87,20 @@ impl BuildScriptOutput {
82
87
None
83
88
}
84
89
"rustc-cdylib-link-arg" | "rustc-link-arg-bin" | "rustc-link-arg-bins" => {
85
- // cargo:rustc-cdylib-link-arg=FLAG — Passes custom flags to a linker for cdylib crates.
86
- // cargo:rustc-link-arg-bin=BIN=FLAG – Passes custom flags to a linker for the binary BIN.
87
- // cargo:rustc-link-arg-bins=FLAG – Passes custom flags to a linker for binaries.
90
+ // cargo:: rustc-cdylib-link-arg=FLAG — Passes custom flags to a linker for cdylib crates.
91
+ // cargo:: rustc-link-arg-bin=BIN=FLAG – Passes custom flags to a linker for the binary BIN.
92
+ // cargo:: rustc-link-arg-bins=FLAG – Passes custom flags to a linker for binaries.
88
93
eprint ! (
89
94
"Warning: build script returned unsupported directive `{}`" ,
90
95
split[ 0 ]
91
96
) ;
92
97
None
93
98
}
94
99
_ => {
95
- // cargo:KEY=VALUE — Metadata, used by links scripts.
100
+ // cargo:: KEY=VALUE — Metadata, used by links scripts.
96
101
Some ( BuildScriptOutput :: DepEnv ( format ! (
97
102
"{}={}" ,
98
- key_split [ 1 ] . to_uppercase( ) . replace( '-' , "_" ) ,
103
+ cargo_instruction_name . to_uppercase( ) . replace( '-' , "_" ) ,
99
104
param
100
105
) ) )
101
106
}
@@ -230,24 +235,27 @@ mod tests {
230
235
fn test_from_read_buffer_to_env_and_flags ( ) {
231
236
let buff = Cursor :: new (
232
237
"
233
- cargo:rustc-link-lib=sdfsdf
234
- cargo:rustc-env=FOO=BAR
235
- cargo:rustc-link-search=/some/absolute/path/bleh
236
- cargo:rustc-env=BAR=FOO
237
- cargo:rustc-flags=-Lblah
238
- cargo:rerun-if-changed=ignored
239
- cargo:rustc-cfg=feature=awesome
240
- cargo:version=123
241
- cargo:version_number=1010107f
242
- cargo:include_path=/some/absolute/path/include
243
- cargo:rustc-env=SOME_PATH=/some/absolute/path/beep
244
- cargo:rustc-link-arg=-weak_framework
245
- cargo:rustc-link-arg=Metal
246
- cargo:rustc-env=no_trailing_newline=true" ,
238
+ cargo::rustc-link-lib=sdfsdf
239
+ cargo::rustc-env=FOO=BAR
240
+ cargo::rustc-link-search=/some/absolute/path/bleh
241
+ cargo::rustc-env=BAR=FOO
242
+ cargo::rustc-flags=-Lblah
243
+ cargo::rerun-if-changed=ignored
244
+ cargo::rustc-cfg=feature=awesome
245
+ cargo::version=123
246
+ cargo::version_number=1010107f
247
+ cargo::include_path=/some/absolute/path/include
248
+ cargo::rustc-env=SOME_PATH=/some/absolute/path/beep
249
+ cargo::rustc-link-arg=-weak_framework
250
+ cargo::rustc-link-arg=Metal
251
+ cargo::rustc-env=no_trailing_newline=true
252
+ non-cargo-prefixes::are-ignored=true
253
+ non-assignment-instructions-are-ignored
254
+ cargo:rustc-env=old_cargo_colon_prefix_works=true" ,
247
255
) ;
248
256
let reader = BufReader :: new ( buff) ;
249
257
let result = BuildScriptOutput :: outputs_from_reader ( reader) ;
250
- assert_eq ! ( result. len( ) , 13 ) ;
258
+ assert_eq ! ( result. len( ) , 14 ) ;
251
259
assert_eq ! ( result[ 0 ] , BuildScriptOutput :: LinkLib ( "sdfsdf" . to_owned( ) ) ) ;
252
260
assert_eq ! ( result[ 1 ] , BuildScriptOutput :: Env ( "FOO=BAR" . to_owned( ) ) ) ;
253
261
assert_eq ! (
@@ -281,13 +289,17 @@ cargo:rustc-env=no_trailing_newline=true",
281
289
result[ 12 ] ,
282
290
BuildScriptOutput :: Env ( "no_trailing_newline=true" . to_owned( ) )
283
291
) ;
292
+ assert_eq ! (
293
+ result[ 13 ] ,
294
+ BuildScriptOutput :: Env ( "old_cargo_colon_prefix_works=true" . to_owned( ) )
295
+ ) ;
284
296
assert_eq ! (
285
297
BuildScriptOutput :: outputs_to_dep_env( & result, "ssh2" , "/some/absolute/path" ) ,
286
298
"DEP_SSH2_VERSION=123\n DEP_SSH2_VERSION_NUMBER=1010107f\n DEP_SSH2_INCLUDE_PATH=${pwd}/include" . to_owned( )
287
299
) ;
288
300
assert_eq ! (
289
301
BuildScriptOutput :: outputs_to_env( & result, "/some/absolute/path" ) ,
290
- "FOO=BAR\n BAR=FOO\n SOME_PATH=${pwd}/beep\n no_trailing_newline=true" . to_owned( )
302
+ "FOO=BAR\n BAR=FOO\n SOME_PATH=${pwd}/beep\n no_trailing_newline=true\n old_cargo_colon_prefix_works=true " . to_owned( )
291
303
) ;
292
304
assert_eq ! (
293
305
BuildScriptOutput :: outputs_to_flags( & result, "/some/absolute/path" ) ,
@@ -307,9 +319,9 @@ cargo:rustc-env=no_trailing_newline=true",
307
319
fn invalid_utf8 ( ) {
308
320
let buff = Cursor :: new (
309
321
b"
310
- cargo:rustc-env=valid1=1
311
- cargo:rustc-env=invalid=\xc3 \x28
312
- cargo:rustc-env=valid2=2
322
+ cargo:: rustc-env=valid1=1
323
+ cargo:: rustc-env=invalid=\xc3 \x28
324
+ cargo:: rustc-env=valid2=2
313
325
" ,
314
326
) ;
315
327
let reader = BufReader :: new ( buff) ;
0 commit comments