diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:59:24 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:59:24 +0000 |
commit | 023939b627b7dc93b01471f7d41fb8553ddb4ffa (patch) | |
tree | 60fc59477c605c72b0a1051409062ddecc43f877 /vendor/rustix/build.rs | |
parent | Adding debian version 1.72.1+dfsg1-1. (diff) | |
download | rustc-023939b627b7dc93b01471f7d41fb8553ddb4ffa.tar.xz rustc-023939b627b7dc93b01471f7d41fb8553ddb4ffa.zip |
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/rustix/build.rs')
-rw-r--r-- | vendor/rustix/build.rs | 193 |
1 files changed, 73 insertions, 120 deletions
diff --git a/vendor/rustix/build.rs b/vendor/rustix/build.rs index 26f306e58..cf7cf6edf 100644 --- a/vendor/rustix/build.rs +++ b/vendor/rustix/build.rs @@ -1,36 +1,20 @@ -#[cfg(feature = "cc")] -use cc::Build; use std::env::var; use std::io::Write; -/// The directory for out-of-line (“outline”) libraries. -const OUTLINE_PATH: &str = "src/backend/linux_raw/arch/outline"; - /// The directory for inline asm. -const INLINE_PATH: &str = "src/backend/linux_raw/arch/inline"; +const ASM_PATH: &str = "src/backend/linux_raw/arch/asm"; fn main() { // Don't rerun this on changes other than build.rs, as we only depend on // the rustc version. println!("cargo:rerun-if-changed=build.rs"); - use_feature_or_nothing("rustc_attrs"); - - // Features only used in no-std configurations. - #[cfg(not(feature = "std"))] - { - use_feature_or_nothing("const_raw_ptr_deref"); - use_feature_or_nothing("core_ffi_c"); - use_feature_or_nothing("core_c_str"); - use_feature_or_nothing("alloc_c_string"); - } - // Gather target information. let arch = var("CARGO_CFG_TARGET_ARCH").unwrap(); - let outline_asm_name = format!("{}/{}.s", OUTLINE_PATH, arch); - let inline_asm_name = format!("{}/{}.rs", INLINE_PATH, arch); + let env = var("CARGO_CFG_TARGET_ENV").unwrap(); + let inline_asm_name = format!("{}/{}.rs", ASM_PATH, arch); let inline_asm_name_present = std::fs::metadata(inline_asm_name).is_ok(); - let target_os = var("CARGO_CFG_TARGET_OS").unwrap(); + let os = var("CARGO_CFG_TARGET_OS").unwrap(); let pointer_width = var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap(); let endian = var("CARGO_CFG_TARGET_ENDIAN").unwrap(); @@ -38,8 +22,8 @@ fn main() { let is_x32 = arch == "x86_64" && pointer_width == "32"; let is_arm64_ilp32 = arch == "aarch64" && pointer_width == "32"; let is_powerpc64be = arch == "powerpc64" && endian == "big"; - let is_mipseb = arch == "mips" && endian == "big"; - let is_mips64eb = arch == "mips64" && endian == "big"; + let is_mipseb = (arch == "mips" || arch == "mips32r6") && endian == "big"; + let is_mips64eb = arch.contains("mips64") && endian == "big"; let is_unsupported_abi = is_x32 || is_arm64_ilp32 || is_powerpc64be || is_mipseb || is_mips64eb; // Check for `--features=use-libc`. This allows crate users to enable the @@ -50,6 +34,13 @@ fn main() { // enable the libc backend even if rustix is depended on transitively. let cfg_use_libc = var("CARGO_CFG_RUSTIX_USE_LIBC").is_ok(); + // Check for eg. `RUSTFLAGS=--cfg=rustix_use_experimental_features`. This + // is a rustc flag rather than a cargo feature flag because it's + // experimental and not something we want accidentally enabled via + // `--all-features`. + let rustix_use_experimental_features = + var("CARGO_CFG_RUSTIX_USE_EXPERIMENTAL_FEATURES").is_ok(); + // Check for eg. `RUSTFLAGS=--cfg=rustix_use_experimental_asm`. This is a // rustc flag rather than a cargo feature flag because it's experimental // and not something we want accidentally enabled via `--all-features`. @@ -59,43 +50,49 @@ fn main() { // libc FFI calls, so if we're running under miri, use the libc backend. let miri = var("CARGO_CFG_MIRI").is_ok(); + // If experimental features are enabled, auto-detect and use available + // features. + if rustix_use_experimental_features { + use_feature_or_nothing("rustc_attrs"); + use_feature_or_nothing("core_intrinsics"); + } + + // Features needed only in no-std configurations. + #[cfg(not(feature = "std"))] + { + use_feature_or_nothing("core_c_str"); + use_feature_or_nothing("core_ffi_c"); + use_feature_or_nothing("alloc_c_string"); + use_feature_or_nothing("alloc_ffi"); + } + + // Feature needed for testing. + if use_static_assertions() { + use_feature("static_assertions"); + } + // If the libc backend is requested, or if we're not on a platform for // which we have linux_raw support, use the libc backend. // // For now Android uses the libc backend; in theory it could use the // linux_raw backend, but to do that we'll need to figure out how to // install the toolchain for it. - if feature_use_libc + let libc = feature_use_libc || cfg_use_libc - || target_os != "linux" + || os != "linux" || !inline_asm_name_present || is_unsupported_abi || miri - { + || ((arch == "powerpc64" || arch == "mips" || arch == "mips64" || arch == "mips64r6") + && !rustix_use_experimental_asm); + if libc { // Use the libc backend. use_feature("libc"); } else { // Use the linux_raw backend. use_feature("linux_raw"); - use_feature_or_nothing("core_intrinsics"); - - // Use inline asm if we have it, or outline asm otherwise. On 32-bit - // x86 our asm support requires naked functions. On PowerPC and MIPS, - // Rust's inline asm is considered experimental, so only use it if - // `--cfg=rustix_use_experimental_asm` is given. - if (arch != "x86" || has_feature("naked_functions")) - && ((arch != "powerpc64" && arch != "mips" && arch != "mips64") - || rustix_use_experimental_asm) - { - use_feature("asm"); - if arch == "x86" { - use_feature("naked_functions"); - } - if rustix_use_experimental_asm { - use_feature("asm_experimental_arch"); - } - } else { - link_in_librustix_outline(&arch, &outline_asm_name); + if rustix_use_experimental_asm { + use_feature("asm_experimental_arch"); } } @@ -106,44 +103,50 @@ fn main() { // Rust's libc crate groups some OS's together which have similar APIs; // create similarly-named features to make `cfg` tests more concise. - if target_os == "freebsd" || target_os == "dragonfly" { + let freebsdlike = os == "freebsd" || os == "dragonfly"; + if freebsdlike { use_feature("freebsdlike"); } - if target_os == "openbsd" || target_os == "netbsd" { + let netbsdlike = os == "openbsd" || os == "netbsd"; + if netbsdlike { use_feature("netbsdlike"); } - if target_os == "macos" || target_os == "ios" || target_os == "tvos" || target_os == "watchos" { + let apple = os == "macos" || os == "ios" || os == "tvos" || os == "watchos"; + if apple { use_feature("apple"); } - if target_os == "linux" - || target_os == "l4re" - || target_os == "android" - || target_os == "emscripten" - { + if os == "linux" || os == "l4re" || os == "android" || os == "emscripten" { use_feature("linux_like"); } - if target_os == "solaris" || target_os == "illumos" { + if os == "solaris" || os == "illumos" { use_feature("solarish"); } - if target_os == "macos" - || target_os == "ios" - || target_os == "tvos" - || target_os == "watchos" - || target_os == "freebsd" - || target_os == "dragonfly" - || target_os == "openbsd" - || target_os == "netbsd" - { + if apple || freebsdlike || netbsdlike { use_feature("bsd"); } // Add some additional common target combinations. - if target_os == "android" || target_os == "linux" { + + // Android and "regular" Linux both use the Linux kernel. + if os == "android" || os == "linux" { use_feature("linux_kernel"); } - if target_os == "wasi" { - use_feature_or_nothing("wasi_ext"); + // These platforms have a 32-bit `time_t`. + if libc + && (arch == "arm" + || arch == "mips" + || arch == "sparc" + || arch == "x86" + || (arch == "wasm32" && os == "emscripten")) + && (apple + || os == "android" + || os == "emscripten" + || os == "haiku" + || env == "gnu" + || (env == "musl" && arch == "x86")) + { + use_feature("fix_y2038"); } println!("cargo:rerun-if-env-changed=CARGO_CFG_RUSTIX_USE_EXPERIMENTAL_ASM"); @@ -156,59 +159,9 @@ fn main() { println!("cargo:rerun-if-env-changed=CARGO_CFG_MIRI"); } -/// Link in the desired version of librustix_outline_{arch}.a, containing the -/// outline assembly code for making syscalls. -fn link_in_librustix_outline(arch: &str, asm_name: &str) { - let name = format!("rustix_outline_{}", arch); - let profile = var("PROFILE").unwrap(); - let to = format!("{}/{}/lib{}.a", OUTLINE_PATH, profile, name); - println!("cargo:rerun-if-changed={}", to); - - // If "cc" is not enabled, use a pre-built library. - #[cfg(not(feature = "cc"))] - { - let _ = asm_name; - println!("cargo:rustc-link-search={}/{}", OUTLINE_PATH, profile); - println!("cargo:rustc-link-lib=static={}", name); - } - - // If "cc" is enabled, build the library from source, update the pre-built - // version, and assert that the pre-built version is checked in. - #[cfg(feature = "cc")] - { - let out_dir = var("OUT_DIR").unwrap(); - // Add `-gdwarf-3` so that we always get the same output, regardless of - // the Rust version we're using. DWARF3 is entirely adequate for our - // simple needs here. - let mut build = Build::new(); - if profile == "debug" { - build.flag("-gdwarf-3"); - } - build.file(&asm_name); - build.compile(&name); - println!("cargo:rerun-if-changed={}", asm_name); - if std::fs::metadata(".git").is_ok() { - let from = format!("{}/lib{}.a", out_dir, name); - let prev_metadata = std::fs::metadata(&to); - std::fs::copy(&from, &to).unwrap(); - assert!( - prev_metadata.is_ok(), - "{} didn't previously exist; please inspect the new file and `git add` it", - to - ); - assert!( - std::process::Command::new("git") - .arg("diff") - .arg("--quiet") - .arg(&to) - .status() - .unwrap() - .success(), - "{} changed; please inspect the change and `git commit` it", - to - ); - } - } +fn use_static_assertions() -> bool { + // `offset_from` was made const in Rust 1.65. + can_compile("const unsafe fn foo(p: *const u8) -> isize { p.offset_from(p) }") } fn use_thumb_mode() -> bool { @@ -242,8 +195,8 @@ fn can_compile<T: AsRef<str>>(test: T) -> bool { let rustc = var("RUSTC").unwrap(); let target = var("TARGET").unwrap(); - // Use `RUSTC_WRAPPER` if it's set, unless it's set to an empty string, - // as documented [here]. + // Use `RUSTC_WRAPPER` if it's set, unless it's set to an empty string, as + // documented [here]. // [here]: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-reads let wrapper = var("RUSTC_WRAPPER") .ok() |