mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
faf6cad78c
Differential Revision: https://phabricator.services.mozilla.com/D45719 --HG-- rename : third_party/rust/regex-0.2.2/src/freqs.rs => third_party/rust/aho-corasick/src/byte_frequencies.rs rename : third_party/rust/crc/Cargo.toml => third_party/rust/blake2b_simd/Cargo.toml rename : third_party/rust/miniz_oxide_c_api/LICENSE => third_party/rust/miniz_oxide/LICENSE rename : third_party/rust/redox_users/tests/group => third_party/rust/redox_users/tests/etc/group rename : third_party/rust/redox_users/tests/passwd => third_party/rust/redox_users/tests/etc/passwd rename : third_party/rust/redox_users/tests/shadow => third_party/rust/redox_users/tests/etc/shadow rename : third_party/rust/utf8-ranges/src/lib.rs => third_party/rust/regex-syntax/src/utf8.rs rename : third_party/rust/crossbeam-channel/LICENSE-APACHE => third_party/rust/rust-argon2/LICENSE-APACHE rename : third_party/rust/memchr-1.0.2/COPYING => third_party/rust/winapi-util/COPYING rename : third_party/rust/ucd-util/Cargo.toml => third_party/rust/winapi-util/Cargo.toml rename : third_party/rust/memchr-1.0.2/LICENSE-MIT => third_party/rust/winapi-util/LICENSE-MIT rename : third_party/rust/memchr-1.0.2/UNLICENSE => third_party/rust/winapi-util/UNLICENSE extra : moz-landing-system : lando
91 lines
2.3 KiB
Rust
91 lines
2.3 KiB
Rust
|
|
use std::env;
|
|
use std::io::Write;
|
|
use std::process::{Command, Stdio};
|
|
|
|
fn main() {
|
|
// we need to output *some* file to opt out of the default
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
|
|
detect_maybe_uninit();
|
|
}
|
|
|
|
fn detect_maybe_uninit() {
|
|
let has_stable_maybe_uninit = probe(&stable_maybe_uninit());
|
|
if has_stable_maybe_uninit {
|
|
println!("cargo:rustc-cfg=has_stable_maybe_uninit");
|
|
return;
|
|
}
|
|
let has_unstable_union_with_md = probe(&maybe_uninit_code(true));
|
|
if has_unstable_union_with_md {
|
|
println!("cargo:rustc-cfg=has_manually_drop_in_union");
|
|
println!("cargo:rustc-cfg=has_union_feature");
|
|
}
|
|
}
|
|
|
|
// To guard against changes in this currently unstable feature, use
|
|
// a detection tests instead of a Rustc version and/or date test.
|
|
fn stable_maybe_uninit() -> String {
|
|
let code = "
|
|
#![allow(warnings)]
|
|
use std::mem::MaybeUninit;
|
|
|
|
fn main() { }
|
|
";
|
|
code.to_string()
|
|
}
|
|
|
|
// To guard against changes in this currently unstable feature, use
|
|
// a detection tests instead of a Rustc version and/or date test.
|
|
fn maybe_uninit_code(use_feature: bool) -> String {
|
|
let feature = if use_feature { "#![feature(untagged_unions)]" } else { "" };
|
|
|
|
let code = "
|
|
#![allow(warnings)]
|
|
use std::mem::ManuallyDrop;
|
|
|
|
#[derive(Copy)]
|
|
pub union MaybeUninit<T> {
|
|
empty: (),
|
|
value: ManuallyDrop<T>,
|
|
}
|
|
|
|
impl<T> Clone for MaybeUninit<T> where T: Copy
|
|
{
|
|
fn clone(&self) -> Self { *self }
|
|
}
|
|
|
|
fn main() {
|
|
let value1 = MaybeUninit::<[i32; 3]> { empty: () };
|
|
let value2 = MaybeUninit { value: ManuallyDrop::new([1, 2, 3]) };
|
|
}
|
|
";
|
|
|
|
|
|
[feature, code].concat()
|
|
}
|
|
|
|
/// Test if a code snippet can be compiled
|
|
fn probe(code: &str) -> bool {
|
|
let rustc = env::var_os("RUSTC").unwrap_or_else(|| "rustc".into());
|
|
let out_dir = env::var_os("OUT_DIR").expect("environment variable OUT_DIR");
|
|
|
|
let mut child = Command::new(rustc)
|
|
.arg("--out-dir")
|
|
.arg(out_dir)
|
|
.arg("--emit=obj")
|
|
.arg("-")
|
|
.stdin(Stdio::piped())
|
|
.spawn()
|
|
.expect("rustc probe");
|
|
|
|
child
|
|
.stdin
|
|
.as_mut()
|
|
.expect("rustc stdin")
|
|
.write_all(code.as_bytes())
|
|
.expect("write rustc stdin");
|
|
|
|
child.wait().expect("rustc probe").success()
|
|
}
|