Code change:
Hello, I'm trying to build a pure-LLVM Rust (no linking to at all). Building rust with set as in returns failure since Clang (the C compiler) doesn't allow . Here's my : Here are the relevant bits of the log: Thanks. A complete log is available here:
I think I may have found the culprit. I'm not well-versed in building rustc (I particularly don't know why rust can build its own LLVM instance, but I assume this is to accommodate systems where LLVM doesn't even exist?), but isn't the choice between and is pretty much irrelevant per libc? And by the way, using gcc as , while it does accept the command, it warns (instead of erroring out like clang-9) because isn't supported in the C compiler.

Related discussion:
text: pub fn compile() { let target = env::var("TARGET").expect("TARGET was not set"); let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap(); <del> let target_vendor = env::var("CARGO_CFG_TARGET_VENDOR").unwrap(); let target_endian_little = env::var("CARGO_CFG_TARGET_ENDIAN").unwrap() != "big"; let cfg = &mut cc::Build::new(); cfg.cpp(true); cfg.cpp_set_stdlib(None); cfg.warnings(false); </del> <ins> let mut cc_cfg = cc::Build::new(); let mut cpp_cfg = cc::Build::new(); let root = Path::new("../../src/llvm-project/libunwind"); </ins> <del> // libunwind expects a __LITTLE_ENDIAN__ macro to be set for LE archs, cf. #65765 if target_endian_little { cfg.define("__LITTLE_ENDIAN__", Some("1")); </del> <ins> cpp_cfg.cpp(true); cpp_cfg.cpp_set_stdlib(None); cpp_cfg.flag("-nostdinc++"); cpp_cfg.flag("-fno-exceptions"); cpp_cfg.flag("-fno-rtti"); cpp_cfg.flag_if_supported("-fvisibility-global-new-delete-hidden"); // Don't set this for clang // By default, Clang builds C code in GNU C17 mode. // By default, Clang builds C++ code according to the C++98 standard, // with many C++11 features accepted as extensions. if cpp_cfg.get_compiler().is_like_gnu() { cpp_cfg.flag("-std=c++11"); cc_cfg.flag("-std=c99"); </ins> } <del> if target_env == "msvc" { // Don't pull in extra libraries on MSVC cfg.flag("/Zl"); cfg.flag("/EHsc"); cfg.define("_CRT_SECURE_NO_WARNINGS", None); cfg.define("_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS", None); } else if target.contains("x86_64-fortanix-unknown-sgx") { cfg.cpp(false); cfg.static_flag(true); cfg.opt_level(3); cfg.flag("-nostdinc++"); cfg.flag("-fno-exceptions"); cfg.flag("-fno-rtti"); cfg.flag("-fstrict-aliasing"); cfg.flag("-funwind-tables"); cfg.flag("-fvisibility=hidden"); cfg.flag("-fno-stack-protector"); cfg.flag("-ffreestanding"); cfg.flag("-fexceptions"); // easiest way to undefine since no API available in cc::Build to undefine cfg.flag("-U_FORTIFY_SOURCE"); cfg.define("_FORTIFY_SOURCE", "0"); cfg.flag_if_supported("-fvisibility-global-new-delete-hidden"); </del> <ins> if target.contains("x86_64-fortanix-unknown-sgx") || target_env == "musl" { // use the same GCC C compiler command to compile C++ code so we do not need to setup the // C++ compiler env variables on the builders. // Don't set this for clang++, as clang++ is able to compile this without libc++. if cpp_cfg.get_compiler().is_like_gnu() { cpp_cfg.cpp(false); } } </ins> <del> cfg.define("_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS", None); cfg.define("RUST_SGX", "1"); cfg.define("__NO_STRING_INLINES", None); cfg.define("__NO_MATH_INLINES", None); cfg.define("_LIBUNWIND_IS_BAREMETAL", None); cfg.define("__LIBUNWIND_IS_NATIVE_ONLY", None); cfg.define("NDEBUG", None); } else { cfg.flag("-std=c99"); cfg.flag("-std=c++11"); cfg.flag("-nostdinc++"); cfg.flag("-fno-exceptions"); cfg.flag("-fno-rtti"); </del> <ins> for cfg in [&mut cc_cfg, &mut cpp_cfg].iter_mut() { cfg.warnings(false); </ins> cfg.flag("-fstrict-aliasing"); cfg.flag("-funwind-tables"); cfg.flag("-fvisibility=hidden"); <del> cfg.flag_if_supported("-fvisibility-global-new-delete-hidden"); </del> cfg.define("_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS", None); <ins> cfg.include(root.join("include")); cfg.cargo_metadata(false); if target.contains("x86_64-fortanix-unknown-sgx") { cfg.static_flag(true); cfg.opt_level(3); cfg.flag("-fno-stack-protector"); cfg.flag("-ffreestanding"); cfg.flag("-fexceptions"); // easiest way to undefine since no API available in cc::Build to undefine cfg.flag("-U_FORTIFY_SOURCE"); cfg.define("_FORTIFY_SOURCE", "0"); cfg.define("RUST_SGX", "1"); cfg.define("__NO_STRING_INLINES", None); cfg.define("__NO_MATH_INLINES", None); cfg.define("_LIBUNWIND_IS_BAREMETAL", None); cfg.define("__LIBUNWIND_IS_NATIVE_ONLY", None); cfg.define("NDEBUG", None); } </ins> } <del> let mut unwind_sources = vec![ "Unwind-EHABI.cpp", "Unwind-seh.cpp", </del> <ins> let mut c_sources = vec![ </ins> "Unwind-sjlj.c", "UnwindLevel1-gcc-ext.c", "UnwindLevel1.c", "UnwindRegistersRestore.S", "UnwindRegistersSave.S", <del> "libunwind.cpp", </del> ]; <del> if target_vendor == "apple" { unwind_sources.push("Unwind_AppleExtras.cpp"); } </del> <ins> let cpp_sources = vec!["Unwind-EHABI.cpp", "Unwind-seh.cpp", "libunwind.cpp"]; let cpp_len = cpp_sources.len(); </ins> if target.contains("x86_64-fortanix-unknown-sgx") { <del> unwind_sources.push("UnwindRustSgx.c"); </del> <ins> c_sources.push("UnwindRustSgx.c"); </ins> } <del> let root = Path::new("../../src/llvm-project/libunwind"); cfg.include(root.join("include")); for src in unwind_sources { cfg.file(root.join("src").join(src)); </del> <ins> for src in c_sources { cc_cfg.file(root.join("src").join(src).canonicalize().unwrap()); </ins> } <del> if target_env == "musl" { // use the same C compiler command to compile C++ code so we do not need to setup the // C++ compiler env variables on the builders cfg.cpp(false); // linking for musl is handled in lib.rs cfg.cargo_metadata(false); println!("cargo:rustc-link-search=native={}", env::var("OUT_DIR").unwrap()); </del> <ins> for src in cpp_sources { cpp_cfg.file(root.join("src").join(src).canonicalize().unwrap()); </ins> } <del> cfg.compile("unwind"); </del> <ins> let out_dir = env::var("OUT_DIR").unwrap(); println!("cargo:rustc-link-search=native={}", &out_dir); cpp_cfg.compile("unwind-cpp"); let mut count = 0; for entry in std::fs::read_dir(&out_dir).unwrap() { let obj = entry.unwrap().path().canonicalize().unwrap(); if let Some(ext) = obj.extension() { if ext == "o" { cc_cfg.object(&obj); count += 1; } } } assert_eq!(cpp_len, count, "Can't get object files from {:?}", &out_dir); cc_cfg.compile("unwind"); </ins> } }