@@ -4,7 +4,7 @@ use std::{env, str};
44// List of cfgs this build script is allowed to set. The list is needed to support check-cfg, as we
55// need to know all the possible cfgs that this script will set. If you need to set another cfg
66// make sure to add it to this list as well.
7- const ALLOWED_CFGS : & ' static [ & ' static str ] = & [
7+ const ALLOWED_CFGS : & [ & str ] = & [
88 "emscripten_old_stat_abi" ,
99 "espidf_time32" ,
1010 "freebsd10" ,
@@ -22,10 +22,11 @@ const ALLOWED_CFGS: &'static [&'static str] = &[
2222 "libc_ctest" ,
2323 // Corresponds to `__USE_TIME_BITS64` in UAPI
2424 "linux_time_bits64" ,
25+ "musl_v1_2_3" ,
2526] ;
2627
2728// 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 ] ) ] = & [
2930 (
3031 "target_os" ,
3132 & [
@@ -89,6 +90,13 @@ fn main() {
8990 _ => ( ) ,
9091 }
9192
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+ }
92100 let linux_time_bits64 = env:: var ( "RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64" ) . is_ok ( ) ;
93101 println ! ( "cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64" ) ;
94102 if linux_time_bits64 {
@@ -130,17 +138,17 @@ fn main() {
130138 if rustc_minor_ver >= 80 {
131139 for cfg in ALLOWED_CFGS {
132140 if rustc_minor_ver >= 75 {
133- println ! ( "cargo:rustc-check-cfg=cfg({})" , cfg ) ;
141+ println ! ( "cargo:rustc-check-cfg=cfg({cfg })" ) ;
134142 } else {
135- println ! ( "cargo:rustc-check-cfg=values({})" , cfg ) ;
143+ println ! ( "cargo:rustc-check-cfg=values({cfg })" ) ;
136144 }
137145 }
138146 for & ( name, values) in CHECK_CFG_EXTRA {
139147 let values = values. join ( "\" ,\" " ) ;
140148 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 }\" ))" ) ;
142150 } else {
143- println ! ( "cargo:rustc-check-cfg=values({},\" {}\" )" , name , values ) ;
151+ println ! ( "cargo:rustc-check-cfg=values({name },\" {values }\" )" ) ;
144152 }
145153 }
146154 }
@@ -169,12 +177,11 @@ fn rustc_version_cmd(is_clippy_driver: bool) -> Output {
169177
170178 let output = cmd. output ( ) . expect ( "Failed to get rustc version" ) ;
171179
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+ ) ;
178185
179186 output
180187}
@@ -201,9 +208,11 @@ fn rustc_minor_nightly() -> (u32, bool) {
201208
202209 let mut pieces = version. split ( '.' ) ;
203210
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+ ) ;
207216
208217 let minor = pieces. next ( ) ;
209218
@@ -213,9 +222,9 @@ fn rustc_minor_nightly() -> (u32, bool) {
213222 // since a nightly build should either come from CI
214223 // or a git checkout
215224 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+ } ) ;
219228 let minor = otry ! ( otry!( minor) . parse( ) . ok( ) ) ;
220229
221230 ( minor, nightly)
@@ -266,8 +275,9 @@ fn emcc_version_code() -> Option<u64> {
266275}
267276
268277fn 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}" ) ;
273283}
0 commit comments