Skip to content

Commit d9a59db

Browse files
authored
Merge pull request #4155 from tgross35/backport-edition-2021
[0.2] Migrate to Rust edition 2021
2 parents 0d227d1 + d6573bc commit d9a59db

File tree

163 files changed

+70810
-70886
lines changed

Some content is hidden

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

163 files changed

+70810
-70886
lines changed

.git-blame-ignore-revs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# Format macro bodies
22
50f26e08e146b7e9c7d1af9614486eba327d1e31
3+
4+
# Automated changes to upgrade to the 2021 edition
5+
643182f7da26cedb09349b8bb3735c2e58ba24e6

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.2.166"
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
@@ -185,9 +185,7 @@ fn rustc_minor_nightly() -> (u32, bool) {
185185
}
186186

187187
fn which_freebsd() -> Option<i32> {
188-
let output = std::process::Command::new("freebsd-version")
189-
.output()
190-
.ok()?;
188+
let output = Command::new("freebsd-version").output().ok()?;
191189
if !output.status.success() {
192190
return None;
193191
}
@@ -206,10 +204,7 @@ fn which_freebsd() -> Option<i32> {
206204
}
207205

208206
fn emcc_version_code() -> Option<u64> {
209-
let output = std::process::Command::new("emcc")
210-
.arg("-dumpversion")
211-
.output()
212-
.ok()?;
207+
let output = Command::new("emcc").arg("-dumpversion").output().ok()?;
213208
if !output.status.success() {
214209
return None;
215210
}

libc-test/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ default-features = false
2121
cc = "1.0.83"
2222
# FIXME: Use fork ctest until the maintainer gets back.
2323
ctest2 = "0.4.3"
24+
regex = "1.11.1"
2425

2526
[features]
2627
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) {
@@ -150,11 +154,37 @@ fn main() {
150154
// Avoid unnecessary re-building.
151155
println!("cargo:rerun-if-changed=build.rs");
152156

157+
let hotfix_dir = src_hotfix_dir();
158+
if std::fs::exists(&hotfix_dir).unwrap() {
159+
std::fs::remove_dir_all(&hotfix_dir).unwrap();
160+
}
161+
162+
// FIXME(ctest): ctest2 cannot parse `crate::` in paths, so replace them with `::`
163+
let re = regex::bytes::Regex::new(r"(?-u:\b)crate::").unwrap();
164+
copy_dir_hotfix(Path::new("../src"), &hotfix_dir, &re, b"::");
165+
153166
do_cc();
154167
do_ctest();
155168
do_semver();
156169
}
157170

171+
fn copy_dir_hotfix(src: &Path, dst: &Path, regex: &regex::bytes::Regex, replace: &[u8]) {
172+
std::fs::create_dir(&dst).unwrap();
173+
for entry in src.read_dir().unwrap() {
174+
let entry = entry.unwrap();
175+
let src_path = entry.path();
176+
let dst_path = dst.join(entry.file_name());
177+
if entry.file_type().unwrap().is_dir() {
178+
copy_dir_hotfix(&src_path, &dst_path, regex, replace);
179+
} else {
180+
// Replace "crate::" with "::"
181+
let src_data = std::fs::read(&src_path).unwrap();
182+
let dst_data = regex.replace_all(&src_data, b"::");
183+
std::fs::write(&dst_path, &dst_data).unwrap();
184+
}
185+
}
186+
}
187+
158188
macro_rules! headers {
159189
($cfg:ident: [$m:expr]: $header:literal) => {
160190
if $m {
@@ -464,7 +494,7 @@ fn test_apple(target: &str) {
464494
"uuid_t" | "vol_capabilities_set_t" => true,
465495
_ => false,
466496
});
467-
cfg.generate("../src/lib.rs", "main.rs");
497+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
468498
}
469499

470500
fn test_openbsd(target: &str) {
@@ -651,7 +681,7 @@ fn test_openbsd(target: &str) {
651681
}
652682
});
653683

654-
cfg.generate("../src/lib.rs", "main.rs");
684+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
655685
}
656686

657687
fn test_windows(target: &str) {
@@ -780,7 +810,7 @@ fn test_windows(target: &str) {
780810
}
781811
});
782812

783-
cfg.generate("../src/lib.rs", "main.rs");
813+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
784814
}
785815

786816
fn test_redox(target: &str) {
@@ -830,7 +860,7 @@ fn test_redox(target: &str) {
830860
"wchar.h",
831861
}
832862

833-
cfg.generate("../src/lib.rs", "main.rs");
863+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
834864
}
835865

836866
fn test_solarish(target: &str) {
@@ -1108,7 +1138,7 @@ fn test_solarish(target: &str) {
11081138
}
11091139
});
11101140

1111-
cfg.generate("../src/lib.rs", "main.rs");
1141+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
11121142
}
11131143

11141144
fn test_netbsd(target: &str) {
@@ -1323,7 +1353,7 @@ fn test_netbsd(target: &str) {
13231353
}
13241354
});
13251355

1326-
cfg.generate("../src/lib.rs", "main.rs");
1356+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
13271357
}
13281358

13291359
fn test_dragonflybsd(target: &str) {
@@ -1549,7 +1579,7 @@ fn test_dragonflybsd(target: &str) {
15491579
(struct_ == "sigevent" && field == "sigev_notify_thread_id")
15501580
});
15511581

1552-
cfg.generate("../src/lib.rs", "main.rs");
1582+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
15531583
}
15541584

15551585
fn test_wasi(target: &str) {
@@ -1656,7 +1686,7 @@ fn test_wasi(target: &str) {
16561686
// doesn't support sizeof.
16571687
cfg.skip_field(|s, field| s == "dirent" && field == "d_name");
16581688

1659-
cfg.generate("../src/lib.rs", "main.rs");
1689+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
16601690
}
16611691

16621692
fn test_android(target: &str) {
@@ -2149,7 +2179,7 @@ fn test_android(target: &str) {
21492179
}
21502180
});
21512181

2152-
cfg.generate("../src/lib.rs", "main.rs");
2182+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
21532183

21542184
test_linux_like_apis(target);
21552185
}
@@ -2821,7 +2851,7 @@ fn test_freebsd(target: &str) {
28212851
});
28222852
}
28232853

2824-
cfg.generate("../src/lib.rs", "main.rs");
2854+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
28252855
}
28262856

28272857
fn test_emscripten(target: &str) {
@@ -3058,7 +3088,7 @@ fn test_emscripten(target: &str) {
30583088
].contains(&field))
30593089
});
30603090

3061-
cfg.generate("../src/lib.rs", "main.rs");
3091+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
30623092
}
30633093

30643094
fn test_neutrino(target: &str) {
@@ -3311,7 +3341,7 @@ fn test_neutrino(target: &str) {
33113341

33123342
cfg.skip_static(move |name| (name == "__dso_handle"));
33133343

3314-
cfg.generate("../src/lib.rs", "main.rs");
3344+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
33153345
}
33163346

33173347
fn test_vxworks(target: &str) {
@@ -3419,7 +3449,7 @@ fn test_vxworks(target: &str) {
34193449
_ => false,
34203450
});
34213451

3422-
cfg.generate("../src/lib.rs", "main.rs");
3452+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
34233453
}
34243454

34253455
fn test_linux(target: &str) {
@@ -4553,7 +4583,7 @@ fn test_linux(target: &str) {
45534583
_ => false,
45544584
});
45554585

4556-
cfg.generate("../src/lib.rs", "main.rs");
4586+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
45574587

45584588
test_linux_like_apis(target);
45594589
}
@@ -4580,7 +4610,7 @@ fn test_linux_like_apis(target: &str) {
45804610
})
45814611
.skip_const(|_| true)
45824612
.skip_struct(|_| true);
4583-
cfg.generate("../src/lib.rs", "linux_strerror_r.rs");
4613+
cfg.generate(src_hotfix_dir().join("lib.rs"), "linux_strerror_r.rs");
45844614
}
45854615

45864616
if linux || android || emscripten {
@@ -4610,7 +4640,7 @@ fn test_linux_like_apis(target: &str) {
46104640
t => t.to_string(),
46114641
});
46124642

4613-
cfg.generate("../src/lib.rs", "linux_fcntl.rs");
4643+
cfg.generate(src_hotfix_dir().join("lib.rs"), "linux_fcntl.rs");
46144644
}
46154645

46164646
if linux || android {
@@ -4634,7 +4664,7 @@ fn test_linux_like_apis(target: &str) {
46344664
t if is_union => format!("union {}", t),
46354665
t => t.to_string(),
46364666
});
4637-
cfg.generate("../src/lib.rs", "linux_termios.rs");
4667+
cfg.generate(src_hotfix_dir().join("lib.rs"), "linux_termios.rs");
46384668
}
46394669

46404670
if linux || android {
@@ -4662,7 +4692,7 @@ fn test_linux_like_apis(target: &str) {
46624692
t if is_union => format!("union {}", t),
46634693
t => t.to_string(),
46644694
});
4665-
cfg.generate("../src/lib.rs", "linux_ipv6.rs");
4695+
cfg.generate(src_hotfix_dir().join("lib.rs"), "linux_ipv6.rs");
46664696
}
46674697

46684698
if linux || android {
@@ -4684,7 +4714,7 @@ fn test_linux_like_apis(target: &str) {
46844714
"Elf64_Phdr" | "Elf32_Phdr" => false,
46854715
_ => true,
46864716
});
4687-
cfg.generate("../src/lib.rs", "linux_elf.rs");
4717+
cfg.generate(src_hotfix_dir().join("lib.rs"), "linux_elf.rs");
46884718
}
46894719

46904720
if linux || android {
@@ -4699,7 +4729,7 @@ fn test_linux_like_apis(target: &str) {
46994729
})
47004730
.skip_struct(|_| true)
47014731
.skip_type(|_| true);
4702-
cfg.generate("../src/lib.rs", "linux_if_arp.rs");
4732+
cfg.generate(src_hotfix_dir().join("lib.rs"), "linux_if_arp.rs");
47034733
}
47044734
}
47054735

@@ -5057,5 +5087,5 @@ fn test_haiku(target: &str) {
50575087
s => s.to_string(),
50585088
}
50595089
});
5060-
cfg.generate("../src/lib.rs", "main.rs");
5090+
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
50615091
}

0 commit comments

Comments
 (0)