rustc: Add support for FreeBSD

This commit is contained in:
Artemis Tosini 2024-05-20 05:06:37 +00:00 committed by Audrey Dutcher
parent ab3905357e
commit 8135af13f1
4 changed files with 14 additions and 3 deletions

View File

@ -49,6 +49,7 @@ import ./default.nix {
aarch64-apple-darwin = "415bb2bc198feb0f2d8329e33c57d0890bbd57977d1ae48b17f6c7e1f632eaa7";
powerpc64le-unknown-linux-gnu = "79582acb339bd2d79fef095b977049049ffa04616011f1af1793fb8e98194b19";
riscv64gc-unknown-linux-gnu = "300fe4861e2d1f6e4c4f5e36ae7997beca8a979343a7f661237ab78a37a54648";
x86_64-unknown-freebsd = "72f49040fc2ed4492cddfaef3b4a9cb28d008f9f5ce5cac50802a5fca910f58c";
};
selectRustPackage = pkgs: pkgs.rust_1_78;

View File

@ -35,7 +35,8 @@ rec {
nativeBuildInputs = lib.optional (!stdenv.isDarwin) autoPatchelfHook;
buildInputs = [ bash ]
++ lib.optionals (!stdenv.isDarwin) [ gcc.cc.lib zlib ]
++ lib.optional (!stdenv.isDarwin && !stdenv.isFreeBSD) gcc.cc.lib
++ lib.optional (!stdenv.isDarwin) zlib
++ lib.optional stdenv.isDarwin Security;
postPatch = ''
@ -81,7 +82,7 @@ rec {
nativeBuildInputs = [ makeWrapper ]
++ lib.optional (!stdenv.isDarwin) autoPatchelfHook;
buildInputs = [ bash ]
++ lib.optional (!stdenv.isDarwin) gcc.cc.lib
++ lib.optional (!stdenv.isDarwin && !stdenv.isFreeBSD) gcc.cc.lib
++ lib.optional stdenv.isDarwin Security;
postPatch = ''

View File

@ -19,6 +19,7 @@ PLATFORMS=(
aarch64-apple-darwin
powerpc64le-unknown-linux-gnu
riscv64gc-unknown-linux-gnu
x86_64-unknown-freebsd
)
BASEURL=https://static.rust-lang.org/dist
VERSION=${1:-}

View File

@ -58,8 +58,11 @@ in stdenv.mkDerivation (finalAttrs: {
NIX_LDFLAGS = toString (
# when linking stage1 libstd: cc: undefined reference to `__cxa_begin_catch'
optional (stdenv.isLinux && !withBundledLLVM) "--push-state --as-needed -lstdc++ --pop-state"
# This doesn't apply to cross-building for FreeBSD because the host
# uses libstdc++, but the target (used for building std) uses libc++
optional (stdenv.isLinux && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD) "--push-state --as-needed -lstdc++ --pop-state"
++ optional (stdenv.isDarwin && !withBundledLLVM) "-lc++ -lc++abi"
++ optional stdenv.isFreeBSD "-rpath ${llvmPackages.libunwind}/lib"
++ optional stdenv.isDarwin "-rpath ${llvmSharedForHost}/lib");
# Increase codegen units to introduce parallelism within the compiler.
@ -214,6 +217,11 @@ in stdenv.mkDerivation (finalAttrs: {
[source.vendored-sources]
directory = "vendor"
EOF
'' + lib.optionalString (stdenv.isFreeBSD) ''
# lzma-sys bundles an old version of xz that doesn't build
# on modern FreeBSD, use the system one instead
substituteInPlace src/bootstrap/src/core/build_steps/tool.rs \
--replace 'cargo.env("LZMA_API_STATIC", "1");' ' '
'';
# rustc unfortunately needs cmake to compile llvm-rt but doesn't