summaryrefslogtreecommitdiffstats
path: root/vendor/io-lifetimes/build.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
commit1376c5a617be5c25655d0d7cb63e3beaa5a6e026 (patch)
tree3bb8d61aee02bc7a15eab3f36e3b921afc2075d0 /vendor/io-lifetimes/build.rs
parentReleasing progress-linux version 1.69.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.tar.xz
rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.zip
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/io-lifetimes/build.rs')
-rw-r--r--vendor/io-lifetimes/build.rs93
1 files changed, 46 insertions, 47 deletions
diff --git a/vendor/io-lifetimes/build.rs b/vendor/io-lifetimes/build.rs
index fd3c6ccce..2fc2a3817 100644
--- a/vendor/io-lifetimes/build.rs
+++ b/vendor/io-lifetimes/build.rs
@@ -8,7 +8,7 @@ fn main() {
}
// Work around
- // https://github.com/rust-lang/rust/issues/103306.
+ // <https://github.com/rust-lang/rust/issues/103306>.
use_feature_or_nothing("wasi_ext");
// Rust 1.56 and earlier don't support panic in const fn.
@@ -33,70 +33,72 @@ fn use_feature(feature: &str) {
/// Test whether the rustc at `var("RUSTC")` supports the given feature.
fn has_feature(feature: &str) -> bool {
+ can_compile(format!(
+ "#![allow(stable_features)]\n#![feature({})]",
+ feature
+ ))
+}
+
+/// Test whether the rustc at `var("RUSTC")` can compile the given code.
+fn can_compile<T: AsRef<str>>(test: T) -> bool {
+ use std::process::Stdio;
+
let out_dir = var("OUT_DIR").unwrap();
let rustc = var("RUSTC").unwrap();
let target = var("TARGET").unwrap();
- let mut child = std::process::Command::new(rustc)
- .arg("--crate-type=rlib") // Don't require `main`.
+ // 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()
+ .and_then(|w| if w.is_empty() { None } else { Some(w) });
+
+ let mut cmd = if let Some(wrapper) = wrapper {
+ let mut cmd = std::process::Command::new(wrapper);
+ // The wrapper's first argument is supposed to be the path to rustc.
+ cmd.arg(rustc);
+ cmd
+ } else {
+ std::process::Command::new(rustc)
+ };
+
+ cmd.arg("--crate-type=rlib") // Don't require `main`.
.arg("--emit=metadata") // Do as little as possible but still parse.
.arg("--target")
.arg(target)
.arg("--out-dir")
- .arg(out_dir) // Put the output somewhere inconsequential.
+ .arg(out_dir); // Put the output somewhere inconsequential.
+
+ // If Cargo wants to set RUSTFLAGS, use that.
+ if let Ok(rustflags) = var("CARGO_ENCODED_RUSTFLAGS") {
+ if !rustflags.is_empty() {
+ for arg in rustflags.split('\x1f') {
+ cmd.arg(arg);
+ }
+ }
+ }
+
+ let mut child = cmd
.arg("-") // Read from stdin.
- .stdin(std::process::Stdio::piped()) // Stdin is a pipe.
+ .stdin(Stdio::piped()) // Stdin is a pipe.
+ .stderr(Stdio::null()) // Errors from feature detection aren't interesting and can be confusing.
.spawn()
.unwrap();
- writeln!(child.stdin.take().unwrap(), "#![feature({})]", feature).unwrap();
+ writeln!(child.stdin.take().unwrap(), "{}", test.as_ref()).unwrap();
child.wait().unwrap().success()
}
/// Test whether the rustc at `var("RUSTC")` supports panic in `const fn`.
fn has_panic_in_const_fn() -> bool {
- let out_dir = var("OUT_DIR").unwrap();
- let rustc = var("RUSTC").unwrap();
- let target = var("TARGET").unwrap();
-
- let mut child = std::process::Command::new(rustc)
- .arg("--crate-type=rlib") // Don't require `main`.
- .arg("--emit=metadata") // Do as little as possible but still parse.
- .arg("--target")
- .arg(target)
- .arg("--out-dir")
- .arg(out_dir) // Put the output somewhere inconsequential.
- .arg("-") // Read from stdin.
- .stdin(std::process::Stdio::piped()) // Stdin is a pipe.
- .spawn()
- .unwrap();
-
- writeln!(child.stdin.take().unwrap(), "const fn foo() {{ panic!() }}").unwrap();
-
- child.wait().unwrap().success()
+ can_compile("const fn foo() {{ panic!() }}")
}
/// Test whether the rustc at `var("RUSTC")` supports the I/O safety feature.
fn has_io_safety() -> bool {
- let out_dir = var("OUT_DIR").unwrap();
- let rustc = var("RUSTC").unwrap();
- let target = var("TARGET").unwrap();
-
- let mut child = std::process::Command::new(rustc)
- .arg("--crate-type=rlib") // Don't require `main`.
- .arg("--emit=metadata") // Do as little as possible but still parse.
- .arg("--target")
- .arg(target)
- .arg("--out-dir")
- .arg(out_dir) // Put the output somewhere inconsequential.
- .arg("-") // Read from stdin.
- .stdin(std::process::Stdio::piped()) // Stdin is a pipe.
- .spawn()
- .unwrap();
-
- writeln!(
- child.stdin.take().unwrap(),
+ can_compile(
"\
#[cfg(unix)]\n\
use std::os::unix::io::OwnedFd as Owned;\n\
@@ -106,9 +108,6 @@ fn has_io_safety() -> bool {
use std::os::windows::io::OwnedHandle as Owned;\n\
\n\
pub type Success = Owned;\n\
- "
+ ",
)
- .unwrap();
-
- child.wait().unwrap().success()
}