From 37a0af6e689d58d97ee24aa0be728a66e4456ba7 Mon Sep 17 00:00:00 2001 From: Alex Zepeda Date: Fri, 21 Jul 2023 23:10:50 -0700 Subject: [PATCH 1/3] rustc_llvm: DragonFlyBSD uses a GNU toolchain When cross building a dragonfly toolchain e.g. host=darwin, build=dragonfly, target=dragonfly LLVM seems to pick up a libc++ runtime. This seems to primarily be an artifact of the stage0 compiler wanting libc++ for darwin. Unsure if this is needed or used but here it is. --- compiler/rustc_llvm/build.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/rustc_llvm/build.rs b/compiler/rustc_llvm/build.rs index aa1121d6bb3f6..5f7c4dbbee475 100644 --- a/compiler/rustc_llvm/build.rs +++ b/compiler/rustc_llvm/build.rs @@ -343,6 +343,8 @@ fn main() { } else if target.contains("netbsd") && llvm_static_stdcpp.is_some() { // NetBSD uses a separate library when relocation is required "stdc++_p" + } else if target.contains("dragonfly") { + "stdc++" } else if llvm_use_libcxx.is_some() { "c++" } else { From bfa4c4a6244113d5d9ed2f0b15acb0df4cac9a04 Mon Sep 17 00:00:00 2001 From: Alex Zepeda Date: Sun, 23 Jul 2023 02:04:48 -0700 Subject: [PATCH 2/3] rustc_llvm: ignore host flags for cross builds For the MacOS -> DragonFly cross build case we seem to pick up some guidance from the MacOS stage0 compiler that conflicts with what's needed for DragonFly. Assuming your cross compiler is already setup to DTRT by default this should unbork cross builds. --- compiler/rustc_llvm/build.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/compiler/rustc_llvm/build.rs b/compiler/rustc_llvm/build.rs index 5f7c4dbbee475..eb5ab3c61f1d9 100644 --- a/compiler/rustc_llvm/build.rs +++ b/compiler/rustc_llvm/build.rs @@ -189,6 +189,18 @@ fn main() { continue; } + // In the cross compiling case we pick up the C++ runtime flags from the host compiler + // and not the target. This breaks the build in the case of the host and target using + // different runtimes. + if is_crossed && flag.starts_with("-stdlib") { + println!("cargo:warning=Skipping attempt to set C++ library to {flag:?} on target {target:?}"); + + // Most targets these days seem to use libc+, but DragonFly uses GNU libstdc++ for sure + if target.contains("dragonfly") { + continue; + } + } + // -Wdate-time is not supported by the netbsd cross compiler if is_crossed && target.contains("netbsd") && flag.contains("date-time") { continue; From 274a58da1d12c0ab6320fc972fa4e9c18071b76d Mon Sep 17 00:00:00 2001 From: Alex Zepeda Date: Sun, 23 Jul 2023 04:06:03 -0700 Subject: [PATCH 3/3] rustc_llvm: Ignore C++ runtime libs for xcompile If we're cross compiling where the C++ flavors aren't the same we'll potentially pick up a hardcoded request for e.g. libc++ from the host's llvm-config. If the target uses GNU's libstdc++ and/or libc++ is otherwise not present for the target build this will not work. --- compiler/rustc_llvm/build.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_llvm/build.rs b/compiler/rustc_llvm/build.rs index eb5ab3c61f1d9..9ad2739074670 100644 --- a/compiler/rustc_llvm/build.rs +++ b/compiler/rustc_llvm/build.rs @@ -382,7 +382,11 @@ fn main() { } else { println!("cargo:rustc-link-lib=static={stdcppname}"); } - } else if cxxflags.contains("stdlib=libc++") { + } else if !is_crossed && cxxflags.contains("stdlib=libc++") { + // If we're in a cross build these flags come from the host + // compiler and not the target compiler. In the case of an + // Apple to non-Apple cross build, there's a good chance we + // don't want libc++. println!("cargo:rustc-link-lib=c++"); } else { println!("cargo:rustc-link-lib={stdcppname}");