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: treewide: Improve pure darwin cross #110914

Draft
wants to merge 2 commits into
base: staging
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions pkgs/build-support/cc-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ let

useGccForLibs = isClang
&& libcxx == null
&& !stdenv.targetPlatform.isDarwin
&& !(stdenv.targetPlatform.useLLVM or false)
&& !(stdenv.targetPlatform.useAndroidPrebuilt or false)
&& !(stdenv.targetPlatform.isiOS or false)
Expand Down
10 changes: 9 additions & 1 deletion pkgs/development/compilers/llvm/10/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ lowPrio, newScope, pkgs, lib, stdenv, cmake, gccForLibs
, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapBintoolsWith
, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapCCWithoutLibc, wrapBintoolsWith
, buildLlvmTools # tools, but from the previous stage, for cross
, targetLlvmLibraries # libraries, but from the next stage, for cross
}:
Expand Down Expand Up @@ -80,6 +80,14 @@ let
extraBuildCommands = mkExtraBuildCommands cc;
};

clangNoLibc = wrapCCWithoutLibc rec {
cc = tools.clang-unwrapped;
extraPackages = [
targetLlvmLibraries.compiler-rt
];
extraBuildCommands = mkExtraBuildCommands cc;
};

lld = callPackage ./lld {};

lldb = callPackage ./lldb {};
Expand Down
10 changes: 9 additions & 1 deletion pkgs/development/compilers/llvm/11/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ lowPrio, newScope, pkgs, lib, stdenv, cmake, gccForLibs
, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapBintoolsWith
, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapCCWithoutLibc, wrapBintoolsWith
, buildLlvmTools # tools, but from the previous stage, for cross
, targetLlvmLibraries # libraries, but from the next stage, for cross
}:
Expand Down Expand Up @@ -82,6 +82,14 @@ let
extraBuildCommands = mkExtraBuildCommands cc;
};

clangNoLibc = wrapCCWithoutLibc rec {
cc = tools.clang-unwrapped;
extraPackages = [
targetLlvmLibraries.compiler-rt
];
extraBuildCommands = mkExtraBuildCommands cc;
};

lld = callPackage ./lld {};

lldb = callPackage ./lldb {};
Expand Down
10 changes: 9 additions & 1 deletion pkgs/development/compilers/llvm/5/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ lowPrio, newScope, pkgs, lib, stdenv, cmake, gccForLibs
, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith
, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapCCWithoutLibc
, buildLlvmTools # tools, but from the previous stage, for cross
, targetLlvmLibraries # libraries, but from the next stage, for cross
}:
Expand Down Expand Up @@ -76,6 +76,14 @@ let
extraBuildCommands = mkExtraBuildCommands cc;
};

clangNoLibc = wrapCCWithoutLibc rec {
cc = tools.clang-unwrapped;
extraPackages = [
targetLlvmLibraries.compiler-rt
];
extraBuildCommands = mkExtraBuildCommands cc;
};

lld = callPackage ./lld {};

lldb = callPackage ./lldb {};
Expand Down
10 changes: 9 additions & 1 deletion pkgs/development/compilers/llvm/6/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ lowPrio, newScope, pkgs, lib, stdenv, cmake, gccForLibs
, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith
, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapCCWithoutLibc
, buildLlvmTools # tools, but from the previous stage, for cross
, targetLlvmLibraries # libraries, but from the next stage, for cross
}:
Expand Down Expand Up @@ -77,6 +77,14 @@ let
extraBuildCommands = mkExtraBuildCommands cc;
};

clangNoLibc = wrapCCWithoutLibc rec {
cc = tools.clang-unwrapped;
extraPackages = [
targetLlvmLibraries.compiler-rt
];
extraBuildCommands = mkExtraBuildCommands cc;
};

lld = callPackage ./lld {};

lldb = callPackage ./lldb {};
Expand Down
63 changes: 59 additions & 4 deletions pkgs/development/compilers/llvm/7/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ lowPrio, newScope, pkgs, lib, stdenv, cmake, gccForLibs
, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapBintoolsWith
, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapCCWithoutLibc, wrapBintoolsWith
, buildLlvmTools # tools, but from the previous stage, for cross
, targetLlvmLibraries # libraries, but from the next stage, for cross
}:
Expand Down Expand Up @@ -82,6 +82,52 @@ let
extraBuildCommands = mkExtraBuildCommands cc;
};

clangNoLibcxx = wrapCCWith rec {
cc = tools.clang-unwrapped;
libcxx = null;
bintools = wrapBintoolsWith {
inherit (tools) bintools;
};
extraPackages = [
targetLlvmLibraries.compiler-rt
];
extraBuildCommands = ''
echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags
echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
echo "-nostdlib++" >> $out/nix-support/cc-cflags
'' + mkExtraBuildCommands cc;
};

clangNoLibcYesCompilerRt = wrapCCWithoutLibc rec {
cc = tools.clang-unwrapped;
extraPackages = [
targetLlvmLibraries.compiler-rt
];
extraBuildCommands = ''
echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags
echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
'' + mkExtraBuildCommands cc;
};

# Darwin "builds" Libsystem then compiler-rt
clangYesLibcNoCompilerRt = wrapCCWith {
cc = tools.clang-unwrapped;
libcxx = null;
extraPackages = [ ];
extraBuildCommands = ''
echo "-nostartfiles" >> $out/nix-support/cc-cflags
'';
};

clangNoLibcNoCompilerRt = wrapCCWithoutLibc {
cc = tools.clang-unwrapped;
libcxx = null;
extraPackages = [ ];
extraBuildCommands = ''
echo "-nostartfiles" >> $out/nix-support/cc-cflags
'';
};

lld = callPackage ./lld {};

lldb = callPackage ./lldb {};
Expand Down Expand Up @@ -167,21 +213,30 @@ let
in {

compiler-rt = callPackage ./compiler-rt {
stdenv = if stdenv.hostPlatform.useLLVM or false
then overrideCC stdenv buildLlvmTools.lldClangNoCompilerRt
else stdenv;
stdenv =
/**/ if stdenv.hostPlatform.useLLVM or false
then overrideCC stdenv buildLlvmTools.lldClangNoCompilerRt
else if stdenv.hostPlatform != stdenv.buildPlatform && stdenv.hostPlatform.isDarwin
then overrideCC stdenv buildLlvmTools.clangYesLibcNoCompilerRt
else stdenv;
};

stdenv = overrideCC stdenv buildLlvmTools.clang;

libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang;

libcxx = callPackage ./libc++ ({} //
(lib.optionalAttrs (stdenv.hostPlatform != stdenv.buildPlatform && stdenv.hostPlatform.isDarwin) {
stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx;
}) //
(lib.optionalAttrs (stdenv.hostPlatform.useLLVM or false) {
stdenv = overrideCC stdenv buildLlvmTools.lldClangNoLibcxx;
}));

libcxxabi = callPackage ./libc++abi ({} //
(lib.optionalAttrs (stdenv.hostPlatform != stdenv.buildPlatform && stdenv.hostPlatform.isDarwin) {
stdenv = overrideCC stdenv buildLlvmTools.clangYesLibcNoCompilerRt;
}) //
(lib.optionalAttrs (stdenv.hostPlatform.useLLVM or false) {
stdenv = overrideCC stdenv buildLlvmTools.lldClangNoLibcxx;
libunwind = libraries.libunwind;
Expand Down
10 changes: 9 additions & 1 deletion pkgs/development/compilers/llvm/8/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ lowPrio, newScope, pkgs, lib, stdenv, cmake, gccForLibs
, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapBintoolsWith
, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapCCWithoutLibc, wrapBintoolsWith
, buildLlvmTools # tools, but from the previous stage, for cross
, targetLlvmLibraries # libraries, but from the next stage, for cross
}:
Expand Down Expand Up @@ -83,6 +83,14 @@ let
extraBuildCommands = mkExtraBuildCommands cc;
};

clangNoLibc = wrapCCWithoutLibc rec {
cc = tools.clang-unwrapped;
extraPackages = [
targetLlvmLibraries.compiler-rt
];
extraBuildCommands = mkExtraBuildCommands cc;
};

lld = callPackage ./lld {};

lldb = callPackage ./lldb {};
Expand Down
10 changes: 9 additions & 1 deletion pkgs/development/compilers/llvm/9/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ lowPrio, newScope, pkgs, lib, stdenv, cmake, gccForLibs
, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapBintoolsWith
, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapCCWithoutLibc, wrapBintoolsWith
, buildLlvmTools # tools, but from the previous stage, for cross
, targetLlvmLibraries # libraries, but from the next stage, for cross
}:
Expand Down Expand Up @@ -83,6 +83,14 @@ let
extraBuildCommands = mkExtraBuildCommands cc;
};

clangNoLibc = wrapCCWithoutLibc rec {
cc = tools.clang-unwrapped;
extraPackages = [
targetLlvmLibraries.compiler-rt
];
extraBuildCommands = mkExtraBuildCommands cc;
};

lld = callPackage ./lld {};

lldb = callPackage ./lldb {};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ lib, appleDerivation }:
{ lib, appleDerivation', stdenvNoCC }:

appleDerivation {
appleDerivation' stdenvNoCC {
dontBuild = true;

installPhase = ''
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ lib, appleDerivation }:
{ lib, appleDerivation', stdenvNoCC }:

appleDerivation {
appleDerivation' stdenvNoCC {
installPhase = ''
mkdir -p $out/include/CommonCrypto
cp include/* $out/include/CommonCrypto
Expand Down
7 changes: 4 additions & 3 deletions pkgs/os-specific/darwin/apple-source-releases/Csu/default.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{ lib, appleDerivation }:
{ lib, appleDerivation', stdenv }:

appleDerivation' stdenv {

appleDerivation {
prePatch = ''
substituteInPlace Makefile \
--replace /usr/lib /lib \
--replace /usr/local/lib /lib \
--replace /usr/bin "" \
--replace /bin/ "" \
--replace "CC = " "CC = cc #" \
--replace "CC = " "CC = ${stdenv.cc.targetPrefix or ""}cc #" \
--replace "SDK_DIR = " "SDK_DIR = . #" \

# Mac OS didn't support rpaths back before 10.5, but we don't care about it.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ lib, appleDerivation, IOKitSrcs, xnu, darwin-stubs }:
{ lib, appleDerivation', stdenv, IOKitSrcs, xnu, darwin-stubs }:

# Someday it'll make sense to split these out into their own packages, but today is not that day.
appleDerivation {
appleDerivation' stdenv {
srcs = lib.attrValues IOKitSrcs;
sourceRoot = ".";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ appleDerivation, ed, unifdef }:
{ appleDerivation', stdenvNoCC, ed, unifdef }:

appleDerivation {
appleDerivation' stdenvNoCC {
nativeBuildInputs = [ ed unifdef ];

installPhase = ''
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ appleDerivation, ed, unifdef, Libc_old, Libc_10-9 }:
{ appleDerivation', stdenvNoCC, ed, unifdef, Libc_old, Libc_10-9 }:

appleDerivation {
appleDerivation' stdenvNoCC {
nativeBuildInputs = [ ed unifdef ];

# TODO: asl.h actually comes from syslog project now
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ appleDerivation }:
{ appleDerivation', stdenvNoCC }:

appleDerivation {
appleDerivation' stdenvNoCC {
installPhase = ''
substituteInPlace xcodescripts/install_files.sh \
--replace "/usr/local/" "/" \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ appleDerivation }:
{ appleDerivation', stdenvNoCC }:

appleDerivation {
appleDerivation' stdenvNoCC {
installPhase = ''
mkdir -p $out/include

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ appleDerivation }:
{ appleDerivation', stdenvNoCC }:

appleDerivation {
appleDerivation' stdenvNoCC {
installPhase = ''
mkdir -p $out/include
cp notify.h $out/include
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{ lib, appleDerivation, cpio, xnu, Libc, Libm, libdispatch, cctools, Libinfo
{ lib, stdenv, buildPackages
, appleDerivation', cpio, xnu, Libc, Libm, libdispatch, Libinfo
, dyld, Csu, architecture, libclosure, CarbonHeaders, ncurses, CommonCrypto
, copyfile, removefile, libresolv, Libnotify, libplatform, libpthread
, mDNSResponder, launchd, libutil, hfs, darling, darwin-stubs }:
, copyfile, removefile, libresolvHeaders, libresolv, Libnotify, libplatform, libpthread
, mDNSResponder, launchd, libutilHeaders, hfsHeaders, darling, darwin-stubs
, headersOnly ? false
, withLibresolv ? !headersOnly
}:

appleDerivation {
appleDerivation' stdenv {
dontBuild = true;
dontFixup = true;

Expand All @@ -21,13 +25,13 @@ appleDerivation {

for dep in ${Libc} ${Libm} ${Libinfo} ${dyld} ${architecture} \
${libclosure} ${CarbonHeaders} ${libdispatch} ${ncurses.dev} \
${CommonCrypto} ${copyfile} ${removefile} ${libresolv} \
${CommonCrypto} ${copyfile} ${removefile} ${libresolvHeaders} \
${Libnotify} ${libplatform} ${mDNSResponder} ${launchd} \
${libutil} ${libpthread} ${hfs}; do
${libutilHeaders} ${libpthread} ${hfsHeaders}; do
(cd $dep/include && find . -name '*.h' | cpio -pdm $out/include)
done

(cd ${cctools.dev}/include/mach-o && find . -name '*.h' | cpio -pdm $out/include/mach-o)
(cd ${buildPackages.darwin.cctools.dev}/include/mach-o && find . -name '*.h' | cpio -pdm $out/include/mach-o)

mkdir -p $out/include/os

Expand Down Expand Up @@ -84,6 +88,7 @@ appleDerivation {
#define TARGET_RT_64_BIT 1
#endif /* __TARGETCONDITIONALS__ */
EOF
'' + lib.optionalString (!headersOnly) ''

# The startup object files
cp ${Csu}/lib/* $out/lib
Expand All @@ -101,14 +106,15 @@ appleDerivation {
for name in c dbm dl info m mx poll proc pthread rpcsvc util gcc_s.10.4 gcc_s.10.5; do
ln -s libSystem.tbd $out/lib/lib$name.tbd
done
'' + lib.optionalString withLibresolv ''

# This probably doesn't belong here, but we want to stay similar to glibc, which includes resolv internally...
cp ${libresolv}/lib/libresolv.9.dylib $out/lib/libresolv.9.dylib
resolv_libSystem=$(otool -L "$out/lib/libresolv.9.dylib" | tail -n +3 | grep -o "$NIX_STORE.*-\S*") || true
resolv_libSystem=$(${stdenv.cc.bintools.targetPrefix}otool -L "$out/lib/libresolv.9.dylib" | tail -n +3 | grep -o "$NIX_STORE.*-\S*") || true
echo $libs

chmod +w $out/lib/libresolv.9.dylib
install_name_tool \
${stdenv.cc.bintools.targetPrefix}install_name_tool \
-id $out/lib/libresolv.9.dylib \
-change "$resolv_libSystem" /usr/lib/libSystem.dylib \
$out/lib/libresolv.9.dylib
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ appleDerivation, darwin-stubs }:
{ appleDerivation', stdenv, darwin-stubs }:

appleDerivation {
appleDerivation' stdenv {
phases = [ "unpackPhase" "installPhase" ];

__propagatedImpureHostDeps = [
Expand Down
Loading