From 4447d4071bc69e2e18aef96aa14fc0ec835fd5cd Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Mon, 2 May 2022 16:31:58 -0400 Subject: [PATCH 01/18] mingw-w64: 9.0.0 -> 10.0.0 --- .../os-specific/windows/mingw-w64/default.nix | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/pkgs/os-specific/windows/mingw-w64/default.nix b/pkgs/os-specific/windows/mingw-w64/default.nix index 38293e65f70..85527157eea 100644 --- a/pkgs/os-specific/windows/mingw-w64/default.nix +++ b/pkgs/os-specific/windows/mingw-w64/default.nix @@ -1,14 +1,31 @@ { lib, stdenv, windows, fetchurl }: let - version = "9.0.0"; + version = "10.0.0"; + + knownArches = [ "32" "64" "arm32" "arm64" ]; + enabledArch = + if stdenv.targetPlatform.isAarch32 + then "arm32" + else if stdenv.targetPlatform.isAarch64 + then "arm64" + else if stdenv.targetPlatform.isx86_32 + then "32" + else if stdenv.targetPlatform.isx86_64 + then "64" + else null; + archFlags = + if enabledArch == null + then [] # maybe autoconf will save us + else map (arch: lib.enableFeature (arch == enabledArch) "lib${arch}") knownArches; + in stdenv.mkDerivation { pname = "mingw-w64"; inherit version; src = fetchurl { url = "mirror://sourceforge/mingw-w64/mingw-w64-v${version}.tar.bz2"; - sha256 = "10a15bi4lyfi0k0haj0klqambicwma6yi7vssgbz8prg815vja8r"; + sha256 = "sha256-umtDCu1yxjo3aFMfaj/8Kw/eLFejslFFDc9ImolPCJQ="; }; outputs = [ "out" "dev" ]; @@ -16,7 +33,7 @@ in stdenv.mkDerivation { configureFlags = [ "--enable-idl" "--enable-secure-api" - ]; + ] ++ archFlags; enableParallelBuilding = true; From 504d38ae7ba872dbf3b9972d33c94912e56807ed Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Mon, 2 May 2022 17:15:18 -0400 Subject: [PATCH 02/18] cross: Allow Windows toolchains to use ucrt as libc. --- pkgs/development/compilers/gcc/10/default.nix | 4 ++-- pkgs/development/compilers/gcc/11/default.nix | 4 ++-- pkgs/development/compilers/gcc/4.8/default.nix | 4 ++-- pkgs/development/compilers/gcc/4.9/default.nix | 4 ++-- pkgs/development/compilers/gcc/6/default.nix | 4 ++-- pkgs/development/compilers/gcc/7/default.nix | 4 ++-- pkgs/development/compilers/gcc/8/default.nix | 4 ++-- pkgs/development/compilers/gcc/9/default.nix | 4 ++-- .../compilers/gcc/common/configure-flags.nix | 2 +- pkgs/development/libraries/boost/generic.nix | 6 +++--- pkgs/development/libraries/libiconv/default.nix | 2 +- pkgs/development/libraries/libjpeg-turbo/default.nix | 2 +- pkgs/development/libraries/libxml2/default.nix | 2 +- pkgs/development/libraries/zlib/default.nix | 8 ++++---- pkgs/os-specific/windows/mingw-w64/default.nix | 3 +++ pkgs/os-specific/windows/mingw-w64/headers.nix | 10 +++++++++- pkgs/top-level/all-packages.nix | 4 ++-- 17 files changed, 41 insertions(+), 30 deletions(-) diff --git a/pkgs/development/compilers/gcc/10/default.nix b/pkgs/development/compilers/gcc/10/default.nix index 88d4831812f..187d43b5091 100644 --- a/pkgs/development/compilers/gcc/10/default.nix +++ b/pkgs/development/compilers/gcc/10/default.nix @@ -79,7 +79,7 @@ let majorVersion = "10"; }); /* Cross-gcc settings (build == host != target) */ - crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt"; + crossMingw = targetPlatform != hostPlatform && targetPlatform.isMinGW; stageNameAddon = if crossStageStatic then "stage-static" else "stage-final"; crossNameAddon = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-${stageNameAddon}-"; @@ -292,7 +292,7 @@ stdenv.mkDerivation ({ }; } -// optionalAttrs (targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt" && crossStageStatic) { +// optionalAttrs (targetPlatform != hostPlatform && targetPlatform.isMinGW && crossStageStatic) { makeFlags = [ "all-gcc" "all-target-libgcc" ]; installTargets = "install-gcc install-target-libgcc"; } diff --git a/pkgs/development/compilers/gcc/11/default.nix b/pkgs/development/compilers/gcc/11/default.nix index ba4b10cf73e..adb441888d8 100644 --- a/pkgs/development/compilers/gcc/11/default.nix +++ b/pkgs/development/compilers/gcc/11/default.nix @@ -82,7 +82,7 @@ let majorVersion = "11"; ++ optional (!crossStageStatic && targetPlatform.isMinGW) ./Added-mcf-thread-model-support-from-mcfgthread.patch; /* Cross-gcc settings (build == host != target) */ - crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt"; + crossMingw = targetPlatform != hostPlatform && targetPlatform.isMinGW; stageNameAddon = if crossStageStatic then "stage-static" else "stage-final"; crossNameAddon = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-${stageNameAddon}-"; @@ -296,7 +296,7 @@ stdenv.mkDerivation ({ }; } -// optionalAttrs (targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt" && crossStageStatic) { +// optionalAttrs (targetPlatform != hostPlatform && targetPlatform.isMinGW && crossStageStatic) { makeFlags = [ "all-gcc" "all-target-libgcc" ]; installTargets = "install-gcc install-target-libgcc"; } diff --git a/pkgs/development/compilers/gcc/4.8/default.nix b/pkgs/development/compilers/gcc/4.8/default.nix index 8cd0d3c9ce8..03646c65220 100644 --- a/pkgs/development/compilers/gcc/4.8/default.nix +++ b/pkgs/development/compilers/gcc/4.8/default.nix @@ -114,7 +114,7 @@ let majorVersion = "4"; javaAwtGtk = langJava && x11Support; /* Cross-gcc settings (build == host != target) */ - crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt"; + crossMingw = targetPlatform != hostPlatform && targetPlatform.isMinGW; stageNameAddon = if crossStageStatic then "stage-static" else "stage-final"; crossNameAddon = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-${stageNameAddon}-"; @@ -316,7 +316,7 @@ stdenv.mkDerivation ({ }; } -// optionalAttrs (targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt" && crossStageStatic) { +// optionalAttrs (targetPlatform != hostPlatform && targetPlatform.isMinGW && crossStageStatic) { makeFlags = [ "all-gcc" "all-target-libgcc" ]; installTargets = "install-gcc install-target-libgcc"; } diff --git a/pkgs/development/compilers/gcc/4.9/default.nix b/pkgs/development/compilers/gcc/4.9/default.nix index b3d0f8d5d50..d3bd1b70641 100644 --- a/pkgs/development/compilers/gcc/4.9/default.nix +++ b/pkgs/development/compilers/gcc/4.9/default.nix @@ -130,7 +130,7 @@ let majorVersion = "4"; javaAwtGtk = langJava && x11Support; /* Cross-gcc settings (build == host != target) */ - crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt"; + crossMingw = targetPlatform != hostPlatform && targetPlatform.isMinGW; stageNameAddon = if crossStageStatic then "stage-static" else "stage-final"; crossNameAddon = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-${stageNameAddon}-"; @@ -332,7 +332,7 @@ stdenv.mkDerivation ({ }; } -// optionalAttrs (targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt" && crossStageStatic) { +// optionalAttrs (targetPlatform != hostPlatform && targetPlatform.isMinGW && crossStageStatic) { makeFlags = [ "all-gcc" "all-target-libgcc" ]; installTargets = "install-gcc install-target-libgcc"; } diff --git a/pkgs/development/compilers/gcc/6/default.nix b/pkgs/development/compilers/gcc/6/default.nix index 62b46df1ab0..d3007f17063 100644 --- a/pkgs/development/compilers/gcc/6/default.nix +++ b/pkgs/development/compilers/gcc/6/default.nix @@ -111,7 +111,7 @@ let majorVersion = "6"; javaAwtGtk = langJava && x11Support; /* Cross-gcc settings (build == host != target) */ - crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt"; + crossMingw = targetPlatform != hostPlatform && targetPlatform.isMinGW; stageNameAddon = if crossStageStatic then "stage-static" else "stage-final"; crossNameAddon = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-${stageNameAddon}-"; @@ -345,7 +345,7 @@ stdenv.mkDerivation ({ }; } -// optionalAttrs (targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt" && crossStageStatic) { +// optionalAttrs (targetPlatform != hostPlatform && targetPlatform.isMinGW && crossStageStatic) { makeFlags = [ "all-gcc" "all-target-libgcc" ]; installTargets = "install-gcc install-target-libgcc"; } diff --git a/pkgs/development/compilers/gcc/7/default.nix b/pkgs/development/compilers/gcc/7/default.nix index 1abf14c8a8c..1eb23061f64 100644 --- a/pkgs/development/compilers/gcc/7/default.nix +++ b/pkgs/development/compilers/gcc/7/default.nix @@ -87,7 +87,7 @@ let majorVersion = "7"; ++ [ ../libsanitizer-no-cyclades-9.patch ]; /* Cross-gcc settings (build == host != target) */ - crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt"; + crossMingw = targetPlatform != hostPlatform && targetPlatform.isMinGW; stageNameAddon = if crossStageStatic then "stage-static" else "stage-final"; crossNameAddon = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-${stageNameAddon}-"; @@ -301,7 +301,7 @@ stdenv.mkDerivation ({ }; } -// optionalAttrs (targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt" && crossStageStatic) { +// optionalAttrs (targetPlatform != hostPlatform && targetPlatform.isMinGW && crossStageStatic) { makeFlags = [ "all-gcc" "all-target-libgcc" ]; installTargets = "install-gcc install-target-libgcc"; } diff --git a/pkgs/development/compilers/gcc/8/default.nix b/pkgs/development/compilers/gcc/8/default.nix index 2dd265b648c..b6c37c77dd0 100644 --- a/pkgs/development/compilers/gcc/8/default.nix +++ b/pkgs/development/compilers/gcc/8/default.nix @@ -71,7 +71,7 @@ let majorVersion = "8"; ++ [ ../libsanitizer-no-cyclades-9.patch ]; /* Cross-gcc settings (build == host != target) */ - crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt"; + crossMingw = targetPlatform != hostPlatform && targetPlatform.isMinGW; stageNameAddon = if crossStageStatic then "stage-static" else "stage-final"; crossNameAddon = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-${stageNameAddon}-"; @@ -280,7 +280,7 @@ stdenv.mkDerivation ({ }; } -// optionalAttrs (targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt" && crossStageStatic) { +// optionalAttrs (targetPlatform != hostPlatform && targetPlatform.isMinGW && crossStageStatic) { makeFlags = [ "all-gcc" "all-target-libgcc" ]; installTargets = "install-gcc install-target-libgcc"; } diff --git a/pkgs/development/compilers/gcc/9/default.nix b/pkgs/development/compilers/gcc/9/default.nix index 2ecfa1bb1cf..09e4ef3fdff 100644 --- a/pkgs/development/compilers/gcc/9/default.nix +++ b/pkgs/development/compilers/gcc/9/default.nix @@ -98,7 +98,7 @@ let majorVersion = "9"; ++ [ ../libsanitizer-no-cyclades-9.patch ]; /* Cross-gcc settings (build == host != target) */ - crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt"; + crossMingw = targetPlatform != hostPlatform && targetPlatform.isMinGW; stageNameAddon = if crossStageStatic then "stage-static" else "stage-final"; crossNameAddon = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-${stageNameAddon}-"; @@ -311,7 +311,7 @@ stdenv.mkDerivation ({ }; } -// optionalAttrs (targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt" && crossStageStatic) { +// optionalAttrs (targetPlatform != hostPlatform && targetPlatform.isMinGW && crossStageStatic) { makeFlags = [ "all-gcc" "all-target-libgcc" ]; installTargets = "install-gcc install-target-libgcc"; } diff --git a/pkgs/development/compilers/gcc/common/configure-flags.nix b/pkgs/development/compilers/gcc/common/configure-flags.nix index bebf91114d7..100d172403a 100644 --- a/pkgs/development/compilers/gcc/common/configure-flags.nix +++ b/pkgs/development/compilers/gcc/common/configure-flags.nix @@ -41,7 +41,7 @@ let inherit (stdenv) buildPlatform hostPlatform targetPlatform; - crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt"; + crossMingw = targetPlatform != hostPlatform && targetPlatform.isMinGW; crossDarwin = targetPlatform != hostPlatform && targetPlatform.libc == "libSystem"; targetPrefix = lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform) diff --git a/pkgs/development/libraries/boost/generic.nix b/pkgs/development/libraries/boost/generic.nix index 34ab5554e74..27b45a85299 100644 --- a/pkgs/development/libraries/boost/generic.nix +++ b/pkgs/development/libraries/boost/generic.nix @@ -9,7 +9,7 @@ , enableDebug ? false , enableSingleThreaded ? false , enableMultiThreaded ? true -, enableShared ? !(with stdenv.hostPlatform; isStatic || libc == "msvcrt") # problems for now +, enableShared ? !(with stdenv.hostPlatform; isStatic || isMinGW) # problems for now , enableStatic ? !enableShared , enablePython ? false , enableNumpy ? false @@ -102,7 +102,7 @@ let ++ optional (toolset != null) "toolset=${toolset}" ++ optional (!enablePython) "--without-python" ++ optional needUserConfig "--user-config=user-config.jam" - ++ optionals (stdenv.hostPlatform.libc == "msvcrt") [ + ++ optionals (stdenv.hostPlatform.isMinGW) [ "threadapi=win32" ] ++ extraB2Args ); @@ -252,7 +252,7 @@ stdenv.mkDerivation { # Make boost header paths relative so that they are not runtime dependencies cd "$dev" && find include \( -name '*.hpp' -or -name '*.h' -or -name '*.ipp' \) \ -exec sed '1s/^\xef\xbb\xbf//;1i#line 1 "{}"' -i '{}' \; - '' + optionalString (stdenv.hostPlatform.libc == "msvcrt") '' + '' + optionalString (stdenv.hostPlatform.isMinGW) '' $RANLIB "$out/lib/"*.a ''; diff --git a/pkgs/development/libraries/libiconv/default.nix b/pkgs/development/libraries/libiconv/default.nix index 5be5ecfd82e..8051cf319e9 100644 --- a/pkgs/development/libraries/libiconv/default.nix +++ b/pkgs/development/libraries/libiconv/default.nix @@ -20,7 +20,7 @@ stdenv.mkDerivation rec { ]; postPatch = - lib.optionalString ((stdenv.hostPlatform != stdenv.buildPlatform && stdenv.hostPlatform.libc == "msvcrt") || stdenv.cc.nativeLibc) + lib.optionalString ((stdenv.hostPlatform != stdenv.buildPlatform && stdenv.hostPlatform.isMinGW) || stdenv.cc.nativeLibc) '' sed '/^_GL_WARN_ON_USE (gets/d' -i srclib/stdio.in.h '' diff --git a/pkgs/development/libraries/libjpeg-turbo/default.nix b/pkgs/development/libraries/libjpeg-turbo/default.nix index 75ec20545ca..2e400f9a31c 100644 --- a/pkgs/development/libraries/libjpeg-turbo/default.nix +++ b/pkgs/development/libraries/libjpeg-turbo/default.nix @@ -27,7 +27,7 @@ stdenv.mkDerivation rec { # This is needed by freeimage patches = [ ./0001-Compile-transupp.c-as-part-of-the-library.patch ] - ++ lib.optional (stdenv.hostPlatform.libc or null == "msvcrt") + ++ lib.optional (stdenv.hostPlatform.isMinGW) ./mingw-boolean.patch; outputs = [ "bin" "dev" "dev_private" "out" "man" "doc" ]; diff --git a/pkgs/development/libraries/libxml2/default.nix b/pkgs/development/libraries/libxml2/default.nix index 06c073c718a..494e9042101 100644 --- a/pkgs/development/libraries/libxml2/default.nix +++ b/pkgs/development/libraries/libxml2/default.nix @@ -14,7 +14,7 @@ , pythonSupport ? enableShared && stdenv.buildPlatform == stdenv.hostPlatform , icuSupport ? false , icu -, enableShared ? stdenv.hostPlatform.libc != "msvcrt" && !stdenv.hostPlatform.isStatic +, enableShared ? !stdenv.hostPlatform.isMinGW && !stdenv.hostPlatform.isStatic , enableStatic ? !enableShared , gnome }: diff --git a/pkgs/development/libraries/zlib/default.nix b/pkgs/development/libraries/zlib/default.nix index 9b9938746ca..ed7ff17dc3d 100644 --- a/pkgs/development/libraries/zlib/default.nix +++ b/pkgs/development/libraries/zlib/default.nix @@ -88,7 +88,7 @@ stdenv.mkDerivation (rec { '' # Non-typical naming confuses libtool which then refuses to use zlib's DLL # in some cases, e.g. when compiling libpng. - + lib.optionalString (stdenv.hostPlatform.libc == "msvcrt" && shared) '' + + lib.optionalString (stdenv.hostPlatform.isMinGW && shared) '' ln -s zlib1.dll $out/bin/libz.dll ''; @@ -101,7 +101,7 @@ stdenv.mkDerivation (rec { dontStrip = stdenv.hostPlatform != stdenv.buildPlatform && static; configurePlatforms = []; - installFlags = lib.optionals (stdenv.hostPlatform.libc == "msvcrt") [ + installFlags = lib.optionals (stdenv.hostPlatform.isMinGW) [ "BINARY_PATH=$(out)/bin" "INCLUDE_PATH=$(dev)/include" "LIBRARY_PATH=$(out)/lib" @@ -112,7 +112,7 @@ stdenv.mkDerivation (rec { makeFlags = [ "PREFIX=${stdenv.cc.targetPrefix}" - ] ++ lib.optionals (stdenv.hostPlatform.libc == "msvcrt") [ + ] ++ lib.optionals (stdenv.hostPlatform.isMinGW) [ "-f" "win32/Makefile.gcc" ] ++ lib.optionals shared [ # Note that as of writing (zlib 1.2.11), this flag only has an effect @@ -134,6 +134,6 @@ stdenv.mkDerivation (rec { preConfigure = '' export CHOST=${stdenv.hostPlatform.config} ''; -} // lib.optionalAttrs (stdenv.hostPlatform.libc == "msvcrt") { +} // lib.optionalAttrs (stdenv.hostPlatform.isMinGW) { dontConfigure = true; }) diff --git a/pkgs/os-specific/windows/mingw-w64/default.nix b/pkgs/os-specific/windows/mingw-w64/default.nix index 85527157eea..02cfd7b04a7 100644 --- a/pkgs/os-specific/windows/mingw-w64/default.nix +++ b/pkgs/os-specific/windows/mingw-w64/default.nix @@ -19,6 +19,7 @@ let then [] # maybe autoconf will save us else map (arch: lib.enableFeature (arch == enabledArch) "lib${arch}") knownArches; + crt = stdenv.hostPlatform.libc; in stdenv.mkDerivation { pname = "mingw-w64"; inherit version; @@ -33,6 +34,7 @@ in stdenv.mkDerivation { configureFlags = [ "--enable-idl" "--enable-secure-api" + "--with-default-msvcrt=${crt}" ] ++ archFlags; enableParallelBuilding = true; @@ -43,5 +45,6 @@ in stdenv.mkDerivation { meta = { platforms = lib.platforms.windows; + broken = !(lib.elem crt [ "msvcrt" "ucrt" ]); }; } diff --git a/pkgs/os-specific/windows/mingw-w64/headers.nix b/pkgs/os-specific/windows/mingw-w64/headers.nix index 1fd27a8c457..13ba330ef2a 100644 --- a/pkgs/os-specific/windows/mingw-w64/headers.nix +++ b/pkgs/os-specific/windows/mingw-w64/headers.nix @@ -1,6 +1,8 @@ { stdenvNoCC, mingw_w64 }: -stdenvNoCC.mkDerivation { +let + crt = stdenvNoCC.hostPlatform.libc; +in stdenvNoCC.mkDerivation { name = "${mingw_w64.name}-headers"; inherit (mingw_w64) src meta; @@ -8,4 +10,10 @@ stdenvNoCC.mkDerivation { cd mingw-w64-headers ''; + configureFlags = [ + "--enable-idl" + "--enable-secure-api" + "--with-default-msvcrt=${crt}" + ]; + } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 6d259511e79..80ee2dc3ea0 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -17415,7 +17415,7 @@ with pkgs; # These are used when buiding compiler-rt / libgcc, prior to building libc. preLibcCrossHeaders = let inherit (stdenv.targetPlatform) libc; - in if libc == "msvcrt" then targetPackages.windows.mingw_w64_headers or windows.mingw_w64_headers + in if libc == "msvcrt" || libc == "ucrt" then targetPackages.windows.mingw_w64_headers or windows.mingw_w64_headers else if libc == "nblibc" then targetPackages.netbsdCross.headers or netbsdCross.headers else if libc == "libSystem" && stdenv.targetPlatform.isAarch64 then targetPackages.darwin.LibsystemCross or darwin.LibsystemCross else null; @@ -17434,7 +17434,7 @@ with pkgs; else if name == "newlib" then targetPackages.newlibCross or newlibCross else if name == "newlib-nano" then targetPackages.newlib-nanoCross or newlib-nanoCross else if name == "musl" then targetPackages.muslCross or muslCross - else if name == "msvcrt" then targetPackages.windows.mingw_w64 or windows.mingw_w64 + else if name == "msvcrt" || name == "ucrt" then targetPackages.windows.mingw_w64 or windows.mingw_w64 else if name == "libSystem" then if stdenv.targetPlatform.useiOSPrebuilt then targetPackages.darwin.iosSdkPkgs.libraries or darwin.iosSdkPkgs.libraries From 4b503b2a58fd7776a497b1c0109f5de1eb76fdb4 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Tue, 3 May 2022 06:15:15 -0400 Subject: [PATCH 03/18] cc-wrapper: clang doesn't support -fPIC on Windows --- pkgs/build-support/cc-wrapper/default.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 3738f628b18..76f218de4d2 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -476,6 +476,8 @@ stdenv.mkDerivation { hardening_unsupported_flags+=" pic" '' + optionalString targetPlatform.isMinGW '' hardening_unsupported_flags+=" stackprotector fortify" + '' + optionalString (targetPlatform.isWindows && isClang) '' + hardening_unsupported_flags+=" pic" '' + optionalString targetPlatform.isAvr '' hardening_unsupported_flags+=" stackprotector pic" '' + optionalString (targetPlatform.libc == "newlib") '' From a73b59a157f149369283eda571b61f7990e6afa3 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Tue, 3 May 2022 08:57:03 -0400 Subject: [PATCH 04/18] llvm-bintools: Include aliases for windres and dlltool on Windows --- pkgs/development/compilers/llvm/13/bintools/default.nix | 9 ++++++--- pkgs/development/compilers/llvm/14/bintools/default.nix | 9 ++++++--- pkgs/development/compilers/llvm/git/bintools/default.nix | 9 ++++++--- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/pkgs/development/compilers/llvm/13/bintools/default.nix b/pkgs/development/compilers/llvm/13/bintools/default.nix index 53f7941e336..e01e152d159 100644 --- a/pkgs/development/compilers/llvm/13/bintools/default.nix +++ b/pkgs/development/compilers/llvm/13/bintools/default.nix @@ -1,11 +1,11 @@ -{ runCommand, stdenv, llvm, lld, version }: +{ runCommand, stdenv, llvm, lld, version, lib }: let prefix = if stdenv.hostPlatform != stdenv.targetPlatform then "${stdenv.targetPlatform.config}-" else ""; -in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; } '' +in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; } ('' mkdir -p $out/bin for prog in ${lld}/bin/*; do ln -s $prog $out/bin/${prefix}$(basename $prog) @@ -26,4 +26,7 @@ in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; } '' ln -s ${llvm}/bin/llvm-strip $out/bin/${prefix}strip ln -s ${lld}/bin/lld $out/bin/${prefix}ld -'' +'' + lib.optionalString stdenv.targetPlatform.isWindows '' + ln -s ${llvm}/bin/llvm-windres $out/bin/${prefix}windres + ln -s ${llvm}/bin/llvm-dlltool $out/bin/${prefix}dlltool +'') diff --git a/pkgs/development/compilers/llvm/14/bintools/default.nix b/pkgs/development/compilers/llvm/14/bintools/default.nix index 53f7941e336..e01e152d159 100644 --- a/pkgs/development/compilers/llvm/14/bintools/default.nix +++ b/pkgs/development/compilers/llvm/14/bintools/default.nix @@ -1,11 +1,11 @@ -{ runCommand, stdenv, llvm, lld, version }: +{ runCommand, stdenv, llvm, lld, version, lib }: let prefix = if stdenv.hostPlatform != stdenv.targetPlatform then "${stdenv.targetPlatform.config}-" else ""; -in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; } '' +in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; } ('' mkdir -p $out/bin for prog in ${lld}/bin/*; do ln -s $prog $out/bin/${prefix}$(basename $prog) @@ -26,4 +26,7 @@ in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; } '' ln -s ${llvm}/bin/llvm-strip $out/bin/${prefix}strip ln -s ${lld}/bin/lld $out/bin/${prefix}ld -'' +'' + lib.optionalString stdenv.targetPlatform.isWindows '' + ln -s ${llvm}/bin/llvm-windres $out/bin/${prefix}windres + ln -s ${llvm}/bin/llvm-dlltool $out/bin/${prefix}dlltool +'') diff --git a/pkgs/development/compilers/llvm/git/bintools/default.nix b/pkgs/development/compilers/llvm/git/bintools/default.nix index 53f7941e336..e01e152d159 100644 --- a/pkgs/development/compilers/llvm/git/bintools/default.nix +++ b/pkgs/development/compilers/llvm/git/bintools/default.nix @@ -1,11 +1,11 @@ -{ runCommand, stdenv, llvm, lld, version }: +{ runCommand, stdenv, llvm, lld, version, lib }: let prefix = if stdenv.hostPlatform != stdenv.targetPlatform then "${stdenv.targetPlatform.config}-" else ""; -in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; } '' +in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; } ('' mkdir -p $out/bin for prog in ${lld}/bin/*; do ln -s $prog $out/bin/${prefix}$(basename $prog) @@ -26,4 +26,7 @@ in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; } '' ln -s ${llvm}/bin/llvm-strip $out/bin/${prefix}strip ln -s ${lld}/bin/lld $out/bin/${prefix}ld -'' +'' + lib.optionalString stdenv.targetPlatform.isWindows '' + ln -s ${llvm}/bin/llvm-windres $out/bin/${prefix}windres + ln -s ${llvm}/bin/llvm-dlltool $out/bin/${prefix}dlltool +'') From dee9af932383801ccd5bbb5f48109a556c1b632c Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Mon, 9 May 2022 09:57:59 -0400 Subject: [PATCH 05/18] bintools: Add isXXX flags to check linker type --- pkgs/build-support/bintools-wrapper/default.nix | 9 +++++++++ pkgs/development/compilers/llvm/10/bintools/default.nix | 2 +- pkgs/development/compilers/llvm/11/bintools/default.nix | 2 +- pkgs/development/compilers/llvm/12/bintools/default.nix | 2 +- pkgs/development/compilers/llvm/13/bintools/default.nix | 2 +- pkgs/development/compilers/llvm/14/bintools/default.nix | 2 +- pkgs/development/compilers/llvm/7/bintools/default.nix | 2 +- pkgs/development/compilers/llvm/8/bintools/default.nix | 2 +- pkgs/development/compilers/llvm/9/bintools/default.nix | 2 +- pkgs/development/compilers/llvm/git/bintools/default.nix | 2 +- pkgs/development/tools/misc/binutils/default.nix | 5 +++++ pkgs/os-specific/darwin/binutils/default.nix | 1 + 12 files changed, 24 insertions(+), 9 deletions(-) diff --git a/pkgs/build-support/bintools-wrapper/default.nix b/pkgs/build-support/bintools-wrapper/default.nix index c2d67169c9c..2a1a8699485 100644 --- a/pkgs/build-support/bintools-wrapper/default.nix +++ b/pkgs/build-support/bintools-wrapper/default.nix @@ -31,6 +31,13 @@ # Darwin code signing support utilities , postLinkSignHook ? null, signingUtils ? null + +# Linker type +, isLld ? bintools.isLld or false +, isCctools ? bintools.isCctools or false +, isGNU ? bintools.isGNU or false +, isGold ? bintools.isGold or false +, isBfd ? bintools.isBfd or false }: with lib; @@ -113,6 +120,8 @@ stdenv.mkDerivation { passthru = { inherit bintools libc nativeTools nativeLibc nativePrefix; + inherit isLld isCctools isGNU isGold isBfd; + emacsBufferSetup = pkgs: '' ; We should handle propagation here too (mapc diff --git a/pkgs/development/compilers/llvm/10/bintools/default.nix b/pkgs/development/compilers/llvm/10/bintools/default.nix index 53f7941e336..5735bf5a685 100644 --- a/pkgs/development/compilers/llvm/10/bintools/default.nix +++ b/pkgs/development/compilers/llvm/10/bintools/default.nix @@ -5,7 +5,7 @@ let if stdenv.hostPlatform != stdenv.targetPlatform then "${stdenv.targetPlatform.config}-" else ""; -in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; } '' +in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; passthru.isLld = true; } '' mkdir -p $out/bin for prog in ${lld}/bin/*; do ln -s $prog $out/bin/${prefix}$(basename $prog) diff --git a/pkgs/development/compilers/llvm/11/bintools/default.nix b/pkgs/development/compilers/llvm/11/bintools/default.nix index 53f7941e336..5735bf5a685 100644 --- a/pkgs/development/compilers/llvm/11/bintools/default.nix +++ b/pkgs/development/compilers/llvm/11/bintools/default.nix @@ -5,7 +5,7 @@ let if stdenv.hostPlatform != stdenv.targetPlatform then "${stdenv.targetPlatform.config}-" else ""; -in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; } '' +in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; passthru.isLld = true; } '' mkdir -p $out/bin for prog in ${lld}/bin/*; do ln -s $prog $out/bin/${prefix}$(basename $prog) diff --git a/pkgs/development/compilers/llvm/12/bintools/default.nix b/pkgs/development/compilers/llvm/12/bintools/default.nix index 53f7941e336..5735bf5a685 100644 --- a/pkgs/development/compilers/llvm/12/bintools/default.nix +++ b/pkgs/development/compilers/llvm/12/bintools/default.nix @@ -5,7 +5,7 @@ let if stdenv.hostPlatform != stdenv.targetPlatform then "${stdenv.targetPlatform.config}-" else ""; -in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; } '' +in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; passthru.isLld = true; } '' mkdir -p $out/bin for prog in ${lld}/bin/*; do ln -s $prog $out/bin/${prefix}$(basename $prog) diff --git a/pkgs/development/compilers/llvm/13/bintools/default.nix b/pkgs/development/compilers/llvm/13/bintools/default.nix index e01e152d159..4c16957aeb4 100644 --- a/pkgs/development/compilers/llvm/13/bintools/default.nix +++ b/pkgs/development/compilers/llvm/13/bintools/default.nix @@ -5,7 +5,7 @@ let if stdenv.hostPlatform != stdenv.targetPlatform then "${stdenv.targetPlatform.config}-" else ""; -in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; } ('' +in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; passthru.isLld = true; } ('' mkdir -p $out/bin for prog in ${lld}/bin/*; do ln -s $prog $out/bin/${prefix}$(basename $prog) diff --git a/pkgs/development/compilers/llvm/14/bintools/default.nix b/pkgs/development/compilers/llvm/14/bintools/default.nix index e01e152d159..4c16957aeb4 100644 --- a/pkgs/development/compilers/llvm/14/bintools/default.nix +++ b/pkgs/development/compilers/llvm/14/bintools/default.nix @@ -5,7 +5,7 @@ let if stdenv.hostPlatform != stdenv.targetPlatform then "${stdenv.targetPlatform.config}-" else ""; -in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; } ('' +in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; passthru.isLld = true; } ('' mkdir -p $out/bin for prog in ${lld}/bin/*; do ln -s $prog $out/bin/${prefix}$(basename $prog) diff --git a/pkgs/development/compilers/llvm/7/bintools/default.nix b/pkgs/development/compilers/llvm/7/bintools/default.nix index 53f7941e336..5735bf5a685 100644 --- a/pkgs/development/compilers/llvm/7/bintools/default.nix +++ b/pkgs/development/compilers/llvm/7/bintools/default.nix @@ -5,7 +5,7 @@ let if stdenv.hostPlatform != stdenv.targetPlatform then "${stdenv.targetPlatform.config}-" else ""; -in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; } '' +in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; passthru.isLld = true; } '' mkdir -p $out/bin for prog in ${lld}/bin/*; do ln -s $prog $out/bin/${prefix}$(basename $prog) diff --git a/pkgs/development/compilers/llvm/8/bintools/default.nix b/pkgs/development/compilers/llvm/8/bintools/default.nix index 53f7941e336..5735bf5a685 100644 --- a/pkgs/development/compilers/llvm/8/bintools/default.nix +++ b/pkgs/development/compilers/llvm/8/bintools/default.nix @@ -5,7 +5,7 @@ let if stdenv.hostPlatform != stdenv.targetPlatform then "${stdenv.targetPlatform.config}-" else ""; -in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; } '' +in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; passthru.isLld = true; } '' mkdir -p $out/bin for prog in ${lld}/bin/*; do ln -s $prog $out/bin/${prefix}$(basename $prog) diff --git a/pkgs/development/compilers/llvm/9/bintools/default.nix b/pkgs/development/compilers/llvm/9/bintools/default.nix index 53f7941e336..5735bf5a685 100644 --- a/pkgs/development/compilers/llvm/9/bintools/default.nix +++ b/pkgs/development/compilers/llvm/9/bintools/default.nix @@ -5,7 +5,7 @@ let if stdenv.hostPlatform != stdenv.targetPlatform then "${stdenv.targetPlatform.config}-" else ""; -in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; } '' +in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; passthru.isLld = true; } '' mkdir -p $out/bin for prog in ${lld}/bin/*; do ln -s $prog $out/bin/${prefix}$(basename $prog) diff --git a/pkgs/development/compilers/llvm/git/bintools/default.nix b/pkgs/development/compilers/llvm/git/bintools/default.nix index e01e152d159..4c16957aeb4 100644 --- a/pkgs/development/compilers/llvm/git/bintools/default.nix +++ b/pkgs/development/compilers/llvm/git/bintools/default.nix @@ -5,7 +5,7 @@ let if stdenv.hostPlatform != stdenv.targetPlatform then "${stdenv.targetPlatform.config}-" else ""; -in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; } ('' +in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; passthru.isLld = true; } ('' mkdir -p $out/bin for prog in ${lld}/bin/*; do ln -s $prog $out/bin/${prefix}$(basename $prog) diff --git a/pkgs/development/tools/misc/binutils/default.nix b/pkgs/development/tools/misc/binutils/default.nix index da2b4864552..4fdda9d67d9 100644 --- a/pkgs/development/tools/misc/binutils/default.nix +++ b/pkgs/development/tools/misc/binutils/default.nix @@ -197,6 +197,11 @@ stdenv.mkDerivation { inherit targetPrefix; hasGold = enableGold; isGNU = true; + # TODO Currently platform.linker == "gold" has no effect outside + # of building GHC. If/when that's fixed, these flags should + # probably move to the invocations of bintools-wrapper + isGold = false; + isBfd = true; }; meta = with lib; { diff --git a/pkgs/os-specific/darwin/binutils/default.nix b/pkgs/os-specific/darwin/binutils/default.nix index c5bc50cafd7..a25306dcf35 100644 --- a/pkgs/os-specific/darwin/binutils/default.nix +++ b/pkgs/os-specific/darwin/binutils/default.nix @@ -65,6 +65,7 @@ stdenv.mkDerivation { passthru = { inherit targetPrefix; + isCctools = true; }; meta = { From 4c0d5f80fcdef2024f73c584f7450a6f37ced8cd Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Tue, 3 May 2022 09:36:46 -0400 Subject: [PATCH 06/18] bintools-wrapper: Don't pass -z to lld targeting Windows --- pkgs/build-support/bintools-wrapper/default.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkgs/build-support/bintools-wrapper/default.nix b/pkgs/build-support/bintools-wrapper/default.nix index 2a1a8699485..16a9a0c7b22 100644 --- a/pkgs/build-support/bintools-wrapper/default.nix +++ b/pkgs/build-support/bintools-wrapper/default.nix @@ -335,6 +335,11 @@ stdenv.mkDerivation { echo "-arch ${targetPlatform.darwinArch}" >> $out/nix-support/libc-ldflags '' + # lld's MinGW driver (e.g. `ld.lld -m i386pep`) does not support the `-z` flag. + + optionalString (targetPlatform.isWindows && isLld) '' + hardening_unsupported_flags+=" relro bindnow" + '' + ## ## GNU specific extra strip flags ## From 078a07708a6add846447272f0797fbde778a0522 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Tue, 3 May 2022 10:51:22 -0400 Subject: [PATCH 07/18] libunwind: Fix build against compiler-rt-using clang --- pkgs/build-support/cc-wrapper/default.nix | 3 ++- pkgs/development/compilers/llvm/13/default.nix | 3 +++ pkgs/development/compilers/llvm/13/libunwind/default.nix | 4 +++- pkgs/development/compilers/llvm/14/default.nix | 3 +++ pkgs/development/compilers/llvm/14/libunwind/default.nix | 4 +++- pkgs/development/compilers/llvm/git/default.nix | 3 +++ pkgs/development/compilers/llvm/git/libunwind/default.nix | 4 +++- 7 files changed, 20 insertions(+), 4 deletions(-) diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 76f218de4d2..202a5cc577b 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -17,6 +17,7 @@ , isGNU ? false, isClang ? cc.isClang or false, gnugrep ? null , buildPackages ? {} , libcxx ? null +, isCompilerRT ? false }: with lib; @@ -145,7 +146,7 @@ stdenv.mkDerivation { # Binutils, and Apple's "cctools"; "bintools" as an attempt to find an # unused middle-ground name that evokes both. inherit bintools; - inherit libc nativeTools nativeLibc nativePrefix isGNU isClang; + inherit libc nativeTools nativeLibc nativePrefix isGNU isClang isCompilerRT; emacsBufferSetup = pkgs: '' ; We should handle propagation here too diff --git a/pkgs/development/compilers/llvm/13/default.nix b/pkgs/development/compilers/llvm/13/default.nix index 874be111ade..b72d4244285 100644 --- a/pkgs/development/compilers/llvm/13/default.nix +++ b/pkgs/development/compilers/llvm/13/default.nix @@ -168,6 +168,7 @@ let '' + lib.optionalString stdenv.targetPlatform.isWasm '' echo "-fno-exceptions" >> $out/nix-support/cc-cflags '' + mkExtraBuildCommands cc; + isCompilerRT = true; }; clangNoLibcxx = wrapCCWith rec { @@ -182,6 +183,7 @@ let echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags echo "-nostdlib++" >> $out/nix-support/cc-cflags '' + mkExtraBuildCommands cc; + isCompilerRT = true; }; clangNoLibc = wrapCCWith rec { @@ -195,6 +197,7 @@ let echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags '' + mkExtraBuildCommands cc; + isCompilerRT = true; }; clangNoCompilerRt = wrapCCWith rec { diff --git a/pkgs/development/compilers/llvm/13/libunwind/default.nix b/pkgs/development/compilers/llvm/13/libunwind/default.nix index b6017e74172..c6cc148239e 100644 --- a/pkgs/development/compilers/llvm/13/libunwind/default.nix +++ b/pkgs/development/compilers/llvm/13/libunwind/default.nix @@ -17,7 +17,9 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ cmake ]; - cmakeFlags = lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF"; + cmakeFlags = + lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF" + ++ lib.optional (stdenv.cc.isCompilerRT) "-DLIBUNWIND_USE_COMPILER_RT=TRUE"; meta = llvm_meta // { # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst diff --git a/pkgs/development/compilers/llvm/14/default.nix b/pkgs/development/compilers/llvm/14/default.nix index 4e5e85684a2..4de667d894e 100644 --- a/pkgs/development/compilers/llvm/14/default.nix +++ b/pkgs/development/compilers/llvm/14/default.nix @@ -168,6 +168,7 @@ let '' + lib.optionalString stdenv.targetPlatform.isWasm '' echo "-fno-exceptions" >> $out/nix-support/cc-cflags '' + mkExtraBuildCommands cc; + isCompilerRT = true; }; clangNoLibcxx = wrapCCWith rec { @@ -182,6 +183,7 @@ let echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags echo "-nostdlib++" >> $out/nix-support/cc-cflags '' + mkExtraBuildCommands cc; + isCompilerRT = true; }; clangNoLibc = wrapCCWith rec { @@ -195,6 +197,7 @@ let echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags '' + mkExtraBuildCommands cc; + isCompilerRT = true; }; clangNoCompilerRt = wrapCCWith rec { diff --git a/pkgs/development/compilers/llvm/14/libunwind/default.nix b/pkgs/development/compilers/llvm/14/libunwind/default.nix index 109b92f1e02..7940fa4b3a1 100644 --- a/pkgs/development/compilers/llvm/14/libunwind/default.nix +++ b/pkgs/development/compilers/llvm/14/libunwind/default.nix @@ -31,7 +31,9 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ cmake ]; - cmakeFlags = lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF"; + cmakeFlags = + lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF" + ++ lib.optional (stdenv.cc.isCompilerRT) "-DLIBUNWIND_USE_COMPILER_RT=TRUE"; meta = llvm_meta // { # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst diff --git a/pkgs/development/compilers/llvm/git/default.nix b/pkgs/development/compilers/llvm/git/default.nix index 0f45acffb27..6b96190c042 100644 --- a/pkgs/development/compilers/llvm/git/default.nix +++ b/pkgs/development/compilers/llvm/git/default.nix @@ -168,6 +168,7 @@ let '' + lib.optionalString stdenv.targetPlatform.isWasm '' echo "-fno-exceptions" >> $out/nix-support/cc-cflags '' + mkExtraBuildCommands cc; + isCompilerRT = true; }; clangNoLibcxx = wrapCCWith rec { @@ -182,6 +183,7 @@ let echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags echo "-nostdlib++" >> $out/nix-support/cc-cflags '' + mkExtraBuildCommands cc; + isCompilerRT = true; }; clangNoLibc = wrapCCWith rec { @@ -195,6 +197,7 @@ let echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags '' + mkExtraBuildCommands cc; + isCompilerRT = true; }; clangNoCompilerRt = wrapCCWith rec { diff --git a/pkgs/development/compilers/llvm/git/libunwind/default.nix b/pkgs/development/compilers/llvm/git/libunwind/default.nix index c6d9eda5e47..30874588d8d 100644 --- a/pkgs/development/compilers/llvm/git/libunwind/default.nix +++ b/pkgs/development/compilers/llvm/git/libunwind/default.nix @@ -31,7 +31,9 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ cmake ]; - cmakeFlags = lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF"; + cmakeFlags = + lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF" + ++ lib.optional stdenv.cc.isCompilerRT "-DLIBUNWIND_USE_COMPILER_RT=TRUE"; meta = llvm_meta // { # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst From 5ca96b948c7acc307b9b0d7d6ff5f60c77763d8e Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Tue, 3 May 2022 10:55:48 -0400 Subject: [PATCH 08/18] libcxxabi: Fix build against compiler-rt-using clang --- pkgs/development/compilers/llvm/13/libcxxabi/default.nix | 3 ++- pkgs/development/compilers/llvm/14/libcxxabi/default.nix | 3 ++- pkgs/development/compilers/llvm/git/libcxxabi/default.nix | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkgs/development/compilers/llvm/13/libcxxabi/default.nix b/pkgs/development/compilers/llvm/13/libcxxabi/default.nix index 0bdbee07b73..93a3b2a1ec8 100644 --- a/pkgs/development/compilers/llvm/13/libcxxabi/default.nix +++ b/pkgs/development/compilers/llvm/13/libcxxabi/default.nix @@ -37,7 +37,8 @@ stdenv.mkDerivation rec { "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" ] ++ lib.optionals (!enableShared) [ "-DLIBCXXABI_ENABLE_SHARED=OFF" - ]; + ] ++ lib.optional stdenv.cc.isCompilerRT + "-DLIBCXXABI_USE_COMPILER_RT=ON"; installPhase = if stdenv.isDarwin then '' diff --git a/pkgs/development/compilers/llvm/14/libcxxabi/default.nix b/pkgs/development/compilers/llvm/14/libcxxabi/default.nix index 07aaa2737ce..25f90230b7b 100644 --- a/pkgs/development/compilers/llvm/14/libcxxabi/default.nix +++ b/pkgs/development/compilers/llvm/14/libcxxabi/default.nix @@ -47,7 +47,8 @@ stdenv.mkDerivation rec { "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" ] ++ lib.optionals (!enableShared) [ "-DLIBCXXABI_ENABLE_SHARED=OFF" - ]; + ] ++ lib.optional stdenv.cc.isCompilerRT + "-DLIBCXXABI_USE_COMPILER_RT=ON"; installPhase = if stdenv.isDarwin then '' diff --git a/pkgs/development/compilers/llvm/git/libcxxabi/default.nix b/pkgs/development/compilers/llvm/git/libcxxabi/default.nix index d64708ab040..0fecc396250 100644 --- a/pkgs/development/compilers/llvm/git/libcxxabi/default.nix +++ b/pkgs/development/compilers/llvm/git/libcxxabi/default.nix @@ -47,7 +47,9 @@ stdenv.mkDerivation rec { "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" ] ++ lib.optionals (!enableShared) [ "-DLIBCXXABI_ENABLE_SHARED=OFF" - ]; + ] ++ lib.optional stdenv.cc.isCompilerRT + "-DLIBCXXABI_USE_COMPILER_RT=ON"; + installPhase = if stdenv.isDarwin then '' From b7b9b73760c421ccf7323ab6827dec3c31bef344 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Tue, 3 May 2022 13:02:37 -0400 Subject: [PATCH 09/18] libcxx/libcxxabi: Fix build on Windows with lld --- .../compilers/llvm/13/libcxx/default.nix | 12 ++++++-- .../compilers/llvm/13/libcxxabi/default.nix | 20 +++++++++---- .../compilers/llvm/14/libcxx/default.nix | 12 ++++++-- .../compilers/llvm/14/libcxxabi/default.nix | 26 +++++++++++++---- .../compilers/llvm/git/libcxx/default.nix | 13 +++++++-- .../compilers/llvm/git/libcxxabi/default.nix | 28 +++++++++++++++---- 6 files changed, 85 insertions(+), 26 deletions(-) diff --git a/pkgs/development/compilers/llvm/13/libcxx/default.nix b/pkgs/development/compilers/llvm/13/libcxx/default.nix index 0ce73ed97af..c5b8293676a 100644 --- a/pkgs/development/compilers/llvm/13/libcxx/default.nix +++ b/pkgs/development/compilers/llvm/13/libcxx/default.nix @@ -1,5 +1,5 @@ { lib, stdenv, llvm_meta, src, cmake, python3, fixDarwinDylibNames, version -, libcxxabi +, libcxxabi, libunwind , enableShared ? !stdenv.hostPlatform.isStatic # If headersOnly is true, the resulting package would only include the headers. @@ -32,7 +32,7 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ cmake python3 ] ++ lib.optional stdenv.isDarwin fixDarwinDylibNames; - buildInputs = lib.optionals (!headersOnly) [ libcxxabi ]; + buildInputs = lib.optionals (!headersOnly) ([ libcxxabi ] ++ lib.optional libcxxabi.useLLVMUnwinder libunwind); cmakeFlags = [ "-DLIBCXX_CXX_ABI=libcxxabi" ] ++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) "-DLIBCXX_HAS_MUSL_LIBC=1" @@ -41,7 +41,13 @@ stdenv.mkDerivation rec { "-DLIBCXX_ENABLE_THREADS=OFF" "-DLIBCXX_ENABLE_FILESYSTEM=OFF" "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" - ] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF"; + ] + ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF" + ++ lib.optionals (!headersOnly && libcxxabi.semi-static) [ + "-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=TRUE" + "-DLIBCXX_CXX_ABI_LIBRARY_PATH=${libcxxabi}/lib" + ] ++ lib.optional (!headersOnly && libcxxabi.useLLVMUnwinder) + "-DLIBCXXABI_USE_LLVM_UNWINDER=ON"; buildFlags = lib.optional headersOnly "generate-cxx-headers"; installTargets = lib.optional headersOnly "install-cxx-headers"; diff --git a/pkgs/development/compilers/llvm/13/libcxxabi/default.nix b/pkgs/development/compilers/llvm/13/libcxxabi/default.nix index 93a3b2a1ec8..66ec96e3518 100644 --- a/pkgs/development/compilers/llvm/13/libcxxabi/default.nix +++ b/pkgs/development/compilers/llvm/13/libcxxabi/default.nix @@ -2,9 +2,14 @@ , enableShared ? !stdenv.hostPlatform.isStatic , standalone ? stdenv.hostPlatform.useLLVM or false , withLibunwind ? !stdenv.isDarwin && !stdenv.isFreeBSD && !stdenv.hostPlatform.isWasm -}: +}: let + # lld doesn't support unresolved references on Windows https://github.com/llvm/llvm-project/issues/55245 + semi-static = enableShared && stdenv.hostPlatform.isWindows && stdenv.cc.bintools.isLld; -stdenv.mkDerivation rec { + enableShared' = enableShared && !semi-static; + + useLLVMUnwinder = standalone && withLibunwind; +in stdenv.mkDerivation rec { pname = "libcxxabi"; inherit version; @@ -26,17 +31,22 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ cmake python3 ]; buildInputs = lib.optional withLibunwind libunwind; + passthru = { inherit semi-static useLLVMUnwinder; }; + cmakeFlags = [ "-DLIBCXXABI_LIBCXX_INCLUDES=${cxx-headers}/include/c++/v1" ] ++ lib.optionals standalone [ "-DLLVM_ENABLE_LIBCXX=ON" - ] ++ lib.optionals (standalone && withLibunwind) [ + ] ++ lib.optionals useLLVMUnwinder [ "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" ] ++ lib.optionals stdenv.hostPlatform.isWasm [ "-DLIBCXXABI_ENABLE_THREADS=OFF" "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" - ] ++ lib.optionals (!enableShared) [ + ] ++ lib.optionals (!enableShared') [ "-DLIBCXXABI_ENABLE_SHARED=OFF" + ] ++ lib.optionals semi-static [ + "-DLIBCXX_ENABLE_SHARED=ON" + "-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON" ] ++ lib.optional stdenv.cc.isCompilerRT "-DLIBCXXABI_USE_COMPILER_RT=ON"; @@ -57,7 +67,7 @@ stdenv.mkDerivation rec { install -d -m 755 $out/include $out/lib install -m 644 lib/libc++abi.a $out/lib install -m 644 ../include/cxxabi.h $out/include - '' + lib.optionalString enableShared '' + '' + lib.optionalString enableShared' '' install -m 644 lib/libc++abi.so.1.0 $out/lib ln -s libc++abi.so.1.0 $out/lib/libc++abi.so ln -s libc++abi.so.1.0 $out/lib/libc++abi.so.1 diff --git a/pkgs/development/compilers/llvm/14/libcxx/default.nix b/pkgs/development/compilers/llvm/14/libcxx/default.nix index 8891a69937a..8bdc7aa7967 100644 --- a/pkgs/development/compilers/llvm/14/libcxx/default.nix +++ b/pkgs/development/compilers/llvm/14/libcxx/default.nix @@ -1,7 +1,7 @@ { lib, stdenv, llvm_meta , monorepoSrc, runCommand , cmake, python3, fixDarwinDylibNames, version -, libcxxabi +, libcxxabi, libunwind , enableShared ? !stdenv.hostPlatform.isStatic # If headersOnly is true, the resulting package would only include the headers. @@ -48,7 +48,7 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ cmake python3 ] ++ lib.optional stdenv.isDarwin fixDarwinDylibNames; - buildInputs = lib.optionals (!headersOnly) [ libcxxabi ]; + buildInputs = lib.optionals (!headersOnly) ([ libcxxabi ] ++ lib.optional libcxxabi.useLLVMUnwinder libunwind); cmakeFlags = [ "-DLIBCXX_CXX_ABI=libcxxabi" ] ++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) "-DLIBCXX_HAS_MUSL_LIBC=1" @@ -57,7 +57,13 @@ stdenv.mkDerivation rec { "-DLIBCXX_ENABLE_THREADS=OFF" "-DLIBCXX_ENABLE_FILESYSTEM=OFF" "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" - ] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF"; + ] + ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF" + ++ lib.optionals (!headersOnly && libcxxabi.semi-static) [ + "-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=TRUE" + "-DLIBCXX_CXX_ABI_LIBRARY_PATH=${libcxxabi}/lib" + ] ++ lib.optional (!headersOnly && libcxxabi.useLLVMUnwinder) + "-DLIBCXXABI_USE_LLVM_UNWINDER=ON"; buildFlags = lib.optional headersOnly "generate-cxx-headers"; installTargets = lib.optional headersOnly "install-cxx-headers"; diff --git a/pkgs/development/compilers/llvm/14/libcxxabi/default.nix b/pkgs/development/compilers/llvm/14/libcxxabi/default.nix index 25f90230b7b..c31c4c90ad2 100644 --- a/pkgs/development/compilers/llvm/14/libcxxabi/default.nix +++ b/pkgs/development/compilers/llvm/14/libcxxabi/default.nix @@ -2,9 +2,17 @@ , monorepoSrc, runCommand , cxx-headers, libunwind, version , enableShared ? !stdenv.hostPlatform.isStatic -}: +}: let + withLibunwind = !stdenv.isDarwin && !stdenv.isFreeBSD && !stdenv.hostPlatform.isWasm; -stdenv.mkDerivation rec { + semi-static = enableShared && stdenv.hostPlatform.isWindows && stdenv.cc.bintools.isLld; + + enableShared' = enableShared && !semi-static; + + standalone = stdenv.hostPlatform.useLLVM or false; + + useLLVMUnwinder = standalone && withLibunwind; +in stdenv.mkDerivation rec { pname = "libcxxabi"; inherit version; @@ -35,18 +43,24 @@ stdenv.mkDerivation rec { ]; nativeBuildInputs = [ cmake python3 ]; - buildInputs = lib.optional (!stdenv.isDarwin && !stdenv.isFreeBSD && !stdenv.hostPlatform.isWasm) libunwind; + buildInputs = lib.optional withLibunwind libunwind; + + passthru = { inherit semi-static useLLVMUnwinder; }; cmakeFlags = [ "-DLIBCXXABI_LIBCXX_INCLUDES=${cxx-headers}/include/c++/v1" - ] ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [ + ] ++ lib.optionals standalone [ "-DLLVM_ENABLE_LIBCXX=ON" + ] ++ lib.optionals useLLVMUnwinder [ "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" ] ++ lib.optionals stdenv.hostPlatform.isWasm [ "-DLIBCXXABI_ENABLE_THREADS=OFF" "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" - ] ++ lib.optionals (!enableShared) [ + ] ++ lib.optionals (!enableShared') [ "-DLIBCXXABI_ENABLE_SHARED=OFF" + ] ++ lib.optionals semi-static [ + "-DLIBCXX_ENABLE_SHARED=ON" + "-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON" ] ++ lib.optional stdenv.cc.isCompilerRT "-DLIBCXXABI_USE_COMPILER_RT=ON"; @@ -67,7 +81,7 @@ stdenv.mkDerivation rec { install -d -m 755 $out/include $out/lib install -m 644 lib/libc++abi.a $out/lib install -m 644 ../include/cxxabi.h $out/include - '' + lib.optionalString enableShared '' + '' + lib.optionalString enableShared' '' install -m 644 lib/libc++abi.so.1.0 $out/lib ln -s libc++abi.so.1.0 $out/lib/libc++abi.so ln -s libc++abi.so.1.0 $out/lib/libc++abi.so.1 diff --git a/pkgs/development/compilers/llvm/git/libcxx/default.nix b/pkgs/development/compilers/llvm/git/libcxx/default.nix index 8891a69937a..774bd8a9a9b 100644 --- a/pkgs/development/compilers/llvm/git/libcxx/default.nix +++ b/pkgs/development/compilers/llvm/git/libcxx/default.nix @@ -1,7 +1,7 @@ { lib, stdenv, llvm_meta , monorepoSrc, runCommand , cmake, python3, fixDarwinDylibNames, version -, libcxxabi +, libcxxabi, libunwind , enableShared ? !stdenv.hostPlatform.isStatic # If headersOnly is true, the resulting package would only include the headers. @@ -48,7 +48,7 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ cmake python3 ] ++ lib.optional stdenv.isDarwin fixDarwinDylibNames; - buildInputs = lib.optionals (!headersOnly) [ libcxxabi ]; + buildInputs = lib.optionals (!headersOnly) ([ libcxxabi ] ++ lib.optional libcxxabi.useLLVMUnwinder libunwind); cmakeFlags = [ "-DLIBCXX_CXX_ABI=libcxxabi" ] ++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) "-DLIBCXX_HAS_MUSL_LIBC=1" @@ -57,7 +57,14 @@ stdenv.mkDerivation rec { "-DLIBCXX_ENABLE_THREADS=OFF" "-DLIBCXX_ENABLE_FILESYSTEM=OFF" "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" - ] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF"; + ] + ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF" + ++ lib.optionals (!headersOnly && libcxxabi.semi-static) [ + "-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=TRUE" + "-DLIBCXX_CXX_ABI_LIBRARY_PATH=${libcxxabi}/lib" + ] ++ lib.optional (!headersOnly && libcxxabi.useLLVMUnwinder) + "-DLIBCXXABI_USE_LLVM_UNWINDER=ON"; + buildFlags = lib.optional headersOnly "generate-cxx-headers"; installTargets = lib.optional headersOnly "install-cxx-headers"; diff --git a/pkgs/development/compilers/llvm/git/libcxxabi/default.nix b/pkgs/development/compilers/llvm/git/libcxxabi/default.nix index 0fecc396250..26388e42f22 100644 --- a/pkgs/development/compilers/llvm/git/libcxxabi/default.nix +++ b/pkgs/development/compilers/llvm/git/libcxxabi/default.nix @@ -2,7 +2,17 @@ , monorepoSrc, runCommand , cxx-headers, libunwind, version , enableShared ? !stdenv.hostPlatform.isStatic -}: +}: let + withLibunwind = !stdenv.isDarwin && !stdenv.isFreeBSD && !stdenv.hostPlatform.isWasm; + + semi-static = enableShared && stdenv.hostPlatform.isWindows && stdenv.cc.bintools.isLld; + + enableShared' = enableShared && !semi-static; + + standalone = stdenv.hostPlatform.useLLVM or false; + + useLLVMUnwinder = standalone && withLibunwind; +in stdenv.mkDerivation rec { pname = "libcxxabi"; @@ -35,22 +45,28 @@ stdenv.mkDerivation rec { ]; nativeBuildInputs = [ cmake python3 ]; - buildInputs = lib.optional (!stdenv.isDarwin && !stdenv.isFreeBSD && !stdenv.hostPlatform.isWasm) libunwind; + buildInputs = lib.optional withLibunwind libunwind; + + passthru = { inherit semi-static useLLVMUnwinder; }; + cmakeFlags = [ "-DLIBCXXABI_LIBCXX_INCLUDES=${cxx-headers}/include/c++/v1" - ] ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [ + ] ++ lib.optionals standalone [ "-DLLVM_ENABLE_LIBCXX=ON" + ] ++ lib.optionals useLLVMUnwinder [ "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" ] ++ lib.optionals stdenv.hostPlatform.isWasm [ "-DLIBCXXABI_ENABLE_THREADS=OFF" "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" - ] ++ lib.optionals (!enableShared) [ + ] ++ lib.optionals (!enableShared') [ "-DLIBCXXABI_ENABLE_SHARED=OFF" + ] ++ lib.optionals semi-static [ + "-DLIBCXX_ENABLE_SHARED=ON" + "-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON" ] ++ lib.optional stdenv.cc.isCompilerRT "-DLIBCXXABI_USE_COMPILER_RT=ON"; - installPhase = if stdenv.isDarwin then '' for file in lib/*.dylib; do @@ -68,7 +84,7 @@ stdenv.mkDerivation rec { install -d -m 755 $out/include $out/lib install -m 644 lib/libc++abi.a $out/lib install -m 644 ../include/cxxabi.h $out/include - '' + lib.optionalString enableShared '' + '' + lib.optionalString enableShared' '' install -m 644 lib/libc++abi.so.1.0 $out/lib ln -s libc++abi.so.1.0 $out/lib/libc++abi.so ln -s libc++abi.so.1.0 $out/lib/libc++abi.so.1 From 5c0654f26211aa9e8a0f6783de3e89c5ca1d2724 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Tue, 3 May 2022 06:16:15 -0400 Subject: [PATCH 10/18] cross: Add mingwW64-llvm cross-system. --- lib/systems/examples.nix | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/systems/examples.nix b/lib/systems/examples.nix index 997a7a8c273..19dba63f4f5 100644 --- a/lib/systems/examples.nix +++ b/lib/systems/examples.nix @@ -301,6 +301,15 @@ rec { libc = "msvcrt"; # This distinguishes the mingw (non posix) toolchain }; + # 64 bit mingw-w64 with a llvm-based toolchain targetting ucrt + # + # Inspired by mstorsjo/llvm-mingw + mingwW64-llvm = { + config = "x86_64-w64-mingw32"; + libc = "ucrt"; + useLLVM = true; + }; + # BSDs amd64-netbsd = lib.warn "The amd64-netbsd system example is deprecated. Use x86_64-netbsd instead." x86_64-netbsd; From 15aa32e082124e37587b5fb250598a7019694500 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Tue, 3 May 2022 15:11:15 -0400 Subject: [PATCH 11/18] llvm-bintools: passthru targetPrefix. This is expected e.g. by the GHC cross-compilation code --- pkgs/development/compilers/llvm/13/bintools/default.nix | 8 +++++++- pkgs/development/compilers/llvm/14/bintools/default.nix | 8 +++++++- pkgs/development/compilers/llvm/git/bintools/default.nix | 8 +++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/pkgs/development/compilers/llvm/13/bintools/default.nix b/pkgs/development/compilers/llvm/13/bintools/default.nix index 4c16957aeb4..dcdad1af46f 100644 --- a/pkgs/development/compilers/llvm/13/bintools/default.nix +++ b/pkgs/development/compilers/llvm/13/bintools/default.nix @@ -5,7 +5,13 @@ let if stdenv.hostPlatform != stdenv.targetPlatform then "${stdenv.targetPlatform.config}-" else ""; -in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; passthru.isLld = true; } ('' +in runCommand "llvm-binutils-${version}" { + preferLocalBuild = true; + passthru = { + isLld = true; + targetPrefix = prefix; + }; +} ('' mkdir -p $out/bin for prog in ${lld}/bin/*; do ln -s $prog $out/bin/${prefix}$(basename $prog) diff --git a/pkgs/development/compilers/llvm/14/bintools/default.nix b/pkgs/development/compilers/llvm/14/bintools/default.nix index 4c16957aeb4..dcdad1af46f 100644 --- a/pkgs/development/compilers/llvm/14/bintools/default.nix +++ b/pkgs/development/compilers/llvm/14/bintools/default.nix @@ -5,7 +5,13 @@ let if stdenv.hostPlatform != stdenv.targetPlatform then "${stdenv.targetPlatform.config}-" else ""; -in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; passthru.isLld = true; } ('' +in runCommand "llvm-binutils-${version}" { + preferLocalBuild = true; + passthru = { + isLld = true; + targetPrefix = prefix; + }; +} ('' mkdir -p $out/bin for prog in ${lld}/bin/*; do ln -s $prog $out/bin/${prefix}$(basename $prog) diff --git a/pkgs/development/compilers/llvm/git/bintools/default.nix b/pkgs/development/compilers/llvm/git/bintools/default.nix index 4c16957aeb4..dcdad1af46f 100644 --- a/pkgs/development/compilers/llvm/git/bintools/default.nix +++ b/pkgs/development/compilers/llvm/git/bintools/default.nix @@ -5,7 +5,13 @@ let if stdenv.hostPlatform != stdenv.targetPlatform then "${stdenv.targetPlatform.config}-" else ""; -in runCommand "llvm-binutils-${version}" { preferLocalBuild = true; passthru.isLld = true; } ('' +in runCommand "llvm-binutils-${version}" { + preferLocalBuild = true; + passthru = { + isLld = true; + targetPrefix = prefix; + }; +} ('' mkdir -p $out/bin for prog in ${lld}/bin/*; do ln -s $prog $out/bin/${prefix}$(basename $prog) From d68a532d1be6b5ef579e3b950d01d85b8bcdfd85 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Fri, 6 May 2022 07:20:03 -0400 Subject: [PATCH 12/18] Set a default machine type when using lld targeting Windows. Fixes autotools checks parsing --help --- .../bintools-wrapper/add-lld-ldflags-before.sh | 6 ++++++ .../build-support/bintools-wrapper/default.nix | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 pkgs/build-support/bintools-wrapper/add-lld-ldflags-before.sh diff --git a/pkgs/build-support/bintools-wrapper/add-lld-ldflags-before.sh b/pkgs/build-support/bintools-wrapper/add-lld-ldflags-before.sh new file mode 100644 index 00000000000..265339eb185 --- /dev/null +++ b/pkgs/build-support/bintools-wrapper/add-lld-ldflags-before.sh @@ -0,0 +1,6 @@ +# ld.lld has two incompatible command-line drivers: One for the gnu-compatible COFF linker and one for +# the ELF linker. If no emulation is set (with -m), it will default to the ELF linker; +# unfortunately, some configure scripts use `ld --help` to check for certain Windows-specific flags, +# which don't show up in the help for the ELF linker. So we set a default -m here. + +extraBefore+=("-m" "@mtype@") diff --git a/pkgs/build-support/bintools-wrapper/default.nix b/pkgs/build-support/bintools-wrapper/default.nix index 16a9a0c7b22..59de0ef90a3 100644 --- a/pkgs/build-support/bintools-wrapper/default.nix +++ b/pkgs/build-support/bintools-wrapper/default.nix @@ -384,6 +384,24 @@ stdenv.mkDerivation { '' ) + ## + ## Set the default machine type so that $prefix-ld.lld uses the COFF driver for --help + ## + ## Needed because autotools parses --help for linker features... + ## + + optionalString (isLld && stdenv.targetPlatform.isWindows) (let + mtype = + /**/ if targetPlatform.isx86_32 then "i386pe" + else if targetPlatform.isx86_64 then "i386pep" + else if targetPlatform.isAarch32 then "thumb2pe" + else if targetPlatform.isAarch64 then "arm64pe" + else throw "unsupported target arch for lld"; + in '' + export mtype=${mtype} + substituteAll ${./add-lld-ldflags-before.sh} add-local-ldflags-before.sh + cat add-local-ldflags-before.sh >> $out/nix-support/add-local-ldflags-before.sh + '') + ## ## Code signing on Apple Silicon ## From 98a853c37d90d4b0696deb6a5f3a47a877f48568 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Fri, 6 May 2022 06:38:25 -0400 Subject: [PATCH 13/18] Add msys2 libtool patch for mingw + clang + compiler-rt libtool upstream seems quite slow to merge... --- ...ingw-Create-UAC-manifest-files.mingw.patch | 99 +++++++++++++++++++ .../libtool/0005-Fix-seems-to-be-moved.patch | 24 +++++ .../0006-Fix-strict-ansi-vs-posix.patch | 22 +++++ ...0007-fix-cr-for-awk-in-configure.all.patch | 22 +++++ ...0010-libtool-2.4.2-include-process-h.patch | 24 +++++ ...-static-archives-compiler-internal-l.patch | 33 +++++++ ...files-over-linker-scripts-for-mingw-.patch | 83 ++++++++++++++++ ...-linking-compiler-support-libraries-.patch | 38 +++++++ .../0014-Support-llvm-objdump-f-output.patch | 39 ++++++++ .../tools/misc/libtool/libtool2.nix | 14 +++ 10 files changed, 398 insertions(+) create mode 100644 pkgs/development/tools/misc/libtool/0002-cygwin-mingw-Create-UAC-manifest-files.mingw.patch create mode 100644 pkgs/development/tools/misc/libtool/0005-Fix-seems-to-be-moved.patch create mode 100644 pkgs/development/tools/misc/libtool/0006-Fix-strict-ansi-vs-posix.patch create mode 100644 pkgs/development/tools/misc/libtool/0007-fix-cr-for-awk-in-configure.all.patch create mode 100644 pkgs/development/tools/misc/libtool/0010-libtool-2.4.2-include-process-h.patch create mode 100644 pkgs/development/tools/misc/libtool/0011-Pick-up-clang_rt-static-archives-compiler-internal-l.patch create mode 100644 pkgs/development/tools/misc/libtool/0012-Prefer-response-files-over-linker-scripts-for-mingw-.patch create mode 100644 pkgs/development/tools/misc/libtool/0013-Allow-statically-linking-compiler-support-libraries-.patch create mode 100644 pkgs/development/tools/misc/libtool/0014-Support-llvm-objdump-f-output.patch diff --git a/pkgs/development/tools/misc/libtool/0002-cygwin-mingw-Create-UAC-manifest-files.mingw.patch b/pkgs/development/tools/misc/libtool/0002-cygwin-mingw-Create-UAC-manifest-files.mingw.patch new file mode 100644 index 00000000000..310002b8231 --- /dev/null +++ b/pkgs/development/tools/misc/libtool/0002-cygwin-mingw-Create-UAC-manifest-files.mingw.patch @@ -0,0 +1,99 @@ +[PATCH 2/6] [cygwin|mingw] Create UAC manifest files. + +* build-aux/ltmain.in (func_emit_exe_manifest): New function. +(func_mode_link) [cygwin|mingw]: Create manifest files for wrapper +and target exe when target name matches heuristic that triggers +UAC problems for newer win32 OSs. Clean up $cwrapper.manifest on +error. Ensure manifest files have executable permission. +(func_mode_uninstall): Clean up manifest files. +Various reports by Eric Blake, Kai Tietz, and Cesar Strauss. +--- + build-auxltmain.in | 50 ++++++++++++++++++++++++++++++++++++++++++- + 1 files changed, 48 insertions(+), 2 deletions(-) + +diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in +index 0418007..1821779 100644 +--- a/build-aux/ltmain.in ++++ b/build-aux/ltmain.in +@@ -4277,6 +4277,41 @@ EOF + } + # end: func_emit_cwrapperexe_src + ++# func_emit_exe_manifest ++# emit a Win32 UAC manifest for executable on stdout ++# Must ONLY be called from within func_mode_link because ++# it depends on a number of variable set therein. ++func_emit_exe_manifest () ++{ ++ cat < ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++EOF ++} ++ + # func_win32_import_lib_p ARG + # True if ARG is an import lib, as indicated by $file_magic_cmd + func_win32_import_lib_p () +@@ -8237,7 +8272,7 @@ EOF + cwrappersource="$output_path/$objdir/lt-$output_name.c" + cwrapper="$output_path/$output_name.exe" + $RM $cwrappersource $cwrapper +- trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15 ++ trap "$RM $cwrappersource $cwrapper $cwrapper.manifest; exit $EXIT_FAILURE" 1 2 15 + + func_emit_cwrapperexe_src > $cwrappersource + +@@ -8257,6 +8292,16 @@ EOF + $opt_dry_run || { + # note: this script will not be executed, so do not chmod. + if test "x$build" = "x$host"; then ++ # Create the UAC manifests first if necessary (but the ++ # manifest files must have executable permission regardless). ++ case $output_name in ++ *instal*|*patch*|*setup*|*update*) ++ func_emit_exe_manifest > $cwrapper.manifest ++ func_emit_exe_manifest > $output_path/$objdir/$output_name.exe.manifest ++ chmod +x $cwrapper.manifest ++ chmod +x $output_path/$objdir/$output_name.exe.manifest ++ ;; ++ esac + $cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result + else + func_emit_wrapper no > $func_ltwrapper_scriptname_result +@@ -8777,8 +8822,9 @@ func_mode_uninstall () + # note $name still contains .exe if it was in $file originally + # as does the version of $file that was added into $rmfiles + func_append rmfiles " $odir/$name $odir/${name}S.$objext" ++ func_append rmfiles " ${name}.manifest $objdir/${name}.manifest" + if test yes = "$fast_install" && test -n "$relink_command"; then +- func_append rmfiles " $odir/lt-$name" ++ func_append rmfiles " $odir/lt-$name $objdir/lt-${name}.manifest" + fi + if test "X$noexename" != "X$name"; then + func_append rmfiles " $odir/lt-$noexename.c" +-- +1.7.1 + diff --git a/pkgs/development/tools/misc/libtool/0005-Fix-seems-to-be-moved.patch b/pkgs/development/tools/misc/libtool/0005-Fix-seems-to-be-moved.patch new file mode 100644 index 00000000000..73c249db391 --- /dev/null +++ b/pkgs/development/tools/misc/libtool/0005-Fix-seems-to-be-moved.patch @@ -0,0 +1,24 @@ +[PATCH 5/6] Fix "seems to be moved" +* build-aux/ltmain.in (func_mode_link): Compare files by inode +to fix "seems to be moved" warning. +--- + build-aux/ltmain.in | 4 +++- + 1 files changed, 3 insertions(+), 1 deletions(-) + +diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in +index af46cb8..244bb5b 100644 +--- a/build-aux/ltmain.in ++++ b/build-aux/ltmain.in +@@ -6283,7 +6283,9 @@ func_mode_link () + eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` + test -z "$libdir" && \ + func_fatal_error "'$deplib' is not a valid libtool archive" +- test "$absdir" != "$libdir" && \ ++ abs_inode=`ls -i "$deplib" | awk '{print $1}'` ++ lib_inode=`ls -i "$libdir/$(basename $deplib)" | awk '{print $1}'` ++ test "$abs_inode" != "$lib_inode" && \ + func_warning "'$deplib' seems to be moved" + + path=-L$absdir +-- +1.7.0.2.msysgit.0 \ No newline at end of file diff --git a/pkgs/development/tools/misc/libtool/0006-Fix-strict-ansi-vs-posix.patch b/pkgs/development/tools/misc/libtool/0006-Fix-strict-ansi-vs-posix.patch new file mode 100644 index 00000000000..486ad76112e --- /dev/null +++ b/pkgs/development/tools/misc/libtool/0006-Fix-strict-ansi-vs-posix.patch @@ -0,0 +1,22 @@ +[PATCH 6/6] Fix STRICT_ANSI vs POSIX +* build-aux/ltmain.in (func_mode_link): Also check for _POSIX +as well as __STRICT_ANSI__ to avoid re-definitions. +--- + build-aux/ltmain.in | 4 +++- + 1 files changed, 1 insertions(+), 1 deletions(-) + +diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in +index af46cb8..244bb5b 100644 +--- a/build-aux/ltmain.in ++++ b/build-aux/ltmain.in +@@ -3382,7 +3382,7 @@ + + /* declarations of non-ANSI functions */ + #if defined __MINGW32__ +-# ifdef __STRICT_ANSI__ ++# if defined(__STRICT_ANSI__) && !defined(__MINGW64_VERSION_MAJOR) || defined(_POSIX_) + int _putenv (const char *); + # endif + #elif defined __CYGWIN__ +-- +1.7.0.2.msysgit.0 \ No newline at end of file diff --git a/pkgs/development/tools/misc/libtool/0007-fix-cr-for-awk-in-configure.all.patch b/pkgs/development/tools/misc/libtool/0007-fix-cr-for-awk-in-configure.all.patch new file mode 100644 index 00000000000..65d5185a36f --- /dev/null +++ b/pkgs/development/tools/misc/libtool/0007-fix-cr-for-awk-in-configure.all.patch @@ -0,0 +1,22 @@ +--- libtool-2.4.2/configure.orig 2011-10-17 10:18:58.000000000 +0000 ++++ libtool-2.4.2/configure 2013-08-04 19:01:30.220494400 +0000 +@@ -28825,7 +28825,7 @@ + fi + ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' /dev/null` + if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then +- ac_cs_awk_cr='\\r' ++ ac_cs_awk_cr='\r' + else + ac_cs_awk_cr=$ac_cr + fi +--- libtool-2.4.2/libltdl/configure.orig 2011-10-17 10:19:47.000000000 +0000 ++++ libtool-2.4.2/libltdl/configure 2013-08-05 11:49:24.990792500 +0000 +@@ -13574,7 +13574,7 @@ + fi + ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' /dev/null` + if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then +- ac_cs_awk_cr='\\r' ++ ac_cs_awk_cr='\r' + else + ac_cs_awk_cr=$ac_cr + fi diff --git a/pkgs/development/tools/misc/libtool/0010-libtool-2.4.2-include-process-h.patch b/pkgs/development/tools/misc/libtool/0010-libtool-2.4.2-include-process-h.patch new file mode 100644 index 00000000000..82ecf5266b7 --- /dev/null +++ b/pkgs/development/tools/misc/libtool/0010-libtool-2.4.2-include-process-h.patch @@ -0,0 +1,24 @@ +diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in +index 0418007..91276c2 100644 +--- a/build-aux/ltmain.in ++++ b/build-aux/ltmain.in +@@ -4163,6 +4163,7 @@ + # include + # include + # ifdef __CYGWIN__ ++# include + # include + # endif + #endif +diff --git a/build-aux/ltmain.sh b/build-aux/ltmain.sh +index 0418007..91276c2 100644 +--- a/build-aux/ltmain.sh ++++ b/build-aux/ltmain.sh +@@ -4163,6 +4163,7 @@ + # include + # include + # ifdef __CYGWIN__ ++# include + # include + # endif + #endif diff --git a/pkgs/development/tools/misc/libtool/0011-Pick-up-clang_rt-static-archives-compiler-internal-l.patch b/pkgs/development/tools/misc/libtool/0011-Pick-up-clang_rt-static-archives-compiler-internal-l.patch new file mode 100644 index 00000000000..49cc0706551 --- /dev/null +++ b/pkgs/development/tools/misc/libtool/0011-Pick-up-clang_rt-static-archives-compiler-internal-l.patch @@ -0,0 +1,33 @@ +From a18473ed4e5574dab899db640b8efeff78939b54 Mon Sep 17 00:00:00 2001 +From: Manoj Gupta +Date: Wed, 10 Oct 2018 10:50:23 +0300 +Subject: [PATCH 1/2] Pick up clang_rt static archives compiler internal + libraries + +Libtool checks only for libraries linked as -l* when trying to +find internal compiler libraries. Clang, however uses the absolute +path to link its internal libraries e.g. compiler_rt. This patch +handles clang's statically linked libraries when finding internal +compiler libraries. +https://crbug.com/749263 +https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27866 +--- + m4/libtool.m4 | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/m4/libtool.m4 b/m4/libtool.m4 +index b55a6e5..d9322d0 100644 +--- a/m4/libtool.m4 ++++ b/m4/libtool.m4 +@@ -7556,7 +7556,7 @@ if AC_TRY_EVAL(ac_compile); then + for p in `eval "$output_verbose_link_cmd"`; do + case $prev$p in + +- -L* | -R* | -l*) ++ -L* | -R* | -l* | */libclang_rt.*.a) + # Some compilers place space between "-{L,R}" and the path. + # Remove the space. + if test x-L = "$p" || +-- +2.7.4 + diff --git a/pkgs/development/tools/misc/libtool/0012-Prefer-response-files-over-linker-scripts-for-mingw-.patch b/pkgs/development/tools/misc/libtool/0012-Prefer-response-files-over-linker-scripts-for-mingw-.patch new file mode 100644 index 00000000000..7bdb62dbfb8 --- /dev/null +++ b/pkgs/development/tools/misc/libtool/0012-Prefer-response-files-over-linker-scripts-for-mingw-.patch @@ -0,0 +1,83 @@ +From ec15841963ca3aab3bc88fb0932c014337284bfc Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Martin=20Storsj=C3=B6?= +Date: Wed, 10 Oct 2018 10:47:21 +0300 +Subject: [PATCH 2/2] Prefer response files over linker scripts for mingw tools + +The GCC/binutils tools support response files just fine, while +lld (impersonating GNU ld) only supports response files, not +linker scripts. Using a linker script as input just to pass a +list of files is overkill for cases when a response file is enough. +--- + build-aux/ltmain.in | 28 ++++++++++++++-------------- + m4/libtool.m4 | 2 ++ + 2 files changed, 16 insertions(+), 14 deletions(-) + +diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in +index e2fb263..db5d590 100644 +--- a/build-aux/ltmain.in ++++ b/build-aux/ltmain.in +@@ -7932,20 +7932,7 @@ EOF + last_robj= + k=1 + +- if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then +- output=$output_objdir/$output_la.lnkscript +- func_verbose "creating GNU ld script: $output" +- echo 'INPUT (' > $output +- for obj in $save_libobjs +- do +- func_to_tool_file "$obj" +- $ECHO "$func_to_tool_file_result" >> $output +- done +- echo ')' >> $output +- func_append delfiles " $output" +- func_to_tool_file "$output" +- output=$func_to_tool_file_result +- elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then ++ if test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then + output=$output_objdir/$output_la.lnk + func_verbose "creating linker input file list: $output" + : > $output +@@ -7964,6 +7951,19 @@ EOF + func_append delfiles " $output" + func_to_tool_file "$output" + output=$firstobj\"$file_list_spec$func_to_tool_file_result\" ++ elif test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then ++ output=$output_objdir/$output_la.lnkscript ++ func_verbose "creating GNU ld script: $output" ++ echo 'INPUT (' > $output ++ for obj in $save_libobjs ++ do ++ func_to_tool_file "$obj" ++ $ECHO "$func_to_tool_file_result" >> $output ++ done ++ echo ')' >> $output ++ func_append delfiles " $output" ++ func_to_tool_file "$output" ++ output=$func_to_tool_file_result + else + if test -n "$save_libobjs"; then + func_verbose "creating reloadable object files..." +diff --git a/m4/libtool.m4 b/m4/libtool.m4 +index d9322d0..9046a84 100644 +--- a/m4/libtool.m4 ++++ b/m4/libtool.m4 +@@ -5130,6 +5130,7 @@ _LT_EOF + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols' + _LT_TAGVAR(exclude_expsyms, $1)=['[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname'] ++ _LT_TAGVAR(file_list_spec, $1)='@' + + if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' +@@ -6706,6 +6707,7 @@ if test yes != "$_lt_caught_CXX_error"; then + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=no + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes ++ _LT_TAGVAR(file_list_spec, $1)='@' + + if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' +-- +2.7.4 + diff --git a/pkgs/development/tools/misc/libtool/0013-Allow-statically-linking-compiler-support-libraries-.patch b/pkgs/development/tools/misc/libtool/0013-Allow-statically-linking-compiler-support-libraries-.patch new file mode 100644 index 00000000000..b75b191a7cb --- /dev/null +++ b/pkgs/development/tools/misc/libtool/0013-Allow-statically-linking-compiler-support-libraries-.patch @@ -0,0 +1,38 @@ +From b9f77cae8cfbe850e58cac686fcb4d246b5bfc51 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Martin=20Storsj=C3=B6?= +Date: Mon, 19 Aug 2019 13:34:51 +0300 +Subject: [PATCH] Allow statically linking compiler support libraries when + linking a library + +For cases with deplibs_check_method="file_magic ..." (as it is for mingw), +there were previously no way that a static library could be accepted +here. +--- + build-aux/ltmain.in | 11 +++++++++-- + 1 file changed, 9 insertions(+), 2 deletions(-) + +diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in +index e2fb2633..db4d775c 100644 +--- a/build-aux/ltmain.in ++++ b/build-aux/ltmain.in +@@ -5870,8 +5870,15 @@ func_mode_link () + fi + case $linkmode in + lib) +- # Linking convenience modules into shared libraries is allowed, +- # but linking other static libraries is non-portable. ++ # Linking convenience modules and compiler provided static libraries ++ # into shared libraries is allowed, but linking other static ++ # libraries is non-portable. ++ case $deplib in ++ */libgcc*.$libext | */libclang_rt*.$libext) ++ deplibs="$deplib $deplibs" ++ continue ++ ;; ++ esac + case " $dlpreconveniencelibs " in + *" $deplib "*) ;; + *) +-- +2.17.1 + diff --git a/pkgs/development/tools/misc/libtool/0014-Support-llvm-objdump-f-output.patch b/pkgs/development/tools/misc/libtool/0014-Support-llvm-objdump-f-output.patch new file mode 100644 index 00000000000..d6570502d94 --- /dev/null +++ b/pkgs/development/tools/misc/libtool/0014-Support-llvm-objdump-f-output.patch @@ -0,0 +1,39 @@ +From 03dabb6a70847761e65572a2a7b770a3b1b9f123 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= +Date: Mon, 12 Apr 2021 23:44:10 +0200 +Subject: [PATCH] Support llvm-objdump -f output + +--- + build-aux/ltmain.in | 2 +- + m4/libtool.m4 | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in +index a9f070a..4a434cc 100644 +--- a/build-aux/ltmain.in ++++ b/build-aux/ltmain.in +@@ -3019,7 +3019,7 @@ func_win32_libid () + *ar\ archive*) # could be an import, or static + # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD. + if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null | +- $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then ++ $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64|coff-arm|coff-arm64|coff-i386|coff-x86-64)' >/dev/null; then + case $nm_interface in + "MS dumpbin") + if func_cygming_ms_implib_p "$1" || +diff --git a/m4/libtool.m4 b/m4/libtool.m4 +index 21a7d60..594be9c 100644 +--- a/m4/libtool.m4 ++++ b/m4/libtool.m4 +@@ -3473,7 +3473,7 @@ mingw* | pw32*) + lt_cv_file_magic_cmd='func_win32_libid' + else + # Keep this pattern in sync with the one in func_win32_libid. +- lt_cv_deplibs_check_method='file_magic file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' ++ lt_cv_deplibs_check_method='file_magic file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64|coff-arm|coff-arm64|coff-i386|coff-x86-64)' + lt_cv_file_magic_cmd='$OBJDUMP -f' + fi + ;; +-- +2.31.1 + diff --git a/pkgs/development/tools/misc/libtool/libtool2.nix b/pkgs/development/tools/misc/libtool/libtool2.nix index 3d15752fc0a..e2f4e97993d 100644 --- a/pkgs/development/tools/misc/libtool/libtool2.nix +++ b/pkgs/development/tools/misc/libtool/libtool2.nix @@ -23,6 +23,20 @@ stdenv.mkDerivation rec { # https://lists.gnu.org/archive/html/autotools-announce/2022-03/msg00000.html FILECMD = "${file}/bin/file"; + patches = [ + # Patches from msys2 fixing various bugs with useClang platforms + # targeting Windows. Especially https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27866 + ./0002-cygwin-mingw-Create-UAC-manifest-files.mingw.patch + ./0005-Fix-seems-to-be-moved.patch + ./0006-Fix-strict-ansi-vs-posix.patch + ./0007-fix-cr-for-awk-in-configure.all.patch + ./0010-libtool-2.4.2-include-process-h.patch + ./0011-Pick-up-clang_rt-static-archives-compiler-internal-l.patch + ./0012-Prefer-response-files-over-linker-scripts-for-mingw-.patch + ./0013-Allow-statically-linking-compiler-support-libraries-.patch + ./0014-Support-llvm-objdump-f-output.patch + ]; + # Normally we'd use autoreconfHook, but that includes libtoolize. postPatch = '' aclocal -I m4 From f4d583000192d0e8759ebaac60ec6b32488117ea Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Fri, 6 May 2022 06:40:35 -0400 Subject: [PATCH 14/18] libffi: autoreconf on Windows for libtool fix --- pkgs/development/libraries/libffi/default.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/development/libraries/libffi/default.nix b/pkgs/development/libraries/libffi/default.nix index 6a22d585fbc..f5ecd2cc876 100644 --- a/pkgs/development/libraries/libffi/default.nix +++ b/pkgs/development/libraries/libffi/default.nix @@ -45,6 +45,8 @@ stdenv.mkDerivation rec { checkInputs = [ dejagnu ]; + nativeBuildInputs = lib.optional stdenv.hostPlatform.isWindows autoreconfHook; + meta = with lib; { description = "A foreign function call interface library"; longDescription = '' From b08eed0cbc92b3bca1347f4534f1059b42e06de4 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Fri, 6 May 2022 07:46:07 -0400 Subject: [PATCH 15/18] libffi: Fix build for Windows with lld --- pkgs/development/libraries/libffi/default.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgs/development/libraries/libffi/default.nix b/pkgs/development/libraries/libffi/default.nix index f5ecd2cc876..890fb9f62e4 100644 --- a/pkgs/development/libraries/libffi/default.nix +++ b/pkgs/development/libraries/libffi/default.nix @@ -32,7 +32,9 @@ stdenv.mkDerivation rec { # https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6155 # https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/283 "--disable-exec-static-tramp" - ]; + ] ++ + # ld.lld on Windows doesn't support --version-script. + lib.optional (stdenv.hostPlatform.isWindows && stdenv.cc.bintools.isLld) "--disable-symvers"; preCheck = '' # The tests use -O0 which is not compatible with -D_FORTIFY_SOURCE. From f28101d2a421da8b9836a9e339dc8b27353f60d3 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Fri, 6 May 2022 07:50:03 -0400 Subject: [PATCH 16/18] gmp: autoreconf on Windows for libtool fixes. --- pkgs/development/libraries/gmp/6.x.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/development/libraries/gmp/6.x.nix b/pkgs/development/libraries/gmp/6.x.nix index af4f15a151f..838fe432caf 100644 --- a/pkgs/development/libraries/gmp/6.x.nix +++ b/pkgs/development/libraries/gmp/6.x.nix @@ -1,6 +1,6 @@ { lib, stdenv, fetchurl, m4 , cxx ? !stdenv.hostPlatform.useAndroidPrebuilt && !stdenv.hostPlatform.isWasm -, buildPackages +, buildPackages, autoreconfHook , withStatic ? stdenv.hostPlatform.isStatic }: @@ -29,7 +29,7 @@ let self = stdenv.mkDerivation rec { passthru.static = self.out; depsBuildBuild = [ buildPackages.stdenv.cc ]; - nativeBuildInputs = [ m4 ]; + nativeBuildInputs = [ m4 ] ++ lib.optional stdenv.hostPlatform.isWindows autoreconfHook; configureFlags = [ "--with-pic" From 5e8a857310a580d6f7a3d56ec99295792143d496 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Fri, 6 May 2022 10:53:39 -0400 Subject: [PATCH 17/18] ncurses: Fix building against ucrt --- pkgs/development/libraries/ncurses/default.nix | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkgs/development/libraries/ncurses/default.nix b/pkgs/development/libraries/ncurses/default.nix index 2740b95986c..a661f5f216c 100644 --- a/pkgs/development/libraries/ncurses/default.nix +++ b/pkgs/development/libraries/ncurses/default.nix @@ -46,7 +46,13 @@ stdenv.mkDerivation rec { ]; # Only the C compiler, and explicitly not C++ compiler needs this flag on solaris: - CFLAGS = lib.optionalString stdenv.isSunOS "-D_XOPEN_SOURCE_EXTENDED"; + CFLAGS = + # Only the C compiler, and explicitly not C++ compiler needs this flag on solaris: + /**/ if stdenv.isSunOS then "-D_XOPEN_SOURCE_EXTENDED" + # ucrt doesn't support X_OK to access() without this flag + else if stdenv.hostPlatform.libc == "ucrt" then "-D__USE_MINGW_ACCESS" + else ""; + depsBuildBuild = [ buildPackages.stdenv.cc From ece10a711f5a2c406d8907c66c99c61f776c2ac1 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Sat, 7 May 2022 06:30:58 -0400 Subject: [PATCH 18/18] ghcHEAD: Fix Windows cross-compilation with lld. By specifying pkgs.libffi here instead of letting callPackage handle it, we confuse the splicing logic and put the host libffi into NIX_LDFLAGS_FOR_TARGET. This previously hasn't been a problem, as we also pass an explicit configure flag pointing to the target libffi, and so the only side-effect is a senseless -rpath flag. ld.lld (rightly) does not recognize the -rpath flag when targeting Windows, however, so this causes build failures. --- pkgs/top-level/haskell-packages.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/pkgs/top-level/haskell-packages.nix b/pkgs/top-level/haskell-packages.nix index c46a7f1bcd2..fac1d546832 100644 --- a/pkgs/top-level/haskell-packages.nix +++ b/pkgs/top-level/haskell-packages.nix @@ -145,7 +145,6 @@ in { inherit (buildPackages.darwin) xattr autoSignDarwinBinariesHook; buildTargetLlvmPackages = pkgsBuildTarget.llvmPackages_12; llvmPackages = pkgs.llvmPackages_12; - libffi = pkgs.libffi; }; ghcjs = compiler.ghcjs810;