Skip to content

Commit

Permalink
Merge pull request #4155 from tgross35/backport-edition-2021
Browse files Browse the repository at this point in the history
[0.2] Migrate to Rust edition 2021
  • Loading branch information
tgross35 authored Nov 27, 2024
2 parents 0d227d1 + d6573bc commit d9a59db
Show file tree
Hide file tree
Showing 163 changed files with 70,810 additions and 70,886 deletions.
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Format macro bodies
50f26e08e146b7e9c7d1af9614486eba327d1e31

# Automated changes to upgrade to the 2021 edition
643182f7da26cedb09349b8bb3735c2e58ba24e6
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.2.166"
authors = ["The Rust Project Developers"]
license = "MIT OR Apache-2.0"
readme = "README.md"
edition = "2015"
edition = "2021"
repository = "https://github.com/rust-lang/libc"
homepage = "https://github.com/rust-lang/libc"
documentation = "https://docs.rs/libc/"
Expand Down
9 changes: 2 additions & 7 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,7 @@ fn rustc_minor_nightly() -> (u32, bool) {
}

fn which_freebsd() -> Option<i32> {
let output = std::process::Command::new("freebsd-version")
.output()
.ok()?;
let output = Command::new("freebsd-version").output().ok()?;
if !output.status.success() {
return None;
}
Expand All @@ -206,10 +204,7 @@ fn which_freebsd() -> Option<i32> {
}

fn emcc_version_code() -> Option<u64> {
let output = std::process::Command::new("emcc")
.arg("-dumpversion")
.output()
.ok()?;
let output = Command::new("emcc").arg("-dumpversion").output().ok()?;
if !output.status.success() {
return None;
}
Expand Down
1 change: 1 addition & 0 deletions libc-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ default-features = false
cc = "1.0.83"
# FIXME: Use fork ctest until the maintainer gets back.
ctest2 = "0.4.3"
regex = "1.11.1"

[features]
default = ["std"]
Expand Down
72 changes: 51 additions & 21 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use std::io::{BufRead, BufReader, BufWriter, Write};
use std::path::{Path, PathBuf};
use std::{env, io};

fn src_hotfix_dir() -> PathBuf {
Path::new(&env::var_os("OUT_DIR").unwrap()).join("src-hotfix")
}

fn do_cc() {
let target = env::var("TARGET").unwrap();
if cfg!(unix) {
Expand Down Expand Up @@ -150,11 +154,37 @@ fn main() {
// Avoid unnecessary re-building.
println!("cargo:rerun-if-changed=build.rs");

let hotfix_dir = src_hotfix_dir();
if std::fs::exists(&hotfix_dir).unwrap() {
std::fs::remove_dir_all(&hotfix_dir).unwrap();
}

// FIXME(ctest): ctest2 cannot parse `crate::` in paths, so replace them with `::`
let re = regex::bytes::Regex::new(r"(?-u:\b)crate::").unwrap();
copy_dir_hotfix(Path::new("../src"), &hotfix_dir, &re, b"::");

do_cc();
do_ctest();
do_semver();
}

fn copy_dir_hotfix(src: &Path, dst: &Path, regex: &regex::bytes::Regex, replace: &[u8]) {
std::fs::create_dir(&dst).unwrap();
for entry in src.read_dir().unwrap() {
let entry = entry.unwrap();
let src_path = entry.path();
let dst_path = dst.join(entry.file_name());
if entry.file_type().unwrap().is_dir() {
copy_dir_hotfix(&src_path, &dst_path, regex, replace);
} else {
// Replace "crate::" with "::"
let src_data = std::fs::read(&src_path).unwrap();
let dst_data = regex.replace_all(&src_data, b"::");
std::fs::write(&dst_path, &dst_data).unwrap();
}
}
}

macro_rules! headers {
($cfg:ident: [$m:expr]: $header:literal) => {
if $m {
Expand Down Expand Up @@ -464,7 +494,7 @@ fn test_apple(target: &str) {
"uuid_t" | "vol_capabilities_set_t" => true,
_ => false,
});
cfg.generate("../src/lib.rs", "main.rs");
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
}

fn test_openbsd(target: &str) {
Expand Down Expand Up @@ -651,7 +681,7 @@ fn test_openbsd(target: &str) {
}
});

cfg.generate("../src/lib.rs", "main.rs");
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
}

fn test_windows(target: &str) {
Expand Down Expand Up @@ -780,7 +810,7 @@ fn test_windows(target: &str) {
}
});

cfg.generate("../src/lib.rs", "main.rs");
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
}

fn test_redox(target: &str) {
Expand Down Expand Up @@ -830,7 +860,7 @@ fn test_redox(target: &str) {
"wchar.h",
}

cfg.generate("../src/lib.rs", "main.rs");
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
}

fn test_solarish(target: &str) {
Expand Down Expand Up @@ -1108,7 +1138,7 @@ fn test_solarish(target: &str) {
}
});

cfg.generate("../src/lib.rs", "main.rs");
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
}

fn test_netbsd(target: &str) {
Expand Down Expand Up @@ -1323,7 +1353,7 @@ fn test_netbsd(target: &str) {
}
});

cfg.generate("../src/lib.rs", "main.rs");
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
}

fn test_dragonflybsd(target: &str) {
Expand Down Expand Up @@ -1549,7 +1579,7 @@ fn test_dragonflybsd(target: &str) {
(struct_ == "sigevent" && field == "sigev_notify_thread_id")
});

cfg.generate("../src/lib.rs", "main.rs");
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
}

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

cfg.generate("../src/lib.rs", "main.rs");
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
}

fn test_android(target: &str) {
Expand Down Expand Up @@ -2149,7 +2179,7 @@ fn test_android(target: &str) {
}
});

cfg.generate("../src/lib.rs", "main.rs");
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");

test_linux_like_apis(target);
}
Expand Down Expand Up @@ -2821,7 +2851,7 @@ fn test_freebsd(target: &str) {
});
}

cfg.generate("../src/lib.rs", "main.rs");
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
}

fn test_emscripten(target: &str) {
Expand Down Expand Up @@ -3058,7 +3088,7 @@ fn test_emscripten(target: &str) {
].contains(&field))
});

cfg.generate("../src/lib.rs", "main.rs");
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
}

fn test_neutrino(target: &str) {
Expand Down Expand Up @@ -3311,7 +3341,7 @@ fn test_neutrino(target: &str) {

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

cfg.generate("../src/lib.rs", "main.rs");
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
}

fn test_vxworks(target: &str) {
Expand Down Expand Up @@ -3419,7 +3449,7 @@ fn test_vxworks(target: &str) {
_ => false,
});

cfg.generate("../src/lib.rs", "main.rs");
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
}

fn test_linux(target: &str) {
Expand Down Expand Up @@ -4553,7 +4583,7 @@ fn test_linux(target: &str) {
_ => false,
});

cfg.generate("../src/lib.rs", "main.rs");
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");

test_linux_like_apis(target);
}
Expand All @@ -4580,7 +4610,7 @@ fn test_linux_like_apis(target: &str) {
})
.skip_const(|_| true)
.skip_struct(|_| true);
cfg.generate("../src/lib.rs", "linux_strerror_r.rs");
cfg.generate(src_hotfix_dir().join("lib.rs"), "linux_strerror_r.rs");
}

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

cfg.generate("../src/lib.rs", "linux_fcntl.rs");
cfg.generate(src_hotfix_dir().join("lib.rs"), "linux_fcntl.rs");
}

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

if linux || android {
Expand Down Expand Up @@ -4662,7 +4692,7 @@ fn test_linux_like_apis(target: &str) {
t if is_union => format!("union {}", t),
t => t.to_string(),
});
cfg.generate("../src/lib.rs", "linux_ipv6.rs");
cfg.generate(src_hotfix_dir().join("lib.rs"), "linux_ipv6.rs");
}

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

if linux || android {
Expand All @@ -4699,7 +4729,7 @@ fn test_linux_like_apis(target: &str) {
})
.skip_struct(|_| true)
.skip_type(|_| true);
cfg.generate("../src/lib.rs", "linux_if_arp.rs");
cfg.generate(src_hotfix_dir().join("lib.rs"), "linux_if_arp.rs");
}
}

Expand Down Expand Up @@ -5057,5 +5087,5 @@ fn test_haiku(target: &str) {
s => s.to_string(),
}
});
cfg.generate("../src/lib.rs", "main.rs");
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
}
Loading

0 comments on commit d9a59db

Please sign in to comment.