Skip to content

Commit f81b8c0

Browse files
authored
Merge pull request #4132 from eduardosm/edition-preview
Migrate to Rust edition 2021
2 parents 3cce47f + 20f6aa4 commit f81b8c0

File tree

160 files changed

+70663
-70729
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+70663
-70729
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "1.0.0-alpha.1"
44
authors = ["The Rust Project Developers"]
55
license = "MIT OR Apache-2.0"
66
readme = "README.md"
7-
edition = "2015"
7+
edition = "2021"
88
repository = "https://github.com/rust-lang/libc"
99
homepage = "https://github.com/rust-lang/libc"
1010
documentation = "https://docs.rs/libc/"

build.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,7 @@ fn rustc_minor_nightly() -> (u32, bool) {
179179
}
180180

181181
fn which_freebsd() -> Option<i32> {
182-
let output = std::process::Command::new("freebsd-version")
183-
.output()
184-
.ok()?;
182+
let output = Command::new("freebsd-version").output().ok()?;
185183
if !output.status.success() {
186184
return None;
187185
}
@@ -200,10 +198,7 @@ fn which_freebsd() -> Option<i32> {
200198
}
201199

202200
fn emcc_version_code() -> Option<u64> {
203-
let output = std::process::Command::new("emcc")
204-
.arg("-dumpversion")
205-
.output()
206-
.ok()?;
201+
let output = Command::new("emcc").arg("-dumpversion").output().ok()?;
207202
if !output.status.success() {
208203
return None;
209204
}

libc-test/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ libc = { path = "..", version = "1.0.0-alpha.1", default-features = false }
1919
cc = "1.0.83"
2020
# FIXME: Use fork ctest until the maintainer gets back.
2121
ctest2 = "0.4.3"
22+
regex = "1.11.1"
2223

2324
[features]
2425
default = ["std"]

libc-test/build.rs

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ use std::io::{BufRead, BufReader, BufWriter, Write};
77
use std::path::{Path, PathBuf};
88
use std::{env, io};
99

10+
fn src_hotfix_dir() -> PathBuf {
11+
Path::new(&env::var_os("OUT_DIR").unwrap()).join("src-hotfix")
12+
}
13+
1014
fn do_cc() {
1115
let target = env::var("TARGET").unwrap();
1216
if cfg!(unix) {
@@ -145,11 +149,37 @@ fn main() {
145149
// Avoid unnecessary re-building.
146150
println!("cargo:rerun-if-changed=build.rs");
147151

152+
let hotfix_dir = src_hotfix_dir();
153+
if std::fs::exists(&hotfix_dir).unwrap() {
154+
std::fs::remove_dir_all(&hotfix_dir).unwrap();
155+
}
156+
157+
// FIXME(ctest): ctest2 cannot parse `crate::` in paths, so replace them with `::`
158+
let re = regex::bytes::Regex::new(r"(?-u:\b)crate::").unwrap();
159+
copy_dir_hotfix(Path::new("../src"), &hotfix_dir, &re, b"::");
160+
148161
do_cc();
149162
do_ctest();
150163
do_semver();
151164
}
152165

166+
fn copy_dir_hotfix(src: &Path, dst: &Path, regex: &regex::bytes::Regex, replace: &[u8]) {
167+
std::fs::create_dir(&dst).unwrap();
168+
for entry in src.read_dir().unwrap() {
169+
let entry = entry.unwrap();
170+
let src_path = entry.path();
171+
let dst_path = dst.join(entry.file_name());
172+
if entry.file_type().unwrap().is_dir() {
173+
copy_dir_hotfix(&src_path, &dst_path, regex, replace);
174+
} else {
175+
// Replace "crate::" with "::"
176+
let src_data = std::fs::read(&src_path).unwrap();
177+
let dst_data = regex.replace_all(&src_data, b"::");
178+
std::fs::write(&dst_path, &dst_data).unwrap();
179+
}
180+
}
181+
}
182+
153183
macro_rules! headers {
154184
($cfg:ident: [$m:expr]: $header:literal) => {
155185
if $m {
@@ -442,7 +472,7 @@ fn test_apple(target: &str) {
442472
"uuid_t" | "vol_capabilities_set_t" => true,
443473
_ => false,
444474
});
445-
cfg.generate("../src/lib.rs", "main.rs");
475+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
446476
}
447477

448478
fn test_openbsd(target: &str) {
@@ -607,7 +637,7 @@ fn test_openbsd(target: &str) {
607637
}
608638
});
609639

610-
cfg.generate("../src/lib.rs", "main.rs");
640+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
611641
}
612642

613643
fn test_windows(target: &str) {
@@ -729,7 +759,7 @@ fn test_windows(target: &str) {
729759

730760
cfg.skip_fn(|_| false);
731761

732-
cfg.generate("../src/lib.rs", "main.rs");
762+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
733763
}
734764

735765
fn test_redox(target: &str) {
@@ -779,7 +809,7 @@ fn test_redox(target: &str) {
779809
"wchar.h",
780810
}
781811

782-
cfg.generate("../src/lib.rs", "main.rs");
812+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
783813
}
784814

785815
fn test_solarish(target: &str) {
@@ -1054,7 +1084,7 @@ fn test_solarish(target: &str) {
10541084
}
10551085
});
10561086

1057-
cfg.generate("../src/lib.rs", "main.rs");
1087+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
10581088
}
10591089

10601090
fn test_netbsd(target: &str) {
@@ -1267,7 +1297,7 @@ fn test_netbsd(target: &str) {
12671297
}
12681298
});
12691299

1270-
cfg.generate("../src/lib.rs", "main.rs");
1300+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
12711301
}
12721302

12731303
fn test_dragonflybsd(target: &str) {
@@ -1490,7 +1520,7 @@ fn test_dragonflybsd(target: &str) {
14901520
(struct_ == "sigevent" && field == "sigev_notify_thread_id")
14911521
});
14921522

1493-
cfg.generate("../src/lib.rs", "main.rs");
1523+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
14941524
}
14951525

14961526
fn test_wasi(target: &str) {
@@ -1597,7 +1627,7 @@ fn test_wasi(target: &str) {
15971627
// doesn't support sizeof.
15981628
cfg.skip_field(|s, field| s == "dirent" && field == "d_name");
15991629

1600-
cfg.generate("../src/lib.rs", "main.rs");
1630+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
16011631
}
16021632

16031633
fn test_android(target: &str) {
@@ -2093,7 +2123,7 @@ fn test_android(target: &str) {
20932123
}
20942124
});
20952125

2096-
cfg.generate("../src/lib.rs", "main.rs");
2126+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
20972127

20982128
test_linux_like_apis(target);
20992129
}
@@ -2752,7 +2782,7 @@ fn test_freebsd(target: &str) {
27522782
});
27532783
}
27542784

2755-
cfg.generate("../src/lib.rs", "main.rs");
2785+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
27562786
}
27572787

27582788
fn test_emscripten(target: &str) {
@@ -2994,7 +3024,7 @@ fn test_emscripten(target: &str) {
29943024
].contains(&field))
29953025
});
29963026

2997-
cfg.generate("../src/lib.rs", "main.rs");
3027+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
29983028
}
29993029

30003030
fn test_neutrino(target: &str) {
@@ -3244,7 +3274,7 @@ fn test_neutrino(target: &str) {
32443274

32453275
cfg.skip_static(move |name| (name == "__dso_handle"));
32463276

3247-
cfg.generate("../src/lib.rs", "main.rs");
3277+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
32483278
}
32493279

32503280
fn test_vxworks(target: &str) {
@@ -3352,7 +3382,7 @@ fn test_vxworks(target: &str) {
33523382
_ => false,
33533383
});
33543384

3355-
cfg.generate("../src/lib.rs", "main.rs");
3385+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
33563386
}
33573387

33583388
fn test_linux(target: &str) {
@@ -4482,7 +4512,7 @@ fn test_linux(target: &str) {
44824512
_ => false,
44834513
});
44844514

4485-
cfg.generate("../src/lib.rs", "main.rs");
4515+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
44864516

44874517
test_linux_like_apis(target);
44884518
}
@@ -4509,7 +4539,7 @@ fn test_linux_like_apis(target: &str) {
45094539
})
45104540
.skip_const(|_| true)
45114541
.skip_struct(|_| true);
4512-
cfg.generate("../src/lib.rs", "linux_strerror_r.rs");
4542+
cfg.generate(src_hotfix_dir().join("lib.rs"), "linux_strerror_r.rs");
45134543
}
45144544

45154545
if linux || android || emscripten {
@@ -4539,7 +4569,7 @@ fn test_linux_like_apis(target: &str) {
45394569
t => t.to_string(),
45404570
});
45414571

4542-
cfg.generate("../src/lib.rs", "linux_fcntl.rs");
4572+
cfg.generate(src_hotfix_dir().join("lib.rs"), "linux_fcntl.rs");
45434573
}
45444574

45454575
if linux || android {
@@ -4563,7 +4593,7 @@ fn test_linux_like_apis(target: &str) {
45634593
t if is_union => format!("union {}", t),
45644594
t => t.to_string(),
45654595
});
4566-
cfg.generate("../src/lib.rs", "linux_termios.rs");
4596+
cfg.generate(src_hotfix_dir().join("lib.rs"), "linux_termios.rs");
45674597
}
45684598

45694599
if linux || android {
@@ -4591,7 +4621,7 @@ fn test_linux_like_apis(target: &str) {
45914621
t if is_union => format!("union {}", t),
45924622
t => t.to_string(),
45934623
});
4594-
cfg.generate("../src/lib.rs", "linux_ipv6.rs");
4624+
cfg.generate(src_hotfix_dir().join("lib.rs"), "linux_ipv6.rs");
45954625
}
45964626

45974627
if linux || android {
@@ -4613,7 +4643,7 @@ fn test_linux_like_apis(target: &str) {
46134643
"Elf64_Phdr" | "Elf32_Phdr" => false,
46144644
_ => true,
46154645
});
4616-
cfg.generate("../src/lib.rs", "linux_elf.rs");
4646+
cfg.generate(src_hotfix_dir().join("lib.rs"), "linux_elf.rs");
46174647
}
46184648

46194649
if linux || android {
@@ -4628,7 +4658,7 @@ fn test_linux_like_apis(target: &str) {
46284658
})
46294659
.skip_struct(|_| true)
46304660
.skip_type(|_| true);
4631-
cfg.generate("../src/lib.rs", "linux_if_arp.rs");
4661+
cfg.generate(src_hotfix_dir().join("lib.rs"), "linux_if_arp.rs");
46324662
}
46334663
}
46344664

@@ -4984,5 +5014,5 @@ fn test_haiku(target: &str) {
49845014
s => s.to_string(),
49855015
}
49865016
});
4987-
cfg.generate("../src/lib.rs", "main.rs");
5017+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
49885018
}

src/fuchsia/aarch64.rs

Lines changed: 54 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,69 @@
1+
use crate::{c_int, c_long, c_uint, c_ulong, c_ulonglong, c_ushort, off_t, size_t};
2+
13
pub type c_char = u8;
2-
pub type __u64 = ::c_ulonglong;
4+
pub type __u64 = c_ulonglong;
35
pub type wchar_t = u32;
4-
pub type nlink_t = ::c_ulong;
5-
pub type blksize_t = ::c_long;
6+
pub type nlink_t = c_ulong;
7+
pub type blksize_t = c_long;
68

79
s! {
810
pub struct stat {
9-
pub st_dev: ::dev_t,
10-
pub st_ino: ::ino_t,
11-
pub st_mode: ::mode_t,
12-
pub st_nlink: ::nlink_t,
13-
pub st_uid: ::uid_t,
14-
pub st_gid: ::gid_t,
15-
pub st_rdev: ::dev_t,
16-
__pad0: ::c_ulong,
17-
pub st_size: ::off_t,
18-
pub st_blksize: ::blksize_t,
19-
__pad1: ::c_int,
20-
pub st_blocks: ::blkcnt_t,
21-
pub st_atime: ::time_t,
22-
pub st_atime_nsec: ::c_long,
23-
pub st_mtime: ::time_t,
24-
pub st_mtime_nsec: ::c_long,
25-
pub st_ctime: ::time_t,
26-
pub st_ctime_nsec: ::c_long,
27-
__unused: [::c_uint; 2],
11+
pub st_dev: crate::dev_t,
12+
pub st_ino: crate::ino_t,
13+
pub st_mode: crate::mode_t,
14+
pub st_nlink: crate::nlink_t,
15+
pub st_uid: crate::uid_t,
16+
pub st_gid: crate::gid_t,
17+
pub st_rdev: crate::dev_t,
18+
__pad0: c_ulong,
19+
pub st_size: off_t,
20+
pub st_blksize: crate::blksize_t,
21+
__pad1: c_int,
22+
pub st_blocks: crate::blkcnt_t,
23+
pub st_atime: crate::time_t,
24+
pub st_atime_nsec: c_long,
25+
pub st_mtime: crate::time_t,
26+
pub st_mtime_nsec: c_long,
27+
pub st_ctime: crate::time_t,
28+
pub st_ctime_nsec: c_long,
29+
__unused: [c_uint; 2],
2830
}
2931

3032
pub struct stat64 {
31-
pub st_dev: ::dev_t,
32-
pub st_ino: ::ino_t,
33-
pub st_mode: ::mode_t,
34-
pub st_nlink: ::nlink_t,
35-
pub st_uid: ::uid_t,
36-
pub st_gid: ::gid_t,
37-
pub st_rdev: ::dev_t,
38-
__pad0: ::c_ulong,
39-
pub st_size: ::off_t,
40-
pub st_blksize: ::blksize_t,
41-
__pad1: ::c_int,
42-
pub st_blocks: ::blkcnt_t,
43-
pub st_atime: ::time_t,
44-
pub st_atime_nsec: ::c_long,
45-
pub st_mtime: ::time_t,
46-
pub st_mtime_nsec: ::c_long,
47-
pub st_ctime: ::time_t,
48-
pub st_ctime_nsec: ::c_long,
49-
__unused: [::c_uint; 2],
33+
pub st_dev: crate::dev_t,
34+
pub st_ino: crate::ino_t,
35+
pub st_mode: crate::mode_t,
36+
pub st_nlink: crate::nlink_t,
37+
pub st_uid: crate::uid_t,
38+
pub st_gid: crate::gid_t,
39+
pub st_rdev: crate::dev_t,
40+
__pad0: c_ulong,
41+
pub st_size: off_t,
42+
pub st_blksize: crate::blksize_t,
43+
__pad1: c_int,
44+
pub st_blocks: crate::blkcnt_t,
45+
pub st_atime: crate::time_t,
46+
pub st_atime_nsec: c_long,
47+
pub st_mtime: crate::time_t,
48+
pub st_mtime_nsec: c_long,
49+
pub st_ctime: crate::time_t,
50+
pub st_ctime_nsec: c_long,
51+
__unused: [c_uint; 2],
5052
}
5153

5254
pub struct ipc_perm {
53-
pub __ipc_perm_key: ::key_t,
54-
pub uid: ::uid_t,
55-
pub gid: ::gid_t,
56-
pub cuid: ::uid_t,
57-
pub cgid: ::gid_t,
58-
pub mode: ::mode_t,
59-
pub __seq: ::c_ushort,
60-
__unused1: ::c_ulong,
61-
__unused2: ::c_ulong,
55+
pub __ipc_perm_key: crate::key_t,
56+
pub uid: crate::uid_t,
57+
pub gid: crate::gid_t,
58+
pub cuid: crate::uid_t,
59+
pub cgid: crate::gid_t,
60+
pub mode: crate::mode_t,
61+
pub __seq: c_ushort,
62+
__unused1: c_ulong,
63+
__unused2: c_ulong,
6264
}
6365
}
6466

6567
// From https://cs.opensource.google/fuchsia/fuchsia/+/main:zircon/third_party/ulib/musl/include/bits/signal.h;l=20-21;drc=0827b18ab9540c46f8037f407d17ea15a79e9ba7
66-
pub const MINSIGSTKSZ: ::size_t = 6144;
67-
pub const SIGSTKSZ: ::size_t = 12288;
68+
pub const MINSIGSTKSZ: size_t = 6144;
69+
pub const SIGSTKSZ: size_t = 12288;

0 commit comments

Comments
 (0)