summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/bors.yml17
-rw-r--r--build.rs105
-rw-r--r--src/wasi.rs5
3 files changed, 102 insertions, 25 deletions
diff --git a/.github/workflows/bors.yml b/.github/workflows/bors.yml
index 49a06de686..e4e342a1b3 100644
--- a/.github/workflows/bors.yml
+++ b/.github/workflows/bors.yml
@@ -317,6 +317,23 @@ jobs:
run: LIBC_CI=1 TOOLCHAIN=${{ matrix.toolchain }} WIN_TARGET=${{ matrix.target }} sh ./ci/build.sh
shell: bash
+ check_cfg:
+ permissions:
+ actions: write # to cancel workflows (rust-lang/simpleinfra/github-actions/cancel-outdated-builds)
+ contents: read # to fetch code (actions/checkout)
+
+ name: "Check #[cfg]s"
+ runs-on: ubuntu-22.04
+ steps:
+ - uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master
+ with:
+ github_token: "${{ secrets.GITHUB_TOKEN }}"
+ - uses: actions/checkout@v3
+ - name: Setup Rust toolchain
+ run: TOOLCHAIN=nightly sh ./ci/install-rust.sh
+ - name: Build with check-cfg
+ run: LIBC_CI=1 LIBC_CHECK_CFG=1 cargo build -Z unstable-options -Z check-cfg=features,names,values,output
+
docs:
permissions:
actions: write # to cancel workflows (rust-lang/simpleinfra/github-actions/cancel-outdated-builds)
diff --git a/build.rs b/build.rs
index e97be1a6ab..e60672a761 100644
--- a/build.rs
+++ b/build.rs
@@ -2,6 +2,40 @@ use std::env;
use std::process::Command;
use std::str;
+// List of cfgs this build script is allowed to set. The list is needed to support check-cfg, as we
+// 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] = &[
+ "freebsd10",
+ "freebsd11",
+ "freebsd12",
+ "freebsd13",
+ "freebsd14",
+ "libc_align",
+ "libc_cfg_target_vendor",
+ "libc_const_extern_fn",
+ "libc_const_extern_fn_unstable",
+ "libc_const_size_of",
+ "libc_core_cvoid",
+ "libc_deny_warnings",
+ "libc_int128",
+ "libc_long_array",
+ "libc_non_exhaustive",
+ "libc_packedN",
+ "libc_priv_mod_use",
+ "libc_ptr_addr_of",
+ "libc_thread_local",
+ "libc_underscore_const_names",
+ "libc_union",
+];
+
+// Extra values to allow for check-cfg.
+const CHECK_CFG_EXTRA: &'static [(&'static str, &'static [&'static str])] = &[
+ ("target_os", &["switch", "aix", "ohos"]),
+ ("target_env", &["illumos", "wasi", "aix", "ohos"]),
+ ("target_arch", &["loongarch64"]),
+];
+
fn main() {
// Avoid unnecessary re-building.
println!("cargo:rerun-if-changed=build.rs");
@@ -11,6 +45,7 @@ fn main() {
let align_cargo_feature = env::var("CARGO_FEATURE_ALIGN").is_ok();
let const_extern_fn_cargo_feature = env::var("CARGO_FEATURE_CONST_EXTERN_FN").is_ok();
let libc_ci = env::var("LIBC_CI").is_ok();
+ let libc_check_cfg = env::var("LIBC_CHECK_CFG").is_ok();
if env::var("CARGO_FEATURE_USE_STD").is_ok() {
println!(
@@ -25,94 +60,107 @@ fn main() {
// On CI, we detect the actual FreeBSD version and match its ABI exactly,
// running tests to ensure that the ABI is correct.
match which_freebsd() {
- Some(10) if libc_ci || rustc_dep_of_std => {
- println!("cargo:rustc-cfg=freebsd10")
- }
- Some(11) if libc_ci => println!("cargo:rustc-cfg=freebsd11"),
- Some(12) if libc_ci => println!("cargo:rustc-cfg=freebsd12"),
- Some(13) if libc_ci => println!("cargo:rustc-cfg=freebsd13"),
- Some(14) if libc_ci => println!("cargo:rustc-cfg=freebsd14"),
- Some(_) | None => println!("cargo:rustc-cfg=freebsd11"),
+ Some(10) if libc_ci || rustc_dep_of_std => set_cfg("freebsd10"),
+ Some(11) if libc_ci => set_cfg("freebsd11"),
+ Some(12) if libc_ci => set_cfg("freebsd12"),
+ Some(13) if libc_ci => set_cfg("freebsd13"),
+ Some(14) if libc_ci => set_cfg("freebsd14"),
+ Some(_) | None => set_cfg("freebsd11"),
}
// On CI: deny all warnings
if libc_ci {
- println!("cargo:rustc-cfg=libc_deny_warnings");
+ set_cfg("libc_deny_warnings");
}
// Rust >= 1.15 supports private module use:
if rustc_minor_ver >= 15 || rustc_dep_of_std {
- println!("cargo:rustc-cfg=libc_priv_mod_use");
+ set_cfg("libc_priv_mod_use");
}
// Rust >= 1.19 supports unions:
if rustc_minor_ver >= 19 || rustc_dep_of_std {
- println!("cargo:rustc-cfg=libc_union");
+ set_cfg("libc_union");
}
// Rust >= 1.24 supports const mem::size_of:
if rustc_minor_ver >= 24 || rustc_dep_of_std {
- println!("cargo:rustc-cfg=libc_const_size_of");
+ set_cfg("libc_const_size_of");
}
// Rust >= 1.25 supports repr(align):
if rustc_minor_ver >= 25 || rustc_dep_of_std || align_cargo_feature {
- println!("cargo:rustc-cfg=libc_align");
+ set_cfg("libc_align");
}
// Rust >= 1.26 supports i128 and u128:
if rustc_minor_ver >= 26 || rustc_dep_of_std {
- println!("cargo:rustc-cfg=libc_int128");
+ set_cfg("libc_int128");
}
// Rust >= 1.30 supports `core::ffi::c_void`, so libc can just re-export it.
// Otherwise, it defines an incompatible type to retaining
// backwards-compatibility.
if rustc_minor_ver >= 30 || rustc_dep_of_std {
- println!("cargo:rustc-cfg=libc_core_cvoid");
+ set_cfg("libc_core_cvoid");
}
// Rust >= 1.33 supports repr(packed(N)) and cfg(target_vendor).
if rustc_minor_ver >= 33 || rustc_dep_of_std {
- println!("cargo:rustc-cfg=libc_packedN");
- println!("cargo:rustc-cfg=libc_cfg_target_vendor");
+ set_cfg("libc_packedN");
+ set_cfg("libc_cfg_target_vendor");
}
// Rust >= 1.40 supports #[non_exhaustive].
if rustc_minor_ver >= 40 || rustc_dep_of_std {
- println!("cargo:rustc-cfg=libc_non_exhaustive");
+ set_cfg("libc_non_exhaustive");
}
// Rust >= 1.47 supports long array:
if rustc_minor_ver >= 47 || rustc_dep_of_std {
- println!("cargo:rustc-cfg=libc_long_array");
+ set_cfg("libc_long_array");
}
if rustc_minor_ver >= 51 || rustc_dep_of_std {
- println!("cargo:rustc-cfg=libc_ptr_addr_of");
+ set_cfg("libc_ptr_addr_of");
}
// Rust >= 1.37.0 allows underscores as anonymous constant names.
if rustc_minor_ver >= 37 || rustc_dep_of_std {
- println!("cargo:rustc-cfg=libc_underscore_const_names");
+ set_cfg("libc_underscore_const_names");
}
// #[thread_local] is currently unstable
if rustc_dep_of_std {
- println!("cargo:rustc-cfg=libc_thread_local");
+ set_cfg("libc_thread_local");
}
// Rust >= 1.62.0 allows to use `const_extern_fn` for "Rust" and "C".
if rustc_minor_ver >= 62 {
- println!("cargo:rustc-cfg=libc_const_extern_fn");
+ set_cfg("libc_const_extern_fn");
} else {
// Rust < 1.62.0 requires a crate feature and feature gate.
if const_extern_fn_cargo_feature {
if !is_nightly || rustc_minor_ver < 40 {
panic!("const-extern-fn requires a nightly compiler >= 1.40");
}
- println!("cargo:rustc-cfg=libc_const_extern_fn_unstable");
- println!("cargo:rustc-cfg=libc_const_extern_fn");
+ set_cfg("libc_const_extern_fn_unstable");
+ set_cfg("libc_const_extern_fn");
+ }
+ }
+
+ // check-cfg is a nightly cargo/rustc feature to warn when unknown cfgs are used across the
+ // codebase. libc can configure it if the appropriate environment variable is passed. Since
+ // rust-lang/rust enforces it, this is useful when using a custom libc fork there.
+ //
+ // https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg
+ if libc_check_cfg {
+ for cfg in ALLOWED_CFGS {
+ println!("cargo:rustc-check-cfg=values({})", cfg);
+ }
+ for &(name, values) in CHECK_CFG_EXTRA {
+ let values = values.join("\",\"");
+ println!("cargo:rustc-check-cfg=values({},\"{}\")", name, values);
}
}
}
@@ -181,3 +229,10 @@ fn which_freebsd() -> Option<i32> {
_ => None,
}
}
+
+fn set_cfg(cfg: &str) {
+ if !ALLOWED_CFGS.contains(&cfg) {
+ panic!("trying to set cfg {}, but it is not in ALLOWED_CFGS", cfg);
+ }
+ println!("cargo:rustc-cfg={}", cfg);
+}
diff --git a/src/wasi.rs b/src/wasi.rs
index abfebd6439..1a855e0e0f 100644
--- a/src/wasi.rs
+++ b/src/wasi.rs
@@ -246,12 +246,15 @@ pub const S_IFREG: mode_t = 32768;
pub const S_IFLNK: mode_t = 40960;
pub const S_IFSOCK: mode_t = 49152;
pub const S_IFMT: mode_t = 57344;
+pub const S_IRWXO: mode_t = 0x7;
pub const S_IXOTH: mode_t = 0x1;
pub const S_IWOTH: mode_t = 0x2;
pub const S_IROTH: mode_t = 0x4;
+pub const S_IRWXG: mode_t = 0x38;
pub const S_IXGRP: mode_t = 0x8;
pub const S_IWGRP: mode_t = 0x10;
pub const S_IRGRP: mode_t = 0x20;
+pub const S_IRWXU: mode_t = 0x1c0;
pub const S_IXUSR: mode_t = 0x40;
pub const S_IWUSR: mode_t = 0x80;
pub const S_IRUSR: mode_t = 0x100;
@@ -822,4 +825,6 @@ extern "C" {
pub fn arc4random() -> u32;
pub fn arc4random_buf(a: *mut c_void, b: size_t);
pub fn arc4random_uniform(a: u32) -> u32;
+
+ pub fn __errno_location() -> *mut ::c_int;
}