Skip to content

Commit cd1ab2f

Browse files
committed
Fix rust build failure for vxworks
1 parent d3877ec commit cd1ab2f

3 files changed

Lines changed: 53 additions & 4 deletions

File tree

library/std/build.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,28 @@ fn main() {
7979
println!("cargo:rustc-cfg=backtrace_in_libstd");
8080

8181
println!("cargo:rustc-env=STD_ENV_ARCH={}", env::var("CARGO_CFG_TARGET_ARCH").unwrap());
82+
83+
println!("cargo:rustc-check-cfg=cfg(vxworks_lt_25_09)");
84+
85+
if target_os == "vxworks" {
86+
match vxworks_version_code() {
87+
Some((major, minor)) if (major, minor) < (25, 9) => {
88+
println!("cargo:rustc-cfg=vxworks_lt_25_09");
89+
}
90+
_ => {}
91+
}
92+
}
93+
}
94+
95+
/// Retrieve the VxWorks release version from the environment variable set by the VxWorks build
96+
/// environment, in `(minor, patch)` form.
97+
fn vxworks_version_code() -> Option<(u32, u32)> {
98+
let version = env::var("WIND_RELEASE_ID").ok()?;
99+
100+
let mut pieces = version.trim().split(['.']);
101+
102+
let major: u32 = pieces.next().and_then(|x| x.parse().ok()).unwrap_or(0);
103+
let minor: u32 = pieces.next().and_then(|x| x.parse().ok()).unwrap_or(0);
104+
105+
Some((major, minor))
82106
}

library/std/src/os/vxworks/fs.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,36 @@ impl MetadataExt for Metadata {
6969
fn st_size(&self) -> u64 {
7070
self.as_inner().as_inner().st_size as u64
7171
}
72+
#[cfg(vxworks_lt_25_09)]
7273
fn st_atime(&self) -> i64 {
7374
self.as_inner().as_inner().st_atime as i64
7475
}
76+
#[cfg(not(vxworks_lt_25_09))]
77+
fn st_atime(&self) -> i64 {
78+
self.as_inner().as_inner().st_atim.tv_sec as i64
79+
}
7580
fn st_atime_nsec(&self) -> i64 {
7681
0
7782
}
83+
#[cfg(vxworks_lt_25_09)]
7884
fn st_mtime(&self) -> i64 {
7985
self.as_inner().as_inner().st_mtime as i64
8086
}
87+
#[cfg(not(vxworks_lt_25_09))]
88+
fn st_mtime(&self) -> i64 {
89+
self.as_inner().as_inner().st_mtim.tv_sec as i64
90+
}
8191
fn st_mtime_nsec(&self) -> i64 {
8292
0
8393
}
94+
#[cfg(vxworks_lt_25_09)]
8495
fn st_ctime(&self) -> i64 {
8596
self.as_inner().as_inner().st_ctime as i64
8697
}
98+
#[cfg(not(vxworks_lt_25_09))]
99+
fn st_ctime(&self) -> i64 {
100+
self.as_inner().as_inner().st_ctim.tv_sec as i64
101+
}
87102
fn st_ctime_nsec(&self) -> i64 {
88103
0
89104
}

library/std/src/sys/fs/unix.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ impl FileAttr {
634634
}
635635

636636
#[cfg(any(
637-
target_os = "vxworks",
637+
all(target_os = "vxworks", vxworks_lt_25_09),
638638
target_os = "espidf",
639639
target_os = "vita",
640640
target_os = "rtems",
@@ -643,7 +643,12 @@ impl FileAttr {
643643
SystemTime::new(self.stat.st_mtime as i64, 0)
644644
}
645645

646-
#[cfg(any(target_os = "horizon", target_os = "hurd", target_os = "nuttx"))]
646+
#[cfg(any(
647+
target_os = "horizon",
648+
target_os = "hurd",
649+
target_os = "nuttx",
650+
all(target_os = "vxworks", not(vxworks_lt_25_09))
651+
))]
647652
pub fn modified(&self) -> io::Result<SystemTime> {
648653
SystemTime::new(self.stat.st_mtim.tv_sec as i64, self.stat.st_mtim.tv_nsec as i64)
649654
}
@@ -669,7 +674,7 @@ impl FileAttr {
669674
}
670675

671676
#[cfg(any(
672-
target_os = "vxworks",
677+
all(target_os = "vxworks", vxworks_lt_25_09),
673678
target_os = "espidf",
674679
target_os = "vita",
675680
target_os = "rtems"
@@ -678,7 +683,12 @@ impl FileAttr {
678683
SystemTime::new(self.stat.st_atime as i64, 0)
679684
}
680685

681-
#[cfg(any(target_os = "horizon", target_os = "hurd", target_os = "nuttx"))]
686+
#[cfg(any(
687+
target_os = "horizon",
688+
target_os = "hurd",
689+
target_os = "nuttx",
690+
all(target_os = "vxworks", not(vxworks_lt_25_09)),
691+
))]
682692
pub fn accessed(&self) -> io::Result<SystemTime> {
683693
SystemTime::new(self.stat.st_atim.tv_sec as i64, self.stat.st_atim.tv_nsec as i64)
684694
}

0 commit comments

Comments
 (0)