@@ -50,23 +50,23 @@ fn do_cc() {
50
50
51
51
fn do_ctest ( ) {
52
52
match & env:: var ( "TARGET" ) . unwrap ( ) {
53
- t if t. contains ( "android" ) => test_android ( t) ,
54
- t if t. contains ( "apple" ) => test_apple ( t) ,
55
- t if t. contains ( "dragonfly" ) => test_dragonflybsd ( t) ,
56
- t if t. contains ( "emscripten" ) => test_emscripten ( t) ,
57
- t if t. contains ( "freebsd" ) => test_freebsd ( t) ,
58
- t if t. contains ( "haiku" ) => test_haiku ( t) ,
59
- t if t. contains ( "linux" ) => test_linux ( t) ,
60
- t if t. contains ( "netbsd" ) => test_netbsd ( t) ,
61
- t if t. contains ( "openbsd" ) => test_openbsd ( t) ,
62
- t if t. contains ( "cygwin" ) => test_cygwin ( t) ,
63
- t if t. contains ( "redox" ) => test_redox ( t) ,
64
- t if t. contains ( "solaris" ) => test_solarish ( t) ,
65
- t if t. contains ( "illumos" ) => test_solarish ( t) ,
66
- t if t. contains ( "wasi" ) => test_wasi ( t) ,
67
- t if t. contains ( "windows" ) => test_windows ( t) ,
68
- t if t. contains ( "vxworks" ) => test_vxworks ( t) ,
69
- t if t. contains ( "nto-qnx" ) => test_neutrino ( t) ,
53
+ t if t. contains ( "android" ) => return test_android ( t) ,
54
+ t if t. contains ( "apple" ) => return test_apple ( t) ,
55
+ t if t. contains ( "dragonfly" ) => return test_dragonflybsd ( t) ,
56
+ t if t. contains ( "emscripten" ) => return test_emscripten ( t) ,
57
+ t if t. contains ( "freebsd" ) => return test_freebsd ( t) ,
58
+ t if t. contains ( "haiku" ) => return test_haiku ( t) ,
59
+ t if t. contains ( "linux" ) => return test_linux ( t) ,
60
+ t if t. contains ( "netbsd" ) => return test_netbsd ( t) ,
61
+ t if t. contains ( "openbsd" ) => return test_openbsd ( t) ,
62
+ t if t. contains ( "cygwin" ) => return test_cygwin ( t) ,
63
+ t if t. contains ( "redox" ) => return test_redox ( t) ,
64
+ t if t. contains ( "solaris" ) => return test_solarish ( t) ,
65
+ t if t. contains ( "illumos" ) => return test_solarish ( t) ,
66
+ t if t. contains ( "wasi" ) => return test_wasi ( t) ,
67
+ t if t. contains ( "windows" ) => return test_windows ( t) ,
68
+ t if t. contains ( "vxworks" ) => return test_vxworks ( t) ,
69
+ t if t. contains ( "nto-qnx" ) => return test_neutrino ( t) ,
70
70
t => panic ! ( "unknown target {t}" ) ,
71
71
}
72
72
}
@@ -104,7 +104,7 @@ fn do_semver() {
104
104
process_semver_file ( & mut output, & mut semver_root, & os) ;
105
105
let os_arch = format ! ( "{os}-{arch}" ) ;
106
106
process_semver_file ( & mut output, & mut semver_root, & os_arch) ;
107
- if ! target_env. is_empty ( ) {
107
+ if target_env != "" {
108
108
let os_env = format ! ( "{os}-{target_env}" ) ;
109
109
process_semver_file ( & mut output, & mut semver_root, & os_env) ;
110
110
@@ -129,21 +129,21 @@ fn process_semver_file<W: Write, P: AsRef<Path>>(output: &mut W, path: &mut Path
129
129
} ;
130
130
let input = BufReader :: new ( input_file) ;
131
131
132
- writeln ! ( output, "// Source: {}." , path. display( ) ) . unwrap ( ) ;
133
- output. write_all ( b"use libc::{\n " ) . unwrap ( ) ;
132
+ write ! ( output, "// Source: {}.\n " , path. display( ) ) . unwrap ( ) ;
133
+ output. write ( b"use libc::{\n " ) . unwrap ( ) ;
134
134
for line in input. lines ( ) {
135
135
let line = line. unwrap ( ) . into_bytes ( ) ;
136
136
match line. first ( ) {
137
137
// Ignore comments and empty lines.
138
138
Some ( b'#' ) | None => continue ,
139
139
_ => {
140
- output. write_all ( b" " ) . unwrap ( ) ;
141
- output. write_all ( & line) . unwrap ( ) ;
142
- output. write_all ( b",\n " ) . unwrap ( ) ;
140
+ output. write ( b" " ) . unwrap ( ) ;
141
+ output. write ( & line) . unwrap ( ) ;
142
+ output. write ( b",\n " ) . unwrap ( ) ;
143
143
}
144
144
}
145
145
}
146
- output. write_all ( b"};\n \n " ) . unwrap ( ) ;
146
+ output. write ( b"};\n \n " ) . unwrap ( ) ;
147
147
path. pop ( ) ;
148
148
}
149
149
@@ -158,21 +158,21 @@ fn main() {
158
158
159
159
// FIXME(ctest): ctest cannot parse `crate::` in paths, so replace them with `::`
160
160
let re = regex:: bytes:: Regex :: new ( r"(?-u:\b)crate::" ) . unwrap ( ) ;
161
- copy_dir_hotfix ( Path :: new ( "../src" ) , & hotfix_dir, & re) ;
161
+ copy_dir_hotfix ( Path :: new ( "../src" ) , & hotfix_dir, & re, b"::" ) ;
162
162
163
163
do_cc ( ) ;
164
164
do_ctest ( ) ;
165
165
do_semver ( ) ;
166
166
}
167
167
168
- fn copy_dir_hotfix ( src : & Path , dst : & Path , regex : & regex:: bytes:: Regex ) {
169
- std:: fs:: create_dir ( dst) . unwrap ( ) ;
168
+ fn copy_dir_hotfix ( src : & Path , dst : & Path , regex : & regex:: bytes:: Regex , replace : & [ u8 ] ) {
169
+ std:: fs:: create_dir ( & dst) . unwrap ( ) ;
170
170
for entry in src. read_dir ( ) . unwrap ( ) {
171
171
let entry = entry. unwrap ( ) ;
172
172
let src_path = entry. path ( ) ;
173
173
let dst_path = dst. join ( entry. file_name ( ) ) ;
174
174
if entry. file_type ( ) . unwrap ( ) . is_dir ( ) {
175
- copy_dir_hotfix ( & src_path, & dst_path, regex) ;
175
+ copy_dir_hotfix ( & src_path, & dst_path, regex, replace ) ;
176
176
} else {
177
177
// Replace "crate::" with "::"
178
178
let src_data = std:: fs:: read ( & src_path) . unwrap ( ) ;
@@ -433,7 +433,10 @@ fn test_apple(target: &str) {
433
433
434
434
cfg. volatile_item ( |i| {
435
435
use ctest:: VolatileItemKind :: * ;
436
- matches ! ( i, StructField ( ref n, ref f) if n == "aiocb" && f == "aio_buf" )
436
+ match i {
437
+ StructField ( ref n, ref f) if n == "aiocb" && f == "aio_buf" => true ,
438
+ _ => false ,
439
+ }
437
440
} ) ;
438
441
439
442
cfg. type_name ( move |ty, is_struct, is_union| {
@@ -709,7 +712,7 @@ fn test_cygwin(target: &str) {
709
712
t if t. ends_with ( "_t" ) => t. to_string ( ) ,
710
713
711
714
// sigval is a struct in Rust, but a union in C:
712
- "sigval" => "union sigval" . to_string ( ) ,
715
+ "sigval" => format ! ( "union sigval" ) ,
713
716
714
717
// put `struct` in front of all structs:.
715
718
t if is_struct => format ! ( "struct {t}" ) ,
@@ -910,7 +913,10 @@ fn test_windows(target: &str) {
910
913
}
911
914
} ) ;
912
915
913
- cfg. skip_field ( |s, field| s == "CONTEXT" && field == "Fp" ) ;
916
+ cfg. skip_field ( move |s, field| match s {
917
+ "CONTEXT" if field == "Fp" => true ,
918
+ _ => false ,
919
+ } ) ;
914
920
// FIXME(windows): All functions point to the wrong addresses?
915
921
cfg. skip_fn_ptrcheck ( |_| true ) ;
916
922
@@ -1096,7 +1102,10 @@ fn test_solarish(target: &str) {
1096
1102
}
1097
1103
}
1098
1104
1099
- cfg. skip_type ( |ty| ty == "sighandler_t" ) ;
1105
+ cfg. skip_type ( move |ty| match ty {
1106
+ "sighandler_t" => true ,
1107
+ _ => false ,
1108
+ } ) ;
1100
1109
1101
1110
cfg. type_name ( move |ty, is_struct, is_union| match ty {
1102
1111
"FILE" => "__FILE" . to_string ( ) ,
@@ -1440,7 +1449,6 @@ fn test_netbsd(target: &str) {
1440
1449
} ) ;
1441
1450
1442
1451
cfg. skip_fn ( move |name| {
1443
- #[ expect( clippy:: wildcard_in_or_patterns) ]
1444
1452
match name {
1445
1453
// FIXME(netbsd): netbsd 10 minimum
1446
1454
"getentropy" | "getrandom" => true ,
@@ -1589,7 +1597,7 @@ fn test_dragonflybsd(target: &str) {
1589
1597
t if t. ends_with ( "_t" ) => t. to_string ( ) ,
1590
1598
1591
1599
// sigval is a struct in Rust, but a union in C:
1592
- "sigval" => "union sigval" . to_string ( ) ,
1600
+ "sigval" => format ! ( "union sigval" ) ,
1593
1601
1594
1602
// put `struct` in front of all structs:.
1595
1603
t if is_struct => format ! ( "struct {t}" ) ,
@@ -1976,7 +1984,7 @@ fn test_android(target: &str) {
1976
1984
t if t. ends_with ( "_t" ) => t. to_string ( ) ,
1977
1985
1978
1986
// sigval is a struct in Rust, but a union in C:
1979
- "sigval" => "union sigval" . to_string ( ) ,
1987
+ "sigval" => format ! ( "union sigval" ) ,
1980
1988
1981
1989
// put `struct` in front of all structs:.
1982
1990
t if is_struct => format ! ( "struct {t}" ) ,
@@ -2338,9 +2346,18 @@ fn test_freebsd(target: &str) {
2338
2346
// Required for making freebsd11_stat available in the headers
2339
2347
cfg. define ( "_WANT_FREEBSD11_STAT" , None ) ;
2340
2348
2341
- let freebsd13 = matches ! ( freebsd_ver, Some ( n) if n >= 13 ) ;
2342
- let freebsd14 = matches ! ( freebsd_ver, Some ( n) if n >= 14 ) ;
2343
- let freebsd15 = matches ! ( freebsd_ver, Some ( n) if n >= 15 ) ;
2349
+ let freebsd13 = match freebsd_ver {
2350
+ Some ( n) if n >= 13 => true ,
2351
+ _ => false ,
2352
+ } ;
2353
+ let freebsd14 = match freebsd_ver {
2354
+ Some ( n) if n >= 14 => true ,
2355
+ _ => false ,
2356
+ } ;
2357
+ let freebsd15 = match freebsd_ver {
2358
+ Some ( n) if n >= 15 => true ,
2359
+ _ => false ,
2360
+ } ;
2344
2361
2345
2362
headers ! { cfg:
2346
2363
"aio.h" ,
@@ -2483,7 +2500,7 @@ fn test_freebsd(target: &str) {
2483
2500
t if t. ends_with ( "_t" ) => t. to_string ( ) ,
2484
2501
2485
2502
// sigval is a struct in Rust, but a union in C:
2486
- "sigval" => "union sigval" . to_string ( ) ,
2503
+ "sigval" => format ! ( "union sigval" ) ,
2487
2504
2488
2505
// put `struct` in front of all structs:.
2489
2506
t if is_struct => format ! ( "struct {t}" ) ,
@@ -3220,7 +3237,7 @@ fn test_neutrino(target: &str) {
3220
3237
3221
3238
let mut cfg = ctest_cfg ( ) ;
3222
3239
if target. ends_with ( "_iosock" ) {
3223
- let qnx_target_val = env:: var ( "QNX_TARGET" )
3240
+ let qnx_target_val = std :: env:: var ( "QNX_TARGET" )
3224
3241
. unwrap_or_else ( |_| "QNX_TARGET_not_set_please_source_qnxsdp" . into ( ) ) ;
3225
3242
3226
3243
cfg. include ( qnx_target_val + "/usr/include/io-sock" ) ;
@@ -3467,17 +3484,17 @@ fn test_neutrino(target: &str) {
3467
3484
struct_ == "_idle_hook" && field == "time"
3468
3485
} ) ;
3469
3486
3470
- cfg. skip_field ( |struct_, field| {
3471
- matches ! (
3472
- ( struct_ , field) ,
3473
- ( "__sched_param" , "reserved" )
3474
- | ( "sched_param" , "reserved" )
3475
- | ( "sigevent" , "__padding1 ") // ensure alignment
3476
- | ( "sigevent" , "__padding2" ) // union
3477
- | ( "sigevent" , "__sigev_un2 ") // union
3478
- | ( "sigaction" , "sa_sigaction" ) // sighandler_t type is super weird
3479
- | ( "syspage_entry" , "__reserved" ) // does not exist
3480
- )
3487
+ cfg. skip_field ( move |struct_, field| {
3488
+ ( struct_ == "__sched_param" && field == "reserved" ) ||
3489
+ ( struct_ == "sched_param" && field == "reserved" ) ||
3490
+ ( struct_ == "sigevent" && field == "__padding1" ) || // ensure alignment
3491
+ ( struct_ == "sigevent" && field == "__padding2" ) || // union
3492
+ ( struct_ == "sigevent" && field == "__sigev_un2 ") || // union
3493
+ // sighandler_t type is super weird
3494
+ ( struct_ == "sigaction" && field == "sa_sigaction ") ||
3495
+ // does not exist
3496
+ ( struct_ == "syspage_entry" && field == "__reserved" ) ||
3497
+ false // keep me for smaller diffs when something is added above
3481
3498
} ) ;
3482
3499
3483
3500
cfg. skip_static ( move |name| ( name == "__dso_handle" ) ) ;
@@ -3557,16 +3574,19 @@ fn test_vxworks(target: &str) {
3557
3574
_ => false ,
3558
3575
} ) ;
3559
3576
// FIXME(vxworks)
3560
- cfg. skip_type ( |ty| matches ! ( ty, "stat64" | "sighandler_t" | "off64_t" ) ) ;
3577
+ cfg. skip_type ( move |ty| match ty {
3578
+ "stat64" | "sighandler_t" | "off64_t" => true ,
3579
+ _ => false ,
3580
+ } ) ;
3561
3581
3562
- cfg. skip_field_type ( |struct_, field| {
3563
- matches ! (
3564
- ( struct_, field) ,
3565
- ( "siginfo_t" , "si_value" ) | ( "stat" , "st_size" ) | ( "sigaction" , "sa_u" )
3566
- )
3582
+ cfg. skip_field_type ( move |struct_, field| match ( struct_, field) {
3583
+ ( "siginfo_t" , "si_value" ) | ( "stat" , "st_size" ) | ( "sigaction" , "sa_u" ) => true ,
3584
+ _ => false ,
3567
3585
} ) ;
3568
3586
3569
- cfg. skip_roundtrip ( |_| false ) ;
3587
+ cfg. skip_roundtrip ( move |s| match s {
3588
+ _ => false ,
3589
+ } ) ;
3570
3590
3571
3591
cfg. type_name ( move |ty, is_struct, is_union| match ty {
3572
3592
"DIR" | "FILE" | "Dl_info" | "RTP_DESC" => ty. to_string ( ) ,
@@ -4822,9 +4842,12 @@ fn test_linux_like_apis(target: &str) {
4822
4842
cfg. skip_type ( |_| true ) . skip_static ( |_| true ) ;
4823
4843
4824
4844
headers ! { cfg: "string.h" }
4825
- cfg. skip_fn ( |f| f != "strerror_r" )
4826
- . skip_const ( |_| true )
4827
- . skip_struct ( |_| true ) ;
4845
+ cfg. skip_fn ( |f| match f {
4846
+ "strerror_r" => false ,
4847
+ _ => true ,
4848
+ } )
4849
+ . skip_const ( |_| true )
4850
+ . skip_struct ( |_| true ) ;
4828
4851
cfg. generate ( src_hotfix_dir ( ) . join ( "lib.rs" ) , "linux_strerror_r.rs" ) ;
4829
4852
}
4830
4853
@@ -4868,11 +4891,10 @@ fn test_linux_like_apis(target: &str) {
4868
4891
cfg. skip_type ( |_| true )
4869
4892
. skip_static ( |_| true )
4870
4893
. skip_fn ( |_| true )
4871
- . skip_const ( |c| {
4872
- !matches ! (
4873
- c,
4874
- "BOTHER" | "IBSHIFT" | "TCGETS2" | "TCSETS2" | "TCSETSW2" | "TCSETSF2"
4875
- )
4894
+ . skip_const ( |c| match c {
4895
+ "BOTHER" | "IBSHIFT" => false ,
4896
+ "TCGETS2" | "TCSETS2" | "TCSETSW2" | "TCSETSF2" => false ,
4897
+ _ => true ,
4876
4898
} )
4877
4899
. skip_struct ( |s| s != "termios2" )
4878
4900
. type_name ( move |ty, is_struct, is_union| match ty {
@@ -4898,15 +4920,13 @@ fn test_linux_like_apis(target: &str) {
4898
4920
. skip_fn ( |_| true )
4899
4921
. skip_const ( |_| true )
4900
4922
. skip_struct ( |_| true )
4901
- . skip_const ( |name| {
4902
- !matches ! (
4903
- name,
4904
- "IPV6_FLOWINFO"
4905
- | "IPV6_FLOWLABEL_MGR"
4906
- | "IPV6_FLOWINFO_SEND"
4907
- | "IPV6_FLOWINFO_FLOWLABEL"
4908
- | "IPV6_FLOWINFO_PRIORITY"
4909
- )
4923
+ . skip_const ( move |name| match name {
4924
+ "IPV6_FLOWINFO"
4925
+ | "IPV6_FLOWLABEL_MGR"
4926
+ | "IPV6_FLOWINFO_SEND"
4927
+ | "IPV6_FLOWINFO_FLOWLABEL"
4928
+ | "IPV6_FLOWINFO_PRIORITY" => false ,
4929
+ _ => true ,
4910
4930
} )
4911
4931
. type_name ( move |ty, is_struct, is_union| match ty {
4912
4932
t if is_struct => format ! ( "struct {t}" ) ,
@@ -4928,8 +4948,14 @@ fn test_linux_like_apis(target: &str) {
4928
4948
. skip_static ( |_| true )
4929
4949
. skip_const ( |_| true )
4930
4950
. type_name ( move |ty, _is_struct, _is_union| ty. to_string ( ) )
4931
- . skip_struct ( |ty| !matches ! ( ty, "Elf64_Phdr" | "Elf32_Phdr" ) )
4932
- . skip_type ( |ty| !matches ! ( ty, "Elf64_Phdr" | "Elf32_Phdr" ) ) ;
4951
+ . skip_struct ( move |ty| match ty {
4952
+ "Elf64_Phdr" | "Elf32_Phdr" => false ,
4953
+ _ => true ,
4954
+ } )
4955
+ . skip_type ( move |ty| match ty {
4956
+ "Elf64_Phdr" | "Elf32_Phdr" => false ,
4957
+ _ => true ,
4958
+ } ) ;
4933
4959
cfg. generate ( src_hotfix_dir ( ) . join ( "lib.rs" ) , "linux_elf.rs" ) ;
4934
4960
}
4935
4961
@@ -4940,7 +4966,10 @@ fn test_linux_like_apis(target: &str) {
4940
4966
cfg. header ( "linux/if_arp.h" ) ;
4941
4967
cfg. skip_fn ( |_| true )
4942
4968
. skip_static ( |_| true )
4943
- . skip_const ( |name| name != "ARPHRD_CAN" )
4969
+ . skip_const ( move |name| match name {
4970
+ "ARPHRD_CAN" => false ,
4971
+ _ => true ,
4972
+ } )
4944
4973
. skip_struct ( |_| true )
4945
4974
. skip_type ( |_| true ) ;
4946
4975
cfg. generate ( src_hotfix_dir ( ) . join ( "lib.rs" ) , "linux_if_arp.rs" ) ;
@@ -5285,7 +5314,7 @@ fn test_haiku(target: &str) {
5285
5314
}
5286
5315
5287
5316
// is actually a union
5288
- "sigval" => "union sigval" . to_string ( ) ,
5317
+ "sigval" => format ! ( "union sigval" ) ,
5289
5318
t if is_union => format ! ( "union {t}" ) ,
5290
5319
t if t. ends_with ( "_t" ) => t. to_string ( ) ,
5291
5320
t if is_struct => format ! ( "struct {t}" ) ,
0 commit comments