Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] mingw-w64 for haskell cross compilation with ghc. #37254

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
86ca043
check if stdenv isDarwin, not if targetPlatform isDarwin
angerman Feb 27, 2018
6bed1f6
Drop targetPlatform == hostPlatform assert
angerman Feb 27, 2018
9919e6a
use custom package database
angerman Mar 1, 2018
df2bbe0
parameterize buildMK; allow ghcFlavour to be overridden.
angerman Mar 1, 2018
9351258
Hardcode the sourceforge mirror, while sourceforge is down.
angerman Mar 3, 2018
bd294f2
Fix /bin/haddock not found.
angerman Mar 5, 2018
8ab98a0
import m4
angerman Mar 5, 2018
8b8a238
Adds `doVerbose` to the generic haskell builder
angerman Mar 11, 2018
5ddaf0c
Doe the `links` dance only if shared is enabled.
angerman Mar 17, 2018
91db81c
Adds buildFlags logic
angerman Mar 17, 2018
be83b84
cleanup
angerman Mar 19, 2018
7fd694a
Revert "[cctools] check if stdenv isDarwin, not if targetPlatform isD…
angerman Mar 19, 2018
84017d0
Revert "[ghc] Drop targetPlatform == hostPlatform assert"
angerman Mar 19, 2018
f932e96
more verbose logic.
angerman Mar 21, 2018
224392f
stdenv.isDarwin -> hostplatform.isDarwin
angerman Mar 21, 2018
3992ea9
Do not enable stm without enabling haskeline
angerman Mar 25, 2018
1f1de5b
allow all platforms.
angerman Mar 25, 2018
6c7fb30
Adds custom Setup derivation.
angerman Mar 25, 2018
2a8ded3
use/provide setup in package sets.
angerman Mar 25, 2018
56d28ed
use Setup derivation when cross compiling.
angerman Mar 25, 2018
dcb0cb8
do not add nativeGhc to the buildInputs
angerman Mar 25, 2018
fcb8be5
no -staticlib for windows.
angerman Mar 25, 2018
cd79349
Adds more asserts
angerman Mar 26, 2018
2276ff8
more logging.
angerman Mar 26, 2018
55f320f
Revert incorrect naming.
angerman Mar 26, 2018
5666ec8
Use buildpackages for nix and nix-prefetch-scripts
angerman Mar 26, 2018
a302505
used stdenv.targetPlatform.isDarwin and not stdenv.isDarwin.
angerman Mar 26, 2018
093afd8
fix python27
angerman Mar 27, 2018
d050c02
Drop `libiconv` on windows.
angerman May 3, 2018
ca6cf4a
WIP
angerman May 9, 2018
a7f9517
fix lz4 cross-build
cleverca22 May 9, 2018
3443dd3
make rocksdb use cmake (doesnt work)
cleverca22 May 9, 2018
45e4258
fix libuv
angerman May 9, 2018
f4f044f
rocksdb (don't fully work yet...)
angerman May 16, 2018
3c032a1
proper mingw names
angerman May 16, 2018
7f86470
revert rocksdb
angerman May 16, 2018
2cce00a
cleanup mingw
angerman May 16, 2018
728ada5
Adds preliminary gcc-ng infra.
angerman May 16, 2018
cd3b3de
Adds wine (darwin)
angerman Mar 27, 2018
1353a6e
make bulding libgcc work.
angerman May 17, 2018
b1adfd1
Revert "revert rocksdb"
angerman May 17, 2018
3c044d2
use gcc7-ng-msvcrt by default.
angerman May 17, 2018
68d2d15
bump
angerman Jun 8, 2018
461b7bb
Stop haskell from generating $out/lib.
angerman Jun 10, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/systems/examples.nix
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ rec {

# 32 bit mingw-w64
mingw32 = {
config = "i686-pc-mingw32";
config = "i686-w64-mingw32";
libc = "msvcrt"; # This distinguishes the mingw (non posix) toolchain
platform = {};
};

# 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 = {};
};
Expand Down
1 change: 1 addition & 0 deletions lib/systems/parse.nix
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ rec {
vendors = setTypes types.openVendor {
apple = {};
pc = {};
w64 = {}; # mingw-w64

unknown = {};
};
Expand Down
86 changes: 86 additions & 0 deletions pkgs/development/compilers/gcc/7/default-ng-prebuilt.nix
Original file line number Diff line number Diff line change
@@ -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;
})
98 changes: 98 additions & 0 deletions pkgs/development/compilers/gcc/7/default-ng.nix
Original file line number Diff line number Diff line change
@@ -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/<target>/<version>
# 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
'';
})
4 changes: 2 additions & 2 deletions pkgs/development/compilers/ghc/8.2.1-binary.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
'' +

Expand Down Expand Up @@ -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
Expand Down
27 changes: 19 additions & 8 deletions pkgs/development/compilers/ghc/8.4.2.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
Loading