Skip to content

Commit 924bfef

Browse files
Rollup merge of rust-lang#153333 - gautam899:main, r=Mark-Simulacrum
Fix bootstrap rust build failure for vxworks Fixes rust-lang#153332 Starting with VxWorks 25.09, struct stat was updated to use struct timespec instead of time_t for timestamp fields. The following changes were made in libc in the commit [libc](rust-lang/libc#4781). As a result, when performing a bootstrap build with VxWorks ≥ 25.09, libc no longer exposes the fields st_mtime, st_atime, and st_ctime, as they are conditionally compiled in src/vxworks/mod.rs here [libc](https://github.com/rust-lang/libc/blob/56caa81b6b433c49c5704bf0400a02d428cfacda/src/vxworks/mod.rs#L229). This causes the build to fail. For VxWorks versions earlier than 25.09, the build completes successfully without errors. This PR resolves the issue by detecting the WIND_RELEASE_ID environment variable (which is set in the VxWorks build environment) and conditionally guarding the affected functions in the two additional files where the errors originate.
2 parents 545036c + 24d86b5 commit 924bfef

4 files changed

Lines changed: 74 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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,54 @@ 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+
}
80+
#[cfg(vxworks_lt_25_09)]
7581
fn st_atime_nsec(&self) -> i64 {
7682
0
7783
}
84+
#[cfg(not(vxworks_lt_25_09))]
85+
fn st_atime_nsec(&self) -> i64 {
86+
self.as_inner().as_inner().st_atim.tv_nsec as i64
87+
}
88+
#[cfg(vxworks_lt_25_09)]
7889
fn st_mtime(&self) -> i64 {
7990
self.as_inner().as_inner().st_mtime as i64
8091
}
92+
#[cfg(not(vxworks_lt_25_09))]
93+
fn st_mtime(&self) -> i64 {
94+
self.as_inner().as_inner().st_mtim.tv_sec as i64
95+
}
96+
#[cfg(vxworks_lt_25_09)]
8197
fn st_mtime_nsec(&self) -> i64 {
8298
0
8399
}
100+
#[cfg(not(vxworks_lt_25_09))]
101+
fn st_mtime_nsec(&self) -> i64 {
102+
self.as_inner().as_inner().st_mtim.tv_nsec as i64
103+
}
104+
#[cfg(vxworks_lt_25_09)]
84105
fn st_ctime(&self) -> i64 {
85106
self.as_inner().as_inner().st_ctime as i64
86107
}
108+
#[cfg(not(vxworks_lt_25_09))]
109+
fn st_ctime(&self) -> i64 {
110+
self.as_inner().as_inner().st_ctim.tv_sec as i64
111+
}
112+
#[cfg(vxworks_lt_25_09)]
87113
fn st_ctime_nsec(&self) -> i64 {
88114
0
89115
}
116+
#[cfg(not(vxworks_lt_25_09))]
117+
fn st_ctime_nsec(&self) -> i64 {
118+
self.as_inner().as_inner().st_ctim.tv_nsec as i64
119+
}
90120
fn st_blksize(&self) -> u64 {
91121
self.as_inner().as_inner().st_blksize as u64
92122
}

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
}

src/doc/rustc/src/platform-support/vxworks.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ Target triplets available:
2828

2929
The minimum supported version is VxWorks 7.
3030

31+
### Environment
32+
33+
#### `WIND_RELEASE_ID`
34+
35+
In VxWorks build environment, the environment variable `WIND_RELEASE_ID` indicates the VxWorks release version used for the build. The `WIND_RELEASE_ID` can be used to conditionally compile features/code or handle version specific behaviour.
36+
3137
## Building
3238

3339
Rust for each target can be cross-compiled with its specific target vsb configuration. Std support is added but not yet fully tested.

0 commit comments

Comments
 (0)