Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 29 additions & 0 deletions lib/customisation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,33 @@ rec {
};
in self;

# Use this if you want to override the native derivation of a
# package without affecting the cross-compiled derivation.
overrideNativeDrv = newNativeDrv: old:
if old ? crossDrv
then
let
nativeDrv = newNativeDrv;
crossDrv = old.crossDrv;
override = newArgs: overrideNativeDrv
(newNativeDrv.override newArgs) (old.override newArgs);
in nativeDrv // { inherit crossDrv nativeDrv override; }
else
newNativeDrv;

# Given a set of new packages and a set of old packages, produces a
# set with the same attribute names as the set of new packages, where
# each attribute value is a derivation that has the native derivation
# from the new set but the cross derivation (crossDrv) from the old
# set.
overrideNativeDrvs = newPkgs: oldPkgs:
let
overrider = attr: {
name = attr;
value = if oldPkgs ? "${attr}" then
(overrideNativeDrv newPkgs.${attr} oldPkgs.${attr})
else (throw "wtf ${attr}");
};
names = builtins.attrNames newPkgs;
in builtins.listToAttrs (map overrider names);
}
11 changes: 10 additions & 1 deletion pkgs/development/compilers/gcc/5/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ with builtins;
let version = "5.4.0";
sha256 = "0fihlcy5hnksdxk0sn6bvgnyq8gfrgs8m794b1jxwd1dxinzg3b0";

# Rename the libcCross argument so we can redefine libcCross to
# null for the native compiler.
libcCrossArg = libcCross;

# Whether building a cross-compiler for GNU/Hurd.
crossGNU = cross != null && cross.config == "i586-pc-gnu";

Expand Down Expand Up @@ -210,7 +214,12 @@ in
# We need all these X libraries when building AWT with GTK+.
assert x11Support -> (filter (x: x == null) ([ gtk2 libart_lgpl ] ++ xlibs)) == [];

stdenv.mkDerivation ({
stdenv.mkDerivationWithCrossArg ( hostCrossSystem:
let
targetCrossSystem = if cross != null then cross else hostCrossSystem;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please comment when targetCrossSystem is non-null, I presume this is is a function of build and host and target being equal or not equal in some combination.

libcCross = if targetCrossSystem != null then libcCrossArg else null;
in {

name = "${name}${if stripped then "" else "-debug"}-${version}" + crossNameAddon;

builder = ../builder.sh;
Expand Down
7 changes: 5 additions & 2 deletions pkgs/development/libraries/boehm-gc/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ stdenv.mkDerivation rec {

doCheck = true;

# Don't run the native `strip' when cross-compiling.
dontStrip = stdenv ? cross;
# This is just here because it was present in previous commits and
# we want to avoid a meaningless mass rebuild.
dontStrip = false;

crossAttrs.dontStrip = true; # Don't run the native `strip' when cross-compiling.

postInstall =
''
Expand Down
6 changes: 5 additions & 1 deletion pkgs/development/libraries/libffi/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ stdenv.mkDerivation rec {

inherit doCheck;

dontStrip = stdenv ? cross; # Don't run the native `strip' when cross-compiling.
# This is just here because it was present in previous commits and
# we want to avoid a meaningless mass rebuild.
dontStrip = false;

crossAttrs.dontStrip = true; # Don't run the native `strip' when cross-compiling.

# Install headers and libs in the right places.
postFixup = ''
Expand Down
27 changes: 15 additions & 12 deletions pkgs/development/libraries/libxml2/default.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{ stdenv, lib, fetchurl, zlib, xz, python2, findXMLCatalogs, libiconv, fetchpatch
, pythonSupport ? (! stdenv ? cross) }:

let
python = python2;
in stdenv.mkDerivation rec {
, pythonSupport ? null }:

stdenv.mkDerivationWithCrossArg(cross:
let
pythonSupportReally = if pythonSupport != null then pythonSupport
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do something like pythonSupportReally, matching the others, so the body of this stays the same.

else cross == null;
python = assert pythonSupportReally; python2;
in rec {
name = "libxml2-${version}";
version = "2.9.4";

Expand All @@ -28,18 +31,18 @@ in stdenv.mkDerivation rec {
};

outputs = [ "bin" "dev" "out" "doc" ]
++ lib.optional pythonSupport "py";
propagatedBuildOutputs = "out bin" + lib.optionalString pythonSupport " py";
++ lib.optional pythonSupportReally "py";
propagatedBuildOutputs = "out bin" + lib.optionalString pythonSupportReally " py";

buildInputs = lib.optional pythonSupport python
buildInputs = lib.optional pythonSupportReally python
# Libxml2 has an optional dependency on liblzma. However, on impure
# platforms, it may end up using that from /usr/lib, and thus lack a
# RUNPATH for that, leading to undefined references for its users.
++ lib.optional stdenv.isFreeBSD xz;

propagatedBuildInputs = [ zlib findXMLCatalogs ];

configureFlags = lib.optional pythonSupport "--with-python=${python}"
configureFlags = lib.optional pythonSupportReally "--with-python=${python}"
++ [ "--exec_prefix=$dev" ];

enableParallelBuilding = true;
Expand All @@ -55,9 +58,9 @@ in stdenv.mkDerivation rec {
propagatedBuildInputs = [ findXMLCatalogs libiconv ];
};

preInstall = lib.optionalString pythonSupport
preInstall = lib.optionalString pythonSupportReally
''substituteInPlace python/libxml2mod.la --replace "${python}" "$py"'';
installFlags = lib.optionalString pythonSupport
installFlags = lib.optionalString pythonSupportReally
''pythondir="$(py)/lib/${python.libPrefix}/site-packages"'';

postFixup = ''
Expand All @@ -75,4 +78,4 @@ in stdenv.mkDerivation rec {
platforms = lib.platforms.unix;
maintainers = [ lib.maintainers.eelco ];
};
}
})
8 changes: 6 additions & 2 deletions pkgs/development/libraries/readline/6.3.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ stdenv.mkDerivation rec {
in
import ./readline-6.3-patches.nix patch);

# Don't run the native `strip' when cross-compiling.
dontStrip = stdenv ? cross;
# This is just here because it was present in previous commits and
# we want to avoid a meaningless mass rebuild.
dontStrip = false;

crossAttrs.dontStrip = true; # Don't run the native `strip' when cross-compiling.

bash_cv_func_sigsetjmp = if stdenv.isCygwin then "missing" else null;

meta = with stdenv.lib; {
Expand Down
6 changes: 5 additions & 1 deletion pkgs/development/tools/misc/libtool/libtool2.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ stdenv.mkDerivation rec {
# leads to the failure of a number of tests.
doCheck = false;

# This is just here because it was present in previous commits and
# we want to avoid a meaningless mass-rebuild.
dontStrip = false;

# Don't run the native `strip' when cross-compiling. This breaks at least
# with `.a' files for MinGW.
dontStrip = stdenv ? cross;
crossAttrs.dontStrip = true;

meta = {
description = "GNU Libtool, a generic library support script";
Expand Down
17 changes: 16 additions & 1 deletion pkgs/stdenv/adapters.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ rec {
# Return a modified stdenv that adds a cross compiler to the
# builds.
makeStdenvCross = stdenv: cross: binutilsCross: gccCross: stdenv //
{ mkDerivation = {name ? "", buildInputs ? [], nativeBuildInputs ? [],
rec { mkDerivation = {name ? "", buildInputs ? [], nativeBuildInputs ? [],
propagatedBuildInputs ? [], propagatedNativeBuildInputs ? [],
selfNativeBuildInput ? false, ...}@args: let

Expand Down Expand Up @@ -115,6 +115,21 @@ rec {
in nativeDrv // {
inherit crossDrv nativeDrv;
};

# mkDerivationWithCrossArg allows us to make arbitary changes to
# derivation depending on what system we are cross-compiling for, without
# affecting the native derivation. The argument to
# mkDerivationWithCrossArg, attrFunc, should be a function that takes a
# single argument named cross. When cross is null, attrFunc should return
# the attributes for making a native version of the derivation (one that
# runs on the system on which it was built). When cross is not null, it
# will be equal to the top-level crossSystem argument (and equal to
# stdenv.cross), and attrFunc should return the attributes for
# cross-compiling a derivation to be run on the specified system.
mkDerivationWithCrossArg = attrFunc:
let nativeDrv = (mkDerivation (attrFunc null)).nativeDrv;
crossDrv = (mkDerivation (attrFunc cross)).crossDrv;
in nativeDrv // { inherit crossDrv nativeDrv; };
} // {
inherit cross gccCross binutilsCross;
ccCross = gccCross;
Expand Down
5 changes: 5 additions & 0 deletions pkgs/stdenv/generic/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ let
# derivation (e.g., in assertions).
passthru);

# This gets overridden in makeStdvenvCross to do something more useful.
mkDerivationWithCrossArg = attrFunc: mkDerivation (attrFunc null);

# The stdenv that we are producing.
result =
derivation (
Expand Down Expand Up @@ -343,6 +346,8 @@ let

inherit mkDerivation;

inherit mkDerivationWithCrossArg;

# For convenience, bring in the library functions in lib/ so
# packages don't have to do that themselves.
inherit lib;
Expand Down
6 changes: 2 additions & 4 deletions pkgs/stdenv/linux/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,10 @@ rec {
];
*/

overrides = pkgs: {
gcc = cc;

overrides = lib.overrideNativeDrvs {
inherit (stage4.pkgs)
gzip bzip2 xz bash binutils coreutils diffutils findutils gawk
glibc gnumake gnused gnutar gnugrep gnupatch patchelf
gcc glibc gnumake gnused gnutar gnugrep gnupatch patchelf
attr acl paxctl zlib pcre;
};
};
Expand Down
2 changes: 1 addition & 1 deletion pkgs/stdenv/linux/make-bootstrap-tools-cross.nix
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ let
gnumake = pkgs.gnumake.crossDrv;
patch = pkgs.patch.crossDrv;
patchelf = pkgs.patchelf.crossDrv;
gcc = pkgs.gcc.cc.crossDrv;
gcc = pkgs.gcc.crossDrv.cc;
gmpxx = pkgs.gmpxx.crossDrv;
mpfr = pkgs.mpfr.crossDrv;
zlib = pkgs.zlib.crossDrv;
Expand Down
52 changes: 33 additions & 19 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4674,18 +4674,18 @@ in

gccApple = throw "gccApple is no longer supported";

gccCrossStageStatic = let
libcCross1 =
if stdenv.cross.libc == "msvcrt" then windows.mingw_w64_headers
else if stdenv.cross.libc == "libSystem" then darwin.xcode
else null;
in wrapGCCCross {
gcc = forceNativeDrv (gcc.cc.override {
gccCrossStageStatic =
wrapGCCCross {
gcc = forceNativeDrv (callPackage ../development/compilers/gcc/5 {
cross = crossSystem;
crossStageStatic = true;
langCC = false;
noSysDirs = true;
isl = isl_0_14;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok for now, see isl comment below

libcCross = libcCross1;
enableShared = false;
langCC = false;
langObjC = false;
langObjCpp = false;
});
libc = libcCross1;
binutils = binutilsCross;
Expand All @@ -4701,13 +4701,19 @@ in
};

gccCrossStageFinal = wrapGCCCross {
gcc = forceNativeDrv (gcc.cc.override {
gcc = forceNativeDrv (callPackage ../development/compilers/gcc/5 {
cross = crossSystem;
crossStageStatic = false;
noSysDirs = true;
isl = isl_0_14;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok for now, but we should figure out why this can't be the default so this and the Linux stdenv don't need to special case.

libcCross = libcCross;

# XXX: We have troubles cross-compiling libstdc++ on MinGW (see
# <http://hydra.nixos.org/build/4268232>), so don't even try.
langCC = crossSystem.config != "i686-pc-mingw32";

langObjC = false;
langObjCpp = false;
});
libc = libcCross;
binutils = binutilsCross;
Expand Down Expand Up @@ -7184,8 +7190,13 @@ in
linuxHeaders = linuxHeadersCross;
});

# We can choose:
libcCrossChooser = name: if name == "glibc" then glibcCross
libcCross1 =
if stdenv.cross.libc == "msvcrt" then windows.mingw_w64_headers
else if stdenv.cross.libc == "libSystem" then darwin.xcode
else null;

libcCrossChooser = name:
if name == "glibc" then glibcCross
else if name == "uclibc" then uclibcCross
else if name == "msvcrt" then windows.mingw_w64
else if name == "libSystem" then darwin.xcode
Expand Down Expand Up @@ -8081,14 +8092,17 @@ in

# glibc provides libiconv so systems with glibc don't need to build libiconv
# separately, but we also provide libiconvReal, which will always be a
# standalone libiconv, just in case you want it
libiconv = if crossSystem != null then
(if crossSystem.libc == "glibc" then libcCross
else if crossSystem.libc == "libSystem" then darwin.libiconv
else libiconvReal)
else if stdenv.isGlibc then glibcIconv stdenv.cc.libc
else if stdenv.isDarwin then darwin.libiconv
else libiconvReal;
# standalone libiconv, just in case you want it.
libiconv =
let
nativeDrv = if stdenv.isGlibc then stdenv.cc.libc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use glibcIconv to strip unneeded

else if stdenv.isDarwin then darwin.libiconv
else libiconvReal;
crossDrv =
if crossSystem.libc == "glibc" then libcCross
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, please use glibcIconv

else if crossSystem.libc == "libSystem" then darwin.libiconv
else libiconvReal.crossDrv;
in nativeDrv // { inherit crossDrv nativeDrv; };

glibcIconv = libc: let
inherit (builtins.parseDrvName libc.name) name version;
Expand Down
12 changes: 4 additions & 8 deletions pkgs/top-level/stage.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,11 @@ let

aliases = self: super: import ./aliases.nix super;

# stdenvOverrides is used to avoid circular dependencies for building
# the standard build environment. This mechanism uses the override
# mechanism to implement some staged compilation of the stdenv.
#
# We don't want stdenv overrides in the case of cross-building, or
# otherwise the basic overridden packages will not be built with the
# crossStdenv adapter.
# stdenvOverrides is used to avoid having multiple of versions
# of certain dependencies that were used in bootstrapping the
# standard environment.
stdenvOverrides = self: super:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#21415 will imminently do half of this. See pkgs/stdenv/cross/default.nix for dealing with the rest.

lib.optionalAttrs (crossSystem == null && super.stdenv ? overrides)
lib.optionalAttrs (super.stdenv ? overrides)
(super.stdenv.overrides super);

# Allow packages to be overridden globally via the `packageOverrides'
Expand Down