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

// Extra values to allow for check-cfg.
Expand Down Expand Up @@ -85,6 +86,12 @@ fn main() {
_ => (),
}

match vxworks_version_code() {
Some(v) if (v < (25, 9)) => set_cfg("vxworks_lt_25_09"),
// VxWorks version >= 25.09
_ => (),
}

let musl_v1_2_3 = env::var("RUST_LIBC_UNSTABLE_MUSL_V1_2_3").is_ok();
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_MUSL_V1_2_3");
// loongarch64 and ohos have already updated
Expand Down Expand Up @@ -274,6 +281,20 @@ fn emcc_version_code() -> Option<u64> {
Some(major * 10000 + minor * 100 + patch)
}

/// Retrieve the VxWorks release version from the environment variable set by the VxWorks build
/// environment, in `(minor, patch)` form. Currently the only major version supported by Rust
/// is 7.
fn vxworks_version_code() -> Option<(u32, u32)> {
let version = env::var("WIND_RELEASE_ID").ok()?;

let mut pieces = version.trim().split(['.']);

let major: u32 = pieces.next().and_then(|x| x.parse().ok()).unwrap_or(0);
let minor: u32 = pieces.next().and_then(|x| x.parse().ok()).unwrap_or(0);

Some((major, minor))
}

fn set_cfg(cfg: &str) {
assert!(
ALLOWED_CFGS.contains(&cfg),
Expand Down
58 changes: 51 additions & 7 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fn do_semver() {
// maintain a file for Android.
// NOTE: AIX doesn't include the unix file because there are definitions
// missing on AIX. It is easier to maintain a file for AIX.
if family != os && !matches!(os.as_str(), "android" | "aix") {
if family != os && !matches!(os.as_str(), "android" | "aix") && os != "vxworks" {
process_semver_file(&mut output, &mut semver_root, &family);
}
// We don't do semver for unknown targets.
Expand Down Expand Up @@ -3333,13 +3333,33 @@ fn test_neutrino(target: &str) {
ctest::generate_test(&mut cfg, "../src/lib.rs", "ctest_output.rs").unwrap();
}

fn which_vxworks() -> Option<(u32, u32)> {
let version = env::var("WIND_RELEASE_ID").ok()?; // When in VxWorks setup, WIND_RELEASE_ID is
// always set as the version of the release.

let mut pieces = version.trim().split(['.']);

let major: u32 = pieces.next().and_then(|x| x.parse().ok()).unwrap_or(0);
let minor: u32 = pieces.next().and_then(|x| x.parse().ok()).unwrap_or(0);

Some((major, minor))
}

fn test_vxworks(target: &str) {
assert!(target.contains("vxworks"));

let mut cfg = ctest_cfg();

let vxworks_ver = which_vxworks();

if vxworks_ver < Some((25, 9)) {
cfg.cfg("vxworks_lt_25_09", None);
}

headers!(
cfg,
"vxWorks.h",
"semLibCommon.h",
"yvals.h",
"nfs/nfsCommon.h",
"rtpLibCommon.h",
Expand All @@ -3356,13 +3376,11 @@ fn test_vxworks(target: &str) {
"elf.h",
"fcntl.h",
"grp.h",
"sys/poll.h",
"ifaddrs.h",
"langinfo.h",
"limits.h",
"link.h",
"locale.h",
"sys/stat.h",
"netdb.h",
"pthread.h",
"pwd.h",
Expand All @@ -3374,6 +3392,9 @@ fn test_vxworks(target: &str) {
"stdio.h",
"stdlib.h",
"string.h",
"sys/select.h",
"sys/stat.h",
"sys/poll.h",
"sys/file.h",
"sys/ioctl.h",
"sys/socket.h",
Expand All @@ -3384,7 +3405,14 @@ fn test_vxworks(target: &str) {
"sys/un.h",
"sys/utsname.h",
"sys/wait.h",
"sys/ttycom.h",
"sys/utsname.h",
"sys/resource.h",
"sys/mman.h",
"netinet/tcp.h",
"netinet/udp.h",
"netinet/in.h",
"netinet6/in6.h",
"syslog.h",
"termios.h",
"time.h",
Expand All @@ -3393,16 +3421,22 @@ fn test_vxworks(target: &str) {
"utime.h",
"wchar.h",
"errno.h",
"sys/mman.h",
"pathLib.h",
"mqueue.h",
"fnmatch.h",
"sioLibCommon.h",
"net/if.h",
);
// FIXME(vxworks)
cfg.skip_const(move |constant| match constant.ident() {
// sighandler_t weirdness
"SIG_DFL" | "SIG_ERR" | "SIG_IGN"
// This is not defined in vxWorks
| "RTLD_DEFAULT" => true,
// These are not defined in VxWorks
| "RTLD_DEFAULT" | "PRIO_PROCESS"
// Sticky bits not supported
| "S_ISVTX"
// The following are obsolete for VxWorks
| "SIGIO" | "SIGWINCH" | "SIGLOST" => true,
_ => false,
});
// FIXME(vxworks)
Expand All @@ -3413,7 +3447,12 @@ fn test_vxworks(target: &str) {

cfg.skip_struct_field_type(
move |struct_, field| match (struct_.ident(), field.ident()) {
("siginfo_t", "si_value") | ("stat", "st_size") | ("sigaction", "sa_u") => true,
("siginfo_t", "si_value")
| ("stat", "st_size")
// sighandler_t type is super weird
| ("sigaction", "sa_sigaction")
// sa_u_t type is not defined in vxworks
| ("sigaction", "sa_u") => true,
_ => false,
},
);
Expand All @@ -3430,11 +3469,16 @@ fn test_vxworks(target: &str) {
cfg.skip_fn(move |func| match func.ident() {
// sighandler_t
"signal"
// This is used a realpath and not _realpath
| "_realpath"
// not used in static linking by default
| "dlerror" => true,
_ => false,
});

// Not defined in vxworks. Just a crate specific union type.
cfg.skip_union(move |u| u.ident() == "sa_u_t");

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

Expand Down
Loading