From 337d8ab2e1b17ff065e69059483bd064271ec2f6 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Sun, 25 Feb 2018 08:20:45 -0500 Subject: [PATCH 01/10] libidn2: Fix cross-compilation --- pkgs/development/libraries/libidn2/default.nix | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkgs/development/libraries/libidn2/default.nix b/pkgs/development/libraries/libidn2/default.nix index 521fe00b56d7..d375785e497e 100644 --- a/pkgs/development/libraries/libidn2/default.nix +++ b/pkgs/development/libraries/libidn2/default.nix @@ -1,4 +1,4 @@ -{ fetchurl, stdenv, libiconv, libunistring, help2man, ronn }: +{ fetchurl, stdenv, libiconv, libunistring, help2man, ronn, buildPackages }: with stdenv.lib; @@ -15,8 +15,10 @@ stdenv.mkDerivation rec { patches = optional stdenv.isDarwin ./fix-error-darwin.patch; - buildInputs = [ libunistring ronn ] - ++ optionals stdenv.isDarwin [ libiconv help2man ]; + nativeBuildInputs = [ ronn ] + ++ optional stdenv.isDarwin help2man; + buildInputs = [ libunistring ] ++ optional stdenv.isDarwin libiconv; + depsBuildBuild = [ buildPackages.stdenv.cc ]; meta = { homepage = "https://www.gnu.org/software/libidn/#libidn2"; From 24ad5077f246f90315569b381b57fc701aa3ef77 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Sun, 25 Feb 2018 08:24:34 -0500 Subject: [PATCH 02/10] libgcrypt: Remove verbosity intended to avoid a systemd rebuild. libidn2 is going to require it anyway --- pkgs/development/libraries/libgcrypt/default.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/development/libraries/libgcrypt/default.nix b/pkgs/development/libraries/libgcrypt/default.nix index a02aefb0a742..6f36199bd1a5 100644 --- a/pkgs/development/libraries/libgcrypt/default.nix +++ b/pkgs/development/libraries/libgcrypt/default.nix @@ -21,18 +21,18 @@ stdenv.mkDerivation rec { # The build enables -O2 by default for everything else. hardeningDisable = stdenv.lib.optional stdenv.cc.isClang "fortify"; - depsBuildBuild = stdenv.lib.optional stdenv.isCross buildPackages.stdenv.cc; + depsBuildBuild = [ buildPackages.stdenv.cc ]; buildInputs = [ libgpgerror ] ++ stdenv.lib.optional stdenv.isDarwin gettext ++ stdenv.lib.optional enableCapabilities libcap; - preConfigure = if stdenv.isCross then '' + preConfigure = stdenv.lib.optionalString stdenv.isCross '' # This is intentional: gpg-error-config is a shell script that will work during the build mkdir -p "$NIX_BUILD_TOP"/bin ln -s ${libgpgerror.dev}/bin/gpg-error-config "$NIX_BUILD_TOP/bin" export PATH="$NIX_BUILD_TOP/bin:$PATH" - '' else null; + ''; # Make sure libraries are correct for .pc and .la files # Also make sure includes are fixed for callers who don't use libgpgcrypt-config From 42c87765713500722b12ca8eab72826d6b279802 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Sun, 25 Feb 2018 09:07:14 -0500 Subject: [PATCH 03/10] systemd: Take python3 from buildPackages. --- pkgs/os-specific/linux/systemd/default.nix | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkgs/os-specific/linux/systemd/default.nix b/pkgs/os-specific/linux/systemd/default.nix index 383e3c340e64..548594d28105 100644 --- a/pkgs/os-specific/linux/systemd/default.nix +++ b/pkgs/os-specific/linux/systemd/default.nix @@ -9,12 +9,13 @@ , patchelf , getent , hostPlatform +, buildPackages }: assert stdenv.isLinux; let - pythonLxmlEnv = python3Packages.python.withPackages ( ps: with ps; [ python3Packages.lxml ]); + pythonLxmlEnv = buildPackages.python3Packages.python.withPackages ( ps: with ps; [ python3Packages.lxml ]); in @@ -35,7 +36,7 @@ in [ pkgconfig intltool gperf libxslt gettext docbook_xsl docbook_xml_dtd_42 docbook_xml_dtd_45 ninja meson coreutils # meson calls date, stat etc. - pythonLxmlEnv glibcLocales + glibcLocales patchelf getent ]; buildInputs = @@ -43,6 +44,8 @@ in /* cryptsetup */ libuuid m4 glib libgcrypt libgpgerror libidn2 libmicrohttpd kexectools libseccomp libffi audit lz4 bzip2 libapparmor iptables gnu-efi + # This is actually native, but we already pull it from buildPackages + pythonLxmlEnv ]; #dontAddPrefix = true; @@ -128,7 +131,7 @@ in for i in src/basic/generate-gperfs.py src/resolve/generate-dns_type-gperf.py src/test/generate-sym-test.py ; do substituteInPlace $i \ - --replace "#!/usr/bin/env python" "#!${python3Packages.python}/bin/python" + --replace "#!/usr/bin/env python" "#!${buildPackages.python3Packages.python}/bin/python" done substituteInPlace src/journal/catalog.c \ From e21300a6ae8997895f2b902e52eef5f11c98ec8a Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Sun, 25 Feb 2018 09:38:55 -0500 Subject: [PATCH 04/10] libapparmor: Fix cross-compilation. --- pkgs/os-specific/linux/apparmor/default.nix | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pkgs/os-specific/linux/apparmor/default.nix b/pkgs/os-specific/linux/apparmor/default.nix index 0bb5561e9572..c8e58dfbf6fb 100644 --- a/pkgs/os-specific/linux/apparmor/default.nix +++ b/pkgs/os-specific/linux/apparmor/default.nix @@ -8,6 +8,7 @@ , swig , ncurses , pam +, buildPackages }: let @@ -29,8 +30,8 @@ let }; prePatchCommon = '' - substituteInPlace ./common/Make.rules --replace "/usr/bin/pod2man" "${perl}/bin/pod2man" - substituteInPlace ./common/Make.rules --replace "/usr/bin/pod2html" "${perl}/bin/pod2html" + substituteInPlace ./common/Make.rules --replace "/usr/bin/pod2man" "${buildPackages.perl}/bin/pod2man" + substituteInPlace ./common/Make.rules --replace "/usr/bin/pod2html" "${buildPackages.perl}/bin/pod2html" substituteInPlace ./common/Make.rules --replace "/usr/include/linux/capability.h" "${linuxHeaders}/include/linux/capability.h" substituteInPlace ./common/Make.rules --replace "/usr/share/man" "share/man" ''; @@ -70,9 +71,10 @@ let swig ncurses which + perl ]; - buildInputs = [ + buildInputs = stdenv.lib.optionals (!stdenv.isCross) [ perl python ]; @@ -87,11 +89,12 @@ let inherit patches; postPatch = "cd ./libraries/libapparmor"; - configureFlags = "--with-python --with-perl"; + # https://gitlab.com/apparmor/apparmor/issues/1 + configureFlags = stdenv.lib.optionalString (!stdenv.isCross) "--with-python --with-perl"; - outputs = [ "out" "python" ]; + outputs = if stdenv.isCross then [ "out" ] else [ "out" "python" ]; - postInstall = '' + postInstall = stdenv.lib.optionalString (!stdenv.isCross) '' mkdir -p $python/lib mv $out/lib/python* $python/lib/ ''; From dcab8d611d1e4652346f10bc1f16e4784368a364 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Sun, 25 Feb 2018 09:46:49 -0500 Subject: [PATCH 05/10] lzip: Fix cross compilation --- pkgs/tools/compression/lzip/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/tools/compression/lzip/default.nix b/pkgs/tools/compression/lzip/default.nix index 298e490be873..2f6f9aca4323 100644 --- a/pkgs/tools/compression/lzip/default.nix +++ b/pkgs/tools/compression/lzip/default.nix @@ -11,7 +11,7 @@ stdenv.mkDerivation rec { sha256 = "1abbch762gv8rjr579q3qyyk6c80plklbv2mw4x0vg71dgsw9bgz"; }; - configureFlags = "CPPFLAGS=-DNDEBUG CFLAGS=-O3 CXXFLAGS=-O3"; + configureFlags = "CPPFLAGS=-DNDEBUG CFLAGS=-O3 CXXFLAGS=-O3" + stdenv.lib.optionalString stdenv.isCross " CXX=${stdenv.cc.targetPrefix}c++"; setupHook = ./lzip-setup-hook.sh; From f79fa7794176c11530a3be3f05ffbc10f1e53003 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Sun, 25 Feb 2018 20:36:43 -0500 Subject: [PATCH 06/10] Guile: Fix cross-compilation --- pkgs/development/interpreters/guile/2.0.nix | 10 +++++----- pkgs/development/interpreters/guile/default.nix | 10 +++++----- pkgs/development/interpreters/guile/riscv.patch | 13 +++++++++++++ 3 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 pkgs/development/interpreters/guile/riscv.patch diff --git a/pkgs/development/interpreters/guile/2.0.nix b/pkgs/development/interpreters/guile/2.0.nix index 5746300fca09..ea8ff924064a 100644 --- a/pkgs/development/interpreters/guile/2.0.nix +++ b/pkgs/development/interpreters/guile/2.0.nix @@ -1,6 +1,6 @@ { fetchurl, stdenv, libtool, readline, gmp, pkgconfig, boehmgc, libunistring , libffi, gawk, makeWrapper, fetchpatch, coverageAnalysis ? null, gnu ? null -, hostPlatform +, hostPlatform, buildPackages }: # Do either a coverage analysis build or a standard build. @@ -19,7 +19,9 @@ outputs = [ "out" "dev" "info" ]; setOutputFlags = false; # $dev gets into the library otherwise - nativeBuildInputs = [ makeWrapper gawk pkgconfig ]; + depsBuildBuild = [ buildPackages.stdenv.cc ]; + nativeBuildInputs = [ makeWrapper gawk pkgconfig ] ++ + stdenv.lib.optional stdenv.isCross buildPackages.buildPackages.guile_2_0; buildInputs = [ readline libtool libunistring libffi ]; propagatedBuildInputs = [ gmp boehmgc ] @@ -29,9 +31,6 @@ # see below. ++ [ libtool libunistring ]; - # A native Guile 2.0 is needed to cross-build Guile. - selfNativeBuildInput = true; - enableParallelBuilding = true; patches = [ ./disable-gc-sensitive-tests.patch ./eai_system.patch ./clang.patch @@ -40,6 +39,7 @@ url = "http://git.savannah.gnu.org/cgit/guile.git/patch/?id=2fbde7f02adb8c6585e9baf6e293ee49cd23d4c4"; sha256 = "0p6c1lmw1iniq03z7x5m65kg3lq543kgvdb4nrxsaxjqf3zhl77v"; }) + ./riscv.patch ] ++ (stdenv.lib.optional (coverageAnalysis != null) ./gcov-file-name.patch); diff --git a/pkgs/development/interpreters/guile/default.nix b/pkgs/development/interpreters/guile/default.nix index e10c5fbb5684..fc7cd2b60ead 100644 --- a/pkgs/development/interpreters/guile/default.nix +++ b/pkgs/development/interpreters/guile/default.nix @@ -1,6 +1,6 @@ { fetchurl, stdenv, libtool, readline, gmp, pkgconfig, boehmgc, libunistring , libffi, gawk, makeWrapper, fetchpatch, coverageAnalysis ? null, gnu ? null -, hostPlatform +, hostPlatform, buildPackages }: # Do either a coverage analysis build or a standard build. @@ -20,7 +20,9 @@ outputs = [ "out" "dev" "info" ]; setOutputFlags = false; # $dev gets into the library otherwise - nativeBuildInputs = [ makeWrapper gawk pkgconfig ]; + depsBuildBuild = [ buildPackages.stdenv.cc ]; + nativeBuildInputs = [ makeWrapper gawk pkgconfig ] ++ + stdenv.lib.optional stdenv.isCross buildPackages.buildPackages.guile; buildInputs = [ readline libtool libunistring libffi ]; propagatedBuildInputs = [ gmp boehmgc ] @@ -30,13 +32,11 @@ # see below. ++ [ libtool libunistring ]; - # A native Guile 2.0 is needed to cross-build Guile. - selfNativeBuildInput = true; - enableParallelBuilding = true; patches = [ ./eai_system.patch + ./riscv.patch ] ++ (stdenv.lib.optional (coverageAnalysis != null) ./gcov-file-name.patch); diff --git a/pkgs/development/interpreters/guile/riscv.patch b/pkgs/development/interpreters/guile/riscv.patch new file mode 100644 index 000000000000..b835e1613838 --- /dev/null +++ b/pkgs/development/interpreters/guile/riscv.patch @@ -0,0 +1,13 @@ +diff --git a/module/system/base/target.scm b/module/system/base/target.scm +index 95ab8d8c9..93616f4a3 100644 +--- a/module/system/base/target.scm ++++ b/module/system/base/target.scm +@@ -86,6 +86,8 @@ + (endianness big)) + ((string=? "aarch64" cpu) + (endianness little)) ++ ((string-match "riscv[1-9][0-9]*" cpu) ++ (endianness little)) + (else + (error "unknown CPU endianness" cpu))))) + From 6b1ab50738d1f61cdb9d2b2f8d85ed8368b76366 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Sun, 25 Feb 2018 20:37:08 -0500 Subject: [PATCH 07/10] Autogen: Fix unnecessary duplication during cross-compilation --- pkgs/development/tools/misc/autogen/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/tools/misc/autogen/default.nix b/pkgs/development/tools/misc/autogen/default.nix index 77944297a972..660917ee9f1f 100644 --- a/pkgs/development/tools/misc/autogen/default.nix +++ b/pkgs/development/tools/misc/autogen/default.nix @@ -14,7 +14,7 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ which pkgconfig perl ] # autogen needs a build autogen when cross-compiling ++ stdenv.lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ - buildPackages.autogen buildPackages.texinfo ]; + buildPackages.buildPackages.autogen buildPackages.texinfo ]; buildInputs = [ guile libxml2 ]; From 4728ef130e17f194fddedfea386e4fc909e1c4cb Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Mon, 26 Feb 2018 05:24:36 -0500 Subject: [PATCH 08/10] RISC-V: Add upstream gcc patch to fix -pthread. Fixes libmicrohttpd build. --- pkgs/development/compilers/gcc/7/default.nix | 4 +++- .../compilers/gcc/7/riscv-pthread-reentrant.patch | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 pkgs/development/compilers/gcc/7/riscv-pthread-reentrant.patch diff --git a/pkgs/development/compilers/gcc/7/default.nix b/pkgs/development/compilers/gcc/7/default.nix index e8997b1efb06..68a47987b2e1 100644 --- a/pkgs/development/compilers/gcc/7/default.nix +++ b/pkgs/development/compilers/gcc/7/default.nix @@ -73,7 +73,9 @@ let version = "7.3.0"; # The GNAT Makefiles did not pay attention to CFLAGS_FOR_TARGET for its # target libraries and tools. ++ optional langAda ../gnat-cflags.patch - ++ optional langFortran ../gfortran-driving.patch; + ++ optional langFortran ../gfortran-driving.patch + # https://gcc.gnu.org/ml/gcc-patches/2018-02/msg00633.html + ++ optional targetPlatform.isRiscV ./riscv-pthread-reentrant.patch; javaEcj = fetchurl { # The `$(top_srcdir)/ecj.jar' file is automatically picked up at diff --git a/pkgs/development/compilers/gcc/7/riscv-pthread-reentrant.patch b/pkgs/development/compilers/gcc/7/riscv-pthread-reentrant.patch new file mode 100644 index 000000000000..c7527ffb2b16 --- /dev/null +++ b/pkgs/development/compilers/gcc/7/riscv-pthread-reentrant.patch @@ -0,0 +1,13 @@ +Index: gcc/config/riscv/linux.h +=================================================================== +--- a/gcc/config/riscv/linux.h (revision 257620) ++++ b/gcc/config/riscv/linux.h (revision 257621) +@@ -47,6 +47,8 @@ + + #define ICACHE_FLUSH_FUNC "__riscv_flush_icache" + ++#define CPP_SPEC "%{pthread:-D_REENTRANT}" ++ + #define LINK_SPEC "\ + -melf" XLEN_SPEC "lriscv \ + %{shared} \ From 284f75a258e0f766b8b5d047c486f11c4c4e102d Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Mon, 26 Feb 2018 06:33:00 -0500 Subject: [PATCH 09/10] meson: Support cross-compiling --- .../tools/build-managers/meson/default.nix | 26 +++++++++++++++++-- .../tools/build-managers/meson/setup-hook.sh | 8 ++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/pkgs/development/tools/build-managers/meson/default.nix b/pkgs/development/tools/build-managers/meson/default.nix index 5db0bce21f79..27aa38cfa7e1 100644 --- a/pkgs/development/tools/build-managers/meson/default.nix +++ b/pkgs/development/tools/build-managers/meson/default.nix @@ -1,5 +1,7 @@ -{ lib, python3Packages }: -python3Packages.buildPythonApplication rec { +{ lib, python3Packages, stdenv, targetPlatform, writeTextDir, m4 }: let + targetPrefix = lib.optionalString stdenv.isCross + (targetPlatform.config + "-"); +in python3Packages.buildPythonApplication rec { version = "0.44.0"; pname = "meson"; name = "${pname}-${version}"; @@ -33,6 +35,26 @@ python3Packages.buildPythonApplication rec { setupHook = ./setup-hook.sh; + crossFile = writeTextDir "cross-file.conf" '' + [binaries] + c = '${targetPrefix}cc' + cpp = '${targetPrefix}c++' + ar = '${targetPrefix}ar' + strip = '${targetPrefix}strip' + pkgconfig = 'pkg-config' + + [properties] + needs_exe_wrapper = true + + [host_machine] + system = '${targetPlatform.parsed.kernel.name}' + cpu_family = '${targetPlatform.parsed.cpu.family}' + cpu = '${targetPlatform.parsed.cpu.name}' + endian = ${if targetPlatform.isLittleEndian then "'little'" else "'big'"} + ''; + + inherit (stdenv) cc isCross; + meta = with lib; { homepage = http://mesonbuild.com; description = "SCons-like build system that use python as a front-end language and Ninja as a building backend"; diff --git a/pkgs/development/tools/build-managers/meson/setup-hook.sh b/pkgs/development/tools/build-managers/meson/setup-hook.sh index 8f96e6146be0..22e46a62cb9d 100644 --- a/pkgs/development/tools/build-managers/meson/setup-hook.sh +++ b/pkgs/development/tools/build-managers/meson/setup-hook.sh @@ -6,11 +6,15 @@ mesonConfigurePhase() { fi # Build release by default. - mesonFlags="--buildtype=${mesonBuildType:-release} $mesonFlags" + if [ -n "@isCross@" ]; then + crossMesonFlags="--cross-file=@crossFile@/cross-file.conf" + fi + + mesonFlags="${crossMesonFlags+$crossMesonFlags }--buildtype=${mesonBuildType:-release} $mesonFlags" echo "meson flags: $mesonFlags ${mesonFlagsArray[@]}" - meson build $mesonFlags "${mesonFlagsArray[@]}" + CC=@cc@/bin/cc CXX=@cc@/bin/c++ meson build $mesonFlags "${mesonFlagsArray[@]}" cd build if ! [[ -v enableParallelBuilding ]]; then From 9d2af8d61ca651b5ad505c37f42e10ace4894fc2 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Mon, 26 Feb 2018 06:38:42 -0500 Subject: [PATCH 10/10] systemd: Fix cross-compiling --- pkgs/os-specific/linux/systemd/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/os-specific/linux/systemd/default.nix b/pkgs/os-specific/linux/systemd/default.nix index 548594d28105..df51284689e2 100644 --- a/pkgs/os-specific/linux/systemd/default.nix +++ b/pkgs/os-specific/linux/systemd/default.nix @@ -37,11 +37,11 @@ in ninja meson coreutils # meson calls date, stat etc. glibcLocales - patchelf getent + patchelf getent m4 ]; buildInputs = [ linuxHeaders libcap kmod xz pam acl - /* cryptsetup */ libuuid m4 glib libgcrypt libgpgerror libidn2 + /* cryptsetup */ libuuid glib libgcrypt libgpgerror libidn2 libmicrohttpd kexectools libseccomp libffi audit lz4 bzip2 libapparmor iptables gnu-efi # This is actually native, but we already pull it from buildPackages