@@ -4,7 +4,7 @@ use std::{env, str};
4
4
// List of cfgs this build script is allowed to set. The list is needed to support check-cfg, as we
5
5
// need to know all the possible cfgs that this script will set. If you need to set another cfg
6
6
// make sure to add it to this list as well.
7
- const ALLOWED_CFGS : & ' static [ & ' static str ] = & [
7
+ const ALLOWED_CFGS : & [ & str ] = & [
8
8
"emscripten_old_stat_abi" ,
9
9
"espidf_time32" ,
10
10
"freebsd10" ,
@@ -22,10 +22,11 @@ const ALLOWED_CFGS: &'static [&'static str] = &[
22
22
"libc_ctest" ,
23
23
// Corresponds to `__USE_TIME_BITS64` in UAPI
24
24
"linux_time_bits64" ,
25
+ "musl_v1_2_3" ,
25
26
] ;
26
27
27
28
// Extra values to allow for check-cfg.
28
- const CHECK_CFG_EXTRA : & ' static [ ( & ' static str , & ' static [ & ' static str ] ) ] = & [
29
+ const CHECK_CFG_EXTRA : & [ ( & str , & [ & str ] ) ] = & [
29
30
(
30
31
"target_os" ,
31
32
& [
@@ -89,6 +90,13 @@ fn main() {
89
90
_ => ( ) ,
90
91
}
91
92
93
+ let musl_v1_2_3 = env:: var ( "RUST_LIBC_UNSTABLE_MUSL_V1_2_3" ) . is_ok ( ) ;
94
+ println ! ( "cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_MUSL_V1_2_3" ) ;
95
+ // loongarch64 and ohos have already updated
96
+ if musl_v1_2_3 || target_os == "loongarch64" || target_env == "ohos" {
97
+ // FIXME(musl): enable time64 api as well
98
+ set_cfg ( "musl_v1_2_3" ) ;
99
+ }
92
100
let linux_time_bits64 = env:: var ( "RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64" ) . is_ok ( ) ;
93
101
println ! ( "cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64" ) ;
94
102
if linux_time_bits64 {
@@ -130,17 +138,17 @@ fn main() {
130
138
if rustc_minor_ver >= 80 {
131
139
for cfg in ALLOWED_CFGS {
132
140
if rustc_minor_ver >= 75 {
133
- println ! ( "cargo:rustc-check-cfg=cfg({})" , cfg ) ;
141
+ println ! ( "cargo:rustc-check-cfg=cfg({cfg })" ) ;
134
142
} else {
135
- println ! ( "cargo:rustc-check-cfg=values({})" , cfg ) ;
143
+ println ! ( "cargo:rustc-check-cfg=values({cfg })" ) ;
136
144
}
137
145
}
138
146
for & ( name, values) in CHECK_CFG_EXTRA {
139
147
let values = values. join ( "\" ,\" " ) ;
140
148
if rustc_minor_ver >= 75 {
141
- println ! ( "cargo:rustc-check-cfg=cfg({},values(\" {}\" ))" , name , values ) ;
149
+ println ! ( "cargo:rustc-check-cfg=cfg({name },values(\" {values }\" ))" ) ;
142
150
} else {
143
- println ! ( "cargo:rustc-check-cfg=values({},\" {}\" )" , name , values ) ;
151
+ println ! ( "cargo:rustc-check-cfg=values({name },\" {values }\" )" ) ;
144
152
}
145
153
}
146
154
}
@@ -169,12 +177,11 @@ fn rustc_version_cmd(is_clippy_driver: bool) -> Output {
169
177
170
178
let output = cmd. output ( ) . expect ( "Failed to get rustc version" ) ;
171
179
172
- if !output. status . success ( ) {
173
- panic ! (
174
- "failed to run rustc: {}" ,
175
- String :: from_utf8_lossy( output. stderr. as_slice( ) )
176
- ) ;
177
- }
180
+ assert ! (
181
+ output. status. success( ) ,
182
+ "failed to run rustc: {}" ,
183
+ String :: from_utf8_lossy( output. stderr. as_slice( ) )
184
+ ) ;
178
185
179
186
output
180
187
}
@@ -201,9 +208,11 @@ fn rustc_minor_nightly() -> (u32, bool) {
201
208
202
209
let mut pieces = version. split ( '.' ) ;
203
210
204
- if pieces. next ( ) != Some ( "rustc 1" ) {
205
- panic ! ( "Failed to get rustc version" ) ;
206
- }
211
+ assert_eq ! (
212
+ pieces. next( ) ,
213
+ Some ( "rustc 1" ) ,
214
+ "Failed to get rustc version"
215
+ ) ;
207
216
208
217
let minor = pieces. next ( ) ;
209
218
@@ -213,9 +222,9 @@ fn rustc_minor_nightly() -> (u32, bool) {
213
222
// since a nightly build should either come from CI
214
223
// or a git checkout
215
224
let nightly_raw = otry ! ( pieces. next( ) ) . split ( '-' ) . nth ( 1 ) ;
216
- let nightly = nightly_raw
217
- . map ( | raw| raw . starts_with ( "dev" ) || raw. starts_with ( "nightly" ) )
218
- . unwrap_or ( false ) ;
225
+ let nightly = nightly_raw. map_or ( false , |raw| {
226
+ raw. starts_with ( "dev" ) || raw. starts_with ( "nightly" )
227
+ } ) ;
219
228
let minor = otry ! ( otry!( minor) . parse( ) . ok( ) ) ;
220
229
221
230
( minor, nightly)
@@ -266,8 +275,9 @@ fn emcc_version_code() -> Option<u64> {
266
275
}
267
276
268
277
fn set_cfg ( cfg : & str ) {
269
- if !ALLOWED_CFGS . contains ( & cfg) {
270
- panic ! ( "trying to set cfg {}, but it is not in ALLOWED_CFGS" , cfg) ;
271
- }
272
- println ! ( "cargo:rustc-cfg={}" , cfg) ;
278
+ assert ! (
279
+ ALLOWED_CFGS . contains( & cfg) ,
280
+ "trying to set cfg {cfg}, but it is not in ALLOWED_CFGS" ,
281
+ ) ;
282
+ println ! ( "cargo:rustc-cfg={cfg}" ) ;
273
283
}
0 commit comments