Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Rust edition 2021 #4132

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = "1.0.0-alpha.1"
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 @@ -179,9 +179,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 @@ -200,10 +198,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 @@ -19,6 +19,7 @@ libc = { path = "..", version = "1.0.0-alpha.1", 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 @@ -145,11 +149,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 @@ -442,7 +472,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 @@ -607,7 +637,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 @@ -729,7 +759,7 @@ fn test_windows(target: &str) {

cfg.skip_fn(|_| false);

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 @@ -779,7 +809,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 @@ -1054,7 +1084,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 @@ -1267,7 +1297,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 @@ -1490,7 +1520,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 @@ -1597,7 +1627,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 @@ -2093,7 +2123,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 @@ -2752,7 +2782,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 @@ -2994,7 +3024,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 @@ -3244,7 +3274,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 @@ -3352,7 +3382,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 @@ -4482,7 +4512,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 @@ -4509,7 +4539,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 @@ -4539,7 +4569,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 @@ -4563,7 +4593,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 @@ -4591,7 +4621,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 @@ -4613,7 +4643,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 @@ -4628,7 +4658,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 @@ -4984,5 +5014,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");
}
106 changes: 54 additions & 52 deletions src/fuchsia/aarch64.rs
Original file line number Diff line number Diff line change
@@ -1,67 +1,69 @@
use crate::{c_int, c_long, c_uint, c_ulong, c_ulonglong, c_ushort, off_t, size_t};

pub type c_char = u8;
pub type __u64 = ::c_ulonglong;
pub type __u64 = c_ulonglong;
pub type wchar_t = u32;
pub type nlink_t = ::c_ulong;
pub type blksize_t = ::c_long;
pub type nlink_t = c_ulong;
pub type blksize_t = c_long;

s! {
pub struct stat {
pub st_dev: ::dev_t,
pub st_ino: ::ino_t,
pub st_mode: ::mode_t,
pub st_nlink: ::nlink_t,
pub st_uid: ::uid_t,
pub st_gid: ::gid_t,
pub st_rdev: ::dev_t,
__pad0: ::c_ulong,
pub st_size: ::off_t,
pub st_blksize: ::blksize_t,
__pad1: ::c_int,
pub st_blocks: ::blkcnt_t,
pub st_atime: ::time_t,
pub st_atime_nsec: ::c_long,
pub st_mtime: ::time_t,
pub st_mtime_nsec: ::c_long,
pub st_ctime: ::time_t,
pub st_ctime_nsec: ::c_long,
__unused: [::c_uint; 2],
pub st_dev: crate::dev_t,
pub st_ino: crate::ino_t,
pub st_mode: crate::mode_t,
pub st_nlink: crate::nlink_t,
pub st_uid: crate::uid_t,
pub st_gid: crate::gid_t,
pub st_rdev: crate::dev_t,
__pad0: c_ulong,
pub st_size: off_t,
pub st_blksize: crate::blksize_t,
__pad1: c_int,
pub st_blocks: crate::blkcnt_t,
pub st_atime: crate::time_t,
pub st_atime_nsec: c_long,
pub st_mtime: crate::time_t,
pub st_mtime_nsec: c_long,
pub st_ctime: crate::time_t,
pub st_ctime_nsec: c_long,
__unused: [c_uint; 2],
}

pub struct stat64 {
pub st_dev: ::dev_t,
pub st_ino: ::ino_t,
pub st_mode: ::mode_t,
pub st_nlink: ::nlink_t,
pub st_uid: ::uid_t,
pub st_gid: ::gid_t,
pub st_rdev: ::dev_t,
__pad0: ::c_ulong,
pub st_size: ::off_t,
pub st_blksize: ::blksize_t,
__pad1: ::c_int,
pub st_blocks: ::blkcnt_t,
pub st_atime: ::time_t,
pub st_atime_nsec: ::c_long,
pub st_mtime: ::time_t,
pub st_mtime_nsec: ::c_long,
pub st_ctime: ::time_t,
pub st_ctime_nsec: ::c_long,
__unused: [::c_uint; 2],
pub st_dev: crate::dev_t,
pub st_ino: crate::ino_t,
pub st_mode: crate::mode_t,
pub st_nlink: crate::nlink_t,
pub st_uid: crate::uid_t,
pub st_gid: crate::gid_t,
pub st_rdev: crate::dev_t,
__pad0: c_ulong,
pub st_size: off_t,
pub st_blksize: crate::blksize_t,
__pad1: c_int,
pub st_blocks: crate::blkcnt_t,
pub st_atime: crate::time_t,
pub st_atime_nsec: c_long,
pub st_mtime: crate::time_t,
pub st_mtime_nsec: c_long,
pub st_ctime: crate::time_t,
pub st_ctime_nsec: c_long,
__unused: [c_uint; 2],
}

pub struct ipc_perm {
pub __ipc_perm_key: ::key_t,
pub uid: ::uid_t,
pub gid: ::gid_t,
pub cuid: ::uid_t,
pub cgid: ::gid_t,
pub mode: ::mode_t,
pub __seq: ::c_ushort,
__unused1: ::c_ulong,
__unused2: ::c_ulong,
pub __ipc_perm_key: crate::key_t,
pub uid: crate::uid_t,
pub gid: crate::gid_t,
pub cuid: crate::uid_t,
pub cgid: crate::gid_t,
pub mode: crate::mode_t,
pub __seq: c_ushort,
__unused1: c_ulong,
__unused2: c_ulong,
}
}

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