From c8de31baa6d820c9275d4708c296c4af370cf63b Mon Sep 17 00:00:00 2001 From: Andreas Rammhold Date: Sat, 28 Mar 2020 20:45:46 +0100 Subject: [PATCH] buildRustCrateTests: Fix link order test on darwin As it turns out Darwin does most of the things differently then "normal" systems. They are using a different shared library extension and require an obscure commandline parameter that has to be added to every build system out there. That issue seems to be with clang on Darwin as on Linux that flag isn't required to build the very same tests (when using clang). After adjusting these two details the tests are running fine on the darwin box that I was able to obtain. --- .../rust/build-rust-crate/test/default.nix | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/pkgs/build-support/rust/build-rust-crate/test/default.nix b/pkgs/build-support/rust/build-rust-crate/test/default.nix index 2251a1b40f2e..598b5daed1be 100644 --- a/pkgs/build-support/rust/build-rust-crate/test/default.nix +++ b/pkgs/build-support/rust/build-rust-crate/test/default.nix @@ -1,4 +1,13 @@ -{ lib, buildRustCrate, runCommand, runCommandCC, writeTextFile, symlinkJoin, callPackage, releaseTools }: +{ lib +, stdenv +, buildRustCrate +, runCommand +, runCommandCC +, writeTextFile +, symlinkJoin +, callPackage +, releaseTools +}: let mkCrate = args: let p = { @@ -284,12 +293,18 @@ let ]; }; buildInputs = let - compile = name: text: runCommandCC name {} '' - mkdir -p $out/lib - $CC -shared -o $out/lib/${name}.so ${writeTextFile { + compile = name: text: let + src = writeTextFile { name = "${name}-src.c"; inherit text; - }} + }; + in runCommandCC name {} '' + mkdir -p $out/lib + # Note: On darwin (which defaults to clang) we have to add + # `-undefined dynamic_lookup` as otherwise the compilation fails. + cc -shared \ + ${lib.optionalString stdenv.isDarwin "-undefined dynamic_lookup"} \ + -o $out/lib/${name}${stdenv.hostPlatform.extensions.sharedLibrary} ${src} ''; b = compile "libb" '' #include