Skip to content
Open
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
30 changes: 26 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const ALLOWED_CFGS: &[&str] = &[
// Corresponds to `__USE_TIME_BITS64` in UAPI
"linux_time_bits64",
"musl_v1_2_3",
// Corresponds to `_REDIR_TIME64` in musl
"musl32_time64",
"vxworks_lt_25_09",
];

Expand All @@ -49,6 +51,9 @@ const CHECK_CFG_EXTRA: &[(&str, &[&str])] = &[
),
];

/// Musl architectures that set `#define _REDIR_TIME64 1`.
const MUSL_REDIR_TIME64_ARCHES: &[&str] = &["arm", "mips", "powerpc", "x86"];

fn main() {
// Avoid unnecessary re-building.
println!("cargo:rerun-if-changed=build.rs");
Expand Down Expand Up @@ -99,12 +104,29 @@ fn main() {
_ => (),
}

let musl_v1_2_3 = env_flag("RUST_LIBC_UNSTABLE_MUSL_V1_2_3");
let mut musl_v1_2_3 = env_flag("RUST_LIBC_UNSTABLE_MUSL_V1_2_3");
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_MUSL_V1_2_3");
// loongarch64 and ohos have already updated
if musl_v1_2_3 || target_arch == "loongarch64" || target_env == "ohos" {
// FIXME(musl): enable time64 api as well

// OpenHarmony uses a fork of the musl libc
let musl = target_env == "musl" || target_env == "ohos";

// loongarch64 and ohos only exist with recent musl
if target_arch == "loongarch64" || target_env == "ohos" {
musl_v1_2_3 = true;
}

if musl && musl_v1_2_3 {
set_cfg("musl_v1_2_3");
if MUSL_REDIR_TIME64_ARCHES.contains(&target_arch.as_str()) {
set_cfg("musl32_time64");
set_cfg("linux_time_bits64");
}
}

let linux_time_bits64 = env::var("RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64").is_ok();
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64");
if linux_time_bits64 {
set_cfg("linux_time_bits64");
}
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS");
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_GNU_TIME_BITS");
Expand Down
92 changes: 10 additions & 82 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3690,6 +3690,7 @@ fn test_linux(target: &str) {
let i686 = target.contains("i686");
let ppc = target.contains("powerpc");
let ppc64 = target.contains("powerpc64");
let ppc32 = ppc && !ppc64;
let s390x = target.contains("s390x");
let sparc64 = target.contains("sparc64");
let x32 = target.contains("x32");
Expand All @@ -3702,6 +3703,8 @@ fn test_linux(target: &str) {
let wasm32 = target.contains("wasm32");
let uclibc = target.contains("uclibc");
let mips = target.contains("mips");
let mips64 = target.contains("mips64");
let mips32 = mips && !mips64;

let musl_v1_2_3 = env::var("RUST_LIBC_UNSTABLE_MUSL_V1_2_3").is_ok();
if musl_v1_2_3 {
Expand All @@ -3710,8 +3713,12 @@ fn test_linux(target: &str) {
let old_musl = musl && !musl_v1_2_3;

let mut cfg = ctest_cfg();
if musl_v1_2_3 {
if (musl_v1_2_3 || loongarch64) && musl {
cfg.cfg("musl_v1_2_3", None);
if arm || ppc32 || x86_32 || mips32 {
cfg.cfg("musl32_time64", None);
cfg.cfg("linux_time_bits64", None);
}
}
cfg.define("_GNU_SOURCE", None)
// This macro re-defines fscanf,scanf,sscanf to link to the symbols that are
Expand Down Expand Up @@ -3965,9 +3972,9 @@ fn test_linux(target: &str) {
cfg.rename_struct_field(move |struct_, field| {
match (struct_.ident(), field.ident()) {
// Our stat *_nsec fields normally don't actually exist but are part
// of a timeval struct
// of a timeval struct - this is fixed in musl_v1_2_3
("stat" | "statfs" | "statvfs" | "stat64" | "statfs64" | "statvfs64", f)
if f.ends_with("_nsec") =>
if !musl_v1_2_3 && f.ends_with("_nsec") =>
{
Some(f.replace("e_nsec", ".tv_nsec"))
}
Expand Down Expand Up @@ -4722,8 +4729,6 @@ fn test_linux(target: &str) {
("xsk_tx_metadata", "xsk_tx_metadata_union") => true,
// After musl 1.2.0, the type becomes `int` instead of `long`.
("utmpx", "ut_session") if musl => true,
// FIXME(musl,time): changed with the musl time updates
("input_event", "time") if musl_v1_2_3 => true,
// `frames` is a flexible array member
("bcm_msg_head", "frames") => true,
// FAM
Expand Down Expand Up @@ -4776,83 +4781,6 @@ fn test_linux(target: &str) {
_ => false,
});

// FIXME(musl,time): these should be resolved with the time64 updates
if musl_v1_2_3 {
// Time primitives changed, as did structs containing them
cfg.skip_alias(|ty| match ty.ident() {
"time_t" | "suseconds_t" => true,
_ => false,
});
cfg.skip_struct(|s| match s.ident() {
"utimbuf" | "timeval" | "timespec" | "rusage" | "itimerval" | "itimerspec"
| "timex" | "ntptimeval" | "stat" | "shmid_ds" | "msqid_ds" => true,
_ => false,
});

cfg.skip_const(|c| match c.ident() {
// Changed syscall numbers under `linux_time_bits64`
"SO_TIMESTAMP" | "SO_TIMESTAMPNS" | "SO_TIMESTAMPING" | "SO_RCVTIMEO"
| "SO_SNDTIMEO" => true,
// Derived from `SO_` constants
"SCM_TIMESTAMP" | "SCM_TIMESTAMPNS" | "SCM_TIMESTAMPING" => true,
// `IPC_STAT` and derived values
"IPC_STAT" | "SEM_STAT" | "SEM_STAT_ANY" => true,
_ => false,
});

// Functions that got a new link name
cfg.skip_fn_ptrcheck(|f| match f {
"pthread_mutex_timedlock"
| "recvmmsg"
| "fstat"
| "stat"
| "fstatat"
| "nanosleep"
| "utime"
| "lstat"
| "getrusage"
| "pthread_cond_timedwait"
| "utimes"
| "dlsym"
| "gmtime_r"
| "localtime_r"
| "mktime"
| "time"
| "gmtime"
| "localtime"
| "difftime"
| "timegm"
| "select"
| "adjtime"
| "pselect"
| "clock_getres"
| "clock_gettime"
| "clock_settime"
| "futimens"
| "utimensat"
| "wait4"
| "aio_suspend"
| "futimes"
| "mq_timedreceive"
| "mq_timedsend"
| "lutimes"
| "timerfd_gettime"
| "timerfd_settime"
| "sigtimedwait"
| "settimeofday"
| "sched_rr_get_interval"
| "sem_timedwait"
| "ppoll"
| "clock_nanosleep"
| "timer_gettime"
| "timer_settime"
| "gettimeofday"
| "adjtimex"
| "clock_adjtime" => true,
_ => false,
});
}

ctest::generate_test(&mut cfg, "../src/lib.rs", "ctest_output.rs").unwrap();

if !l4re {
Expand Down
16 changes: 16 additions & 0 deletions libc-test/semver/linux-powerpc-gnu.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
KEYCTL_CAPABILITIES
KEYCTL_CAPS0_BIG_KEY
KEYCTL_CAPS0_CAPABILITIES
KEYCTL_CAPS0_DIFFIE_HELLMAN
KEYCTL_CAPS0_INVALIDATE
KEYCTL_CAPS0_MOVE
KEYCTL_CAPS0_PERSISTENT_KEYRINGS
KEYCTL_CAPS0_PUBLIC_KEY
KEYCTL_CAPS0_RESTRICT_KEYRING
KEYCTL_CAPS1_NS_KEYRING_NAME
KEYCTL_CAPS1_NS_KEY_TAG
KEYCTL_MOVE
PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
sysctl
16 changes: 0 additions & 16 deletions libc-test/semver/linux-powerpc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,12 @@ B2500000
B3000000
B3500000
B4000000
KEYCTL_CAPABILITIES
KEYCTL_CAPS0_BIG_KEY
KEYCTL_CAPS0_CAPABILITIES
KEYCTL_CAPS0_DIFFIE_HELLMAN
KEYCTL_CAPS0_INVALIDATE
KEYCTL_CAPS0_MOVE
KEYCTL_CAPS0_PERSISTENT_KEYRINGS
KEYCTL_CAPS0_PUBLIC_KEY
KEYCTL_CAPS0_RESTRICT_KEYRING
KEYCTL_CAPS1_NS_KEYRING_NAME
KEYCTL_CAPS1_NS_KEY_TAG
KEYCTL_MOVE
MADV_SOFT_OFFLINE
MAP_SYNC
NFT_MSG_DELOBJ
NFT_MSG_GETOBJ
NFT_MSG_GETOBJ_RESET
NFT_MSG_NEWOBJ
PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
PTRACE_GETFPREGS
PTRACE_GETREGS
PTRACE_SETFPREGS
Expand Down Expand Up @@ -158,4 +143,3 @@ TIOCSRS485
flock64
fsblkcnt64_t
fsfilcnt64_t
sysctl
31 changes: 9 additions & 22 deletions libc-test/tests/style_lib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ use syn::visit::{
use syn::Token;

const ALLOWED_REPEATED_MACROS: &[&str] = &["s", "s_no_extra_traits", "s_paren"];
const ALLOWED_POSITIVE_S_CFGS: &[&str] = &[
"gnu_file_offset_bits64",
"gnu_time_bits64",
"musl32_time64",
"musl_v1_2_3",
];

pub type Error = Box<dyn std::error::Error>;
pub type Result<T> = std::result::Result<T, Error>;
Expand Down Expand Up @@ -236,25 +242,6 @@ impl StyleChecker {
self.state = initial_state;
}

/// If we see a normal s! macro without any attributes we just need
/// to check if there are any duplicates.
fn handle_s_macro_no_attrs(&mut self, item_macro: &syn::ItemMacro) {
let span = item_macro.span();
match self.seen_s_macro_cfgs.get("") {
Some(seen_span) => {
self.error(
"duplicate s! macro".to_string(),
span,
format!("other s! macro"),
(Some(*seen_span), "combine the two".to_string()),
);
}
None => {
self.seen_s_macro_cfgs.insert(String::new(), span);
}
}
}

/// If an s! macro has attributes we check for any duplicates as well
/// as if they are standalone positive cfgs that would be better
/// in a separate file.
Expand Down Expand Up @@ -285,6 +272,8 @@ impl StyleChecker {
if !meta_str.starts_with("not")
&& !meta_str.starts_with("any")
&& !meta_str.starts_with("all")
&& !meta_str.starts_with("target_endian")
&& !ALLOWED_POSITIVE_S_CFGS.contains(&meta_str.as_str())
{
self.error(
"positive #[cfg] for s! macro".to_string(),
Expand Down Expand Up @@ -359,9 +348,7 @@ impl<'ast> Visit<'ast> for StyleChecker {
/// instead of [syn::Macro] because it contains the attributes.
fn visit_item_macro(&mut self, item_macro: &'ast syn::ItemMacro) {
if item_macro.mac.path.is_ident("s") {
if item_macro.attrs.is_empty() {
self.handle_s_macro_no_attrs(item_macro);
} else {
if !item_macro.attrs.is_empty() {
self.handle_s_macro_with_attrs(item_macro);
}
}
Expand Down
13 changes: 0 additions & 13 deletions libc-test/tests/style_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,6 @@ s! { pub struct bar { /* ... */ } }
checker.finalize().unwrap();
}

#[test]
fn check_style_reject_duplicated_s_macro() {
let contents = r#"
s! {}
s! {}
"#
.to_string();

let mut checker = StyleChecker::new();
checker.check_string(contents).unwrap();
assert!(checker.finalize().is_err());
}

#[test]
fn check_style_reject_duplicated_s_macro_cfg() {
let contents = r#"
Expand Down
1 change: 1 addition & 0 deletions src/new/common/posix/pthread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ extern "C" {

#[cfg(any(target_os = "android", target_os = "l4re", target_os = "linux"))]
#[cfg_attr(gnu_time_bits64, link_name = "__pthread_mutex_timedlock64")]
#[cfg_attr(musl32_time64, link_name = "__pthread_mutex_timedlock_time64")]
pub fn pthread_mutex_timedlock(
lock: *mut crate::pthread_mutex_t,
abstime: *const crate::timespec,
Expand Down
1 change: 1 addition & 0 deletions src/new/emscripten/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
//! * Headers: <https://github.com/emscripten-core/emscripten/tree/main/system/lib/libc>

pub(crate) mod pthread;
pub(crate) mod sched;
pub(crate) mod unistd;
38 changes: 38 additions & 0 deletions src/new/emscripten/sched.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use crate::prelude::*;

cfg_if! {
if #[cfg(musl_v1_2_3)] {
s! {
struct __c_anon_sched_param__reserved2 {
__reserved1: crate::time_t,
__reserved2: c_long,
}

pub struct sched_param {
pub sched_priority: c_int,

__reserved1: Padding<c_int>,
#[cfg(musl32_time64)]
__reserved2: Padding<[c_long; 4]>,
#[cfg(not(musl32_time64))]
__reserved2: Padding<[__c_anon_sched_param__reserved2; 2]>,
__reserved3: Padding<c_int>,
}
}
} else {
s! {
pub struct sched_param {
pub sched_priority: c_int,

#[deprecated(since = "0.2.173", note = "This field has been removed upstream")]
pub sched_ss_low_priority: c_int,
#[deprecated(since = "0.2.173", note = "This field has been removed upstream")]
pub sched_ss_repl_period: crate::timespec,
#[deprecated(since = "0.2.173", note = "This field has been removed upstream")]
pub sched_ss_init_budget: crate::timespec,
#[deprecated(since = "0.2.173", note = "This field has been removed upstream")]
pub sched_ss_max_repl: c_int,
}
}
}
}
2 changes: 2 additions & 0 deletions src/new/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ cfg_if! {
pub(crate) use dragonfly::*;
} else if #[cfg(target_os = "emscripten")] {
mod emscripten;
pub use emscripten::sched::*;
pub(crate) use emscripten::*;
} else if #[cfg(target_os = "espidf")] {
mod espidf;
Expand Down Expand Up @@ -150,6 +151,7 @@ cfg_if! {
} else if #[cfg(any(target_env = "musl", target_env = "ohos"))] {
// OhOS also uses the musl libc
mod musl;
pub use musl::sched::*;
pub(crate) use musl::*;
} else if #[cfg(target_env = "newlib")] {
mod newlib;
Expand Down
1 change: 1 addition & 0 deletions src/new/musl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ pub(crate) mod sys {
pub(crate) mod socket;
}

pub(crate) mod sched;
pub(crate) mod unistd;
Loading