Skip to content

Commit a97640a

Browse files
committed
Auto merge of #3282 - kleisauke:emscripten-new-stat, r=JohnTitor
Fix ABI compatibility with Emscripten >= 3.1.42 See: emscripten-core/emscripten#19569 (comment)
2 parents e2b5151 + 92db93c commit a97640a

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

build.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::string::String;
77
// need to know all the possible cfgs that this script will set. If you need to set another cfg
88
// make sure to add it to this list as well.
99
const ALLOWED_CFGS: &'static [&'static str] = &[
10+
"emscripten_new_stat_abi",
1011
"freebsd10",
1112
"freebsd11",
1213
"freebsd12",
@@ -69,6 +70,12 @@ fn main() {
6970
Some(_) | None => set_cfg("freebsd11"),
7071
}
7172

73+
match emcc_version_code() {
74+
Some(v) if (v >= 30142) => set_cfg("emscripten_new_stat_abi"),
75+
// Non-Emscripten or version < 3.1.42.
76+
Some(_) | None => (),
77+
}
78+
7279
// On CI: deny all warnings
7380
if libc_ci {
7481
set_cfg("libc_deny_warnings");
@@ -238,6 +245,33 @@ fn which_freebsd() -> Option<i32> {
238245
}
239246
}
240247

248+
fn emcc_version_code() -> Option<u64> {
249+
let output = std::process::Command::new("emcc")
250+
.arg("-dumpversion")
251+
.output()
252+
.ok();
253+
if output.is_none() {
254+
return None;
255+
}
256+
let output = output.unwrap();
257+
if !output.status.success() {
258+
return None;
259+
}
260+
261+
let stdout = String::from_utf8(output.stdout).ok();
262+
if stdout.is_none() {
263+
return None;
264+
}
265+
let version = stdout.unwrap();
266+
let mut pieces = version.trim().split('.');
267+
268+
let major = pieces.next().and_then(|x| x.parse().ok()).unwrap_or(0);
269+
let minor = pieces.next().and_then(|x| x.parse().ok()).unwrap_or(0);
270+
let patch = pieces.next().and_then(|x| x.parse().ok()).unwrap_or(0);
271+
272+
Some(major * 10000 + minor * 100 + patch)
273+
}
274+
241275
fn set_cfg(cfg: &str) {
242276
if !ALLOWED_CFGS.contains(&cfg) {
243277
panic!("trying to set cfg {}, but it is not in ALLOWED_CFGS", cfg);

src/unix/linux_like/emscripten/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,16 @@ s! {
260260
}
261261
pub struct stat {
262262
pub st_dev: ::dev_t,
263+
#[cfg(not(emscripten_new_stat_abi))]
263264
__st_dev_padding: ::c_int,
265+
#[cfg(not(emscripten_new_stat_abi))]
264266
__st_ino_truncated: ::c_long,
265267
pub st_mode: ::mode_t,
266268
pub st_nlink: ::nlink_t,
267269
pub st_uid: ::uid_t,
268270
pub st_gid: ::gid_t,
269271
pub st_rdev: ::dev_t,
272+
#[cfg(not(emscripten_new_stat_abi))]
270273
__st_rdev_padding: ::c_int,
271274
pub st_size: ::off_t,
272275
pub st_blksize: ::blksize_t,
@@ -282,13 +285,16 @@ s! {
282285

283286
pub struct stat64 {
284287
pub st_dev: ::dev_t,
288+
#[cfg(not(emscripten_new_stat_abi))]
285289
__st_dev_padding: ::c_int,
290+
#[cfg(not(emscripten_new_stat_abi))]
286291
__st_ino_truncated: ::c_long,
287292
pub st_mode: ::mode_t,
288293
pub st_nlink: ::nlink_t,
289294
pub st_uid: ::uid_t,
290295
pub st_gid: ::gid_t,
291296
pub st_rdev: ::dev_t,
297+
#[cfg(not(emscripten_new_stat_abi))]
292298
__st_rdev_padding: ::c_int,
293299
pub st_size: ::off_t,
294300
pub st_blksize: ::blksize_t,

0 commit comments

Comments
 (0)