Skip to content

Commit 63b0d67

Browse files
committed
Fix ABI compatibility with Emscripten >= 3.1.42
See: emscripten-core/emscripten#19569 (comment)
1 parent 1e8943d commit 63b0d67

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

build.rs

+40
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,18 @@ fn main() {
6970
Some(_) | None => set_cfg("freebsd11"),
7071
}
7172

73+
match emcc_version() {
74+
Some((major, minor, patch))
75+
if (major > 3)
76+
|| (major == 3 && minor > 1)
77+
|| (major == 3 && minor == 1 && patch >= 42) =>
78+
{
79+
set_cfg("emscripten_new_stat_abi")
80+
}
81+
// Non-Emscripten or version < 3.1.42.
82+
Some(_) | None => (),
83+
}
84+
7285
// On CI: deny all warnings
7386
if libc_ci {
7487
set_cfg("libc_deny_warnings");
@@ -238,6 +251,33 @@ fn which_freebsd() -> Option<i32> {
238251
}
239252
}
240253

254+
fn emcc_version() -> Option<(u32, u32, u32)> {
255+
let output = std::process::Command::new("emcc")
256+
.arg("-dumpversion")
257+
.output()
258+
.ok();
259+
if output.is_none() {
260+
return None;
261+
}
262+
let output = output.unwrap();
263+
if !output.status.success() {
264+
return None;
265+
}
266+
267+
let stdout = String::from_utf8(output.stdout).ok();
268+
if stdout.is_none() {
269+
return None;
270+
}
271+
let version = stdout.unwrap();
272+
let mut pieces = version.trim().split('.');
273+
274+
let major = pieces.next()?.parse().unwrap();
275+
let minor = pieces.next()?.parse().unwrap();
276+
let patch = pieces.next()?.parse().unwrap();
277+
278+
Some((major, minor, patch))
279+
}
280+
241281
fn set_cfg(cfg: &str) {
242282
if !ALLOWED_CFGS.contains(&cfg) {
243283
panic!("trying to set cfg {}, but it is not in ALLOWED_CFGS", cfg);

src/unix/linux_like/emscripten/mod.rs

+6
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)