Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ABI compatibility with Emscripten >= 3.1.42 #3282

Merged
merged 2 commits into from Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 40 additions & 0 deletions build.rs
Expand Up @@ -7,6 +7,7 @@ use std::string::String;
// need to know all the possible cfgs that this script will set. If you need to set another cfg
// make sure to add it to this list as well.
const ALLOWED_CFGS: &'static [&'static str] = &[
"emscripten_new_stat_abi",
"freebsd10",
"freebsd11",
"freebsd12",
Expand Down Expand Up @@ -69,6 +70,18 @@ fn main() {
Some(_) | None => set_cfg("freebsd11"),
}

match emcc_version() {
Some((major, minor, patch))
if (major > 3)
|| (major == 3 && minor > 1)
|| (major == 3 && minor == 1 && patch >= 42) =>
{
set_cfg("emscripten_new_stat_abi")
}
// Non-Emscripten or version < 3.1.42.
Some(_) | None => (),
}

// On CI: deny all warnings
if libc_ci {
set_cfg("libc_deny_warnings");
Expand Down Expand Up @@ -238,6 +251,33 @@ fn which_freebsd() -> Option<i32> {
}
}

fn emcc_version() -> Option<(u32, u32, u32)> {
let output = std::process::Command::new("emcc")
.arg("-dumpversion")
.output()
.ok();
if output.is_none() {
return None;
}
let output = output.unwrap();
if !output.status.success() {
return None;
}

let stdout = String::from_utf8(output.stdout).ok();
if stdout.is_none() {
return None;
}
let version = stdout.unwrap();
let mut pieces = version.trim().split('.');

let major = pieces.next()?.parse().unwrap();
let minor = pieces.next()?.parse().unwrap();
let patch = pieces.next()?.parse().unwrap();

Some((major, minor, patch))
}

fn set_cfg(cfg: &str) {
if !ALLOWED_CFGS.contains(&cfg) {
panic!("trying to set cfg {}, but it is not in ALLOWED_CFGS", cfg);
Expand Down
6 changes: 6 additions & 0 deletions src/unix/linux_like/emscripten/mod.rs
Expand Up @@ -260,13 +260,16 @@ s! {
}
pub struct stat {
pub st_dev: ::dev_t,
#[cfg(not(emscripten_new_stat_abi))]
__st_dev_padding: ::c_int,
#[cfg(not(emscripten_new_stat_abi))]
__st_ino_truncated: ::c_long,
pub st_mode: ::mode_t,
pub st_nlink: ::nlink_t,
pub st_uid: ::uid_t,
pub st_gid: ::gid_t,
pub st_rdev: ::dev_t,
#[cfg(not(emscripten_new_stat_abi))]
__st_rdev_padding: ::c_int,
pub st_size: ::off_t,
pub st_blksize: ::blksize_t,
Expand All @@ -282,13 +285,16 @@ s! {

pub struct stat64 {
pub st_dev: ::dev_t,
#[cfg(not(emscripten_new_stat_abi))]
__st_dev_padding: ::c_int,
#[cfg(not(emscripten_new_stat_abi))]
__st_ino_truncated: ::c_long,
pub st_mode: ::mode_t,
pub st_nlink: ::nlink_t,
pub st_uid: ::uid_t,
pub st_gid: ::gid_t,
pub st_rdev: ::dev_t,
#[cfg(not(emscripten_new_stat_abi))]
__st_rdev_padding: ::c_int,
pub st_size: ::off_t,
pub st_blksize: ::blksize_t,
Expand Down