|| (target.contains("sgx") && target.contains("fortanix"))
|| target.contains("-none")
|| target.contains("nvptx")
+ || target.contains("uefi")
{
println!("cargo:rustc-cfg=feature=\"mem\"");
}
// unlikely that the C is really that much better than our own Rust.
// * nvptx - everything is bitcode, not compatible with mixed C/Rust
// * riscv - the rust-lang/rust distribution container doesn't have a C
- // compiler nor is cc-rs ready for compilation to riscv (at this
- // time). This can probably be removed in the future
- if !target.contains("wasm") && !target.contains("nvptx") && !target.starts_with("riscv") {
+ // compiler.
+ if !target.contains("wasm")
+ && !target.contains("nvptx")
+ && (!target.starts_with("riscv") || target.contains("xous"))
+ {
#[cfg(feature = "c")]
c::compile(&llvm_target, &target);
}
use std::collections::{BTreeMap, HashSet};
use std::env;
- use std::fs::File;
+ use std::fs::{self, File};
use std::io::Write;
use std::path::{Path, PathBuf};
cfg.define("VISIBILITY_HIDDEN", None);
}
+ // int_util.c tries to include stdlib.h if `_WIN32` is defined,
+ // which it is when compiling UEFI targets with clang. This is
+ // at odds with compiling with `-ffreestanding`, as the header
+ // may be incompatible or not present. Create a minimal stub
+ // header to use instead.
+ if target_os == "uefi" {
+ let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
+ let include_dir = out_dir.join("include");
+ if !include_dir.exists() {
+ fs::create_dir(&include_dir).unwrap();
+ }
+ fs::write(include_dir.join("stdlib.h"), "#include <stddef.h>").unwrap();
+ cfg.flag(&format!("-I{}", include_dir.to_str().unwrap()));
+ }
+
let mut sources = Sources::new();
sources.extend(&[
("__absvdi2", "absvdi2.c"),
("__absvsi2", "absvsi2.c"),
("__addvdi3", "addvdi3.c"),
("__addvsi3", "addvsi3.c"),
- ("apple_versioning", "apple_versioning.c"),
("__clzdi2", "clzdi2.c"),
("__clzsi2", "clzsi2.c"),
("__cmpdi2", "cmpdi2.c"),
if target_env == "msvc" {
if target_arch == "x86_64" {
- sources.extend(&[
- ("__floatdisf", "x86_64/floatdisf.c"),
- ("__floatdixf", "x86_64/floatdixf.c"),
- ]);
+ sources.extend(&[("__floatdixf", "x86_64/floatdixf.c")]);
}
} else {
// None of these seem to be used on x86_64 windows, and they've all
if target_os != "windows" {
if target_arch == "x86_64" {
sources.extend(&[
- ("__floatdisf", "x86_64/floatdisf.c"),
("__floatdixf", "x86_64/floatdixf.c"),
- ("__floatundidf", "x86_64/floatundidf.S"),
- ("__floatundisf", "x86_64/floatundisf.S"),
("__floatundixf", "x86_64/floatundixf.S"),
]);
}
("__ashldi3", "i386/ashldi3.S"),
("__ashrdi3", "i386/ashrdi3.S"),
("__divdi3", "i386/divdi3.S"),
- ("__floatdidf", "i386/floatdidf.S"),
- ("__floatdisf", "i386/floatdisf.S"),
("__floatdixf", "i386/floatdixf.S"),
- ("__floatundidf", "i386/floatundidf.S"),
- ("__floatundisf", "i386/floatundisf.S"),
("__floatundixf", "i386/floatundixf.S"),
("__lshrdi3", "i386/lshrdi3.S"),
("__moddi3", "i386/moddi3.S"),
("__fe_getround", "fp_mode.c"),
("__divtf3", "divtf3.c"),
("__trunctfdf2", "trunctfdf2.c"),
+ ("__trunctfsf2", "trunctfsf2.c"),
]);
}
// Remove the assembly implementations that won't compile for the target
- if llvm_target[0] == "thumbv6m" || llvm_target[0] == "thumbv8m.base" {
+ if llvm_target[0] == "thumbv6m" || llvm_target[0] == "thumbv8m.base" || target_os == "uefi"
+ {
let mut to_remove = Vec::new();
for (k, v) in sources.map.iter() {
if v.ends_with(".S") {
sources.remove(&["__aeabi_cdcmp", "__aeabi_cfcmp"]);
}
+ // Android uses emulated TLS so we need a runtime support function.
+ if target_os == "android" {
+ sources.extend(&[("__emutls_get_address", "emutls.c")]);
+
+ // Work around a bug in the NDK headers (fixed in
+ // https://r.android.com/2038949 which will be released in a future
+ // NDK version) by providing a definition of LONG_BIT.
+ cfg.define("LONG_BIT", "(8 * sizeof(long))");
+ }
+
+ // OpenHarmony also uses emulated TLS.
+ if target_env == "ohos" {
+ sources.extend(&[("__emutls_get_address", "emutls.c")]);
+ }
+
// When compiling the C code we require the user to tell us where the
// source code is, and this is largely done so when we're compiling as
// part of rust-lang/rust we can use the same llvm-project repository as