diff --git a/lib/systems/examples.nix b/lib/systems/examples.nix index 9c43d9b1bbc78..0542e504eee92 100644 --- a/lib/systems/examples.nix +++ b/lib/systems/examples.nix @@ -133,7 +133,7 @@ rec { # 32 bit mingw-w64 mingw32 = { - config = "i686-pc-mingw32"; + config = "i686-w64-mingw32"; libc = "msvcrt"; # This distinguishes the mingw (non posix) toolchain platform = {}; }; @@ -141,7 +141,7 @@ rec { # 64 bit mingw-w64 mingwW64 = { # That's the triplet they use in the mingw-w64 docs. - config = "x86_64-pc-mingw32"; + config = "x86_64-w64-mingw32"; libc = "msvcrt"; # This distinguishes the mingw (non posix) toolchain platform = {}; }; diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index d79947ad3dea3..41311a1100926 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -110,6 +110,7 @@ rec { vendors = setTypes types.openVendor { apple = {}; pc = {}; + w64 = {}; # mingw-w64 unknown = {}; }; diff --git a/pkgs/development/compilers/gcc/7/default-ng-prebuilt.nix b/pkgs/development/compilers/gcc/7/default-ng-prebuilt.nix new file mode 100644 index 0000000000000..9ccdabd13d605 --- /dev/null +++ b/pkgs/development/compilers/gcc/7/default-ng-prebuilt.nix @@ -0,0 +1,86 @@ +{ stdenv, targetPackages, fetchurl, targetPlatform, hostPlatform +, langC ? true, langCC ? true, langFortran ? false +, langObjC ? targetPlatform.isDarwin +, langObjCpp ? targetPlatform.isDarwin +, langJava ? false +, langGo ? false +# build deps +, gmp, mpfr, libmpc +, binutils +, extraBuildInputs ? [] +, extraConfigureFlags ? [] +, threadModel ? "posix" +, ... }: + +with stdenv.lib; + +let version = "7.3.0"; +in stdenv.mkDerivation ({ + + name = "gcc-${version}-prebuilt" + optionalString (targetPlatform != hostPlatform) "-${targetPlatform.config}"; + + src = fetchurl { + url = "mirror://gcc/releases/gcc-${version}/gcc-${version}.tar.xz"; + sha256 = "0p71bij6bfhzyrs8676a8jmpjsfz392s2rg862sdnsk30jpacb43"; + }; + + buildInputs = [ + gmp mpfr libmpc #libelf + binutils + ] ++ extraBuildInputs; + + # bould out of tree. We don't use `pwd` in the `configureScript` so + # that we do not hardcode the build location. We are going to re-use + # the build folder in a different derivation again when actually + # installing `gcc`, `libgcc`, ... + preConfigure = '' + mkdir ../build + cd ../build + + configureScript="../$sourceRoot/configure" + ''; + + configurePlatforms = [ "build" "host" ] ++ optional (targetPlatform != hostPlatform) "target"; + + configureFlags = [ + "--enable-languages=${ + concatStrings (intersperse "," + ( optional langC "c" + ++ optional langCC "c++" + ++ optional langFortran "fortran" + ++ optional langJava "java" + ++ optional langGo "go" + ++ optional langObjC "objc" + ++ optional langObjCpp "obj-c++" + ) + ) + }" + "--disable-multilib" + "--with-bugurl=https://github.com/nixos/nixpkgs/issues" + "--with-gmp-include=${gmp.dev}/include" + "--with-gmp-lib=${gmp.out}/lib" + "--with-mpfr-include=${mpfr.dev}/include" + "--with-mpfr-lib=${mpfr.out}/lib" + "--with-mpc=${libmpc}" + + "--enable-threads=posix" + + # we need to ensure that we set the proper assembler and linker. If we don't + # we can't change this at runtime anymore -- m( + "--with-as=${binutils}/bin/${targetPlatform.config}-as" + "--with-ld=${binutils}/bin/${targetPlatform.config}-ld" + ] ++ extraConfigureFlags; + + # don't fail with: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security] + hardeningDisable = [ "format" ]; + enableParallelBuilding = true; + + makeFlags = [ "all-gcc" ]; + # installTargets = "install-${component}"; + installPhase = '' + cd .. + mkdir -p $out && tar -czf $out/prebuilt.tar.gz "$sourceRoot" build + ''; + fixpuPhase = ""; + dontPatchShebangs = true; +}) diff --git a/pkgs/development/compilers/gcc/7/default-ng.nix b/pkgs/development/compilers/gcc/7/default-ng.nix new file mode 100644 index 0000000000000..58da50deb12c6 --- /dev/null +++ b/pkgs/development/compilers/gcc/7/default-ng.nix @@ -0,0 +1,98 @@ +{ stdenv, targetPackages, windows, gcc-prebuilt, component, hostPlatform, targetPlatform +, gmp, mpfr, libmpc, gcc, extraBuildInputs ? [] }: + +with stdenv.lib; + +let version = "7.3.0"; +in stdenv.mkDerivation ({ + + name = "gcc-${version}-${component}" + optionalString (targetPlatform != hostPlatform) "-${targetPlatform.config}"; + + buildInputs = extraBuildInputs ++ [ + gcc-prebuilt + gmp mpfr libmpc + ]; + + src = "${gcc-prebuilt}/prebuilt.tar.gz"; + # prebuilt doesn't have a root directory. + setSourceRoot = "sourceRoot=`pwd`"; + + # We'll need to replace all the paths to the prebuilt version + # with the current $out as the prefix. We also need to injet + # -B to the mingw_w64/lib folder so we find libcrt2.o and + # the other windows libraires (libmvcrt, ...). Adding -L + # would not help gcc find libcrt2.o. + # + # For pthread support also need to inject the include and lib + # dirs. Ideally this would be handled by the cc-wrapper. But + # we still use the build cc here. + # + # TODO: the linking of the mingw_w64_headers into $out/mingw + # is rather annoying but gcc currently expect them there. + # Ideally I'd like to link them into `mingw` in the + # libc (windows.mingw_w64). + postPatch = '' + echo "rewriting prefix from ${gcc-prebuilt} -> $out" + find . \( -name mkheaders\* -o -name Makefile \) -exec \ + sed -i -e "s|${gcc-prebuilt}|$out|g" {} \; + '' + optionalString (component != "gcc") '' + sed -i -e 's|SYSROOT_CFLAGS_FOR_TARGET = |SYSROOT_CFLAGS_FOR_TARGET = -B${windows.mingw_w64}/lib -I${windows.mingw_w64_pthreads}/include -L${windows.mingw_w64_pthreads}/lib|g' build/Makefile + mkdir -p $out && ln -s ${windows.mingw_w64_headers} $out/mingw + ''; + + # don't fail with: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security] + hardeningDisable = [ "format" ]; + enableParallelBuilding = true; #(component == "gcc"); #true; + + # We've already done the treewide configure + # in the gcc-prebuilt. + configurePhase = '' + echo "configure disabled" + ''; + dontStrip = true; + + # the -prebuilt tarball contains `gcc-X.Y` and `build` + # which is the out of tree build directory for gcc. + # So we'll change into it prior to buildinging/installing. + preBuild = '' + cd build + ''; + + makeFlags = [ "all-${component}" ]; + installTargets = "install-${component}"; +} // optionalAttrs (component == "gcc") { + # gcc has already been built by the -prebuilt step. + # as such, we don't need to rebuild it here. + # Maybe we can skip this hack, and just run make + # it should be a no-op mostly anyway, and would + # simplify the expression. + buildPhase = ""; +} // optionalAttrs (component != "gcc") { + # alright, so if we do build the components + # separately, they still end up in + # $out/lib/gcc// + # that's also where the include folder ends + # up in. As we'll only push $out/lib and + # $out/include into the NIX_CFLAGS and NIX_LDFLAGS + # we need to move them into place. + postInstall = '' + set -v + mv $out/lib $out/lib.old + mv $(ls -d $out/lib.old/gcc/*/*) $out/lib + mv $out/lib/include $out/include + mkdir -p $out/include + mv $out/*/lib/* $out/lib + mkdir -p $out/lib + ls $out + targetDir=$(find $out -name "*-*-*" -mindepth 1 -maxdepth 1 -type d) + if [[ -d "$targetDir/include" ]]; then + mv $targetDir/include/*/*/* $out/include + fi + targetDir2=$(find $out/include -name "*-*-*" -mindepth 1 -maxdepth 1 -type d) + if [[ -d "$targetDir2" ]]; then + cp -r $targetDir2/* $out/include + fi + rm -fR $out/lib.old + set +v + ''; +}) diff --git a/pkgs/development/compilers/ghc/8.2.1-binary.nix b/pkgs/development/compilers/ghc/8.2.1-binary.nix index c88d2a8685a6b..0a53433089acd 100644 --- a/pkgs/development/compilers/ghc/8.2.1-binary.nix +++ b/pkgs/development/compilers/ghc/8.2.1-binary.nix @@ -61,7 +61,7 @@ stdenv.mkDerivation rec { for exe in $(find . -type f -executable); do isScript $exe && continue ln -fs ${libiconv}/lib/libiconv.dylib $(dirname $exe)/libiconv.dylib - install_name_tool -change /usr/lib/libiconv.2.dylib @executable_path/libiconv.dylib -change /usr/local/lib/gcc/6/libgcc_s.1.dylib ${gcc.cc.lib}/lib/libgcc_s.1.dylib $exe + install_name_tool -change /usr/lib/libiconv.2.dylib @executable_path/libiconv.dylib $exe done '' + @@ -131,7 +131,7 @@ stdenv.mkDerivation rec { for exe in $(find "$out" -type f -executable); do isScript $exe && continue ln -fs ${libiconv}/lib/libiconv.dylib $(dirname $exe)/libiconv.dylib - install_name_tool -change /usr/lib/libiconv.2.dylib @executable_path/libiconv.dylib -change /usr/local/lib/gcc/6/libgcc_s.1.dylib ${gcc.cc.lib}/lib/libgcc_s.1.dylib $exe + install_name_tool -change /usr/lib/libiconv.2.dylib @executable_path/libiconv.dylib $exe done for file in $(find "$out" -name setup-config); do diff --git a/pkgs/development/compilers/ghc/8.4.2.nix b/pkgs/development/compilers/ghc/8.4.2.nix index 94555482d28be..ed05e494187b0 100644 --- a/pkgs/development/compilers/ghc/8.4.2.nix +++ b/pkgs/development/compilers/ghc/8.4.2.nix @@ -15,7 +15,7 @@ , # If enabled, GHC will be built with the GPL-free but slower integer-simple # library instead of the faster but GPLed integer-gmp library. - enableIntegerSimple ? false, gmp ? null, m4 + enableIntegerSimple ? targetPlatform != hostPlatform, gmp ? null, m4 , # If enabled, use -fPIC when compiling static libs. enableRelocatedStaticLibs ? targetPlatform != hostPlatform @@ -24,7 +24,12 @@ # platform). Static libs are always built. enableShared ? !targetPlatform.useAndroidPrebuilt +, # Whetherto build terminfo. + enableTerminfo ? !targetPlatform.isWindows + , version ? "8.4.2" +, ghcFlavour ? "" +, ghcCrossFlavour ? "perf-cross" }: assert !enableIntegerSimple -> gmp != null; @@ -38,11 +43,13 @@ let "${targetPlatform.config}-"; buildMK = '' + BuildFlavour = ${if targetPlatform != hostPlatform then ghcCrossFlavour else ghcFlavour} + ifneq \"\$(BuildFlavour)\" \"\" + include mk/flavours/\$(BuildFlavour).mk + endif DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"} - '' + stdenv.lib.optionalString enableIntegerSimple '' - INTEGER_LIBRARY = integer-simple + INTEGER_LIBRARY = ${if enableIntegerSimple then "integer-simple" else "integer-gmp"} '' + stdenv.lib.optionalString (targetPlatform != hostPlatform) '' - BuildFlavour = perf-cross Stage1Only = YES HADDOCK_DOCS = NO BUILD_SPHINX_HTML = NO @@ -55,9 +62,9 @@ let ''; # Splicer will pull out correct variations - libDeps = platform: [ ncurses ] + libDeps = platform: stdenv.lib.optional enableTerminfo [ ncurses ] ++ stdenv.lib.optional (!enableIntegerSimple) gmp - ++ stdenv.lib.optional (platform.libc != "glibc") libiconv; + ++ stdenv.lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv; toolsForTarget = if hostPlatform == buildPlatform then @@ -125,7 +132,7 @@ stdenv.mkDerivation rec { "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib" ] ++ stdenv.lib.optional (targetPlatform == hostPlatform && ! enableIntegerSimple) [ "--with-gmp-includes=${gmp.dev}/include" "--with-gmp-libraries=${gmp.out}/lib" - ] ++ stdenv.lib.optional (targetPlatform == hostPlatform && hostPlatform.libc != "glibc") [ + ] ++ stdenv.lib.optional (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [ "--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib" ] ++ stdenv.lib.optionals (targetPlatform != hostPlatform) [ "--enable-bootstrap-with-devel-snapshot" @@ -165,7 +172,11 @@ stdenv.mkDerivation rec { # zsh and other shells are smart about `{ghc}` but bash isn't, and doesn't # treat that as a unary `{x,y,z,..}` repetition. postInstall = '' - paxmark m $out/lib/${name}/bin/${if targetPlatform != hostPlatform then "ghc" else "{ghc,haddock}"} + for f in $out/lib/${name}/bin/${if targetPlatform != hostPlatform then "ghc" else "{ghc,haddock}"}; do + if [ -f $f ]; then + paxmark m $f + fi + done # Install the bash completion file. install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc diff --git a/pkgs/development/compilers/ghc/head.nix b/pkgs/development/compilers/ghc/head.nix index 7e1c73d166a23..d1739e0585cbc 100644 --- a/pkgs/development/compilers/ghc/head.nix +++ b/pkgs/development/compilers/ghc/head.nix @@ -15,16 +15,26 @@ , # If enabled, GHC will be built with the GPL-free but slower integer-simple # library instead of the faster but GPLed integer-gmp library. - enableIntegerSimple ? false, gmp ? null + enableIntegerSimple ? targetPlatform != hostPlatform, gmp ? null, m4 , # If enabled, use -fPIC when compiling static libs. enableRelocatedStaticLibs ? targetPlatform != hostPlatform , # Whether to build dynamic libs for the standard library (on the target # platform). Static libs are always built. - enableShared ? !targetPlatform.useAndroidPrebuilt + # + # We don't do this by default if target != host, or if we target windows. + enableShared ? (targetPlatform == hostPlatform && !targetPlatform.isWindows && !targetPlatform.useAndroidPrebuilt) + +, # Whetherto build terminfo. + enableTerminfo ? !targetPlatform.isWindows , version ? "8.5.20180118" +, ghcRevision ? "e1d4140be4d2a1508015093b69e1ef53516e1eb6" +, ghcSha256 ? "1gdcr10dd968d40qgljdwx9vfkva3yrvjm9a4nis7whaaac3ag58" +, ghcFlavour ? "" +, ghcCrossFlavour ? "perf-cross" +, ghcDiffs ? [] }: assert !enableIntegerSimple -> gmp != null; @@ -38,11 +48,14 @@ let "${targetPlatform.config}-"; buildMK = '' + BuildFlavour = ${if targetPlatform != hostPlatform then ghcCrossFlavour else ghcFlavour} + ifneq \"\$(BuildFlavour)\" \"\" + include mk/flavours/\$(BuildFlavour).mk + endif DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"} '' + stdenv.lib.optionalString enableIntegerSimple '' INTEGER_LIBRARY = integer-simple '' + stdenv.lib.optionalString (targetPlatform != hostPlatform) '' - BuildFlavour = perf-cross Stage1Only = YES HADDOCK_DOCS = NO BUILD_SPHINX_HTML = NO @@ -54,10 +67,11 @@ let EXTRA_CC_OPTS += -std=gnu99 ''; + # Splicer will pull out correct variations - libDeps = platform: [ ncurses ] + libDeps = platform: stdenv.lib.optional enableTerminfo [ ncurses ] ++ stdenv.lib.optional (!enableIntegerSimple) gmp - ++ stdenv.lib.optional (platform.libc != "glibc") libiconv; + ++ stdenv.lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv; toolsForTarget = if hostPlatform == buildPlatform then @@ -75,8 +89,8 @@ stdenv.mkDerivation rec { src = fetchgit { url = "git://git.haskell.org/ghc.git"; - rev = "e1d4140be4d2a1508015093b69e1ef53516e1eb6"; - sha256 = "1gdcr10dd968d40qgljdwx9vfkva3yrvjm9a4nis7whaaac3ag58"; + rev = "${ghcRevision}"; + sha256 = "${ghcSha256}"; }; enableParallelBuilding = true; @@ -123,7 +137,7 @@ stdenv.mkDerivation rec { "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib" ] ++ stdenv.lib.optional (targetPlatform == hostPlatform && ! enableIntegerSimple) [ "--with-gmp-includes=${gmp.dev}/include" "--with-gmp-libraries=${gmp.out}/lib" - ] ++ stdenv.lib.optional (targetPlatform == hostPlatform && hostPlatform.libc != "glibc") [ + ] ++ stdenv.lib.optional (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [ "--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib" ] ++ stdenv.lib.optionals (targetPlatform != hostPlatform) [ "--enable-bootstrap-with-devel-snapshot" @@ -141,7 +155,7 @@ stdenv.mkDerivation rec { # masss-rebuild. crossConfig = true; - nativeBuildInputs = [ ghc perl autoconf automake happy alex python3 ]; + nativeBuildInputs = [ ghc perl autoconf automake m4 happy alex python3 ]; # For building runtime libs depsBuildTarget = toolsForTarget; @@ -163,7 +177,11 @@ stdenv.mkDerivation rec { # zsh and other shells are smart about `{ghc}` but bash isn't, and doesn't # treat that as a unary `{x,y,z,..}` repetition. postInstall = '' - paxmark m $out/lib/${name}/bin/${if targetPlatform != hostPlatform then "ghc" else "{ghc,haddock}"} + for f in $out/lib/${name}/bin/${if targetPlatform != hostPlatform then "ghc" else "{ghc,haddock}"}; do + if [ -f $f ]; then + paxmark m $f + fi + done # Install the bash completion file. install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc diff --git a/pkgs/development/haskell-modules/configuration-ghc-head.nix b/pkgs/development/haskell-modules/configuration-ghc-head.nix index 99003102ec584..1fa4b6b2344fa 100644 --- a/pkgs/development/haskell-modules/configuration-ghc-head.nix +++ b/pkgs/development/haskell-modules/configuration-ghc-head.nix @@ -24,6 +24,8 @@ self: super: { ghc-prim = null; ghci = null; haskeline = null; + stm = null; + hoopl = null; hpc = null; integer-gmp = null; @@ -92,5 +94,6 @@ self: super: { test-framework = doJailbreak super.test-framework; atomic-primops = doJailbreak (appendPatch super.atomic-primops ./patches/atomic-primops-Cabal-1.25.patch); hashable = doJailbreak super.hashable; - stm = doJailbreak super.stm; +# haskeline = doJailbreak super.haskeline; +# stm = doJailbreak super.stm; } diff --git a/pkgs/development/haskell-modules/configuration-nix.nix b/pkgs/development/haskell-modules/configuration-nix.nix index 469b249010fa6..2f1eb1ad97a86 100644 --- a/pkgs/development/haskell-modules/configuration-nix.nix +++ b/pkgs/development/haskell-modules/configuration-nix.nix @@ -128,7 +128,7 @@ self: super: builtins.intersectAttrs super { # Prevents needing to add security_tool as a build tool to all of x509-system's # dependencies. - x509-system = if pkgs.stdenv.isDarwin && !pkgs.stdenv.cc.nativeLibc + x509-system = if pkgs.stdenv.targetPlatform.isDarwin && !pkgs.stdenv.cc.nativeLibc then let inherit (pkgs.darwin) security_tool; in pkgs.lib.overrideDerivation (addBuildDepend super.x509-system security_tool) (drv: { postPatch = (drv.postPatch or "") + '' diff --git a/pkgs/development/haskell-modules/generic-builder.nix b/pkgs/development/haskell-modules/generic-builder.nix index 3ab77c42cbbad..f00c0197af3b3 100644 --- a/pkgs/development/haskell-modules/generic-builder.nix +++ b/pkgs/development/haskell-modules/generic-builder.nix @@ -19,9 +19,11 @@ in , buildTarget ? "" , buildTools ? [], libraryToolDepends ? [], executableToolDepends ? [], testToolDepends ? [], benchmarkToolDepends ? [] , configureFlags ? [] +, buildFlags ? [] , description ? "" , doCheck ? !isCross && (stdenv.lib.versionOlder "7.4" ghc.version) , doBenchmark ? false +, doVerbose ? false , doHoogle ? true , editedCabalFile ? null , enableLibraryProfiling ? true @@ -126,13 +128,15 @@ let crossCabalFlagsString = stdenv.lib.optionalString isCross (" " + stdenv.lib.concatStringsSep " " crossCabalFlags); + buildFlagsString = optionalString (buildFlags != []) (" " + concatStringsSep " " buildFlags); + defaultConfigureFlags = [ - "--verbose" "--prefix=$out" "--libdir=\\$prefix/lib/\\$compiler" "--libsubdir=\\$pkgid" + "--verbose" "--prefix=$out" "--libdir=\\$prefix/\\$compiler" "--libsubdir=\\$pkgid" (optionalString enableSeparateDataOutput "--datadir=$data/share/${ghc.name}") (optionalString enableSeparateDocOutput "--docdir=${docdir "$doc"}") "--with-gcc=$CC" # Clang won't work without that extra information. "--package-db=$packageConfDir" - (optionalString (enableSharedExecutables && stdenv.isLinux) "--ghc-option=-optl=-Wl,-rpath=$out/lib/${ghc.name}/${pname}-${version}") + (optionalString (enableSharedExecutables && stdenv.isLinux) "--ghc-option=-optl=-Wl,-rpath=$out/${ghc.name}/${pname}-${version}") (optionalString (enableSharedExecutables && stdenv.isDarwin) "--ghc-option=-optl=-Wl,-headerpad_max_install_names") (optionalString enableParallelBuilding "--ghc-option=-j$NIX_BUILD_CORES") (optionalString useCpphs "--with-cpphs=${cpphs}/bin/cpphs --ghc-options=-cpp --ghc-options=-pgmP${cpphs}/bin/cpphs --ghc-options=-optP--cpp") @@ -142,7 +146,9 @@ let (enableFeature enableExecutableProfiling (if versionOlder ghc.version "8" then "executable-profiling" else "profiling")) (enableFeature enableSharedLibraries "shared") (optionalString (versionAtLeast ghc.version "7.10") (enableFeature doCoverage "coverage")) - (optionalString (versionOlder "8.4" ghc.version) (enableFeature enableStaticLibraries "static")) + # --enable-static does not work on windows. This is a bug in GHC. + # --enable-static will pass -staticlib to ghc, which only works for mach-o and elf. + (optionalString (!hostPlatform.isWindows && versionOlder "8.4" ghc.version) (enableFeature enableStaticLibraries "static")) (optionalString (isGhcjs || versionOlder "7.4" ghc.version) (enableFeature enableSharedExecutables "executable-dynamic")) (optionalString (isGhcjs || versionOlder "7" ghc.version) (enableFeature doCheck "tests")) "--enable-library-vanilla" # TODO: Should this be configurable? @@ -168,7 +174,8 @@ let allPkgconfigDepends = pkgconfigDepends ++ libraryPkgconfigDepends ++ executablePkgconfigDepends ++ optionals doCheck testPkgconfigDepends ++ optionals doBenchmark benchmarkPkgconfigDepends; - nativeBuildInputs = [ ghc nativeGhc removeReferencesTo ] ++ optional (allPkgconfigDepends != []) pkgconfig ++ + nativeBuildInputs = [ ghc removeReferencesTo ] ++ optional (!isCross && ghc != nativeGhc) nativeGhc + ++ optional (allPkgconfigDepends != []) pkgconfig ++ buildTools ++ libraryToolDepends ++ executableToolDepends; propagatedBuildInputs = buildDepends ++ libraryHaskellDepends ++ executableHaskellDepends; otherBuildInputs = setupHaskellDepends ++ extraLibraries ++ librarySystemDepends ++ executableSystemDepends ++ @@ -182,7 +189,21 @@ let ghcEnv = ghc.withPackages (p: haskellBuildInputs); - setupCommand = "./Setup"; + simpleSetup = buildHaskellPackages.setup {}; + configureSetup = buildHaskellPackages.setup { setupHs = '' + import Distribution.Simple + main = defaultMainWithHooks autoconfUserHooks +''; +}; + + setupCommand = if isCross then '' + if [ -f configure ]; then + HS_SETUP=${configureSetup} + else + HS_SETUP=${simpleSetup} + fi + $HS_SETUP/Setup'' + else "./Setup"; ghcCommand' = if isGhcjs then "ghcjs" else "ghc"; ghcCommand = "${ghc.targetPrefix}${ghcCommand'}"; @@ -203,7 +224,11 @@ stdenv.mkDerivation ({ pos = builtins.unsafeGetAttrPos "pname" args; prePhases = ["setupCompilerEnvironmentPhase"]; - preConfigurePhases = ["compileBuildDriverPhase"]; + + # when cross compiling, we only support Simple or Configure build-types. + # Custom build-types are silently ignored! Hence we use the Setup + # derivations and don't need the compileBuildDriverPhase. + preConfigurePhases = optionals (!isCross) ["compileBuildDriverPhase"]; preInstallPhases = ["haddockPhase"]; inherit src; @@ -224,7 +249,10 @@ stdenv.mkDerivation ({ ${jailbreak-cabal}/bin/jailbreak-cabal ${pname}.cabal '' + postPatch; - setupCompilerEnvironmentPhase = '' + setupCompilerEnvironmentPhase = + (optionalString doVerbose '' + # set -x + '') + '' runHook preSetupCompilerEnvironment echo "Build with ${ghc}." @@ -232,14 +260,20 @@ stdenv.mkDerivation ({ packageConfDir="$TMPDIR/package.conf.d" mkdir -p $packageConfDir - + '' + (optionalString (isCross && setupHaskellDepends != []) '' + setupPackageConfDir="$TMPDIR/setup-package.conf.d" + mkdir -p $setupPackageConfDir + '') + '' setupCompileFlags="${concatStringsSep " " setupCompileFlags}" configureFlags="${concatStringsSep " " defaultConfigureFlags} $configureFlags" # host.*Pkgs defined in stdenv/setup.hs for p in "''${pkgsHostHost[@]}" "''${pkgsHostTarget[@]}"; do - if [ -d "$p/lib/${ghc.name}/package.conf.d" ]; then - cp -f "$p/lib/${ghc.name}/package.conf.d/"*.conf $packageConfDir/ + ${optionalString doVerbose '' + echo $p + echo $p/${ghc.name}/package.conf.d + ''}if [ -d "$p/${ghc.name}/package.conf.d" ]; then + cp -f "$p/${ghc.name}/package.conf.d/"*.conf $packageConfDir/ continue fi if [ -d "$p/include" ]; then @@ -253,7 +287,7 @@ stdenv.mkDerivation ({ # only use the links hack if we're actually building dylibs. otherwise, the # "dynamic-library-dirs" point to nonexistent paths, and the ln command becomes # "ln -s $out/lib/links", which tries to recreate the links dir and fails - + (optionalString (stdenv.isDarwin && enableSharedLibraries) '' + + (optionalString (stdenv.isDarwin && (enableSharedLibraries || enableSharedExecutables)) '' # Work around a limit in the macOS Sierra linker on the number of paths # referenced by any one dynamic library: # @@ -282,7 +316,11 @@ stdenv.mkDerivation ({ done echo setupCompileFlags: $setupCompileFlags - ${nativeGhcCommand} $setupCompileFlags --make -o Setup -odir $TMPDIR -hidir $TMPDIR $i + ${optionalString (isCross && setupHaskellDepends != []) + '' + echo GHC_PACKAGE_PATH="$setupPackageConfDir:" + GHC_PACKAGE_PATH="$setupPackageConfDir:" '' + }${nativeGhcCommand} $setupCompileFlags --make -o Setup -odir $TMPDIR -hidir $TMPDIR $i${optionalString doVerbose " -v3"} runHook postCompileBuildDriver ''; @@ -310,7 +348,7 @@ stdenv.mkDerivation ({ buildPhase = '' runHook preBuild - ${setupCommand} build ${buildTarget}${crossCabalFlagsString} + ${setupCommand} build ${buildTarget}${crossCabalFlagsString}${buildFlagsString}${optionalString doVerbose ""} runHook postBuild ''; @@ -335,7 +373,7 @@ stdenv.mkDerivation ({ ${if !hasActiveLibrary then "${setupCommand} install" else '' ${setupCommand} copy - local packageConfDir="$out/lib/${ghc.name}/package.conf.d" + local packageConfDir="$out/${ghc.name}/package.conf.d" local packageConfFile="$packageConfDir/${pname}-${version}.conf" mkdir -p "$packageConfDir" ${setupCommand} register --gen-pkg-config=$packageConfFile @@ -360,7 +398,7 @@ stdenv.mkDerivation ({ ${optionalString doCoverage "mkdir -p $out/share && cp -r dist/hpc $out/share"} ${optionalString (enableSharedExecutables && isExecutable && !isGhcjs && stdenv.isDarwin && stdenv.lib.versionOlder ghc.version "7.10") '' for exe in "$out/bin/"* ; do - install_name_tool -add_rpath "$out/lib/ghc-${ghc.version}/${pname}-${version}" "$exe" + install_name_tool -add_rpath "$out/ghc-${ghc.version}/${pname}-${version}" "$exe" done ''} @@ -441,4 +479,5 @@ stdenv.mkDerivation ({ // optionalAttrs (dontStrip) { inherit dontStrip; } // optionalAttrs (hardeningDisable != []) { inherit hardeningDisable; } // optionalAttrs (buildPlatform.libc == "glibc"){ LOCALE_ARCHIVE = "${glibcLocales}/lib/locale/locale-archive"; } + // optionalAttrs doVerbose { NIX_DEBUG = 1; } ) diff --git a/pkgs/development/haskell-modules/lib.nix b/pkgs/development/haskell-modules/lib.nix index ff86e06979c1d..fedb0fa8de836 100644 --- a/pkgs/development/haskell-modules/lib.nix +++ b/pkgs/development/haskell-modules/lib.nix @@ -131,6 +131,8 @@ rec { */ appendConfigureFlag = drv: x: overrideCabal drv (drv: { configureFlags = (drv.configureFlags or []) ++ [x]; }); + appendBuildFlag = drv: x: overrideCabal drv (drv: { buildFlags = (drv.buildFlags or []) ++ [x]; }); + appendBuildFlags = drv: xs: overrideCabal drv (drv: { buildFlags = (drv.buildFlags or []) ++ xs; }); /* removeConfigureFlag drv x is a Haskell package like drv, but with all cabal configure arguments that are equal to x removed. diff --git a/pkgs/development/haskell-modules/make-package-set.nix b/pkgs/development/haskell-modules/make-package-set.nix index bde4f85f67846..1d5d57767a8a7 100644 --- a/pkgs/development/haskell-modules/make-package-set.nix +++ b/pkgs/development/haskell-modules/make-package-set.nix @@ -40,6 +40,11 @@ let inherit (stdenv.lib) fix' extends makeOverridable; inherit (haskellLib) overrideCabal; + setupImpl = pkgs.callPackage ./setup.nix { + inherit stdenv; + inherit (self) ghc; + }; + mkDerivationImpl = pkgs.callPackage ./generic-builder.nix { inherit stdenv; nodejs = buildPackages.nodejs-slim; @@ -66,6 +71,8 @@ let }; mkDerivation = makeOverridable mkDerivationImpl; + setup = makeOverridable setupImpl; + # manualArgs are the arguments that were explictly passed to `callPackage`, like: # @@ -151,7 +158,7 @@ let in package-set { inherit pkgs stdenv callPackage; } self // { - inherit mkDerivation callPackage haskellSrc2nix hackage2nix; + inherit mkDerivation setup callPackage haskellSrc2nix hackage2nix; inherit (haskellLib) packageSourceOverrides; diff --git a/pkgs/development/haskell-modules/setup.nix b/pkgs/development/haskell-modules/setup.nix new file mode 100644 index 0000000000000..ec7cf17acf0a1 --- /dev/null +++ b/pkgs/development/haskell-modules/setup.nix @@ -0,0 +1,42 @@ +# This is the generic `Setup` installer for haskell packages. +# +# For now we just build the `Setup.hs` against the +{ stdenv, ghc, lib }: +{ setupHaskellDepends ? [] +, setupHs ? '' + import Distribution.Simple + main = defaultMain +'' +} @ args: +stdenv.mkDerivation (rec { + name = "Setup"; + + phases = [ "buildPhase" ]; + + buildInputs = [ ghc ] ++ setupHaskellDepends; + LANG = "en_US.UTF-8"; + + # build up the package database, with the additional dependencies + preBuild = '' + setupPackageConfDir="$TMPDIR/setup-package.conf.d" + mkdir -p "$setupPackageConfDir" + + # Add the setupHaskellDepends to a custom package-db, + # which ghc will be provided with. + + for p in ${lib.escapeShellArgs setupHaskellDepends}; do + if [ -d "$p/lib/${ghc.name}/package.conf.d" ]; then + cp -f "$p/lib/${ghc.name}/package.conf.d/"*.conf $setupPackageConfDir/ + fi + done + ${ghc.targetPrefix}ghc-pkg --package-db="$setupPackageConfDir" recache + ''; + + buildPhase = '' + runHook preBuild + echo "$setupPackageConfDir" + mkdir -p $out + GHC_PACKAGE_PATH="$setupPackageConfDir:" ghc --make -o $out/Setup -odir $TMPDIR -hidir $TMPDIR ${builtins.toFile "Setup.hs" setupHs} + runHook postBuild + ''; +}) diff --git a/pkgs/development/interpreters/python/cpython/2.7/default.nix b/pkgs/development/interpreters/python/cpython/2.7/default.nix index 98e5b4b1da0e7..7f116e3230cb9 100644 --- a/pkgs/development/interpreters/python/cpython/2.7/default.nix +++ b/pkgs/development/interpreters/python/cpython/2.7/default.nix @@ -153,7 +153,7 @@ let ++ optional hostPlatform.isCygwin expat ++ [ db gdbm ncurses sqlite readline ] ++ optionals x11Support [ tcl tk xlibsWrapper libX11 ] - ++ optionals stdenv.isDarwin ([ CF ] ++ optional (configd != null) configd); + ++ optionals hostPlatform.isDarwin ([ CF ] ++ optional (configd != null) configd); nativeBuildInputs = optionals (hostPlatform != buildPlatform) [ buildPackages.stdenv.cc buildPackages.python ]; diff --git a/pkgs/development/libraries/gmp/6.x.nix b/pkgs/development/libraries/gmp/6.x.nix index 551e7e5e1f6b9..1cac1a45b1344 100644 --- a/pkgs/development/libraries/gmp/6.x.nix +++ b/pkgs/development/libraries/gmp/6.x.nix @@ -1,10 +1,11 @@ { stdenv, fetchurl, m4, cxx ? true +, targetPlatform , buildPackages , withStatic ? false }: let inherit (stdenv.lib) optional optionalString; in -let self = stdenv.mkDerivation rec { +let self = stdenv.mkDerivation (rec { name = "gmp-6.1.2"; src = fetchurl { # we need to use bz2, others aren't in bootstrapping stdenv @@ -78,5 +79,15 @@ let self = stdenv.mkDerivation rec { platforms = platforms.all; maintainers = [ maintainers.peti maintainers.vrthra ]; }; -}; +} // stdenv.lib.optionalAttrs targetPlatform.isWindows { + # NOTE: can not use stdenv.cc.isGNU / isClang, as that results in + # an infinite recursion at the gmp = gmp6 line in all-packages. + # + # do *not* pass CXXSTDLIB when cc is not clang, gcc doesn't understand + # -stdlib=libc++. If the buildPackages compiler is clang, we will + # inject this, and certainly do not want it for the cc compiler. + preConfigure = '' + export NIX_CXXSTDLIB_LINK="" + ''; +}); in self diff --git a/pkgs/development/libraries/libyaml/default.nix b/pkgs/development/libraries/libyaml/default.nix index e441d1e6b6150..20053190e3bc9 100644 --- a/pkgs/development/libraries/libyaml/default.nix +++ b/pkgs/development/libraries/libyaml/default.nix @@ -14,7 +14,7 @@ stdenv.mkDerivation { homepage = http://pyyaml.org/; description = "A YAML 1.1 parser and emitter written in C"; license = licenses.mit; - platforms = platforms.unix; + platforms = platforms.all; maintainers = with maintainers; [ wkennington ]; }; } diff --git a/pkgs/development/libraries/openssl/default.nix b/pkgs/development/libraries/openssl/default.nix index 1eac225387d21..a12f95f61ca5f 100644 --- a/pkgs/development/libraries/openssl/default.nix +++ b/pkgs/development/libraries/openssl/default.nix @@ -76,7 +76,11 @@ let # Parallel building is broken in OpenSSL. enableParallelBuilding = false; - postInstall = '' + postInstall = (stdenv.lib.optionalString hostPlatform.isWindows '' + echo $out/* + echo $out/lib/* + echo $out/bin/* + '') + '' # If we're building dynamic libraries, then don't install static # libraries. if [ -n "$(echo $out/lib/*.so $out/lib/*.dylib $out/lib/*.dll)" ]; then @@ -93,6 +97,8 @@ let rm -r $out/etc/ssl/misc rmdir $out/etc/ssl/{certs,private} + '' + stdenv.lib.optionalString hostPlatform.isWindows '' + cp $bin/bin/*.dll $out/lib/ ''; postFixup = '' diff --git a/pkgs/development/libraries/rocksdb/default.nix b/pkgs/development/libraries/rocksdb/default.nix index bb36d942a69b8..3043a91a7dc1e 100644 --- a/pkgs/development/libraries/rocksdb/default.nix +++ b/pkgs/development/libraries/rocksdb/default.nix @@ -1,7 +1,8 @@ { stdenv , fetchFromGitHub , fixDarwinDylibNames -, which, perl +, hostPlatform, lib +, which, perl, cmake # Optional Arguments , snappy ? null, google-gflags ? null, zlib ? null, bzip2 ? null, lz4 ? null @@ -11,6 +12,7 @@ , jemalloc ? null, gperftools ? null , enableLite ? false +, windows }: let @@ -21,7 +23,7 @@ stdenv.mkDerivation rec { name = "rocksdb-${version}"; version = "5.11.3"; - outputs = [ "dev" "out" "static" "bin" ]; +# outputs = [ "dev" "out" "static" "bin" ]; src = fetchFromGitHub { owner = "facebook"; @@ -30,50 +32,85 @@ stdenv.mkDerivation rec { sha256 = "15x2r7aib1xinwcchl32wghs8g96k4q5xgv6z97mxgp35475x01p"; }; - nativeBuildInputs = [ which perl ]; - buildInputs = [ snappy google-gflags zlib bzip2 lz4 malloc fixDarwinDylibNames ]; + nativeBuildInputs = [ which perl snappy google-gflags ]; + buildInputs = [ zlib bzip2 malloc fixDarwinDylibNames ] # lz4 ]; + ++ lib.optional (hostPlatform.libc == "msvcrt") [ windows.mingw_w64_pthreads windows.mingw_w64_headers ]; + crossAttrs = { + nativeBuildInputs = [ which perl snappy google-gflags cmake ]; + }; - postPatch = '' - # Hack to fix typos - sed -i 's,#inlcude,#include,g' build_tools/build_detect_platform +# cmakeFlags = "-DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ "; + cmakeFlags = "-DJNI=0 -DWITH_GFLAGS=0 -DCMAKE_SYSTEM_NAME=Windows"; + buildFlags = "rocksdb-shared rocksdb"; + +# preInstall = '' +# mv librocksdb.a .. +# cd .. +# ''; + + installPhase = '' + install -d $out/lib + cd .. + for header_dir in `find "include/rocksdb" -type d`; do \ + install -d $out/$header_dir; \ + done + for header in `find "include/rocksdb" -type f -name "*.h"`; do \ + install -C -m 644 $header $out/$header; \ + done + cd build + for lib in `find . -type f -name "*rocksdb*.a"`; do \ + install -C -m 755 $lib $out/lib + done + for lib in `find . -type f -name "*rocksdb*.dll"`; do \ + install -C -m 755 $lib $out/lib + done ''; - # Environment vars used for building certain configurations + NIX_CFLAGS_COMPILE = [ "-Wno-unused-but-set-variable" "-D_POSIX_C_SOURCE" "-static-libstdc++" ]; + + # postPatch = '' + # # Hack to fix typos + # sed -i 's,#inlcude,#include,g' build_tools/build_detect_platform + # ''; + hardeningDisable = [ "format" "stackprotector" ]; + # # Environment vars used for building certain configurations PORTABLE = "1"; USE_SSE = "1"; - CMAKE_CXX_FLAGS = "-std=gnu++11"; - JEMALLOC_LIB = stdenv.lib.optionalString (malloc == jemalloc) "-ljemalloc"; - - LIBNAME = "librocksdb${stdenv.lib.optionalString enableLite "_lite"}"; - ${if enableLite then "CXXFLAGS" else null} = "-DROCKSDB_LITE=1"; - - buildAndInstallFlags = [ - "USE_RTTI=1" - "DEBUG_LEVEL=0" - "DISABLE_WARNING_AS_ERROR=1" - ]; - - buildFlags = buildAndInstallFlags ++ [ - "shared_lib" - "static_lib" - ] ++ tools ; - - installFlags = buildAndInstallFlags ++ [ - "INSTALL_PATH=\${out}" - "install-shared" - "install-static" - ]; - - postInstall = '' - # Might eventually remove this when we are confident in the build process - echo "BUILD CONFIGURATION FOR SANITY CHECKING" - cat make_config.mk - mkdir -pv $static/lib/ - mv -vi $out/lib/${LIBNAME}.a $static/lib/ - - install -d ''${!outputBin}/bin - install -D ${stdenv.lib.concatStringsSep " " tools} ''${!outputBin}/bin - ''; +# CMAKE_CXX_FLAGS = "-static-libstdc++"; +# CXXFLAGS = "-static-libstdc++"; + #CMAKE_CXX_FLAGS = "-std=c++11 -pthread -pthreads"; + # JEMALLOC_LIB = stdenv.lib.optionalString (malloc == jemalloc) "-ljemalloc"; + + # LIBNAME = "librocksdb${stdenv.lib.optionalString enableLite "_lite"}"; + # ${if enableLite then "CXXFLAGS" else null} = "-DROCKSDB_LITE=1"; + + # buildAndInstallFlags = [ + # "USE_RTTI=1" + # "DEBUG_LEVEL=0" + # "DISABLE_WARNING_AS_ERROR=1" + # ]; + + # buildFlags = buildAndInstallFlags ++ [ + # "shared_lib" + # "static_lib" + # ] ++ tools ; + +# installFlags = [ +# "INSTALL_PATH=\${out}" +# "install-shared" +# "install-headers" +# ]; + + # postInstall = '' + # # Might eventually remove this when we are confident in the build process + # echo "BUILD CONFIGURATION FOR SANITY CHECKING" + # cat make_config.mk + # mkdir -pv $static/lib/ + # mv -vi $out/lib/${LIBNAME}.a $static/lib/ + + # install -d ''${!outputBin}/bin + # install -D ${stdenv.lib.concatStringsSep " " tools} ''${!outputBin}/bin + # ''; enableParallelBuilding = true; diff --git a/pkgs/misc/emulators/wine/base.nix b/pkgs/misc/emulators/wine/base.nix index e064609941500..f5d1dee770a17 100644 --- a/pkgs/misc/emulators/wine/base.nix +++ b/pkgs/misc/emulators/wine/base.nix @@ -6,7 +6,8 @@ buildScript ? null, configureFlags ? "" }: -assert stdenv.cc.cc.isGNU or false; +assert stdenv.isLinux || stdenv.isDarwin; +# assert stdenv.cc.cc.isGNU or false; with import ./util.nix { inherit lib; }; @@ -54,9 +55,14 @@ stdenv.mkDerivation ((lib.optionalAttrs (! isNull buildScript) { ++ lib.optionals xmlSupport [ pkgs.libxml2 pkgs.libxslt ] ++ lib.optionals tlsSupport [ pkgs.openssl pkgs.gnutls ] ++ lib.optionals openglSupport [ pkgs.libGLU_combined pkgs.mesa_noglu.osmesa pkgs.libdrm ] - ++ (with pkgs.xorg; [ - libX11 libXi libXcursor libXrandr libXrender libXxf86vm libXcomposite libXext - ]))); + ++ lib.optionals stdenv.isDarwin (with pkgs.buildPackages.darwin.apple_sdk.frameworks; [ + CoreServices Foundation ForceFeedback AppKit OpenGL IOKit DiskArbitration Security + ApplicationServices AudioToolbox CoreAudio AudioUnit CoreMIDI OpenAL OpenCL Cocoa Carbon + ]) + ++ lib.optionals stdenv.isLinux (with pkgs.xorg; [ + libXi libXcursor libXrandr libXrender libXxf86vm libXcomposite libXext + ]) + ++ [ pkgs.xorg.libX11 ])); # Wine locates a lot of libraries dynamically through dlopen(). Add # them to the RPATH so that the user doesn't have to set them in @@ -115,4 +121,6 @@ stdenv.mkDerivation ((lib.optionalAttrs (! isNull buildScript) { description = "An Open Source implementation of the Windows API on top of X, OpenGL, and Unix"; maintainers = with stdenv.lib.maintainers; [ avnik raskin bendlas ]; }; -}) + } // lib.optionalAttrs stdenv.isDarwin { + hardeningDisable = [ "fortify" ]; + }) diff --git a/pkgs/misc/emulators/wine/packages.nix b/pkgs/misc/emulators/wine/packages.nix index a786babc79de9..d2305aa37ba6b 100644 --- a/pkgs/misc/emulators/wine/packages.nix +++ b/pkgs/misc/emulators/wine/packages.nix @@ -20,7 +20,7 @@ in with src; { geckos = [ gecko64 ]; monos = [ mono ]; configureFlags = [ "--enable-win64" ]; - platforms = [ "x86_64-linux" ]; + platforms = [ "x86_64-linux" "x86_64-darwin" ]; }; wineWow = callPackage ./base.nix { name = "wine-wow-${version}"; diff --git a/pkgs/os-specific/darwin/cctools/port.nix b/pkgs/os-specific/darwin/cctools/port.nix index d8abdc2c6f843..4637a74187cf5 100644 --- a/pkgs/os-specific/darwin/cctools/port.nix +++ b/pkgs/os-specific/darwin/cctools/port.nix @@ -21,6 +21,8 @@ let "${targetPlatform.config}-"; in +assert targetPlatform.isDarwin; + # Non-Darwin alternatives assert (!hostPlatform.isDarwin) -> (maloader != null && xctoolchain != null); diff --git a/pkgs/os-specific/windows/mingw-w64/common.nix b/pkgs/os-specific/windows/mingw-w64/common.nix index 102d9489fe9ff..6a9d714da88e8 100644 --- a/pkgs/os-specific/windows/mingw-w64/common.nix +++ b/pkgs/os-specific/windows/mingw-w64/common.nix @@ -1,3 +1,22 @@ +# The Mingw-w64 toolchain +# ======================= +# +# The mingw-w64 toolchain provides whas is essentially the msvcrt (libc for windows). +# It comes in the following components: +# - headers. These proivde the basic headers needed to build against the msvcrt. +# - msvcrt. The libc itself (headers + lirbary) +# - winpthreads. A pthreads implementation for windows. This is notably required +# to allow GCC to use the posix thread-model, which is an essential requirement +# for c++11 support in GCC. +# +# Installation instructions can be found at +# https://sourceforge.net/p/mingw-w64/wiki2/Cross%20Win32%20and%20Win64%20compiler/ +# +# Note: while the installation instruction explicitly state that we need to place +# the headers and crt into as of v3. This does not seem to be acurate +# anymore. As nix CC wrapper picks up the ~include~ folder from ~$out~, we will +# use just ~$out~ instead of ~$out/x86_64-w64-mingw~. +# { fetchurl }: rec { @@ -5,12 +24,7 @@ rec { name = "mingw-w64-${version}"; src = fetchurl { - url = "mirror://sourceforge/mingw-w64/mingw-w64-v${version}.tar.bz2"; + url = "http://cfhcable.dl.sourceforge.net/project/mingw-w64/mingw-w64/mingw-w64-release/mingw-w64-v${version}.tar.bz2"; sha256 = "1d4wrjfdlq5xqpv9zg6ssw4lm8jnv6522xf7d6zbjygmkswisq1a"; }; - - configureFlags = [ - "--enable-idl" - "--enable-secure-api" - ]; } diff --git a/pkgs/os-specific/windows/mingw-w64/default.nix b/pkgs/os-specific/windows/mingw-w64/default.nix index 53050435256fb..234a6899ad279 100644 --- a/pkgs/os-specific/windows/mingw-w64/default.nix +++ b/pkgs/os-specific/windows/mingw-w64/default.nix @@ -1,8 +1,21 @@ -{ stdenv, callPackage, windows }: +{ stdenv, callPackage, targetPlatform, windows }: +with stdenv.lib; +let inherit (callPackage ./common.nix {}) name src; +in stdenv.mkDerivation { + + name = name + "-msvcrt"; + inherit src; -stdenv.mkDerivation { - inherit (callPackage ./common.nix {}) name src; buildInputs = [ windows.mingw_w64_headers ]; + dontStrip = true; hardeningDisable = [ "stackprotector" "fortify" ]; + + preConfigure = '' + cd mingw-w64-crt + ''; + + postInstall = '' + ln -s ${windows.mingw_w64_headers} $out/mingw + ''; } diff --git a/pkgs/os-specific/windows/mingw-w64/headers.nix b/pkgs/os-specific/windows/mingw-w64/headers.nix index 03dbf712e2e51..76f7973a17491 100644 --- a/pkgs/os-specific/windows/mingw-w64/headers.nix +++ b/pkgs/os-specific/windows/mingw-w64/headers.nix @@ -1,13 +1,19 @@ -{ stdenvNoCC, callPackage }: +{ stdenvNoCC, callPackage, hostPlatform, targetPlatform }: let inherit (callPackage ./common.nix {}) name src; in stdenvNoCC.mkDerivation { - name = name + "-headers"; + name = name + "-headers" + stdenvNoCC.lib.optionalString (targetPlatform != hostPlatform) "-${targetPlatform.config}"; inherit src; preConfigure = '' cd mingw-w64-headers ''; + + configureFlags = [ + "--enable-idl" + "--enable-secure-api" + # "--with-default-win32-winnt=0x600" + ]; } diff --git a/pkgs/os-specific/windows/mingw-w64/pthreads.nix b/pkgs/os-specific/windows/mingw-w64/pthreads.nix index 1a33e8db07e81..02471b107f32b 100644 --- a/pkgs/os-specific/windows/mingw-w64/pthreads.nix +++ b/pkgs/os-specific/windows/mingw-w64/pthreads.nix @@ -1,13 +1,15 @@ -{ stdenv, callPackage }: - -let - inherit (callPackage ./common.nix {}) name src; - +{ stdenv, callPackage, windows }: +with stdenv.lib; +let inherit (callPackage ./common.nix {}) name src; in stdenv.mkDerivation { name = name + "-pthreads"; inherit src; + buildInputs = [ windows.mingw_w64_headers windows.mingw_w64 ]; + preConfigure = '' cd mingw-w64-libraries/winpthreads ''; + + hardeningDisable = [ "stackprotector" ]; } diff --git a/pkgs/os-specific/windows/pthread-w32/default.nix b/pkgs/os-specific/windows/pthread-w32/default.nix index ef42dadc2973a..1813afad3be63 100644 --- a/pkgs/os-specific/windows/pthread-w32/default.nix +++ b/pkgs/os-specific/windows/pthread-w32/default.nix @@ -1,7 +1,7 @@ { fetchurl, stdenv, mingw_header, hostPlatform, buildPlatform }: # This file is tweaked for cross-compilation only. -assert hostPlatform != buildPlatform; +assert stdenv.hostPlatform != stdenv.buildPlatform; stdenv.mkDerivation { name = "pthread-w32-1.10.0"; diff --git a/pkgs/tools/compression/lz4/default.nix b/pkgs/tools/compression/lz4/default.nix index 04c83fa03fcf9..19c54de876ca7 100644 --- a/pkgs/tools/compression/lz4/default.nix +++ b/pkgs/tools/compression/lz4/default.nix @@ -22,7 +22,7 @@ stdenv.mkDerivation rec { doCheck = false; # tests take a very long time checkTarget = "test"; - patches = [ ./install-on-freebsd.patch ] ; + patches = [ ./install-on-freebsd.patch ./windows.patch ] ; postInstall = "rm $out/lib/*.a"; diff --git a/pkgs/tools/compression/lz4/windows.patch b/pkgs/tools/compression/lz4/windows.patch new file mode 100644 index 0000000000000..8d67ded90766b --- /dev/null +++ b/pkgs/tools/compression/lz4/windows.patch @@ -0,0 +1,12 @@ +diff -u -r source-orig/programs/lz4io.c source/programs/lz4io.c +--- source-orig/programs/lz4io.c 2018-05-09 03:06:04.447422696 -0300 ++++ source/programs/lz4io.c 2018-05-09 03:06:21.383557382 -0300 +@@ -66,7 +66,7 @@ + # include /* _setmode, _fileno, _get_osfhandle */ + # if !defined(__DJGPP__) + # define SET_BINARY_MODE(file) { int unused=_setmode(_fileno(file), _O_BINARY); (void)unused; } +-# include /* DeviceIoControl, HANDLE, FSCTL_SET_SPARSE */ ++# include /* DeviceIoControl, HANDLE, FSCTL_SET_SPARSE */ + # define SET_SPARSE_FILE_MODE(file) { DWORD dw; DeviceIoControl((HANDLE) _get_osfhandle(_fileno(file)), FSCTL_SET_SPARSE, 0, 0, 0, 0, &dw, 0); } + # if defined(_MSC_VER) && (_MSC_VER >= 1400) /* Avoid MSVC fseek()'s 2GiB barrier */ + # define fseek _fseeki64 diff --git a/pkgs/tools/package-management/nix-prefetch-scripts/default.nix b/pkgs/tools/package-management/nix-prefetch-scripts/default.nix index a2ff38ab3004e..f63640d683db7 100644 --- a/pkgs/tools/package-management/nix-prefetch-scripts/default.nix +++ b/pkgs/tools/package-management/nix-prefetch-scripts/default.nix @@ -2,6 +2,13 @@ git, subversion, mercurial, bazaar, cvs, unzip, curl, gnused, coreutils, nix }: +# these scripts should only be run on the build machine +# and as such the target and host for these scripts should +# be identical. +assert stdenv.targetPlatform == stdenv.hostPlatform; +# these scripts are also only supported on Linux and Darwin +assert stdenv.targetPlatform.isUnix; + let mkPrefetchScript = tool: src: deps: stdenv.mkDerivation { name = "nix-prefetch-${tool}"; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 66bdda119d0be..d9953cf93013e 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -940,8 +940,8 @@ with pkgs; install -D $out/bin/${drv.pname} $exe rm -rf $out/{bin,lib,share} makeWrapper $exe $out/bin/${drv.pname} \ - --prefix PATH ":" "${nix}/bin" \ - --prefix PATH ":" "${nix-prefetch-scripts}/bin" + --prefix PATH ":" "${buildPackages.nix}/bin" \ + --prefix PATH ":" "${buildPackages.nix-prefetch-scripts}/bin" mkdir -p $out/share/{bash-completion/completions,zsh/vendor-completions,fish/completions} $exe --bash-completion-script $exe >$out/share/bash-completion/completions/${drv.pname} $exe --zsh-completion-script $exe >$out/share/zsh/vendor-completions/_${drv.pname} @@ -6092,7 +6092,7 @@ with pkgs; gerbil-unstable = callPackage ../development/compilers/gerbil/unstable.nix { }; gccFun = callPackage ../development/compilers/gcc/7; - gcc = gcc7; + gcc = gcc7-ng; gcc-unwrapped = gcc.cc; gccStdenv = if stdenv.cc.isGNU then stdenv else stdenv.override { @@ -6160,7 +6160,17 @@ with pkgs; crossLibcStdenv = buildPackages.makeStdenvCross { inherit (buildPackages.buildPackages) stdenv; inherit buildPlatform hostPlatform targetPlatform; - cc = buildPackages.gccCrossStageStatic; + cc = buildPackages.gcc7-ng;#-msvcrt; #gccCrossStageStatic; + }; + crossLibcStdenvNoLibgcc = buildPackages.makeStdenvCross { + inherit (buildPackages.buildPackages) stdenv; + inherit buildPlatform hostPlatform targetPlatform; + cc = buildPackages.gcc7-ng-msvcrt;#-msvcrt; #gccCrossStageStatic; + }; + crossLibcStdenvNolibc = buildPackages.makeStdenvCross { + inherit (buildPackages.buildPackages) stdenv; + inherit buildPlatform hostPlatform targetPlatform; + cc = buildPackages.gcc7-ng-nolibc; #gccCrossStageStatic; }; # The GCC used to build libc for the target platform. Normal gccs will be @@ -6262,6 +6272,89 @@ with pkgs; isl = if !stdenv.isDarwin then isl_0_17 else null; })); + # the idea is the following: + # - build binutils with the build-cc, and build-libc + # - prebuild gcc with the build-cc, and build-libc + # == Now we have a gcc that targets the target + # - install gcc from the prebuilt-gcc. + # - build libc (msvcrt) with the gcc we just built + # - link the mingw-headers into a mingw symlink + # into the msvcrt result. + # == Now we also have a libc that targets the target. + # - using the msvcrt we just built, set --sysroot + # and build winpthreads + # - finish building the rest of gcc. (libgcc, ...) + + # Dependencies: + # + # + # gcc7 + # - gcc7-ng-msvcrt + # - mingw_w64 + # - mingw_w64_headers + # - gcc7-ng-libgcc + # - bintools + # - mingw_w64 + # - mingw_w64_pthreads + + gcc7-ng-prebuilt = + let libc = targetPackages.windows.mingw_w64_headers; + bintools = wrapBintoolsWith { bintools = binutils-unwrapped; libc = libc; }; + in callPackage ../development/compilers/gcc/7/default-ng-prebuilt.nix { binutils = bintools; }; + + gcc7-ng-nolibc = + let libc = targetPackages.windows.mingw_w64_headers; + bintools = wrapBintoolsWith { bintools = binutils-unwrapped; libc = libc; }; + in wrapCCWith { + cc = callPackage ../development/compilers/gcc/7/default-ng.nix { gcc-prebuilt = gcc7-ng-prebuilt; component = "gcc"; }; + libc = libc; + bintools = bintools; + }; + + gcc7-ng-msvcrt = + let libc = targetPackages.windows.mingw_w64; + bintools = wrapBintoolsWith { bintools = binutils-unwrapped; libc = libc; }; + in wrapCCWith { + extraPackages = [ libc targetPackages.windows.mingw_w64_headers ]; + cc = callPackage ../development/compilers/gcc/7/default-ng.nix { gcc-prebuilt = gcc7-ng-prebuilt; component = "gcc"; }; + libc = libc; + bintools = bintools; + }; + + gcc7-ng = + let libc = targetPackages.windows.mingw_w64; + bintools = wrapBintoolsWith { bintools = binutils-unwrapped; libc = libc; }; + in wrapCCWith { + extraPackages = [ targetPackages.gcc7-ng-libgcc targetPackages.gcc7-ng-libssp targetPackages.gcc7-ng-libstdcpp-v3 + libc targetPackages.windows.mingw_w64_headers targetPackages.windows.mingw_w64_pthreads + ]; + cc = callPackage ../development/compilers/gcc/7/default-ng.nix { gcc-prebuilt = gcc7-ng-prebuilt; component = "gcc"; }; + libc = libc; + bintools = bintools; + }; + + # this is a rather convoluted setup to achive the following: + # still use the build machiens CC, yet build a target library. + gcc7-ng-libgcc = callPackage ../development/compilers/gcc/7/default-ng.nix { gcc-prebuilt = buildPackages.gcc7-ng-prebuilt; component = "target-libgcc"; + stdenv = buildPackages.stdenv; + extraBuildInputs = [ windows.mingw_w64 buildPackages.binutils-unwrapped windows.mingw_w64_pthreads ]; + inherit (buildPackages) gmp mpfr libmpc; + }; + + # this is a rather convoluted setup to achive the following: + # still use the build machiens CC, yet build a target library. + gcc7-ng-libssp = callPackage ../development/compilers/gcc/7/default-ng.nix { gcc-prebuilt = buildPackages.gcc7-ng-prebuilt; component = "target-libssp"; + stdenv = buildPackages.stdenv; + extraBuildInputs = [ windows.mingw_w64 buildPackages.binutils-unwrapped windows.mingw_w64_pthreads ]; + inherit (buildPackages) gmp mpfr libmpc; + }; + + gcc7-ng-libstdcpp-v3 = callPackage ../development/compilers/gcc/7/default-ng.nix { gcc-prebuilt = buildPackages.gcc7-ng-prebuilt; component = "target-libstdc++-v3"; + stdenv = buildPackages.stdenv; + extraBuildInputs = [ windows.mingw_w64 buildPackages.binutils-unwrapped windows.mingw_w64_pthreads ]; + inherit (buildPackages) gmp mpfr libmpc; + }; + gcc8 = lowPrio (wrapCC (callPackage ../development/compilers/gcc/8 { inherit noSysDirs; @@ -6275,7 +6368,7 @@ with pkgs; gcc-snapshot = lowPrio (wrapCC (callPackage ../development/compilers/gcc/snapshot { inherit noSysDirs; - + # PGO seems to speed up compilation by gcc by ~10%, see #445 discussion profiledCompiler = with stdenv; (!isDarwin && (isi686 || isx86_64)); @@ -6976,7 +7069,7 @@ with pkgs; wla-dx = callPackage ../development/compilers/wla-dx { }; - wrapCCWith = { name ? "", cc, bintools, libc, extraBuildCommands ? "" }: + wrapCCWith = { name ? "", cc, bintools, libc, extraBuildCommands ? "", extraPackages ? [] }: ccWrapperFun rec { nativeTools = targetPlatform == hostPlatform && stdenv.cc.nativeTools or false; nativeLibc = targetPlatform == hostPlatform && stdenv.cc.nativeLibc or false; @@ -6986,7 +7079,7 @@ with pkgs; isGNU = cc.isGNU or false; isClang = cc.isClang or false; - inherit name cc bintools libc extraBuildCommands; + inherit name cc bintools libc extraBuildCommands extraPackages; }; ccWrapperFun = callPackage ../build-support/cc-wrapper; @@ -7294,7 +7387,7 @@ with pkgs; python27 = callPackage ../development/interpreters/python/cpython/2.7 { self = python27; - inherit (darwin) CF configd; + inherit (buildPackages.darwin) CF configd; }; python34 = callPackage ../development/interpreters/python/cpython/3.4 { inherit (darwin) CF configd; @@ -10489,7 +10582,7 @@ with pkgs; else callPackage ../development/libraries/libunwind { }; libuv = callPackage ../development/libraries/libuv { - inherit (darwin.apple_sdk.frameworks) ApplicationServices CoreServices; + inherit (buildPackages.darwin.apple_sdk.frameworks) ApplicationServices CoreServices; }; libv4l = lowPrio (v4l_utils.override { @@ -14227,12 +14320,14 @@ with pkgs; }; mingw_w64 = callPackage ../os-specific/windows/mingw-w64 { - stdenv = crossLibcStdenv; + stdenv = crossLibcStdenvNolibc; }; mingw_w64_headers = callPackage ../os-specific/windows/mingw-w64/headers.nix { }; - mingw_w64_pthreads = callPackage ../os-specific/windows/mingw-w64/pthreads.nix { }; + mingw_w64_pthreads = callPackage ../os-specific/windows/mingw-w64/pthreads.nix { + stdenv = crossLibcStdenvNoLibgcc; + }; pthreads = callPackage ../os-specific/windows/pthread-w32 { mingw_headers = mingw_headers3;