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

misc pkgs: Darwin -> Linux cross compilation #46534

Merged
merged 3 commits into from
Oct 24, 2018
Merged
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
4 changes: 3 additions & 1 deletion pkgs/development/libraries/glibc/common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ stdenv.mkDerivation ({

depsBuildBuild = [ buildPackages.stdenv.cc ];
nativeBuildInputs = [ bison ];
buildInputs = lib.optionals withGd [ gd libpng ];
# TODO make linuxHeaders unconditional next mass rebuild
buildInputs = lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) linuxHeaders
++ lib.optionals withGd [ gd libpng ];

# Needed to install share/zoneinfo/zone.tab. Set to impure /bin/sh to
# prevent a retained dependency on the bootstrap tools in the stdenv-linux
Expand Down
58 changes: 52 additions & 6 deletions pkgs/os-specific/linux/kernel-headers/default.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{ stdenvNoCC, lib, buildPackages
, fetchurl, perl
, fetchurl, fetchpatch, perl
, elf-header
}:

let
common = { version, sha256, patches ? [] }: stdenvNoCC.mkDerivation {
common = { version, sha256, patches ? [] }: stdenvNoCC.mkDerivation ({
name = "linux-headers-${version}";

src = fetchurl {
Expand All @@ -16,18 +17,55 @@ let
# It may look odd that we use `stdenvNoCC`, and yet explicit depend on a cc.
# We do this so we have a build->build, not build->host, C compiler.
depsBuildBuild = [ buildPackages.stdenv.cc ];
nativeBuildInputs = [ perl ];
# TODO make unconditional next mass rebuild
nativeBuildInputs = [ perl ] ++ lib.optional
(stdenvNoCC.hostPlatform != stdenvNoCC.buildPlatform)
elf-header;

extraIncludeDirs = lib.optional stdenvNoCC.hostPlatform.isPowerPC ["ppc"];

# "patches" array defaults to 'null' to avoid changing hash
# and causing mass rebuild
inherit patches;

buildPhase = ''
# TODO avoid native hack next rebuild
makeFlags = if stdenvNoCC.hostPlatform == stdenvNoCC.buildPlatform then null else [
"SHELL=bash"
# Avoid use of runtime build->host compilers for checks. These
# checks only cared to work around bugs in very old compilers, so
# these changes should be safe.
"cc-version:=9999"
Copy link
Member

Choose a reason for hiding this comment

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

ugh... Another thing to report upstream, but it is probably fine for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well... it's arguably not a bug. I checked and this version is just used to work around bugs in old GCCs; I assume/hope newer GCCs are given better testing so hopefully it won't a happen again. But we could generate the actual version number thing just as a precaution.

Then again, upstream could provide the right hook in the configure script so faking this number wouldn't be downstream's burden.

"cc-fullversion:=999999"
# `$(..)` expanded by make alone
"HOSTCC:=$(BUILD_CC)"
"HOSTCXX:=$(BUILD_CXX)"
];

# TODO avoid native hack next rebuild
# Skip clean on darwin, case-sensitivity issues.
buildPhase = if stdenvNoCC.hostPlatform == stdenvNoCC.buildPlatform then ''
make mrproper headers_check SHELL=bash
'' else lib.optionalString (!stdenvNoCC.buildPlatform.isDarwin) ''
make mrproper $makeFlags
''
# For some reason, doing `make install_headers` twice, first without
# INSTALL_HDR_PATH=$out then with, is neccessary to get this to work
# for darwin cross. @Ericson2314 has no idea why.
+ ''
make headers_install $makeFlags
'';

# TODO avoid native hack next rebuild
checkPhase = if stdenvNoCC.hostPlatform == stdenvNoCC.buildPlatform then null else ''
make headers_check $makeFlags
'';

installPhase = ''
# TODO avoid native hack next rebuild
installPhase = (if stdenvNoCC.hostPlatform == stdenvNoCC.buildPlatform then ''
make INSTALL_HDR_PATH=$out headers_install
'' else ''
make headers_install INSTALL_HDR_PATH=$out $makeFlags
'') + ''

# Some builds (e.g. KVM) want a kernel.release.
mkdir -p $out/include/config
Expand All @@ -39,11 +77,19 @@ let
license = licenses.gpl2;
platforms = platforms.linux;
};
};
} // lib.optionalAttrs (stdenvNoCC.hostPlatform != stdenvNoCC.buildPlatform) {
# TODO Make unconditional next mass rebuild
hardeningDisable = lib.optional stdenvNoCC.buildPlatform.isDarwin "format";
});
in {

linuxHeaders = common {
version = "4.18.3";
sha256 = "1m23hjd02bg8mqnd8dc4z4m3kxds1cyrc6j5saiwnhzbz373rvc1";
# TODO make unconditional next mass rebuild
patches = lib.optionals (stdenvNoCC.hostPlatform != stdenvNoCC.buildPlatform) [
./no-relocs.patch # for building x86 kernel headers on non-ELF platforms
./no-dynamic-cc-version-check.patch # so we can use `stdenvNoCC`, see `makeFlags` above
];
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
diff --git a/Makefile b/Makefile
index 863f58503bee..b778d5023208 100644
--- a/Makefile
+++ b/Makefile
@@ -501,11 +501,9 @@ KBUILD_CFLAGS += $(call cc-option,-fno-PIE)
KBUILD_AFLAGS += $(call cc-option,-fno-PIE)

# check for 'asm goto'
-ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC) $(KBUILD_CFLAGS)), y)
CC_HAVE_ASM_GOTO := 1
KBUILD_CFLAGS += -DCC_HAVE_ASM_GOTO
KBUILD_AFLAGS += -DCC_HAVE_ASM_GOTO
-endif

# The expansion should be delayed until arch/$(SRCARCH)/Makefile is included.
# Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile.
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 065324a8046f..d09c67194549 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -216,11 +216,8 @@ cc-disable-warning = $(call try-run-cached,\
cc-name = $(call shell-cached,$(CC) -v 2>&1 | grep -q "clang version" && echo clang || echo gcc)

# cc-version
-cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC))

# cc-fullversion
-cc-fullversion = $(shell $(CONFIG_SHELL) \
- $(srctree)/scripts/gcc-version.sh -p $(CC))

# cc-ifversion
# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1)
13 changes: 13 additions & 0 deletions pkgs/os-specific/linux/kernel-headers/no-relocs.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index fad55160dcb9..a48c8331cbb2 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -239,7 +239,7 @@ ifdef CONFIG_RETPOLINE
endif

archscripts: scripts_basic
- $(Q)$(MAKE) $(build)=arch/x86/tools relocs
+ $(Q)$(MAKE) $(build)=arch/x86/tools

###
# Syscall table generation
4 changes: 2 additions & 2 deletions pkgs/top-level/release-cross.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
*/

{ # The platforms *from* which we cross compile.
supportedSystems ? [ "x86_64-linux" "x86_64-darwin" ]
supportedSystems ? [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" ]
, # Strip most of attributes when evaluating to spare memory usage
scrubJobs ? true
}:

with import ./release-lib.nix { inherit supportedSystems scrubJobs; };

let
nativePlatforms = linux;
nativePlatforms = all;

common = {
buildPackages.binutils = nativePlatforms;
Expand Down