From 0a5dcc9840ee52170fb0eccb5cac819753a0b452 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 16:22:26 +0900 Subject: [PATCH 01/71] gnutar: fix cross compilation on darwin --- pkgs/tools/archivers/gnutar/default.nix | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkgs/tools/archivers/gnutar/default.nix b/pkgs/tools/archivers/gnutar/default.nix index 5f456f92217..fcc92e673a5 100644 --- a/pkgs/tools/archivers/gnutar/default.nix +++ b/pkgs/tools/archivers/gnutar/default.nix @@ -30,9 +30,8 @@ stdenv.mkDerivation rec { outputs = [ "out" "info" ]; - buildInputs = [ ] - ++ lib.optional stdenv.isLinux acl - ++ lib.optional stdenv.isDarwin autoreconfHook; + nativeBuildInputs = lib.optional stdenv.isDarwin autoreconfHook; + buildInputs = lib.optional stdenv.isLinux acl; # May have some issues with root compilation because the bootstrap tool # cannot be used as a login shell for now. From 529346745c0203297084a40ee3a11df5c004b85b Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 16:24:56 +0900 Subject: [PATCH 02/71] openssl: Apple Silicon support --- pkgs/development/libraries/openssl/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/development/libraries/openssl/default.nix b/pkgs/development/libraries/openssl/default.nix index a336dd18fae..2a586f9e9ef 100644 --- a/pkgs/development/libraries/openssl/default.nix +++ b/pkgs/development/libraries/openssl/default.nix @@ -69,6 +69,7 @@ let armv6l-linux = "./Configure linux-armv4 -march=armv6"; armv7l-linux = "./Configure linux-armv4 -march=armv7-a"; x86_64-darwin = "./Configure darwin64-x86_64-cc"; + aarch64-darwin = "./Configure darwin64-arm64-cc"; x86_64-linux = "./Configure linux-x86_64"; x86_64-solaris = "./Configure solaris64-x86_64-gcc"; }.${stdenv.hostPlatform.system} or ( From 4e09c26ea1e6c69f528efafee59bd11ab02153b1 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 16:25:51 +0900 Subject: [PATCH 03/71] openssh: disable kerberos on Apple Silicon --- pkgs/tools/networking/openssh/common.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/tools/networking/openssh/common.nix b/pkgs/tools/networking/openssh/common.nix index 21ad012f3fb..40011a14c89 100644 --- a/pkgs/tools/networking/openssh/common.nix +++ b/pkgs/tools/networking/openssh/common.nix @@ -19,7 +19,7 @@ , pkg-config , pam , etcDir ? null -, withKerberos ? true +, withKerberos ? !(stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) , libkrb5 , libfido2 , nixosTests From 9ad03b1ed9064e8e7a9a94ba00ce7c67473aba12 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 16:28:52 +0900 Subject: [PATCH 04/71] flex: fix cross compilation --- pkgs/development/tools/parsing/flex/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/development/tools/parsing/flex/default.nix b/pkgs/development/tools/parsing/flex/default.nix index 42b007300a9..0bc26db5750 100644 --- a/pkgs/development/tools/parsing/flex/default.nix +++ b/pkgs/development/tools/parsing/flex/default.nix @@ -34,8 +34,8 @@ stdenv.mkDerivation rec { propagatedBuildInputs = [ m4 ]; preConfigure = lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ - "ac_cv_func_malloc_0_nonnull=yes" - "ac_cv_func_realloc_0_nonnull=yes" + "export ac_cv_func_malloc_0_nonnull=yes" + "export ac_cv_func_realloc_0_nonnull=yes" ]; postConfigure = lib.optionalString (stdenv.isDarwin || stdenv.isCygwin) '' From 2931a2e1d519a0ab433854589d3de86573bcd015 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 16:29:47 +0900 Subject: [PATCH 05/71] pbzx: fix cross compilation --- pkgs/tools/compression/pbzx/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/tools/compression/pbzx/default.nix b/pkgs/tools/compression/pbzx/default.nix index 8a57d483ab2..03b984bb643 100644 --- a/pkgs/tools/compression/pbzx/default.nix +++ b/pkgs/tools/compression/pbzx/default.nix @@ -11,7 +11,7 @@ stdenv.mkDerivation rec { }; buildInputs = [ xz xar ]; buildPhase = '' - cc pbzx.c -llzma -lxar -o pbzx + ${stdenv.cc.targetPrefix}cc pbzx.c -llzma -lxar -o pbzx ''; installPhase = '' mkdir -p $out/bin From 1fc0499569a783134f7a2f4aa175a29194a614a5 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 16:30:16 +0900 Subject: [PATCH 06/71] xar: fix cross compilation --- ...dd-useless-descriptions-to-AC_DEFINE.patch | 95 +++++++++++++++++++ .../xar/0002-Use-pkg-config-for-libxml2.patch | 89 +++++++++++++++++ pkgs/tools/compression/xar/default.nix | 14 ++- 3 files changed, 193 insertions(+), 5 deletions(-) create mode 100644 pkgs/tools/compression/xar/0001-Add-useless-descriptions-to-AC_DEFINE.patch create mode 100644 pkgs/tools/compression/xar/0002-Use-pkg-config-for-libxml2.patch diff --git a/pkgs/tools/compression/xar/0001-Add-useless-descriptions-to-AC_DEFINE.patch b/pkgs/tools/compression/xar/0001-Add-useless-descriptions-to-AC_DEFINE.patch new file mode 100644 index 00000000000..a605d2db170 --- /dev/null +++ b/pkgs/tools/compression/xar/0001-Add-useless-descriptions-to-AC_DEFINE.patch @@ -0,0 +1,95 @@ +From a14be07c0aae3bf6f732d1ca5f625ba375702121 Mon Sep 17 00:00:00 2001 +From: Andrew Childs +Date: Sun, 15 Nov 2020 19:12:33 +0900 +Subject: [PATCH 1/2] Add useless descriptions to AC_DEFINE + +Removes autoheader warnings. +--- + configure.ac | 42 +++++++++++++++++++++--------------------- + 1 file changed, 21 insertions(+), 21 deletions(-) + +diff --git a/configure.ac b/configure.ac +index 812b5ff..358ab89 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -210,48 +210,48 @@ AC_CHECK_MEMBERS([struct stat.st_flags]) + + AC_CHECK_SIZEOF(uid_t) + if test $ac_cv_sizeof_uid_t = "4"; then +-AC_DEFINE(UID_STRING, RId32) +-AC_DEFINE(UID_CAST, (uint32_t)) ++AC_DEFINE([UID_STRING], RId32, [UID_STRING]) ++AC_DEFINE([UID_CAST], (uint32_t), [UID_CAST]) + elif test $ac_cv_sizeof_uid_t = "8"; then +-AC_DEFINE(UID_STRING, PRId64) +-AC_DEFINE(UID_CAST, (uint64_t)) ++AC_DEFINE([UID_STRING], PRId64, [UID_STRING]) ++AC_DEFINE([UID_CAST], (uint64_t), [UID_CAST]) + else + AC_ERROR(can not detect the size of your system's uid_t type) + fi + + AC_CHECK_SIZEOF(gid_t) + if test $ac_cv_sizeof_gid_t = "4"; then +-AC_DEFINE(GID_STRING, PRId32) +-AC_DEFINE(GID_CAST, (uint32_t)) ++AC_DEFINE([GID_STRING], PRId32, [GID_STRING]) ++AC_DEFINE([GID_CAST], (uint32_t), [GID_CAST]) + elif test $ac_cv_sizeof_gid_t = "8"; then +-AC_DEFINE(GID_STRING, PRId64) +-AC_DEFINE(GID_CAST, (uint64_t)) ++AC_DEFINE([GID_STRING], PRId64, [GID_STRING]) ++AC_DEFINE([GID_CAST], (uint64_t), [GID_CAST]) + else + AC_ERROR(can not detect the size of your system's gid_t type) + fi + + AC_CHECK_SIZEOF(ino_t) + if test $ac_cv_sizeof_ino_t = "4"; then +-AC_DEFINE(INO_STRING, PRId32) +-AC_DEFINE(INO_HEXSTRING, PRIx32) +-AC_DEFINE(INO_CAST, (uint32_t)) ++AC_DEFINE([INO_STRING], PRId32, [INO_STRING]) ++AC_DEFINE([INO_HEXSTRING], PRIx32, [INO_HEXSTRING]) ++AC_DEFINE([INO_CAST], (uint32_t), [INO_CAST]) + elif test $ac_cv_sizeof_ino_t = "8"; then +-AC_DEFINE(INO_STRING, PRId64) +-AC_DEFINE(INO_HEXSTRING, PRIx64) +-AC_DEFINE(INO_CAST, (uint64_t)) ++AC_DEFINE([INO_STRING], PRId64, [INO_STRING]) ++AC_DEFINE([INO_HEXSTRING], PRIx64, [INO_HEXSTRING]) ++AC_DEFINE([INO_CAST], (uint64_t), [INO_CAST]) + else + AC_ERROR(can not detect the size of your system's ino_t type) + fi + + AC_CHECK_SIZEOF(dev_t) + if test $ac_cv_sizeof_dev_t = "4"; then +-AC_DEFINE(DEV_STRING, PRId32) +-AC_DEFINE(DEV_HEXSTRING, PRIx32) +-AC_DEFINE(DEV_CAST, (uint32_t)) ++AC_DEFINE([DEV_STRING], PRId32, [DEV_STRING]) ++AC_DEFINE([DEV_HEXSTRING], PRIx32, [DEV_HEXSTRING]) ++AC_DEFINE([DEV_CAST], (uint32_t), [DEV_CAST]) + elif test $ac_cv_sizeof_dev_t = "8"; then +-AC_DEFINE(DEV_STRING, PRId64) +-AC_DEFINE(DEV_HEXSTRING, PRIx64) +-AC_DEFINE(DEV_CAST, (uint64_t)) ++AC_DEFINE([DEV_STRING], PRId64, [DEV_STRING]) ++AC_DEFINE([DEV_HEXSTRING], PRIx64, [DEV_HEXSTRING]) ++AC_DEFINE([DEV_CAST], (uint64_t), [DEV_CAST]) + else + AC_ERROR(can not detect the size of your system's dev_t type) + fi +@@ -261,7 +261,7 @@ AC_CHECK_LIB(acl, acl_get_file) + dnl Check for paths + AC_PREFIX_DEFAULT(/usr/local) + +-AC_CHECK_FUNC([asprintf], AC_DEFINE([HAVE_ASPRINTF])) ++AC_CHECK_FUNC([asprintf], AC_DEFINE([HAVE_ASPRINTF], [], [HAVE_ASPRINTF])) + + dnl + dnl Configure libxml2. +-- +2.28.0 + diff --git a/pkgs/tools/compression/xar/0002-Use-pkg-config-for-libxml2.patch b/pkgs/tools/compression/xar/0002-Use-pkg-config-for-libxml2.patch new file mode 100644 index 00000000000..d71ad4b753c --- /dev/null +++ b/pkgs/tools/compression/xar/0002-Use-pkg-config-for-libxml2.patch @@ -0,0 +1,89 @@ +From 276833851657c85651c053ee16b8e1a8dc768a50 Mon Sep 17 00:00:00 2001 +From: Andrew Childs +Date: Sun, 15 Nov 2020 19:12:56 +0900 +Subject: [PATCH 2/2] Use pkg-config for libxml2 + +--- + configure.ac | 66 +++++++++------------------------------------------- + 1 file changed, 11 insertions(+), 55 deletions(-) + +diff --git a/configure.ac b/configure.ac +index 358ab89..984a694 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -268,61 +268,17 @@ dnl Configure libxml2. + dnl + LIBXML2_VERSION_MIN=2.6.11 + +-have_libxml2="1" +- +-AC_ARG_WITH([xml2-config], [ --with-xml2-config libxml2 config program], +-if test "x${with_xml2_config}" = "xno" ; then +- XML2_CONFIG= +-else +- XML2_CONFIG="${with_xml2_config}" +-fi +-, +- XML2_CONFIG= +-) +-if test "x${XML2_CONFIG}" != "x" ; then +- if test ! -x "${XML2_CONFIG}" ; then +- AC_MSG_ERROR([Unusable or missing xml2-config: ${XML2_CONFIG}]) +- fi +-else +- AC_PATH_PROG([XML2_CONFIG], [xml2-config], , [${PATH}]) +- if test "x${XML2_CONFIG}" = "x" ; then +- AC_MSG_ERROR([Cannot configure without xml2-config]) +- fi +-fi +- +-dnl Make sure the version of libxml2 found is sufficient. +-AC_MSG_CHECKING([for libxml >= ${LIBXML2_VERSION_MIN}]) +-LIBXML2_FOUND=`2>&1 ${XML2_CONFIG} --version` +-LIBXML2_MAJOR=`echo ${LIBXML2_FOUND} | tr . " " | awk '{print $1}'` +-LIBXML2_MINOR=`echo ${LIBXML2_FOUND} | tr . " " | awk '{print $2}' | tr a-z " " |awk '{print $1}'` +-LIBXML2_BRANCH=`echo ${LIBXML2_FOUND} | tr . " " | awk '{print $3}' | tr a-z " " |awk '{print $1}'` +-if test "x${LIBXML2_BRANCH}" = "x" ; then +- LIBXML2_BRANCH=0 +-fi +-LIBXML2_MAJOR_MIN=`echo ${LIBXML2_VERSION_MIN} | tr . " " | awk '{print $1}'` +-LIBXML2_MINOR_MIN=`echo ${LIBXML2_VERSION_MIN} | tr . " " | awk '{print $2}'` +-LIBXML2_BRANCH_MIN=`echo ${LIBXML2_VERSION_MIN} | tr . " " | awk '{print $3}'` +-if test ${LIBXML2_MAJOR} -gt ${LIBXML2_MAJOR_MIN} \ +- -o ${LIBXML2_MAJOR} -eq ${LIBXML2_MAJOR_MIN} \ +- -a ${LIBXML2_MINOR} -gt ${LIBXML2_MINOR_MIN} \ +- -o ${LIBXML2_MAJOR} -eq ${LIBXML2_MAJOR_MIN} \ +- -a ${LIBXML2_MINOR} -eq ${LIBXML2_MINOR_MIN} \ +- -a ${LIBXML2_BRANCH} -ge $LIBXML2_BRANCH_MIN ; then +- AC_MSG_RESULT([${LIBXML2_MAJOR}.${LIBXML2_MINOR}.${LIBXML2_BRANCH}]) +- have_libxml2="1" +- CPPFLAGS="${CPPFLAGS} `${XML2_CONFIG} --cflags`" +- LIBS="${LIBS} `${XML2_CONFIG} --libs`" +-else +- AC_MSG_RESULT([no]) +- have_libxml2="0" +-fi +-if test "x${have_libxml2}" = "x1" ; then +- dnl Final sanity check, to make sure that xmlwriter is present. +- AC_CHECK_HEADER([libxml/xmlwriter.h], , [have_libxml2="0"]) +-fi +-if test "x${have_libxml2}" = "x0" ; then +- AC_MSG_ERROR([Cannot build without libxml2]) +-fi ++PKG_PROG_PKG_CONFIG ++ ++PKG_CHECK_MODULES(LIBXML2_PKGCONFIG, [libxml-2.0 >= ${LIBXML2_VERSION_MIN}], ++ [ ++ have_libxml2=1 ++ CPPFLAGS="${CPPFLAGS} ${LIBXML2_PKGCONFIG_CFLAGS}" ++ LIBS="${LIBS} ${LIBXML2_PKGCONFIG_LIBS}" ++ ], ++ [ ++ have_libxml2=0 ++ ]) + + dnl + dnl Configure libcrypto (part of OpenSSL). +-- +2.28.0 + diff --git a/pkgs/tools/compression/xar/default.nix b/pkgs/tools/compression/xar/default.nix index 32b6c6d005c..d4baab17b91 100644 --- a/pkgs/tools/compression/xar/default.nix +++ b/pkgs/tools/compression/xar/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, fetchurl, libxml2, xz, openssl, zlib, bzip2, fts, autoconf }: +{ lib, stdenv, fetchurl, pkg-config, libxml2, xz, openssl, zlib, bzip2, fts, autoreconfHook }: stdenv.mkDerivation rec { version = "1.6.1"; @@ -9,16 +9,20 @@ stdenv.mkDerivation rec { sha256 = "0ghmsbs6xwg1092v7pjcibmk5wkyifwxw6ygp08gfz25d2chhipf"; }; - buildInputs = [ libxml2 xz openssl zlib bzip2 fts autoconf ]; + nativeBuildInputs = [ autoreconfHook pkg-config ]; + buildInputs = [ libxml2 xz openssl zlib bzip2 fts ]; - prePatch = '' + patches = [ + ./0001-Add-useless-descriptions-to-AC_DEFINE.patch + ./0002-Use-pkg-config-for-libxml2.patch + ]; + + postPatch = '' substituteInPlace configure.ac \ --replace 'OpenSSL_add_all_ciphers' 'OPENSSL_init_crypto' \ --replace 'openssl/evp.h' 'openssl/crypto.h' ''; - preConfigure = "./autogen.sh"; - meta = { homepage = "https://mackyle.github.io/xar/"; description = "Extensible Archiver"; From 9088e445fe3ae2920318805b40c0909ce33ecf53 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Wed, 25 Nov 2020 13:56:19 +0900 Subject: [PATCH 07/71] glib: fix build It's not clear why this is required, but glib includes CoreServices headers and calls CoreServices functions, so it's reasonable to link against the framework explicitly. --- pkgs/development/libraries/glib/default.nix | 1 + .../libraries/glib/link-with-coreservices.patch | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 pkgs/development/libraries/glib/link-with-coreservices.patch diff --git a/pkgs/development/libraries/glib/default.nix b/pkgs/development/libraries/glib/default.nix index adaca105df0..e15f5975786 100644 --- a/pkgs/development/libraries/glib/default.nix +++ b/pkgs/development/libraries/glib/default.nix @@ -54,6 +54,7 @@ stdenv.mkDerivation rec { patches = optionals stdenv.isDarwin [ ./darwin-compilation.patch + ./link-with-coreservices.patch ] ++ optionals stdenv.hostPlatform.isMusl [ ./quark_init_on_demand.patch ./gobject_init_on_demand.patch diff --git a/pkgs/development/libraries/glib/link-with-coreservices.patch b/pkgs/development/libraries/glib/link-with-coreservices.patch new file mode 100644 index 00000000000..dcc0a8998cc --- /dev/null +++ b/pkgs/development/libraries/glib/link-with-coreservices.patch @@ -0,0 +1,11 @@ +--- a/meson.build.orig 2020-11-25 13:47:38.499149252 +0900 ++++ b/meson.build 2020-11-25 13:48:47.098444800 +0900 +@@ -742,7 +742,7 @@ + + if glib_have_carbon + glib_conf.set('HAVE_CARBON', true) +- osx_ldflags += '-Wl,-framework,Carbon' ++ osx_ldflags += ['-Wl,-framework,Carbon', '-Wl,-framework,CoreServices'] + glib_have_os_x_9_or_later = objcc.compiles('''#include + #if MAC_OS_X_VERSION_MIN_REQUIRED < 1090 + #error Compiling for minimum OS X version before 10.9 From 24a378c070a1cebf63b2308f4ede6bdaf1126487 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 16:36:36 +0900 Subject: [PATCH 08/71] zlib: fix cross compilation on darwin --- pkgs/development/libraries/zlib/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/development/libraries/zlib/default.nix b/pkgs/development/libraries/zlib/default.nix index 998550d1fee..a9fadf46c4b 100644 --- a/pkgs/development/libraries/zlib/default.nix +++ b/pkgs/development/libraries/zlib/default.nix @@ -37,8 +37,8 @@ stdenv.mkDerivation (rec { postPatch = lib.optionalString stdenv.hostPlatform.isDarwin '' substituteInPlace configure \ - --replace '/usr/bin/libtool' 'ar' \ - --replace 'AR="libtool"' 'AR="ar"' \ + --replace '/usr/bin/libtool' '${stdenv.cc.targetPrefix}ar' \ + --replace 'AR="libtool"' 'AR="${stdenv.cc.targetPrefix}ar"' \ --replace 'ARFLAGS="-o"' 'ARFLAGS="-r"' ''; From aa3361326b8823e5726df90b495d96772b3c0702 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 17:16:34 +0900 Subject: [PATCH 09/71] darwin.adv_cmds: fix cross compilation --- .../darwin/apple-source-releases/adv_cmds/boot.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkgs/os-specific/darwin/apple-source-releases/adv_cmds/boot.nix b/pkgs/os-specific/darwin/apple-source-releases/adv_cmds/boot.nix index b4c28e23c14..2ca2d061591 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/adv_cmds/boot.nix +++ b/pkgs/os-specific/darwin/apple-source-releases/adv_cmds/boot.nix @@ -1,4 +1,4 @@ -{ lib, appleDerivation, fetchzip, bsdmake, perl, flex, bison +{ lib, stdenv, buildPackages, appleDerivation, fetchzip, bsdmake, perl, flex, bison }: # this derivation sucks @@ -16,6 +16,7 @@ let recentAdvCmds = fetchzip { }; in appleDerivation { + depsBuildBuild = [ buildPackages.stdenv.cc ]; nativeBuildInputs = [ bsdmake perl bison flex ]; buildInputs = [ flex ]; @@ -61,7 +62,7 @@ in appleDerivation { bsdmake -C usr-share-locale.tproj - clang ${recentAdvCmds}/ps/*.c -o ps + ${stdenv.cc.targetPrefix}clang ${recentAdvCmds}/ps/*.c -o ps ''; installPhase = '' From cbe172fa678615c903dce18dd8680c1cc2038cd8 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 17:21:44 +0900 Subject: [PATCH 10/71] darwin.ICU: cross compilation --- .../apple-source-releases/ICU/default.nix | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/pkgs/os-specific/darwin/apple-source-releases/ICU/default.nix b/pkgs/os-specific/darwin/apple-source-releases/ICU/default.nix index 032b1447463..f2dd63cf2de 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/ICU/default.nix +++ b/pkgs/os-specific/darwin/apple-source-releases/ICU/default.nix @@ -1,8 +1,20 @@ -{ appleDerivation, python3 }: +{ appleDerivation, lib, stdenv, buildPackages, python3 }: + +let + formatVersionNumeric = version: + let + versionParts = lib.versions.splitVersion version; + major = lib.toInt (lib.elemAt versionParts 0); + minor = lib.toInt (lib.elemAt versionParts 1); + patch = if lib.length versionParts > 2 then lib.toInt (lib.elemAt versionParts 2) else 0; + in toString (major * 10000 + minor * 100 + patch); +in appleDerivation { nativeBuildInputs = [ python3 ]; + depsBuildBuild = lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) [ buildPackages.stdenv.cc ]; + postPatch = '' substituteInPlace makefile \ --replace "/usr/bin/" "" \ @@ -26,6 +38,13 @@ appleDerivation { --replace "&TestMailFilterCSS" "NULL" patchShebangs icuSources + '' + lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' + + # This looks like a bug in the makefile. It defines ENV_BUILDHOST to + # propagate the correct value of CC, CXX, etc, but has the following double + # expansion that results in the empty string. + substituteInPlace makefile \ + --replace '$($(ENV_BUILDHOST))' '$(ENV_BUILDHOST)' ''; # APPLE is using makefile to save its default configuration and call ./configure, so we hack makeFlags @@ -42,8 +61,19 @@ appleDerivation { "DATA_LOOKUP_DIR=$(DSTROOT)$(DATA_INSTALL_DIR)" # hack to use our lower macos version - "MAC_OS_X_VERSION_MIN_REQUIRED=__MAC_OS_X_VERSION_MIN_REQUIRED" - "OSX_HOST_VERSION_MIN_STRING=$(MACOSX_DEPLOYMENT_TARGET)" + "MAC_OS_X_VERSION_MIN_REQUIRED=${formatVersionNumeric stdenv.hostPlatform.darwinMinVersion}" + "ICU_TARGET_VERSION=-m${stdenv.hostPlatform.darwinPlatform}-version-min=${stdenv.hostPlatform.darwinMinVersion}" + ] + ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ + "CROSS_BUILD=YES" + "BUILD_TYPE=" + "RC_ARCHS=${stdenv.hostPlatform.darwinArch}" + "HOSTCC=cc" + "HOSTCXX=c++" + "CC=${stdenv.cc.targetPrefix}cc" + "CXX=${stdenv.cc.targetPrefix}c++" + "HOSTISYSROOT=" + "OSX_HOST_VERSION_MIN_STRING=${stdenv.buildPlatform.darwinMinVersion}" ]; doCheck = true; From 8e33b341a3093bad5abcf41ef891f7f13518a0db Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 16:37:26 +0900 Subject: [PATCH 11/71] pcre: disable jit on Apple Silicon --- pkgs/development/libraries/pcre/default.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/development/libraries/pcre/default.nix b/pkgs/development/libraries/pcre/default.nix index 8d9b9ec0259..c91d4e2bd0c 100644 --- a/pkgs/development/libraries/pcre/default.nix +++ b/pkgs/development/libraries/pcre/default.nix @@ -23,7 +23,8 @@ in stdenv.mkDerivation { outputs = [ "bin" "dev" "out" "doc" "man" ]; - configureFlags = optional (!stdenv.hostPlatform.isRiscV) "--enable-jit" ++ [ + # Disable jit on Apple Silicon, https://github.com/zherczeg/sljit/issues/51 + configureFlags = optional (!stdenv.hostPlatform.isRiscV && !(stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64)) "--enable-jit" ++ [ "--enable-unicode-properties" "--disable-cpp" ] From 48a1e1cb2259dbed06293dff9c9a1861168c3261 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Sat, 28 Nov 2020 14:45:35 +0900 Subject: [PATCH 12/71] pcre2: disable jit on Apple Silicon --- pkgs/development/libraries/pcre2/default.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/development/libraries/pcre2/default.nix b/pkgs/development/libraries/pcre2/default.nix index 6bf6cff98bb..188fa9b16b7 100644 --- a/pkgs/development/libraries/pcre2/default.nix +++ b/pkgs/development/libraries/pcre2/default.nix @@ -8,10 +8,11 @@ stdenv.mkDerivation rec { sha256 = "0p3699msps07p40g9426lvxa3b41rg7k2fn7qxl2jm0kh4kkkvx9"; }; + # Disable jit on Apple Silicon, https://github.com/zherczeg/sljit/issues/51 configureFlags = [ "--enable-pcre2-16" "--enable-pcre2-32" - ] ++ lib.optional (!stdenv.hostPlatform.isRiscV) "--enable-jit"; + ] ++ lib.optional (!stdenv.hostPlatform.isRiscV && !(stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64)) "--enable-jit"; outputs = [ "bin" "dev" "out" "doc" "man" "devdoc" ]; From c9af80e44aa020e6a34469b74ab38dd134883d47 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Fri, 27 Nov 2020 13:27:02 +0900 Subject: [PATCH 13/71] fontconfig: backport atomics fixes for aarch64-darwin --- .../libraries/fontconfig/default.nix | 5 +++ .../libraries/fontconfig/macos-atomics.h | 39 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 pkgs/development/libraries/fontconfig/macos-atomics.h diff --git a/pkgs/development/libraries/fontconfig/default.nix b/pkgs/development/libraries/fontconfig/default.nix index 5eb180731f3..c0846edbbfe 100644 --- a/pkgs/development/libraries/fontconfig/default.nix +++ b/pkgs/development/libraries/fontconfig/default.nix @@ -61,6 +61,11 @@ stdenv.mkDerivation rec { url = "https://gitlab.freedesktop.org/fontconfig/fontconfig/commit/409b37c62780728755c908991c912a6b16f2389c.patch"; sha256 = "zJFh37QErSAINPGFkFVJyhYRP27BuIN7PIgoDl/PIwI="; }) + + # Combination of + # https://gitlab.freedesktop.org/fontconfig/fontconfig/-/merge_requests/88 + # https://gitlab.freedesktop.org/fontconfig/fontconfig/-/merge_requests/131 + ./macos-atomics.h ]; outputs = [ "bin" "dev" "lib" "out" ]; # $out contains all the config diff --git a/pkgs/development/libraries/fontconfig/macos-atomics.h b/pkgs/development/libraries/fontconfig/macos-atomics.h new file mode 100644 index 00000000000..07b0cf1d52d --- /dev/null +++ b/pkgs/development/libraries/fontconfig/macos-atomics.h @@ -0,0 +1,39 @@ +--- a/src/fcatomic.h 2020-11-27 13:23:44.000000000 +0900 ++++ b/src/fcatomic.h 2020-11-27 13:24:43.000000000 +0900 +@@ -70,24 +70,25 @@ + #elif !defined(FC_NO_MT) && defined(__APPLE__) + + #include +-#ifdef __MAC_OS_X_MIN_REQUIRED + #include +-#elif defined(__IPHONE_OS_MIN_REQUIRED) +-#include +-#endif + + typedef int fc_atomic_int_t; + #define fc_atomic_int_add(AI, V) (OSAtomicAdd32Barrier ((V), &(AI)) - (V)) + +-#define fc_atomic_ptr_get(P) (OSMemoryBarrier (), (void *) *(P)) +-#if (MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4 || __IPHONE_VERSION_MIN_REQUIRED >= 20100) +-#define fc_atomic_ptr_cmpexch(P,O,N) OSAtomicCompareAndSwapPtrBarrier ((void *) (O), (void *) (N), (void **) (P)) +-#else +-#if __ppc64__ || __x86_64__ +-#define fc_atomic_ptr_cmpexch(P,O,N) OSAtomicCompareAndSwap64Barrier ((int64_t) (O), (int64_t) (N), (int64_t*) (P)) ++#if (MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4 || __IPHONE_OS_VERSION_MIN_REQUIRED >= 20100) ++ ++#if SIZEOF_VOID_P == 8 ++#define fc_atomic_ptr_get(P) OSAtomicAdd64Barrier (0, (int64_t*)(P)) ++#elif SIZEOF_VOID_P == 4 ++#define fc_atomic_ptr_get(P) OSAtomicAdd32Barrier (0, (int32_t*)(P)) + #else +-#define fc_atomic_ptr_cmpexch(P,O,N) OSAtomicCompareAndSwap32Barrier ((int32_t) (O), (int32_t) (N), (int32_t*) (P)) ++#error "SIZEOF_VOID_P not 4 or 8 (assumes CHAR_BIT is 8)" + #endif ++ ++#define fc_atomic_ptr_cmpexch(P,O,N) OSAtomicCompareAndSwapPtrBarrier ((void *) (O), (void *) (N), (void **) (P)) ++ ++#else ++#error "Your macOS / iOS targets are too old" + #endif + + #elif !defined(FC_NO_MT) && defined(HAVE_INTEL_ATOMIC_PRIMITIVES) From 5ed7e55167aef1f1a856af8bcc597f896d572bbe Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 16:37:54 +0900 Subject: [PATCH 14/71] groff: fix build with clang >= 9 --- pkgs/tools/text/groff/default.nix | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkgs/tools/text/groff/default.nix b/pkgs/tools/text/groff/default.nix index 892aeb463f8..5b158f2cbb0 100644 --- a/pkgs/tools/text/groff/default.nix +++ b/pkgs/tools/text/groff/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, fetchurl, perl +{ lib, stdenv, fetchurl, fetchpatch, perl , ghostscript #for postscript and html output , psutils, netpbm #for html output , buildPackages @@ -22,6 +22,13 @@ stdenv.mkDerivation rec { patches = [ ./0001-Fix-cross-compilation-by-looking-for-ar.patch + ] + ++ lib.optionals (stdenv.cc.isClang && lib.versionAtLeast stdenv.cc.version "9") [ + # https://trac.macports.org/ticket/59783 + (fetchpatch { + url = "https://raw.githubusercontent.com/openembedded/openembedded-core/ce265cf467f1c3e5ba2edbfbef2170df1a727a52/meta/recipes-extended/groff/files/0001-Include-config.h.patch"; + sha256 = "1b0mg31xkpxkzlx696nr08rcc7ndpaxdplvysy0hw5099c4n1wyf"; + }) ]; postPatch = lib.optionalString (psutils != null) '' From e44dd84664f7723ed393e1c4e7e9b9fc95b1cc16 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 18 Feb 2021 13:38:19 +0900 Subject: [PATCH 15/71] libtool2: macOS 11 support --- .../tools/misc/libtool/libtool2-macos11.patch | 32 +++++++++++++++++++ .../tools/misc/libtool/libtool2.nix | 23 +++++++++++-- 2 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 pkgs/development/tools/misc/libtool/libtool2-macos11.patch diff --git a/pkgs/development/tools/misc/libtool/libtool2-macos11.patch b/pkgs/development/tools/misc/libtool/libtool2-macos11.patch new file mode 100644 index 00000000000..1552ae7a949 --- /dev/null +++ b/pkgs/development/tools/misc/libtool/libtool2-macos11.patch @@ -0,0 +1,32 @@ +Signed-off-by: Jeremy Huddleston Sequoia +--- + m4/libtool.m4 | 13 ++++--------- + 1 file changed, 4 insertions(+), 9 deletions(-) + +diff --git a/m4/libtool.m4 b/m4/libtool.m4 +index f2d1f398..b971e8e7 100644 +--- a/m4/libtool.m4 ++++ b/m4/libtool.m4 +@@ -1067,16 +1067,11 @@ _LT_EOF + _lt_dar_allow_undefined='$wl-undefined ${wl}suppress' ;; + darwin1.*) + _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;; +- darwin*) # darwin 5.x on +- # if running on 10.5 or later, the deployment target defaults +- # to the OS version, if on x86, and 10.4, the deployment +- # target defaults to 10.4. Don't you love it? +- case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in +- 10.0,*86*-darwin8*|10.0,*-darwin[[91]]*) +- _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;; +- 10.[[012]][[,.]]*) ++ darwin*) ++ case ${MACOSX_DEPLOYMENT_TARGET},$host in ++ 10.[[012]],*|,*powerpc*) + _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;; +- 10.*) ++ *) + _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;; + esac + ;; +-- +2.24.3 (Apple Git-128) diff --git a/pkgs/development/tools/misc/libtool/libtool2.nix b/pkgs/development/tools/misc/libtool/libtool2.nix index 6d7c4a9087f..89018027e6e 100644 --- a/pkgs/development/tools/misc/libtool/libtool2.nix +++ b/pkgs/development/tools/misc/libtool/libtool2.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, fetchurl, m4, perl, help2man +{ lib, stdenv, fetchurl, fetchpatch, autoconf, automake, m4, perl, help2man }: stdenv.mkDerivation rec { @@ -12,7 +12,26 @@ stdenv.mkDerivation rec { outputs = [ "out" "lib" ]; - nativeBuildInputs = [ perl help2man m4 ]; + patches = [ + # Suport macOS version 11.0 + # https://lists.gnu.org/archive/html/libtool-patches/2020-06/msg00001.html + ./libtool2-macos11.patch + ]; + + # Normally we'd use autoreconfHook, but that includes libtoolize. + postPatch = '' + aclocal -I m4 + automake + autoconf + + pushd libltdl + aclocal -I ../m4 + automake + autoconf + popd + ''; + + nativeBuildInputs = [ perl help2man m4 ] ++ [ autoconf automake ]; propagatedBuildInputs = [ m4 ]; # Don't fixup "#! /bin/sh" in Libtool, otherwise it will use the From bd4a45f5d44c470c2646d15ae73c70eb1579ea77 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 16:39:27 +0900 Subject: [PATCH 16/71] cctools: drop suspicious dependency --- pkgs/os-specific/darwin/cctools/port.nix | 4 ++-- pkgs/top-level/darwin-packages.nix | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pkgs/os-specific/darwin/cctools/port.nix b/pkgs/os-specific/darwin/cctools/port.nix index 50e0a2eb3fb..bace6f0689d 100644 --- a/pkgs/os-specific/darwin/cctools/port.nix +++ b/pkgs/os-specific/darwin/cctools/port.nix @@ -1,6 +1,6 @@ { lib, stdenv, fetchFromGitHub, autoconf, automake, libtool, autoreconfHook , installShellFiles -, libcxxabi, libuuid +, libuuid , libobjc ? null, maloader ? null , enableTapiSupport ? true, libtapi }: @@ -32,7 +32,7 @@ stdenv.mkDerivation { nativeBuildInputs = [ autoconf automake libtool autoreconfHook installShellFiles ]; buildInputs = [ libuuid ] - ++ lib.optionals stdenv.isDarwin [ libcxxabi libobjc ] + ++ lib.optionals stdenv.isDarwin [ libobjc ] ++ lib.optional enableTapiSupport libtapi; patches = [ ./ld-ignore-rpath-link.patch ./ld-rpath-nonfinal.patch ]; diff --git a/pkgs/top-level/darwin-packages.nix b/pkgs/top-level/darwin-packages.nix index 2af799e5646..0209af4455a 100644 --- a/pkgs/top-level/darwin-packages.nix +++ b/pkgs/top-level/darwin-packages.nix @@ -59,7 +59,6 @@ impure-cmds // apple-source-releases // { cctools = callPackage ../os-specific/darwin/cctools/port.nix { stdenv = if stdenv.isDarwin then stdenv else pkgs.libcxxStdenv; - libcxxabi = pkgs.libcxxabi; }; # TODO: remove alias. From 314c92c5428d7e05df435490ed34e59dcc08112f Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 16:41:58 +0900 Subject: [PATCH 17/71] curl: disable gssSupport for Apple Silicon --- pkgs/tools/networking/curl/default.nix | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkgs/tools/networking/curl/default.nix b/pkgs/tools/networking/curl/default.nix index f73ab773876..05b91bfba05 100644 --- a/pkgs/tools/networking/curl/default.nix +++ b/pkgs/tools/networking/curl/default.nix @@ -7,8 +7,15 @@ , gnutlsSupport ? false, gnutls ? null , wolfsslSupport ? false, wolfssl ? null , scpSupport ? zlibSupport && !stdenv.isSunOS && !stdenv.isCygwin, libssh2 ? null -, # a very sad story re static: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=439039 - gssSupport ? with stdenv.hostPlatform; !isWindows && !isStatic, libkrb5 ? null +, gssSupport ? with stdenv.hostPlatform; !( + !isWindows && + # a very sad story re static: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=439039 + !isStatic && + # the "mig" tool does not configure its compiler correctly. This could be + # fixed in mig, but losing gss support on cross compilation to darwin is + # not worth the effort. + !(isDarwin && (stdenv.buildPlatform != stdenv.hostPlatform)) + ), libkrb5 ? null , c-aresSupport ? false, c-ares ? null , brotliSupport ? false, brotli ? null }: From 1182552332a0f0a312c6c73ce958cee342de3c2b Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 16:43:15 +0900 Subject: [PATCH 18/71] gmp: disable assembly on Apple Silicon --- pkgs/development/libraries/gmp/6.x.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/libraries/gmp/6.x.nix b/pkgs/development/libraries/gmp/6.x.nix index bf03bf08779..177c1567052 100644 --- a/pkgs/development/libraries/gmp/6.x.nix +++ b/pkgs/development/libraries/gmp/6.x.nix @@ -46,7 +46,7 @@ let self = stdenv.mkDerivation rec { # to build a .dll on windows, we need --disable-static + --enable-shared # see https://gmplib.org/manual/Notes-for-Particular-Systems.html ++ optional (!withStatic && stdenv.hostPlatform.isWindows) "--disable-static --enable-shared" - ; + ++ optional (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) "--disable-assembly"; doCheck = true; # not cross; From 257cb1c8e8db768f1a32245d388c46d7c6e60c6a Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 16:48:10 +0900 Subject: [PATCH 19/71] print-reexports: rehome, tbd4 support, cross compilation --- .../print-reexports/default.nix | 4 +- .../{apple-sdk => }/print-reexports/main.c | 81 +++++++++++++++++-- .../darwin/print-reexports/setup-hook.sh | 19 +++++ pkgs/top-level/darwin-packages.nix | 6 +- 4 files changed, 99 insertions(+), 11 deletions(-) rename pkgs/os-specific/darwin/{apple-sdk => }/print-reexports/default.nix (75%) rename pkgs/os-specific/darwin/{apple-sdk => }/print-reexports/main.c (64%) create mode 100644 pkgs/os-specific/darwin/print-reexports/setup-hook.sh diff --git a/pkgs/os-specific/darwin/apple-sdk/print-reexports/default.nix b/pkgs/os-specific/darwin/print-reexports/default.nix similarity index 75% rename from pkgs/os-specific/darwin/apple-sdk/print-reexports/default.nix rename to pkgs/os-specific/darwin/print-reexports/default.nix index a548d8da753..740bcb48ef5 100644 --- a/pkgs/os-specific/darwin/apple-sdk/print-reexports/default.nix +++ b/pkgs/os-specific/darwin/print-reexports/default.nix @@ -7,11 +7,11 @@ stdenv.mkDerivation { buildInputs = [ libyaml ]; buildPhase = '' - $CC -lyaml -o $name main.c + $CC -lyaml -o print-reexports main.c ''; installPhase = '' mkdir -p $out/bin - mv $name $out/bin + mv print-reexports $out/bin ''; } diff --git a/pkgs/os-specific/darwin/apple-sdk/print-reexports/main.c b/pkgs/os-specific/darwin/print-reexports/main.c similarity index 64% rename from pkgs/os-specific/darwin/apple-sdk/print-reexports/main.c rename to pkgs/os-specific/darwin/print-reexports/main.c index df46e3f18e8..e6ff527da96 100644 --- a/pkgs/os-specific/darwin/apple-sdk/print-reexports/main.c +++ b/pkgs/os-specific/darwin/print-reexports/main.c @@ -21,6 +21,10 @@ #include #include +#define LOG(str, ...) fprintf(stderr, "%s", str) + +#define LOGF(...) fprintf(stderr, __VA_ARGS__) + static yaml_node_t *get_mapping_entry(yaml_document_t *document, yaml_node_t *mapping, const char *name) { if (!mapping) { fprintf(stderr, "get_mapping_entry: mapping is null\n"); @@ -35,12 +39,12 @@ static yaml_node_t *get_mapping_entry(yaml_document_t *document, yaml_node_t *ma yaml_node_t *key = yaml_document_get_node(document, pair->key); if (!key) { - fprintf(stderr, "get_mapping_entry: key (%i) is null\n", pair->key); + LOGF("key (%d) is null\n", pair->key); return NULL; } if (key->type != YAML_SCALAR_NODE) { - fprintf(stderr, "get_mapping_entry: key is not a scalar\n"); + LOG("get_mapping_entry: key is not a scalar\n"); return NULL; } @@ -54,18 +58,17 @@ static yaml_node_t *get_mapping_entry(yaml_document_t *document, yaml_node_t *ma return NULL; } -static int emit_reexports(yaml_document_t *document) { +static int emit_reexports_v2(yaml_document_t *document) { yaml_node_t *root = yaml_document_get_root_node(document); yaml_node_t *exports = get_mapping_entry(document, root, "exports"); if (!exports) { - fprintf(stderr, "emit_reexports: no exports found\n"); - return 0; + return 1; } if (exports->type != YAML_SEQUENCE_NODE) { - fprintf(stderr, "emit_reexports, value is not a sequence\n"); + LOG("value is not a sequence\n"); return 0; } @@ -82,6 +85,11 @@ static int emit_reexports(yaml_document_t *document) { continue; } + if (reexports->type != YAML_SEQUENCE_NODE) { + LOG("re-exports is not a sequence\n"); + return 0; + } + for ( yaml_node_item_t *reexport = reexports->data.sequence.items.start; reexport < reexports->data.sequence.items.top; @@ -90,7 +98,58 @@ static int emit_reexports(yaml_document_t *document) { yaml_node_t *val = yaml_document_get_node(document, *reexport); if (val->type != YAML_SCALAR_NODE) { - fprintf(stderr, "item is not a scalar\n"); + LOG("item is not a scalar\n"); + return 0; + } + + fwrite(val->data.scalar.value, val->data.scalar.length, 1, stdout); + putchar('\n'); + } + } + + return 1; +} + +static int emit_reexports_v4(yaml_document_t *document) { + yaml_node_t *root = yaml_document_get_root_node(document); + yaml_node_t *reexports = get_mapping_entry(document, root, "reexported-libraries"); + + if (!reexports) { + return 1; + } + + if (reexports->type != YAML_SEQUENCE_NODE) { + LOG("value is not a sequence\n"); + return 0; + } + + for ( + yaml_node_item_t *entry = reexports->data.sequence.items.start; + entry < reexports->data.sequence.items.top; + ++entry + ) { + yaml_node_t *entry_node = yaml_document_get_node(document, *entry); + + yaml_node_t *libs = get_mapping_entry(document, entry_node, "libraries"); + + if (!libs) { + continue; + } + + if (libs->type != YAML_SEQUENCE_NODE) { + LOG("libraries is not a sequence\n"); + return 0; + } + + for ( + yaml_node_item_t *lib = libs->data.sequence.items.start; + lib < libs->data.sequence.items.top; + ++lib + ) { + yaml_node_t *val = yaml_document_get_node(document, *lib); + + if (val->type != YAML_SCALAR_NODE) { + LOG("item is not a scalar\n"); return 0; } @@ -135,7 +194,13 @@ int main(int argc, char **argv) { goto err_yaml; } - emit_reexports(&yaml_document); + // Try both, only fail if one reports an error. A lack of re-exports is not + // considered an error. + int ok = 1; + ok = ok && emit_reexports_v2(&yaml_document); + ok = ok && emit_reexports_v4(&yaml_document); + + result = !ok; err_yaml: yaml_parser_delete(&yaml_parser); diff --git a/pkgs/os-specific/darwin/print-reexports/setup-hook.sh b/pkgs/os-specific/darwin/print-reexports/setup-hook.sh new file mode 100644 index 00000000000..9efb00aeb4d --- /dev/null +++ b/pkgs/os-specific/darwin/print-reexports/setup-hook.sh @@ -0,0 +1,19 @@ +fixupOutputHooks+=('checkTbdReexports') + +checkTbdReexports() { + local dir="$1" + + while IFS= read -r -d $'\0' tbd; do + echo "checkTbdRexports: checking re-exports in $tbd" + while read -r target; do + local expected="${target%.dylib}.tbd" + if ! [ -e "$expected" ]; then + echo -e "Re-export missing:\n\t'$target'\n\t(expected '$expected')" + echo -e "While processing\n\t'$tbd'" + exit 1 + else + echo "Re-exported target '$target' ok" + fi + done < <(print-reexports "$tbd") + done < <(find $prefix -type f -name '*.tbd' -print0) +} diff --git a/pkgs/top-level/darwin-packages.nix b/pkgs/top-level/darwin-packages.nix index 0209af4455a..212a1761e87 100644 --- a/pkgs/top-level/darwin-packages.nix +++ b/pkgs/top-level/darwin-packages.nix @@ -68,7 +68,11 @@ impure-cmds // apple-source-releases // { darwin-stubs = callPackage ../os-specific/darwin/darwin-stubs { }; - print-reexports = callPackage ../os-specific/darwin/apple-sdk/print-reexports { }; + print-reexports = callPackage ../os-specific/darwin/print-reexports { }; + + checkReexportsHook = makeSetupHook { + deps = [ pkgs.darwin.print-reexports ]; + } ../os-specific/darwin/print-reexports/setup-hook.sh; maloader = callPackage ../os-specific/darwin/maloader { }; From b7abec31d4914acd3c286dd46d1a5c99a33c626e Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 16:45:11 +0900 Subject: [PATCH 20/71] rewrite-tbd: init --- pkgs/os-specific/darwin/rewrite-tbd/default.nix | 16 ++++++++++++++++ pkgs/top-level/darwin-packages.nix | 2 ++ 2 files changed, 18 insertions(+) create mode 100644 pkgs/os-specific/darwin/rewrite-tbd/default.nix diff --git a/pkgs/os-specific/darwin/rewrite-tbd/default.nix b/pkgs/os-specific/darwin/rewrite-tbd/default.nix new file mode 100644 index 00000000000..f41b81b3bc9 --- /dev/null +++ b/pkgs/os-specific/darwin/rewrite-tbd/default.nix @@ -0,0 +1,16 @@ +{ stdenv, fetchFromGitHub, cmake, pkg-config, libyaml }: + +stdenv.mkDerivation { + pname = "rewrite-tbd"; + version = "20201114"; + + src = fetchFromGitHub { + owner = "thefloweringash"; + repo = "rewrite-tbd"; + rev = "988f29c6ccbca9b883966225263d8d78676da6a3"; + sha256 = "08sk91zwj6n9x2ymwid2k7y0rwv5b7p6h1b25ipx1dv0i43p6v1a"; + }; + + nativeBuildInputs = [ cmake pkg-config ]; + buildInputs = [ libyaml ]; +} diff --git a/pkgs/top-level/darwin-packages.nix b/pkgs/top-level/darwin-packages.nix index 212a1761e87..139d648629c 100644 --- a/pkgs/top-level/darwin-packages.nix +++ b/pkgs/top-level/darwin-packages.nix @@ -70,6 +70,8 @@ impure-cmds // apple-source-releases // { print-reexports = callPackage ../os-specific/darwin/print-reexports { }; + rewrite-tbd = callPackage ../os-specific/darwin/rewrite-tbd { }; + checkReexportsHook = makeSetupHook { deps = [ pkgs.darwin.print-reexports ]; } ../os-specific/darwin/print-reexports/setup-hook.sh; From eb8f8afac7a5ca3b824cc9032f900a6486f68536 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 16:50:49 +0900 Subject: [PATCH 21/71] libtapi: cross compilation --- pkgs/os-specific/darwin/libtapi/default.nix | 40 +++++++++++++++---- .../darwin/libtapi/disable-rpath.patch | 14 +++++++ .../darwin/libtapi/native-clang-tblgen.patch | 21 ++++++++++ 3 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 pkgs/os-specific/darwin/libtapi/disable-rpath.patch create mode 100644 pkgs/os-specific/darwin/libtapi/native-clang-tblgen.patch diff --git a/pkgs/os-specific/darwin/libtapi/default.nix b/pkgs/os-specific/darwin/libtapi/default.nix index 8c83b4ae1e6..da071074097 100644 --- a/pkgs/os-specific/darwin/libtapi/default.nix +++ b/pkgs/os-specific/darwin/libtapi/default.nix @@ -1,6 +1,6 @@ -{ lib, stdenv, fetchFromGitHub, cmake, python3, ncurses }: +{ lib, stdenv, fetchFromGitHub, pkgsBuildBuild, cmake, python3, ncurses }: -stdenv.mkDerivation rec { +stdenv.mkDerivation { pname = "libtapi"; version = "1100.0.11"; # determined by looking at VERSION.txt @@ -13,13 +13,43 @@ stdenv.mkDerivation rec { sourceRoot = "source/src/llvm"; + # Backported from newer llvm, fixes configure error when cross compiling. + # Also means we don't have to manually fix the result with install_name_tool. + patches = [ + ./disable-rpath.patch + ] ++ lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) [ + # TODO: make unconditional and rebuild the world + # TODO: send upstream + ./native-clang-tblgen.patch + ]; + nativeBuildInputs = [ cmake python3 ]; # ncurses is required here to avoid a reference to bootstrap-tools, which is # not allowed for the stdenv. buildInputs = [ ncurses ]; - cmakeFlags = [ "-DLLVM_INCLUDE_TESTS=OFF" ]; + cmakeFlags = [ "-DLLVM_INCLUDE_TESTS=OFF" ] + ++ lib.optional (stdenv.buildPlatform != stdenv.hostPlatform) [ + "-DCMAKE_CROSSCOMPILING=True" + # This package could probably have a llvm_6 llvm-tblgen and clang-tblgen + # provided to reduce some building. This package seems intended to + # include all of its dependencies, including enough of LLVM to build the + # required tablegens. + ( + let + nativeCC = pkgsBuildBuild.stdenv.cc; + nativeBintools = nativeCC.bintools.bintools; + nativeToolchainFlags = [ + "-DCMAKE_C_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}cc" + "-DCMAKE_CXX_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}c++" + "-DCMAKE_AR=${nativeBintools}/bin/${nativeBintools.targetPrefix}ar" + "-DCMAKE_STRIP=${nativeBintools}/bin/${nativeBintools.targetPrefix}strip" + "-DCMAKE_RANLIB=${nativeBintools}/bin/${nativeBintools.targetPrefix}ranlib" + ]; + in "-DCROSS_TOOLCHAIN_FLAGS_NATIVE:list=${lib.concatStringsSep ";" nativeToolchainFlags}" + ) + ]; # fixes: fatal error: 'clang/Basic/Diagnostic.h' file not found # adapted from upstream @@ -35,10 +65,6 @@ stdenv.mkDerivation rec { installTargets = [ "install-libtapi" "install-tapi-headers" "install-tapi" ]; - postInstall = lib.optionalString stdenv.isDarwin '' - install_name_tool -id $out/lib/libtapi.dylib $out/lib/libtapi.dylib - ''; - meta = with lib; { description = "Replaces the Mach-O Dynamic Library Stub files in Apple's SDKs to reduce the size"; homepage = "https://github.com/tpoechtrager/apple-libtapi"; diff --git a/pkgs/os-specific/darwin/libtapi/disable-rpath.patch b/pkgs/os-specific/darwin/libtapi/disable-rpath.patch new file mode 100644 index 00000000000..87c0cf3330d --- /dev/null +++ b/pkgs/os-specific/darwin/libtapi/disable-rpath.patch @@ -0,0 +1,14 @@ +diff --git a/src/llvm/cmake/modules/AddLLVM.cmake b/src/llvm/cmake/modules/AddLLVM.cmake +index a53016eb0..b65e608a4 100644 +--- a/cmake/modules/AddLLVM.cmake ++++ b/cmake/modules/AddLLVM.cmake +@@ -1683,8 +1683,7 @@ function(llvm_setup_rpath name) + endif() + + if (APPLE) +- set(_install_name_dir INSTALL_NAME_DIR "@rpath") +- set(_install_rpath "@loader_path/../lib" ${extra_libdir}) ++ set(_install_name_dir) + elseif(UNIX) + set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") diff --git a/pkgs/os-specific/darwin/libtapi/native-clang-tblgen.patch b/pkgs/os-specific/darwin/libtapi/native-clang-tblgen.patch new file mode 100644 index 00000000000..9b715766a12 --- /dev/null +++ b/pkgs/os-specific/darwin/libtapi/native-clang-tblgen.patch @@ -0,0 +1,21 @@ +diffprojects/libtapi/CMakeLists.txt b/src/llvm/projects/libtapi/CMakeLists.txt +index 8ee6d8138..8277be147 100644 +--- a/projects/libtapi/CMakeLists.txt ++++ b/projects/libtapi/CMakeLists.txt +@@ -193,7 +193,15 @@ if (NOT DEFINED CLANG_VERSION) + set(CLANG_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}") + endif () + if (NOT DEFINED CLANG_TABLEGEN_EXE) +- set(CLANG_TABLEGEN_EXE "${LLVM_TOOLS_BINARY_DIR}/clang-tblgen") ++ if(LLVM_USE_HOST_TOOLS) ++ if (NOT CMAKE_CONFIGURATION_TYPES) ++ set(CLANG_TABLEGEN_EXE "${LLVM_NATIVE_BUILD}/bin/clang-tblgen") ++ else() ++ set(CLANG_TABLEGEN_EXE "${LLVM_NATIVE_BUILD}/Release/bin/clang-tblgen") ++ endif() ++ else() ++ set(CLANG_TABLEGEN_EXE "${LLVM_TOOLS_BINARY_DIR}/clang-tblgen") ++ endif () + endif () + + # Include must go first. From 15637fe6214833a63f732c227604ea32930a1203 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 16:55:25 +0900 Subject: [PATCH 22/71] bintools-wrapper: support post linker hooks --- .../bintools-wrapper/ld-wrapper.sh | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/bintools-wrapper/ld-wrapper.sh b/pkgs/build-support/bintools-wrapper/ld-wrapper.sh index 7ccf5510c88..e54dd6f4714 100644 --- a/pkgs/build-support/bintools-wrapper/ld-wrapper.sh +++ b/pkgs/build-support/bintools-wrapper/ld-wrapper.sh @@ -102,6 +102,8 @@ declare -a libDirs declare -A libs declare -i relocatable=0 link32=0 +linkerOutput="a.out" + if [ "$NIX_DONT_SET_RPATH_@suffixSalt@" != 1 ] \ || [ "$NIX_SET_BUILD_ID_@suffixSalt@" = 1 ] \ @@ -153,6 +155,24 @@ then done fi +# Determine linkerOutput +prev= +for p in \ + ${extraBefore+"${extraBefore[@]}"} \ + ${params+"${params[@]}"} \ + ${extraAfter+"${extraAfter[@]}"} +do + case "$prev" in + -o) + # Informational for post-link-hook + linkerOutput="$p" + ;; + *) + ;; + esac + prev="$p" +done + if [[ "$link32" = "1" && "$setDynamicLinker" = 1 && -e "@out@/nix-support/dynamic-linker-m32" ]]; then # We have an alternate 32-bit linker and we're producing a 32-bit ELF, let's # use it. @@ -223,7 +243,11 @@ fi PATH="$path_backup" # Old bash workaround, see above. -exec @prog@ \ +@prog@ \ ${extraBefore+"${extraBefore[@]}"} \ ${params+"${params[@]}"} \ ${extraAfter+"${extraAfter[@]}"} + +if [ -e "@out@/nix-support/post-link-hook" ]; then + source @out@/nix-support/post-link-hook +fi From 0ba7a04743f40dd1fe44d1fa10e984c5929a513b Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 16:56:03 +0900 Subject: [PATCH 23/71] darwin/binutils: include codesign_allocate --- pkgs/os-specific/darwin/binutils/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/os-specific/darwin/binutils/default.nix b/pkgs/os-specific/darwin/binutils/default.nix index 29ae1871ddb..5dc57f43e4a 100644 --- a/pkgs/os-specific/darwin/binutils/default.nix +++ b/pkgs/os-specific/darwin/binutils/default.nix @@ -9,6 +9,7 @@ let cmds = [ "ar" "ranlib" "as" "install_name_tool" "ld" "strip" "otool" "lipo" "nm" "strings" "size" + "codesign_allocate" ]; in From fe0d5a54c1d27e7d628aec25f4ce7eded64905dd Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 17:14:51 +0900 Subject: [PATCH 24/71] darwin/apple-sdk-11.0: inject an sdk for macOS 11 --- .../darwin/apple-sdk-11.0/apple_sdk.nix | 147 +++++++++++++ .../darwin/apple-sdk-11.0/default.nix | 58 ++++++ .../darwin/apple-sdk-11.0/frameworks.nix | 193 ++++++++++++++++++ .../darwin/apple-sdk-11.0/libSystem.nix | 78 +++++++ .../darwin/apple-sdk-11.0/libcharset.nix | 16 ++ .../darwin/apple-sdk-11.0/libnetwork.nix | 20 ++ .../darwin/apple-sdk-11.0/libobjc.nix | 21 ++ .../darwin/apple-sdk-11.0/libunwind.nix | 24 +++ .../apple-sdk-11.0/private-frameworks.nix | 17 ++ 9 files changed, 574 insertions(+) create mode 100644 pkgs/os-specific/darwin/apple-sdk-11.0/apple_sdk.nix create mode 100644 pkgs/os-specific/darwin/apple-sdk-11.0/default.nix create mode 100644 pkgs/os-specific/darwin/apple-sdk-11.0/frameworks.nix create mode 100644 pkgs/os-specific/darwin/apple-sdk-11.0/libSystem.nix create mode 100644 pkgs/os-specific/darwin/apple-sdk-11.0/libcharset.nix create mode 100644 pkgs/os-specific/darwin/apple-sdk-11.0/libnetwork.nix create mode 100644 pkgs/os-specific/darwin/apple-sdk-11.0/libobjc.nix create mode 100644 pkgs/os-specific/darwin/apple-sdk-11.0/libunwind.nix create mode 100644 pkgs/os-specific/darwin/apple-sdk-11.0/private-frameworks.nix diff --git a/pkgs/os-specific/darwin/apple-sdk-11.0/apple_sdk.nix b/pkgs/os-specific/darwin/apple-sdk-11.0/apple_sdk.nix new file mode 100644 index 00000000000..8e464b1d4fc --- /dev/null +++ b/pkgs/os-specific/darwin/apple-sdk-11.0/apple_sdk.nix @@ -0,0 +1,147 @@ +{ lib, stdenvNoCC, buildPackages, fetchurl, xar, cpio, pkgs, python3, pbzx, MacOSX-SDK }: + +# TODO: reorganize to make this just frameworks, and move libs to default.nix + +let + stdenv = stdenvNoCC; + + standardFrameworkPath = name: private: + "/System/Library/${lib.optionalString private "Private"}Frameworks/${name}.framework"; + + mkDepsRewrites = deps: + let + mergeRewrites = x: y: { + prefix = lib.mergeAttrs (x.prefix or {}) (y.prefix or {}); + const = lib.mergeAttrs (x.const or {}) (y.const or {}); + }; + + rewriteArgs = { prefix ? {}, const ? {} }: lib.concatLists ( + (lib.mapAttrsToList (from: to: [ "-p" "${from}:${to}" ]) prefix) ++ + (lib.mapAttrsToList (from: to: [ "-c" "${from}:${to}" ]) const) + ); + + rewrites = depList: lib.fold mergeRewrites {} + (map (dep: dep.tbdRewrites) + (lib.filter (dep: dep ? tbdRewrites) depList)); + in + lib.escapeShellArgs (rewriteArgs (rewrites (builtins.attrValues deps))); + + mkFramework = { name, deps, private ? false }: + let self = stdenv.mkDerivation { + pname = "apple-${lib.optionalString private "private-"}framework-${name}"; + version = MacOSX-SDK.version; + + dontUnpack = true; + + # because we copy files from the system + preferLocalBuild = true; + + disallowedRequisites = [ MacOSX-SDK ]; + + nativeBuildInputs = [ buildPackages.darwin.rewrite-tbd ]; + + installPhase = '' + mkdir -p $out/Library/Frameworks + + cp -r ${MacOSX-SDK}${standardFrameworkPath name private} $out/Library/Frameworks + + # Fix and check tbd re-export references + chmod u+w -R $out + find $out -name '*.tbd' -type f | while read tbd; do + echo "Fixing re-exports in $tbd" + rewrite-tbd \ + -p ${standardFrameworkPath name private}/:$out/Library/Frameworks/${name}.framework/ \ + ${mkDepsRewrites deps} \ + -r ${builtins.storeDir} \ + "$tbd" + done + ''; + + propagatedBuildInputs = builtins.attrValues deps; + + passthru = { + tbdRewrites = { + prefix."${standardFrameworkPath name private}/" = "${self}/Library/Frameworks/${name}.framework/"; + }; + }; + + meta = with lib; { + description = "Apple SDK framework ${name}"; + maintainers = with maintainers; [ copumpkin ]; + platforms = platforms.darwin; + }; + }; + in self; + + framework = name: deps: mkFramework { inherit name deps; private = false; }; + privateFramework = name: deps: mkFramework { inherit name deps; private = true; }; +in rec { + libs = { + xpc = stdenv.mkDerivation { + name = "apple-lib-xpc"; + dontUnpack = true; + + installPhase = '' + mkdir -p $out/include + pushd $out/include >/dev/null + cp -r "${MacOSX-SDK}/usr/include/xpc" $out/include/xpc + cp "${MacOSX-SDK}/usr/include/launch.h" $out/include/launch.h + popd >/dev/null + ''; + }; + + Xplugin = stdenv.mkDerivation { + name = "apple-lib-Xplugin"; + dontUnpack = true; + + propagatedBuildInputs = with frameworks; [ + OpenGL ApplicationServices Carbon IOKit CoreGraphics CoreServices CoreText + ]; + + installPhase = '' + mkdir -p $out/include $out/lib + ln -s "${MacOSX-SDK}/include/Xplugin.h" $out/include/Xplugin.h + cp ${MacOSX-SDK}/usr/lib/libXplugin.1.tbd $out/lib + ln -s libXplugin.1.tbd $out/lib/libXplugin.tbd + ''; + }; + + utmp = stdenv.mkDerivation { + name = "apple-lib-utmp"; + dontUnpack = true; + + installPhase = '' + mkdir -p $out/include + pushd $out/include >/dev/null + ln -s "${MacOSX-SDK}/include/utmp.h" + ln -s "${MacOSX-SDK}/include/utmpx.h" + popd >/dev/null + ''; + }; + + libDER = stdenv.mkDerivation { + name = "apple-lib-libDER"; + dontUnpack = true; + installPhase = '' + mkdir -p $out/include + cp -r ${MacOSX-SDK}/usr/include/libDER $out/include + ''; + }; + }; + + overrides = super: {}; + + bareFrameworks = ( + lib.mapAttrs framework (import ./frameworks.nix { + inherit frameworks libs; + inherit (pkgs.darwin) libobjc Libsystem; + inherit (pkgs.darwin.apple_sdk) libnetwork; + }) + ) // ( + lib.mapAttrs privateFramework (import ./private-frameworks.nix { + inherit frameworks; + }) + ); + + frameworks = bareFrameworks // overrides bareFrameworks; +} diff --git a/pkgs/os-specific/darwin/apple-sdk-11.0/default.nix b/pkgs/os-specific/darwin/apple-sdk-11.0/default.nix new file mode 100644 index 00000000000..03a6650d9d9 --- /dev/null +++ b/pkgs/os-specific/darwin/apple-sdk-11.0/default.nix @@ -0,0 +1,58 @@ +{ stdenvNoCC, fetchurl, newScope, pkgs +, xar, cpio, python3, pbzx }: + +let + MacOSX-SDK = stdenvNoCC.mkDerivation rec { + pname = "MacOSX-SDK"; + version = "11.0.0"; + + # https://swscan.apple.com/content/catalogs/others/index-10.16.merged-1.sucatalog + src = fetchurl { + url = "http://swcdn.apple.com/content/downloads/58/37/001-75138-A_59RXKDS8YM/12ksm19hgzscfc7cau3yhecz4vpkps7wbq/CLTools_macOSNMOS_SDK.pkg"; + sha256 = "0n51ba926ckwm62w5c8lk3w5hj4ihk0p5j02321qi75wh824hl8m"; + }; + + dontBuild = true; + darwinDontCodeSign = true; + + nativeBuildInputs = [ cpio pbzx ]; + + outputs = [ "out" ]; + + unpackPhase = '' + pbzx $src | cpio -idm + ''; + + installPhase = '' + cd Library/Developer/CommandLineTools/SDKs/MacOSX11.0.sdk + + mkdir $out + cp -r System usr $out/ + ''; + + passthru = { + inherit version; + }; + }; + + callPackage = newScope (packages // pkgs.darwin // { inherit MacOSX-SDK; }); + + packages = { + inherit (callPackage ./apple_sdk.nix {}) frameworks libs; + + # TODO: this is nice to be private. is it worth the callPackage above? + # Probably, I don't think that callPackage costs much at all. + inherit MacOSX-SDK; + + Libsystem = callPackage ./libSystem.nix {}; + LibsystemCross = pkgs.darwin.Libsystem; + libcharset = callPackage ./libcharset.nix {}; + libunwind = callPackage ./libunwind.nix {}; + libnetwork = callPackage ./libnetwork.nix {}; + objc4 = callPackage ./libobjc.nix {}; + + # questionable aliases + configd = pkgs.darwin.apple_sdk.frameworks.SystemConfiguration; + IOKit = pkgs.darwin.apple_sdk.frameworks.IOKit; + }; +in packages diff --git a/pkgs/os-specific/darwin/apple-sdk-11.0/frameworks.nix b/pkgs/os-specific/darwin/apple-sdk-11.0/frameworks.nix new file mode 100644 index 00000000000..0a605c198a1 --- /dev/null +++ b/pkgs/os-specific/darwin/apple-sdk-11.0/frameworks.nix @@ -0,0 +1,193 @@ +{ frameworks, libs, libobjc, Libsystem, libnetwork }: with frameworks; with libs; +{ + AGL = { inherit Carbon OpenGL; }; + AVFoundation = { inherit ApplicationServices AVFCapture AVFCore CoreGraphics; }; + AVKit = {}; + Accelerate = { inherit CoreWLAN IOBluetooth; }; + Accessibility = {}; + Accounts = {}; + AdSupport = {}; + AddressBook = { inherit AddressBookCore Carbon ContactsPersistence libobjc; }; + AppKit = { inherit ApplicationServices AudioToolbox AudioUnit Foundation QuartzCore UIFoundation; }; + AppTrackingTransparency = {}; + AppleScriptKit = {}; + AppleScriptObjC = {}; + ApplicationServices = { inherit ColorSync CoreGraphics CoreServices CoreText ImageIO; }; + AudioToolbox = { inherit AudioToolboxCore CoreAudio CoreMIDI; }; + AudioUnit = { inherit AudioToolbox Carbon CoreAudio; }; + AudioVideoBridging = { inherit Foundation; }; + AuthenticationServices = {}; + AutomaticAssessmentConfiguration = {}; + Automator = {}; + BackgroundTasks = {}; + BusinessChat = {}; + CFNetwork = {}; + CalendarStore = {}; + CallKit = {}; + Carbon = { inherit ApplicationServices CoreServices Foundation IOKit QuartzCore Security libobjc; }; + ClassKit = {}; + CloudKit = {}; + Cocoa = { inherit AppKit CoreData; }; + Collaboration = {}; + ColorSync = {}; + Combine = {}; + Contacts = {}; + ContactsUI = {}; + CoreAudio = { inherit IOKit; }; + CoreAudioKit = { inherit AudioUnit; }; + CoreAudioTypes = {}; + CoreBluetooth = {}; + CoreData = {}; + CoreDisplay = {}; + CoreFoundation = { inherit libobjc; }; + CoreGraphics = { inherit Accelerate IOKit IOSurface SystemConfiguration; }; + CoreHaptics = {}; + CoreImage = {}; + CoreLocation = {}; + CoreMIDI = {}; + CoreMIDIServer = { inherit CoreMIDI; }; + CoreML = {}; + CoreMedia = { inherit ApplicationServices AudioToolbox AudioUnit CoreAudio CoreGraphics CoreVideo; }; + CoreMediaIO = { inherit CoreMedia; }; + CoreMotion = {}; + CoreServices = { inherit CFNetwork CoreAudio CoreData CoreFoundation DiskArbitration NetFS OpenDirectory Security ServiceManagement; }; + CoreSpotlight = {}; + CoreTelephony = {}; + CoreText = { inherit CoreGraphics; }; + CoreVideo = { inherit ApplicationServices CoreGraphics IOSurface OpenGL; }; + CoreWLAN = { inherit SecurityFoundation; }; + CryptoKit = {}; + CryptoTokenKit = {}; + DVDPlayback = {}; + DeveloperToolsSupport = {}; + DeviceCheck = {}; + DirectoryService = {}; + DiscRecording = { inherit CoreServices IOKit libobjc; }; + DiscRecordingUI = {}; + DiskArbitration = { inherit IOKit; }; + DriverKit = {}; + EventKit = {}; + ExceptionHandling = {}; + ExecutionPolicy = {}; + ExternalAccessory = {}; + FWAUserLib = {}; + FileProvider = {}; + FileProviderUI = {}; + FinderSync = {}; + ForceFeedback = { inherit IOKit; }; + Foundation = { inherit ApplicationServices CoreFoundation Security SystemConfiguration libobjc; }; + GLKit = {}; + GLUT = { inherit OpenGL; }; + GSS = {}; + GameController = {}; + GameKit = { inherit Cocoa Foundation GameCenterFoundation GameCenterUI GameCenterUICore GameController GameplayKit Metal MetalKit ModelIO ReplayKit SceneKit SpriteKit; }; + GameplayKit = {}; + HIDDriverKit = {}; + Hypervisor = {}; + ICADevices = { inherit Carbon IOBluetooth libobjc; }; + IMServicePlugIn = {}; + IOBluetooth = { inherit CoreBluetooth IOKit; }; + IOBluetoothUI = { inherit IOBluetooth; }; + IOKit = {}; + IOSurface = { inherit IOKit xpc; }; + IOUSBHost = {}; + IdentityLookup = {}; + ImageCaptureCore = {}; + ImageIO = { inherit CoreGraphics; }; + InputMethodKit = { inherit Carbon; }; + InstallerPlugins = {}; + InstantMessage = {}; + Intents = {}; + JavaNativeFoundation = {}; + JavaRuntimeSupport = {}; + JavaScriptCore = { inherit libobjc; }; + Kerberos = {}; + Kernel = { inherit IOKit; }; + KernelManagement = {}; + LDAP = {}; + LatentSemanticMapping = { inherit Carbon; }; + LinkPresentation = { inherit URLFormatting; }; + LocalAuthentication = {}; + MLCompute = {}; + MapKit = {}; + MediaAccessibility = { inherit CoreGraphics CoreText QuartzCore; }; + MediaLibrary = {}; + MediaPlayer = {}; + MediaToolbox = { inherit AudioToolbox AudioUnit CoreMedia; }; + Message = {}; + Metal = {}; + MetalKit = { inherit Metal ModelIO; }; + MetalPerformanceShaders = {}; + MetalPerformanceShadersGraph = {}; + MetricKit = { inherit SignpostMetrics; }; + ModelIO = {}; + MultipeerConnectivity = {}; + NaturalLanguage = {}; + NearbyInteraction = {}; + NetFS = {}; + Network = { inherit libnetwork; }; + NetworkExtension = { inherit Network; }; + NetworkingDriverKit = {}; + NotificationCenter = {}; + OSAKit = { inherit Carbon; }; + OSLog = {}; + OpenAL = {}; + OpenCL = { inherit IOSurface OpenGL; }; + OpenDirectory = {}; + OpenGL = {}; + PCIDriverKit = {}; + PCSC = { inherit CoreData; }; + PDFKit = {}; + ParavirtualizedGraphics = {}; + PassKit = { inherit PassKitCore; }; + PencilKit = {}; + Photos = {}; + PhotosUI = {}; + PreferencePanes = {}; + PushKit = {}; + Python = {}; + QTKit = { inherit CoreMedia CoreMediaIO MediaToolbox VideoToolbox; }; + Quartz = { inherit QTKit QuartzCore QuickLook PDFKit; }; + QuartzCore = { inherit ApplicationServices CoreImage CoreVideo Metal OpenCL libobjc; }; + QuickLook = { inherit ApplicationServices; }; + QuickLookThumbnailing = {}; + RealityKit = {}; + ReplayKit = {}; + Ruby = {}; + SafariServices = {}; + SceneKit = {}; + ScreenSaver = {}; + ScreenTime = {}; + ScriptingBridge = {}; + Security = { inherit IOKit libDER; }; + SecurityFoundation = { inherit Security; }; + SecurityInterface = { inherit Security SecurityFoundation; }; + SensorKit = {}; + ServiceManagement = { inherit Security; }; + Social = {}; + SoundAnalysis = {}; + Speech = {}; + SpriteKit = {}; + StoreKit = {}; + SwiftUI = {}; + SyncServices = {}; + System = {}; + SystemConfiguration = { inherit Security; }; + SystemExtensions = {}; + TWAIN = { inherit Carbon; }; + Tcl = {}; + Tk = {}; + USBDriverKit = {}; + UniformTypeIdentifiers = {}; + UserNotifications = {}; + UserNotificationsUI = {}; + VideoDecodeAcceleration = { inherit CoreVideo; }; + VideoSubscriberAccount = {}; + VideoToolbox = { inherit CoreMedia CoreVideo; }; + Virtualization = {}; + Vision = {}; + WebKit = { inherit ApplicationServices Carbon JavaScriptCore OpenGL libobjc; }; + WidgetKit = {}; + iTunesLibrary = {}; + vmnet = {}; +} diff --git a/pkgs/os-specific/darwin/apple-sdk-11.0/libSystem.nix b/pkgs/os-specific/darwin/apple-sdk-11.0/libSystem.nix new file mode 100644 index 00000000000..f04b964f755 --- /dev/null +++ b/pkgs/os-specific/darwin/apple-sdk-11.0/libSystem.nix @@ -0,0 +1,78 @@ +{ stdenvNoCC, buildPackages, MacOSX-SDK }: + +stdenvNoCC.mkDerivation { + pname = "libSystem"; + version = MacOSX-SDK.version; + + dontBuild = true; + dontUnpack = true; + + nativeBuildInputs = [ buildPackages.darwin.rewrite-tbd ]; + + includeDirs = [ + "CommonCrypto" "_types" "architecture" "arpa" "atm" "bank" "bsd" "bsm" + "corecrypto" "corpses" "default_pager" "device" "dispatch" "hfs" "i386" + "iokit" "kern" "libkern" "mach" "mach-o" "mach_debug" "machine" "malloc" + "miscfs" "net" "netinet" "netinet6" "netkey" "nfs" "os" "osfmk" "pexpert" + "platform" "protocols" "pthread" "rpc" "rpcsvc" "secure" "security" + "servers" "sys" "uuid" "vfs" "voucher" "xlocale" + ] ++ [ + "arm" "xpc" "arm64" + ]; + + csu = [ + "bundle1.o" "crt0.o" "crt1.10.5.o" "crt1.10.6.o" "crt1.o" "dylib1.10.5.o" + "dylib1.o" "gcrt1.o" "lazydylib1.o" + ]; + + installPhase = '' + mkdir -p $out/{include,lib} + + for dir in $includeDirs; do + from=${MacOSX-SDK}/usr/include/$dir + if [ -e "$from" ]; then + cp -dr $from $out/include + else + echo "Header directory '$from' doesn't exist: skipping" + fi + done + + cp -d \ + ${MacOSX-SDK}/usr/include/*.h \ + $out/include + + rm $out/include/tk*.h $out/include/tcl*.h + + cp -dr \ + ${MacOSX-SDK}/usr/lib/libSystem.* \ + ${MacOSX-SDK}/usr/lib/system \ + $out/lib + + # Extra libraries + for name in c dbm dl info m mx poll proc pthread rpcsvc util gcc_s.1 resolv; do + cp -d \ + ${MacOSX-SDK}/usr/lib/lib$name.tbd \ + ${MacOSX-SDK}/usr/lib/lib$name.*.tbd \ + $out/lib + done + + for f in $csu; do + from=${MacOSX-SDK}/usr/lib/$f + if [ -e "$from" ]; then + cp -d $from $out/lib + else + echo "Csu file '$from' doesn't exist: skipping" + fi + done + + chmod u+w -R $out/lib + find $out -name '*.tbd' -type f | while read tbd; do + rewrite-tbd \ + -c /usr/lib/libsystem.dylib:$out/lib/libsystem.dylib \ + -p /usr/lib/system/:$out/lib/system/ \ + -r ${builtins.storeDir} \ + "$tbd" + done + ''; +} + diff --git a/pkgs/os-specific/darwin/apple-sdk-11.0/libcharset.nix b/pkgs/os-specific/darwin/apple-sdk-11.0/libcharset.nix new file mode 100644 index 00000000000..bf55037ab60 --- /dev/null +++ b/pkgs/os-specific/darwin/apple-sdk-11.0/libcharset.nix @@ -0,0 +1,16 @@ +{ stdenvNoCC, buildPackages, MacOSX-SDK }: + +stdenvNoCC.mkDerivation { + pname = "libcharset"; + version = MacOSX-SDK.version; + + dontUnpack = true; + dontBuild = true; + + nativeBuildInputs = [ buildPackages.darwin.checkReexportsHook ]; + + installPhase = '' + mkdir -p $out/{include,lib} + cp ${MacOSX-SDK}/usr/lib/libcharset* $out/lib + ''; +} diff --git a/pkgs/os-specific/darwin/apple-sdk-11.0/libnetwork.nix b/pkgs/os-specific/darwin/apple-sdk-11.0/libnetwork.nix new file mode 100644 index 00000000000..2e5c0593bf4 --- /dev/null +++ b/pkgs/os-specific/darwin/apple-sdk-11.0/libnetwork.nix @@ -0,0 +1,20 @@ +{ stdenvNoCC, buildPackages, MacOSX-SDK }: + +let self = stdenvNoCC.mkDerivation { + pname = "libnetwork"; + version = MacOSX-SDK.version; + + dontUnpack = true; + dontBuild = true; + + installPhase = '' + mkdir -p $out/lib + cp ${MacOSX-SDK}/usr/lib/libnetwork* $out/lib + ''; + + passthru = { + tbdRewrites = { + const."/usr/lib/libnetwork.dylib" = "${self}/lib/libnetwork.dylib"; + }; + }; +}; in self diff --git a/pkgs/os-specific/darwin/apple-sdk-11.0/libobjc.nix b/pkgs/os-specific/darwin/apple-sdk-11.0/libobjc.nix new file mode 100644 index 00000000000..63ef2a1c263 --- /dev/null +++ b/pkgs/os-specific/darwin/apple-sdk-11.0/libobjc.nix @@ -0,0 +1,21 @@ +{ stdenvNoCC, MacOSX-SDK, libcharset }: + +let self = stdenvNoCC.mkDerivation { + pname = "libobjc"; + version = MacOSX-SDK.version; + + dontUnpack = true; + dontBuild = true; + + installPhase = '' + mkdir -p $out/{include,lib} + cp -r ${MacOSX-SDK}/usr/include/objc $out/include + cp ${MacOSX-SDK}/usr/lib/libobjc* $out/lib + ''; + + passthru = { + tbdRewrites = { + const."/usr/lib/libobjc.A.dylib" = "${self}/lib/libobjc.A.dylib"; + }; + }; +}; in self diff --git a/pkgs/os-specific/darwin/apple-sdk-11.0/libunwind.nix b/pkgs/os-specific/darwin/apple-sdk-11.0/libunwind.nix new file mode 100644 index 00000000000..885780eba75 --- /dev/null +++ b/pkgs/os-specific/darwin/apple-sdk-11.0/libunwind.nix @@ -0,0 +1,24 @@ +{ stdenvNoCC, buildPackages, MacOSX-SDK }: + +stdenvNoCC.mkDerivation { + pname = "libunwind"; + version = MacOSX-SDK.version; + + dontUnpack = true; + dontBuild = true; + + nativeBuildInputs = [ buildPackages.darwin.checkReexportsHook ]; + + installPhase = '' + mkdir -p $out/include/mach-o + + cp \ + ${MacOSX-SDK}/usr/include/libunwind.h \ + ${MacOSX-SDK}/usr/include/unwind.h \ + $out/include + + cp \ + ${MacOSX-SDK}/usr/include/mach-o/compact_unwind_encoding.h \ + $out/include/mach-o + ''; +} diff --git a/pkgs/os-specific/darwin/apple-sdk-11.0/private-frameworks.nix b/pkgs/os-specific/darwin/apple-sdk-11.0/private-frameworks.nix new file mode 100644 index 00000000000..48b373bbd22 --- /dev/null +++ b/pkgs/os-specific/darwin/apple-sdk-11.0/private-frameworks.nix @@ -0,0 +1,17 @@ +{ frameworks }: with frameworks; +# generated by hand to avoid exposing all private frameworks +# frameworks here are only the necessary ones used by public frameworks. +{ + AVFCapture = {}; + AVFCore = {}; + AddressBookCore = { inherit ContactsPersistence; }; + AudioToolboxCore = {}; + ContactsPersistence = {}; + UIFoundation = {}; + GameCenterFoundation = {}; + GameCenterUI = {}; + GameCenterUICore = {}; + URLFormatting = {}; + SignpostMetrics = {}; + PassKitCore = {}; +} From 9fb892438995607d651663821f7848ec56a54c7b Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 17:23:29 +0900 Subject: [PATCH 25/71] darwin: integrate macOS 11 sdk --- pkgs/top-level/darwin-packages.nix | 43 +++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/pkgs/top-level/darwin-packages.nix b/pkgs/top-level/darwin-packages.nix index 139d648629c..b63fd9c13d0 100644 --- a/pkgs/top-level/darwin-packages.nix +++ b/pkgs/top-level/darwin-packages.nix @@ -21,17 +21,43 @@ lib.makeScopeWithSplicing splicePackages newScope otherSplices (_: {}) (spliced: # Must use pkgs.callPackage to avoid infinite recursion. - apple-source-releases = pkgs.callPackage ../os-specific/darwin/apple-source-releases { } self; + # Open source packages that are built from source + appleSourcePackages = pkgs.callPackage ../os-specific/darwin/apple-source-releases { } self; impure-cmds = pkgs.callPackage ../os-specific/darwin/impure-cmds { }; - apple_sdk = pkgs.callPackage ../os-specific/darwin/apple-sdk { + # macOS 10.12 SDK + apple_sdk_10_12 = pkgs.callPackage ../os-specific/darwin/apple-sdk { inherit (buildPackages.darwin) print-reexports; inherit (self) darwin-stubs; }; + + # macOS 11.0 SDK + apple_sdk_11_0 = pkgs.callPackage ../os-specific/darwin/apple-sdk-11.0 { }; + + # Pick an SDK + apple_sdk = if stdenv.hostPlatform.isAarch64 then apple_sdk_11_0 else apple_sdk_10_12; + + # Pick the source of libraries: either Apple's open source releases, or the + # SDK. + useAppleSDKLibs = stdenv.hostPlatform.isAarch64; + + chooseLibs = { + inherit ( + if useAppleSDKLibs + then apple_sdk + else appleSourcePackages + ) Libsystem LibsystemCross libcharset libunwind objc4 configd IOKit; + + inherit ( + if useAppleSDKLibs + then apple_sdk.frameworks + else appleSourcePackages + ) Security; + }; in -impure-cmds // apple-source-releases // { +impure-cmds // appleSourcePackages // chooseLibs // { inherit apple_sdk; @@ -41,7 +67,7 @@ impure-cmds // apple-source-releases // { binutils-unwrapped = callPackage ../os-specific/darwin/binutils { inherit (pkgs) binutils-unwrapped; - inherit (pkgs.llvmPackages_7) llvm clang-unwrapped; + inherit (pkgs.llvmPackages) llvm clang-unwrapped; }; binutils = pkgs.wrapBintoolsWith { @@ -72,7 +98,7 @@ impure-cmds // apple-source-releases // { rewrite-tbd = callPackage ../os-specific/darwin/rewrite-tbd { }; - checkReexportsHook = makeSetupHook { + checkReexportsHook = pkgs.makeSetupHook { deps = [ pkgs.darwin.print-reexports ]; } ../os-specific/darwin/print-reexports/setup-hook.sh; @@ -89,7 +115,7 @@ impure-cmds // apple-source-releases // { iproute2mac = callPackage ../os-specific/darwin/iproute2mac { }; - libobjc = apple-source-releases.objc4; + libobjc = self.objc4; lsusb = callPackage ../os-specific/darwin/lsusb { }; @@ -110,7 +136,10 @@ impure-cmds // apple-source-releases // { CoreSymbolication = callPackage ../os-specific/darwin/CoreSymbolication { }; - CF = callPackage ../os-specific/darwin/swift-corelibs/corefoundation.nix { }; + # TODO: make swift-corefoundation build with apple_sdk_11_0.Libsystem + CF = if useAppleSDKLibs + then apple_sdk.frameworks.CoreFoundation + else callPackage ../os-specific/darwin/swift-corelibs/corefoundation.nix { }; # As the name says, this is broken, but I don't want to lose it since it's a direction we want to go in # libdispatch-broken = callPackage ../os-specific/darwin/swift-corelibs/libdispatch.nix { }; From c696fcdacb04d382ae95f0581d293bd40540d871 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 17:18:44 +0900 Subject: [PATCH 26/71] fixDarwinDylibNames: set name of install_name_tool --- pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh | 2 +- pkgs/top-level/all-packages.nix | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh b/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh index af2ff0cc966..55e196e654d 100644 --- a/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh +++ b/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh @@ -23,7 +23,7 @@ fixDarwinDylibNames() { for fn in "$@"; do if [ -L "$fn" ]; then continue; fi echo "$fn: fixing dylib" - int_out=$(install_name_tool -id "$fn" "${flags[@]}" "$fn" 2>&1) + int_out=$(@targetPrefix@install_name_tool -id "$fn" "${flags[@]}" "$fn" 2>&1) result=$? if [ "$result" -ne 0 ] && ! grep "shared library stub file and can't be changed" <<< "$out" diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 08f94a54a58..07aba73d0fc 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -641,7 +641,9 @@ in setJavaClassPath = makeSetupHook { } ../build-support/setup-hooks/set-java-classpath.sh; - fixDarwinDylibNames = makeSetupHook { } ../build-support/setup-hooks/fix-darwin-dylib-names.sh; + fixDarwinDylibNames = makeSetupHook { + substitutions = { inherit (binutils) targetPrefix; }; + } ../build-support/setup-hooks/fix-darwin-dylib-names.sh; keepBuildTree = makeSetupHook { } ../build-support/setup-hooks/keep-build-tree.sh; From 9e05276949045b8620a0ebd7de3aa75bb6af21cc Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 17:25:00 +0900 Subject: [PATCH 27/71] bash: provide a working binutils Why does bash need binutils at all? What's wrong with stdenv? This avoids a broken ld wrapper, since binutils is binutils wrapped for linux, even though it's only required on darwin. --- pkgs/top-level/all-packages.nix | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 07aba73d0fc..99169c48802 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -9988,15 +9988,21 @@ in any-nix-shell = callPackage ../shells/any-nix-shell { }; - bash = lowPrio (callPackage ../shells/bash/4.4.nix { }); - bash_5 = lowPrio (callPackage ../shells/bash/5.1.nix { }); + bash = lowPrio (callPackage ../shells/bash/4.4.nix { + binutils = stdenv.cc.bintools; + }); + bash_5 = lowPrio (callPackage ../shells/bash/5.1.nix { + binutils = stdenv.cc.bintools; + }); bashInteractive_5 = lowPrio (callPackage ../shells/bash/5.1.nix { + binutils = stdenv.cc.bintools; interactive = true; withDocs = true; }); # WARNING: this attribute is used by nix-shell so it shouldn't be removed/renamed bashInteractive = callPackage ../shells/bash/4.4.nix { + binutils = stdenv.cc.bintools; interactive = true; withDocs = true; }; From a7bcb6b93683dd9e2bbaabd8f06d56a2301f3410 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 17:27:27 +0900 Subject: [PATCH 28/71] darwin cross: include CoreFoundation in stdenv --- pkgs/stdenv/cross/default.nix | 4 +++- pkgs/top-level/all-packages.nix | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pkgs/stdenv/cross/default.nix b/pkgs/stdenv/cross/default.nix index a9fd21534ff..18a6e2a4737 100644 --- a/pkgs/stdenv/cross/default.nix +++ b/pkgs/stdenv/cross/default.nix @@ -48,7 +48,9 @@ in lib.init bootStages ++ [ # Prior overrides are surely not valid as packages built with this run on # a different platform, and so are disabled. overrides = _: _: {}; - extraBuildInputs = [ ]; # Old ones run on wrong platform + extraBuildInputs = [ ] # Old ones run on wrong platform + ++ lib.optionals hostPlatform.isDarwin [ buildPackages.targetPackages.darwin.apple_sdk.frameworks.CoreFoundation ] + ; allowedRequisites = null; hasCC = !targetPlatform.isGhcjs; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 99169c48802..a9da6ce0707 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -30,7 +30,18 @@ in # just the plain stdenv. stdenv_32bit = lowPrio (if stdenv.hostPlatform.is32bit then stdenv else multiStdenv); - stdenvNoCC = stdenv.override { cc = null; hasCC = false; }; + stdenvNoCC = stdenv.override ( + { cc = null; hasCC = false; } + + // lib.optionalAttrs (stdenv.hostPlatform.isDarwin && (stdenv.hostPlatform != stdenv.buildPlatform)) { + # TODO: This is a hack to use stdenvNoCC to produce a CF when cross + # compiling. It's not very sound. The cross stdenv has: + # extraBuildInputs = [ targetPackages.darwin.apple_sdks.frameworks.CoreFoundation ] + # and uses stdenvNoCC. In order to make this not infinitely recursive, we need to exclude + # this extraBuildInput. + extraBuildInputs = []; + } + ); mkStdenvNoLibs = stdenv: let bintools = stdenv.cc.bintools.override { From 4c890ce9aa557cbae67fb571687d74af8cc9e73a Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 16:41:41 +0900 Subject: [PATCH 29/71] darwin.sigtool: init --- pkgs/os-specific/darwin/sigtool/default.nix | 24 +++++++++++++++++++++ pkgs/top-level/darwin-packages.nix | 2 ++ 2 files changed, 26 insertions(+) create mode 100644 pkgs/os-specific/darwin/sigtool/default.nix diff --git a/pkgs/os-specific/darwin/sigtool/default.nix b/pkgs/os-specific/darwin/sigtool/default.nix new file mode 100644 index 00000000000..933ef784879 --- /dev/null +++ b/pkgs/os-specific/darwin/sigtool/default.nix @@ -0,0 +1,24 @@ +{ lib, stdenv, fetchFromGitHub, pkg-config, cmake, makeWrapper, openssl }: + +stdenv.mkDerivation { + name = "sigtool"; + + src = fetchFromGitHub { + owner = "thefloweringash"; + repo = "sigtool"; + rev = "4a3719b42dc91c3f513df94048851cc98e7c7fcf"; + sha256 = "04ra1cx7k1sdbkj5yrvl0s3l333vpir8rnm8k1dh2zy1w0a6hpqa"; + }; + + nativeBuildInputs = [ pkg-config makeWrapper ]; + buildInputs = [ openssl ]; + + installFlags = [ "PREFIX=$(out)" ]; + + # Upstream (me) asserts the driver script is optional. + postInstall = '' + substitute $NIX_BUILD_TOP/$sourceRoot/codesign.sh $out/bin/codesign \ + --replace sigtool "$out/bin/sigtool" + chmod a+x $out/bin/codesign + ''; +} diff --git a/pkgs/top-level/darwin-packages.nix b/pkgs/top-level/darwin-packages.nix index b63fd9c13d0..9f6ea813663 100644 --- a/pkgs/top-level/darwin-packages.nix +++ b/pkgs/top-level/darwin-packages.nix @@ -102,6 +102,8 @@ impure-cmds // appleSourcePackages // chooseLibs // { deps = [ pkgs.darwin.print-reexports ]; } ../os-specific/darwin/print-reexports/setup-hook.sh; + sigtool = callPackage ../os-specific/darwin/sigtool { }; + maloader = callPackage ../os-specific/darwin/maloader { }; From bfd9a7784eb4aeb7b02289d645ede4cd225183a3 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 17:22:54 +0900 Subject: [PATCH 30/71] darwin.postLinkSignHook: init --- pkgs/top-level/darwin-packages.nix | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pkgs/top-level/darwin-packages.nix b/pkgs/top-level/darwin-packages.nix index 9f6ea813663..0921557c90c 100644 --- a/pkgs/top-level/darwin-packages.nix +++ b/pkgs/top-level/darwin-packages.nix @@ -14,6 +14,12 @@ let selfTargetTarget = pkgsTargetTarget.darwin or {}; # might be missing }; + # Prefix for binaries. Customarily ends with a dash separator. + # + # TODO(@Ericson2314) Make unconditional, or optional but always true by + # default. + targetPrefix = lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform) + (stdenv.targetPlatform.config + "-"); in lib.makeScopeWithSplicing splicePackages newScope otherSplices (_: {}) (spliced: spliced.apple_sdk.frameworks) (self: let @@ -104,6 +110,16 @@ impure-cmds // appleSourcePackages // chooseLibs // { sigtool = callPackage ../os-specific/darwin/sigtool { }; + postLinkSignHook = pkgs.writeTextFile { + name = "post-link-sign-hook"; + executable = true; + + text = '' + CODESIGN_ALLOCATE=${targetPrefix}codesign_allocate \ + ${self.sigtool}/bin/codesign -f -s - "$linkerOutput" + ''; + }; + maloader = callPackage ../os-specific/darwin/maloader { }; From 7eb1e3695dfae415700b46725e5fda51df05bc3c Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Mon, 15 Feb 2021 14:54:58 +0900 Subject: [PATCH 31/71] darwin.signingUtils: init Helper scripts for code signing on darwin. --- .../darwin/signing-utils/auto-sign-hook.sh | 20 +++++++++ .../darwin/signing-utils/default.nix | 24 +++++++++++ .../os-specific/darwin/signing-utils/utils.sh | 43 +++++++++++++++++++ pkgs/top-level/darwin-packages.nix | 6 +++ 4 files changed, 93 insertions(+) create mode 100644 pkgs/os-specific/darwin/signing-utils/auto-sign-hook.sh create mode 100644 pkgs/os-specific/darwin/signing-utils/default.nix create mode 100644 pkgs/os-specific/darwin/signing-utils/utils.sh diff --git a/pkgs/os-specific/darwin/signing-utils/auto-sign-hook.sh b/pkgs/os-specific/darwin/signing-utils/auto-sign-hook.sh new file mode 100644 index 00000000000..430aba8cdc7 --- /dev/null +++ b/pkgs/os-specific/darwin/signing-utils/auto-sign-hook.sh @@ -0,0 +1,20 @@ +fixupOutputHooks+=('signDarwinBinariesIn $prefix') + +# Uses signingUtils, see definition of autoSignDarwinBinariesHook in +# darwin-packages.nix + +signDarwinBinariesIn() { + local dir="$1" + + if [ ! -d "$dir" ]; then + return 0 + fi + + if [ "${darwinDontCodeSign:-}" ]; then + return 0 + fi + + while IFS= read -r -d $'\0' f; do + signIfRequired "$f" + done < <(find "$dir" -type f -print0) +} diff --git a/pkgs/os-specific/darwin/signing-utils/default.nix b/pkgs/os-specific/darwin/signing-utils/default.nix new file mode 100644 index 00000000000..035ac59b725 --- /dev/null +++ b/pkgs/os-specific/darwin/signing-utils/default.nix @@ -0,0 +1,24 @@ +{ stdenvNoCC +, sigtool +, cctools +}: + +let + stdenv = stdenvNoCC; +in + +stdenv.mkDerivation { + name = "signing-utils"; + + dontUnpack = true; + dontConfigure = true; + dontBuild = true; + + installPhase = '' + substituteAll ${./utils.sh} $out + ''; + + # Substituted variables + inherit sigtool; + codesignAllocate = "${cctools}/bin/${cctools.targetPrefix}codesign_allocate"; +} diff --git a/pkgs/os-specific/darwin/signing-utils/utils.sh b/pkgs/os-specific/darwin/signing-utils/utils.sh new file mode 100644 index 00000000000..6d23a461fc9 --- /dev/null +++ b/pkgs/os-specific/darwin/signing-utils/utils.sh @@ -0,0 +1,43 @@ +# Work around for some odd behaviour where we can't codesign a file +# in-place if it has been called before. This happens for example if +# you try to fix-up a binary using strip/install_name_tool, after it +# had been used previous. The solution is to copy the binary (with +# the corrupted signature from strip/install_name_tool) to some +# location, sign it there and move it back into place. +# +# This does not appear to happen with the codesign tool that ships +# with recent macOS BigSur installs on M1 arm64 machines. However it +# had also been happening with the tools that shipped with the DTKs. +sign() { + local tmpdir + tmpdir=$(mktemp -d) + + # $1 is the file + + cp "$1" "$tmpdir" + CODESIGN_ALLOCATE=@codesignAllocate@ \ + @sigtool@/bin/codesign -f -s - "$tmpdir/$(basename "$1")" + mv "$tmpdir/$(basename "$1")" "$1" + rmdir "$tmpdir" +} + +checkRequiresSignature() { + local file=$1 + local rc=0 + + @sigtool@/bin/sigtool --file "$file" check-requires-signature || rc=$? + + if [ "$rc" -eq 0 ] || [ "$rc" -eq 1 ]; then + return "$rc" + fi + + echo "Unexpected exit status from sigtool: $rc" + exit 1 +} + +signIfRequired() { + local file=$1 + if checkRequiresSignature "$file"; then + sign "$file" + fi +} diff --git a/pkgs/top-level/darwin-packages.nix b/pkgs/top-level/darwin-packages.nix index 0921557c90c..5c49aecd2a5 100644 --- a/pkgs/top-level/darwin-packages.nix +++ b/pkgs/top-level/darwin-packages.nix @@ -120,6 +120,12 @@ impure-cmds // appleSourcePackages // chooseLibs // { ''; }; + signingUtils = callPackage ../os-specific/darwin/signing-utils { }; + + autoSignDarwinBinariesHook = pkgs.makeSetupHook { + deps = [ self.signingUtils ]; + } ../os-specific/darwin/signing-utils/auto-sign-hook.sh; + maloader = callPackage ../os-specific/darwin/maloader { }; From 772b66531ac723b9fd6f171370ab643a2350eed9 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 21 Jan 2021 14:18:51 +0900 Subject: [PATCH 32/71] darwin: wrap strip and install_name_tool to codesign modified files Co-authored-by: Moritz Angermann --- .../darwin-install_name_tool-wrapper.sh | 49 ++++++++++++ .../bintools-wrapper/darwin-strip-wrapper.sh | 78 +++++++++++++++++++ .../bintools-wrapper/default.nix | 21 +++++ pkgs/top-level/all-packages.nix | 1 + 4 files changed, 149 insertions(+) create mode 100755 pkgs/build-support/bintools-wrapper/darwin-install_name_tool-wrapper.sh create mode 100755 pkgs/build-support/bintools-wrapper/darwin-strip-wrapper.sh diff --git a/pkgs/build-support/bintools-wrapper/darwin-install_name_tool-wrapper.sh b/pkgs/build-support/bintools-wrapper/darwin-install_name_tool-wrapper.sh new file mode 100755 index 00000000000..376a7abfe41 --- /dev/null +++ b/pkgs/build-support/bintools-wrapper/darwin-install_name_tool-wrapper.sh @@ -0,0 +1,49 @@ +#! @shell@ +# shellcheck shell=bash + +set -eu -o pipefail +o posix +shopt -s nullglob + +if (( "${NIX_DEBUG:-0}" >= 7 )); then + set -x +fi + +source @signingUtils@ + +extraAfter=() +extraBefore=() +params=("$@") + +input= + +pprev= +prev= +for p in \ + ${extraBefore+"${extraBefore[@]}"} \ + ${params+"${params[@]}"} \ + ${extraAfter+"${extraAfter[@]}"} +do + if [ "$pprev" != "-change" ] && [[ "$prev" != -* ]] && [[ "$p" != -* ]]; then + input="$p" + fi + pprev="$prev" + prev="$p" +done + +# Optionally print debug info. +if (( "${NIX_DEBUG:-0}" >= 1 )); then + # Old bash workaround, see above. + echo "extra flags before to @prog@:" >&2 + printf " %q\n" ${extraBefore+"${extraBefore[@]}"} >&2 + echo "original flags to @prog@:" >&2 + printf " %q\n" ${params+"${params[@]}"} >&2 + echo "extra flags after to @prog@:" >&2 + printf " %q\n" ${extraAfter+"${extraAfter[@]}"} >&2 +fi + +@prog@ \ + ${extraBefore+"${extraBefore[@]}"} \ + ${params+"${params[@]}"} \ + ${extraAfter+"${extraAfter[@]}"} + +sign "$input" diff --git a/pkgs/build-support/bintools-wrapper/darwin-strip-wrapper.sh b/pkgs/build-support/bintools-wrapper/darwin-strip-wrapper.sh new file mode 100755 index 00000000000..a67699547a6 --- /dev/null +++ b/pkgs/build-support/bintools-wrapper/darwin-strip-wrapper.sh @@ -0,0 +1,78 @@ +#! @shell@ +# shellcheck shell=bash + +set -eu -o pipefail +o posix +shopt -s nullglob + +if (( "${NIX_DEBUG:-0}" >= 7 )); then + set -x +fi + +source @signingUtils@ + +extraAfter=() +extraBefore=() +params=("$@") + +output= +inputs=() + +restAreFiles= +prev= +for p in \ + ${extraBefore+"${extraBefore[@]}"} \ + ${params+"${params[@]}"} \ + ${extraAfter+"${extraAfter[@]}"} +do + if [ "$restAreFiles" ]; then + inputs+=("$p") + else + case "$prev" in + -s|-R|-d|-arch) + # Unrelated arguments with values + ;; + -o) + # Explicit output + output="$p" + ;; + *) + # Any other orgument either takes no value, or is a file. + if [[ "$p" != -* ]]; then + inputs+=("$p") + fi + ;; + esac + + if [ "$p" == - ]; then + restAreFiles=1 + fi + fi + + prev="$p" +done + +# Optionally print debug info. +if (( "${NIX_DEBUG:-0}" >= 1 )); then + # Old bash workaround, see above. + echo "extra flags before to @prog@:" >&2 + printf " %q\n" ${extraBefore+"${extraBefore[@]}"} >&2 + echo "original flags to @prog@:" >&2 + printf " %q\n" ${params+"${params[@]}"} >&2 + echo "extra flags after to @prog@:" >&2 + printf " %q\n" ${extraAfter+"${extraAfter[@]}"} >&2 +fi + +@prog@ \ + ${extraBefore+"${extraBefore[@]}"} \ + ${params+"${params[@]}"} \ + ${extraAfter+"${extraAfter[@]}"} + +if [ "$output" ]; then + # Single explicit output + signIfRequired "$output" +else + # Multiple inputs, rewritten in place + for input in "${inputs[@]}"; do + signIfRequired "$input" + done +fi diff --git a/pkgs/build-support/bintools-wrapper/default.nix b/pkgs/build-support/bintools-wrapper/default.nix index 859e3790594..b2b47901981 100644 --- a/pkgs/build-support/bintools-wrapper/default.nix +++ b/pkgs/build-support/bintools-wrapper/default.nix @@ -14,6 +14,9 @@ , extraPackages ? [], extraBuildCommands ? "" , buildPackages ? {} , useMacosReexportHack ? false + +# Darwin code signing support utilities +, postLinkSignHook ? null, signingUtils ? null }: with lib; @@ -339,6 +342,24 @@ stdenv.mkDerivation { '' ) + ## + ## Code signing on Apple Silicon + ## + + optionalString (targetPlatform.isDarwin && targetPlatform.isAarch64) '' + echo 'source ${postLinkSignHook}' >> $out/nix-support/post-link-hook + + export signingUtils=${signingUtils} + + wrap \ + ${targetPrefix}install_name_tool \ + ${./darwin-install_name_tool-wrapper.sh} \ + "${bintools_bin}/bin/${targetPrefix}install_name_tool" + + wrap \ + ${targetPrefix}strip ${./darwin-strip-wrapper.sh} \ + "${bintools_bin}/bin/${targetPrefix}strip" + '' + ## ## Extra custom steps ## diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index a9da6ce0707..ba9f9f8d94a 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -11857,6 +11857,7 @@ in noLibc = (self.libc == null); inherit bintools libc; + inherit (darwin) postLinkSignHook signingUtils; } // extraArgs; in self); yaml-language-server = nodePackages.yaml-language-server; From 3eacdfe24aef2d6aef539172b172bf0439bef74f Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 17:28:00 +0900 Subject: [PATCH 33/71] stdenv/darwin: bootstrap tools for Apple Silicon --- pkgs/stdenv/darwin/make-bootstrap-tools.nix | 94 +++++++++++++++------ 1 file changed, 67 insertions(+), 27 deletions(-) diff --git a/pkgs/stdenv/darwin/make-bootstrap-tools.nix b/pkgs/stdenv/darwin/make-bootstrap-tools.nix index 4b6562a205a..a42499eebce 100644 --- a/pkgs/stdenv/darwin/make-bootstrap-tools.nix +++ b/pkgs/stdenv/darwin/make-bootstrap-tools.nix @@ -1,9 +1,15 @@ -{ pkgspath ? ../../.., test-pkgspath ? pkgspath, system ? builtins.currentSystem }: - -with import pkgspath { inherit system; }; +{ pkgspath ? ../../.., test-pkgspath ? pkgspath, system ? builtins.currentSystem, crossSystem ? null }: let - llvmPackages = llvmPackages_7; + pkgs = import pkgspath ({ inherit system; } // (if (crossSystem != null) then { inherit crossSystem; } else {})); +in + +with pkgs; + +let + llvmPackageSet = if stdenv.hostPlatform.isAarch64 then "llvmPackages_11" else "llvmPackages_7"; + llvmPackages = pkgs."${llvmPackageSet}"; + storePrefixLen = builtins.stringLength builtins.storeDir; in rec { coreutils_ = coreutils.override (args: { # We want coreutils without ACL support. @@ -23,23 +29,26 @@ in rec { build = stdenv.mkDerivation { name = "stdenv-bootstrap-tools"; - buildInputs = [nukeReferences cpio]; + nativeBuildInputs = [ buildPackages.nukeReferences buildPackages.cpio ] + ++ lib.optionals targetPlatform.isAarch64 [ buildPackages.darwin.sigtool ]; buildCommand = '' - mkdir -p $out/bin $out/lib $out/lib/system + mkdir -p $out/bin $out/lib $out/lib/system $out/lib/darwin - # Copy libSystem's .o files for various low-level boot stuff. - cp -d ${darwin.Libsystem}/lib/*.o $out/lib + ${lib.optionalString stdenv.targetPlatform.isx86_64 '' + # Copy libSystem's .o files for various low-level boot stuff. + cp -d ${darwin.Libsystem}/lib/*.o $out/lib - # Resolv is actually a link to another package, so let's copy it properly - cp -L ${darwin.Libsystem}/lib/libresolv.9.dylib $out/lib + # Resolv is actually a link to another package, so let's copy it properly + cp -L ${darwin.Libsystem}/lib/libresolv.9.dylib $out/lib - cp -rL ${darwin.Libsystem}/include $out - chmod -R u+w $out/include - cp -rL ${darwin.ICU}/include* $out/include - cp -rL ${libiconv}/include/* $out/include - cp -rL ${gnugrep.pcre.dev}/include/* $out/include - mv $out/include $out/include-Libsystem + cp -rL ${darwin.Libsystem}/include $out + chmod -R u+w $out/include + cp -rL ${darwin.ICU}/include* $out/include + cp -rL ${libiconv}/include/* $out/include + cp -rL ${gnugrep.pcre.dev}/include/* $out/include + mv $out/include $out/include-Libsystem + ''} # Copy coreutils, bash, etc. cp ${coreutils_}/bin/* $out/bin @@ -76,39 +85,60 @@ in rec { # Copy what we need of clang cp -d ${llvmPackages.clang-unwrapped}/bin/clang* $out/bin - - cp -rL ${llvmPackages.clang-unwrapped.lib}/lib/clang $out/lib + cp -rd ${llvmPackages.clang-unwrapped.lib}/lib/* $out/lib cp -d ${llvmPackages.libcxx}/lib/libc++*.dylib $out/lib cp -d ${llvmPackages.libcxxabi}/lib/libc++abi*.dylib $out/lib + cp -d ${llvmPackages.compiler-rt}/lib/darwin/libclang_rt* $out/lib/darwin + cp -d ${llvmPackages.compiler-rt}/lib/libclang_rt* $out/lib cp -d ${llvmPackages.llvm.lib}/lib/libLLVM.dylib $out/lib cp -d ${libffi}/lib/libffi*.dylib $out/lib mkdir $out/include cp -rd ${llvmPackages.libcxx.dev}/include/c++ $out/include + ${lib.optionalString targetPlatform.isAarch64 '' + # copy .tbd assembly utils + cp -d ${pkgs.darwin.rewrite-tbd}/bin/rewrite-tbd $out/bin + cp -d ${pkgs.libyaml}/lib/libyaml*.dylib $out/lib + + # copy package extraction tools + cp -d ${pkgs.pbzx}/bin/pbzx $out/bin + cp -d ${pkgs.xar}/lib/libxar*.dylib $out/lib + cp -d ${pkgs.bzip2.out}/lib/libbz2*.dylib $out/lib + + # copy sigtool + cp -d ${pkgs.darwin.sigtool}/bin/sigtool $out/bin + cp -d ${pkgs.darwin.sigtool}/bin/codesign $out/bin + ''} + cp -d ${darwin.ICU}/lib/libicu*.dylib $out/lib cp -d ${zlib.out}/lib/libz.* $out/lib cp -d ${gmpxx.out}/lib/libgmp*.* $out/lib cp -d ${xz.out}/lib/liblzma*.* $out/lib # Copy binutils. - for i in as ld ar ranlib nm strip otool install_name_tool lipo; do + for i in as ld ar ranlib nm strip otool install_name_tool lipo codesign_allocate; do cp ${cctools_}/bin/$i $out/bin done cp -d ${darwin.libtapi}/lib/libtapi* $out/lib - cp -rd ${pkgs.darwin.CF}/Library $out + ${lib.optionalString targetPlatform.isx86_64 '' + cp -rd ${pkgs.darwin.CF}/Library $out + ''} chmod -R u+w $out nuke-refs $out/bin/* rpathify() { - local libs=$(${cctools_}/bin/otool -L "$1" | tail -n +2 | grep -o "$NIX_STORE.*-\S*") || true + local libs=$(${stdenv.cc.targetPrefix}otool -L "$1" | tail -n +2 | grep -o "$NIX_STORE.*-\S*") || true + local newlib for lib in $libs; do - ${cctools_}/bin/install_name_tool -change $lib "@rpath/$(basename $lib)" "$1" + newlib=''${lib:${toString (storePrefixLen + 1)}} + newlib=''${newlib#*/} + ${stdenv.cc.targetPrefix}install_name_tool -change $lib "@rpath/$newlib" "$1" done } @@ -116,20 +146,27 @@ in rec { for i in $out/bin/*; do if test -x $i -a ! -L $i; then chmod +w $i - strip $i || true + ${stdenv.cc.targetPrefix}strip $i || true fi done - for i in $out/bin/* $out/lib/*.dylib $out/lib/clang/*/lib/darwin/*.dylib $out/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation; do + for i in $out/bin/* $out/lib/*.dylib $out/lib/darwin/*.dylib $out/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation; do if test -x "$i" -a ! -L "$i"; then echo "Adding rpath to $i" rpathify $i fi done + for i in $out/bin/*; do + if test -x "$i" -a ! -L "$i" -a "$(basename $i)" != codesign; then + echo "Adding @executable_path to rpath in $i" + ${stdenv.cc.targetPrefix}install_name_tool -add_rpath '@executable_path/..' $i + fi + done + nuke-refs $out/lib/* nuke-refs $out/lib/system/* - nuke-refs $out/lib/clang/*/lib/darwin/* + nuke-refs $out/lib/darwin/* nuke-refs $out/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation mkdir $out/.pack @@ -143,7 +180,7 @@ in rec { cp ${bzip2_.bin}/bin/bzip2 $out/on-server chmod u+w $out/on-server/* - strip $out/on-server/* + ${stdenv.cc.targetPrefix}strip $out/on-server/* nuke-refs $out/on-server/* (cd $out/pack && (find | cpio -o -H newc)) | bzip2 > $out/on-server/bootstrap-tools.cpio.bz2 @@ -318,7 +355,10 @@ in rec { # The ultimate test: bootstrap a whole stdenv from the tools specified above and get a package set out of it test-pkgs = import test-pkgspath { - inherit system; + # if the bootstrap tools are for another platform, we should be testing + # that platform. + system = if crossSystem != null then crossSystem else system; + stdenvStages = args: let args' = args // { inherit bootstrapFiles; }; in (import (test-pkgspath + "/pkgs/stdenv/darwin") args').stagesDarwin; From 768aae66efcb50672f0ed728f218f18348193e27 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 17:28:20 +0900 Subject: [PATCH 34/71] stdenv/darwin: Apple Silicon support --- pkgs/stdenv/darwin/default.nix | 356 ++++++++++++------ .../darwin/unpack-bootstrap-tools-aarch64.sh | 52 +++ pkgs/stdenv/default.nix | 1 + 3 files changed, 299 insertions(+), 110 deletions(-) create mode 100644 pkgs/stdenv/darwin/unpack-bootstrap-tools-aarch64.sh diff --git a/pkgs/stdenv/darwin/default.nix b/pkgs/stdenv/darwin/default.nix index 6ccebd20ade..caa3cb8e201 100644 --- a/pkgs/stdenv/darwin/default.nix +++ b/pkgs/stdenv/darwin/default.nix @@ -1,18 +1,33 @@ { lib , localSystem, crossSystem, config, overlays, crossOverlays ? [] # Allow passing in bootstrap files directly so we can test the stdenv bootstrap process when changing the bootstrap tools -, bootstrapFiles ? let - fetch = { file, sha256, executable ? true }: import { - url = "http://tarballs.nixos.org/stdenv-darwin/x86_64/5ab5783e4f46c373c6de84deac9ad59b608bb2e6/${file}"; - inherit (localSystem) system; - inherit sha256 executable; - }; in { - sh = fetch { file = "sh"; sha256 = "sha256-nbb4XEk3go7ttiWrQyKQMLzPr+qUnwnHkWMtVCZsMCs="; }; - bzip2 = fetch { file = "bzip2"; sha256 = "sha256-ybnA+JWrKhXSfn20+GVKXkHFTp2Zt79hat8hAVmsUOc="; }; - mkdir = fetch { file = "mkdir"; sha256 = "sha256-nmvMxmfcY41/60Z/E8L9u0vgePW5l30Dqw1z+Nr02Hk="; }; - cpio = fetch { file = "cpio"; sha256 = "sha256-cB36rN3NLj19Tk37Kc5bodMFMO+mCpEQkKKo0AEMkaU="; }; - tarball = fetch { file = "bootstrap-tools.cpio.bz2"; sha256 = "sha256-kh2vKmjCr/HvR06czZbxUxV5KDRxSF27M6nN3cyofRI="; executable = false; }; - } +, bootstrapFiles ? + if localSystem.isAarch64 then + let + fetch = { file, sha256, executable ? true }: import { + url = null; # to be built by hydra and injected here + inherit (localSystem) system; + inherit sha256 executable; + }; in { + sh = fetch { file = "sh"; sha256 = "0000000000000000000000000000000000000000000000000000"; }; + bzip2 = fetch { file = "bzip2"; sha256 = "0000000000000000000000000000000000000000000000000000"; }; + mkdir = fetch { file = "mkdir"; sha256 = "0000000000000000000000000000000000000000000000000000"; }; + cpio = fetch { file = "cpio"; sha256 = "0000000000000000000000000000000000000000000000000000"; }; + tarball = fetch { file = "bootstrap-tools.cpio.bz2"; sha256 = "0000000000000000000000000000000000000000000000000000"; executable = false; }; + } + else + let + fetch = { file, sha256, executable ? true }: import { + url = "http://tarballs.nixos.org/stdenv-darwin/x86_64/5ab5783e4f46c373c6de84deac9ad59b608bb2e6/${file}"; + inherit (localSystem) system; + inherit sha256 executable; + }; in { + sh = fetch { file = "sh"; sha256 = "sha256-nbb4XEk3go7ttiWrQyKQMLzPr+qUnwnHkWMtVCZsMCs="; }; + bzip2 = fetch { file = "bzip2"; sha256 = "sha256-ybnA+JWrKhXSfn20+GVKXkHFTp2Zt79hat8hAVmsUOc="; }; + mkdir = fetch { file = "mkdir"; sha256 = "sha256-nmvMxmfcY41/60Z/E8L9u0vgePW5l30Dqw1z+Nr02Hk="; }; + cpio = fetch { file = "cpio"; sha256 = "sha256-cB36rN3NLj19Tk37Kc5bodMFMO+mCpEQkKKo0AEMkaU="; }; + tarball = fetch { file = "bootstrap-tools.cpio.bz2"; sha256 = "sha256-kh2vKmjCr/HvR06czZbxUxV5KDRxSF27M6nN3cyofRI="; executable = false; }; + } }: assert crossSystem == localSystem; @@ -20,13 +35,22 @@ assert crossSystem == localSystem; let inherit (localSystem) system; - bootstrapClangVersion = "7.1.0"; + # Bootstrap version needs to be known to reference headers included in the bootstrap tools + bootstrapLlvmVersion = if localSystem.isAarch64 then "11.1.0" else "7.1.0"; + + useAppleSDKLibs = localSystem.isAarch64; + haveKRB5 = localSystem.isx86_64; + + # final toolchain is injected into llvmPackages_${finalLlvmVersion} + finalLlvmVersion = if localSystem.isAarch64 then "11" else "7"; + finalLlvmPackages = "llvmPackages_${finalLlvmVersion}"; commonImpureHostDeps = [ "/bin/sh" "/usr/lib/libSystem.B.dylib" "/usr/lib/system/libunc.dylib" # This dependency is "hidden", so our scanning code doesn't pick it up ]; + in rec { commonPreHook = '' export NIX_ENFORCE_NO_NATIVE=''${NIX_ENFORCE_NO_NATIVE-1} @@ -45,7 +69,7 @@ in rec { name = "bootstrap-tools"; builder = bootstrapFiles.sh; # Not a filename! Attribute 'sh' on bootstrapFiles - args = [ ./unpack-bootstrap-tools.sh ]; + args = if localSystem.isAarch64 then [ ./unpack-bootstrap-tools-aarch64.sh ] else [ ./unpack-bootstrap-tools.sh ]; inherit (bootstrapFiles) mkdir bzip2 cpio tarball; @@ -70,11 +94,14 @@ in rec { inherit (last) stdenv; }; + doSign = localSystem.isAarch64 && last != null; + doUpdateAutoTools = localSystem.isAarch64 && last != null; + mkExtraBuildCommands = cc: '' rsrc="$out/resource-root" mkdir "$rsrc" ln -s "${cc.lib or cc}/lib/clang/${cc.version}/include" "$rsrc" - ln -s "${last.pkgs.llvmPackages_7.compiler-rt.out}/lib" "$rsrc/lib" + ln -s "${last.pkgs."${finalLlvmPackages}".compiler-rt.out}/lib" "$rsrc/lib" echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags ''; @@ -90,13 +117,13 @@ in rec { bintools = last.pkgs.darwin.binutils; libc = last.pkgs.darwin.Libsystem; isClang = true; - cc = last.pkgs.llvmPackages_7.clang-unwrapped; + cc = last.pkgs."${finalLlvmPackages}".clang-unwrapped; }; in args // (overrides args)); cc = if last == null then "/dev/null" else mkCC ({ cc, ... }: { extraPackages = [ - last.pkgs.llvmPackages_7.libcxxabi - last.pkgs.llvmPackages_7.compiler-rt + last.pkgs."${finalLlvmPackages}".libcxxabi + last.pkgs."${finalLlvmPackages}".compiler-rt ]; extraBuildCommands = mkExtraBuildCommands cc; }); @@ -104,11 +131,11 @@ in rec { ccNoLibcxx = if last == null then "/dev/null" else mkCC ({ cc, ... }: { libcxx = null; extraPackages = [ - last.pkgs.llvmPackages_7.compiler-rt + last.pkgs."${finalLlvmPackages}".compiler-rt ]; extraBuildCommands = '' echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags - echo "-B${last.pkgs.llvmPackages_7.compiler-rt}/lib" >> $out/nix-support/cc-cflags + echo "-B${last.pkgs."${finalLlvmPackages}".compiler-rt}/lib" >> $out/nix-support/cc-cflags echo "-nostdlib++" >> $out/nix-support/cc-cflags '' + mkExtraBuildCommands cc; }); @@ -116,9 +143,20 @@ in rec { thisStdenv = import ../generic { name = "${name}-stdenv-darwin"; - inherit config shell extraNativeBuildInputs extraBuildInputs; + inherit config shell extraBuildInputs; + + extraNativeBuildInputs = extraNativeBuildInputs ++ lib.optionals doUpdateAutoTools [ + last.pkgs.updateAutotoolsGnuConfigScriptsHook last.pkgs.gnu-config + ]; + allowedRequisites = if allowedRequisites == null then null else allowedRequisites ++ [ cc.expand-response-params cc.bintools + ] ++ lib.optionals doUpdateAutoTools [ + last.pkgs.updateAutotoolsGnuConfigScriptsHook last.pkgs.gnu-config + ] ++ lib.optionals doSign [ + last.pkgs.darwin.postLinkSignHook + last.pkgs.darwin.sigtool + last.pkgs.darwin.signingUtils ]; buildPlatform = localSystem; @@ -176,7 +214,97 @@ in rec { ''; }; + pbzx = stdenv.mkDerivation { + name = "bootstrap-stage0-pbzx"; + phases = [ "installPhase" ]; + installPhase = '' + mkdir -p $out/bin + ln -s ${bootstrapTools}/bin/pbzx $out/bin + ''; + }; + + cpio = stdenv.mkDerivation { + name = "bootstrap-stage0-cpio"; + phases = [ "installPhase" ]; + installPhase = '' + mkdir -p $out/bin + ln -s ${bootstrapFiles.cpio} $out/bin/cpio + ''; + }; + darwin = super.darwin.overrideScope (selfDarwin: superDarwin: { + darwin-stubs = superDarwin.darwin-stubs.override { inherit (self) stdenvNoCC fetchurl; }; + + dyld = { + name = "bootstrap-stage0-dyld"; + buildCommand = '' + mkdir -p $out + ln -s ${bootstrapTools}/lib $out/lib + ln -s ${bootstrapTools}/include $out/include + ''; + }; + + sigtool = stdenv.mkDerivation { + name = "bootstrap-stage0-sigtool"; + phases = [ "installPhase" ]; + installPhase = '' + mkdir -p $out/bin + ln -s ${bootstrapTools}/bin/sigtool $out/bin + + # Rewrite nuked references + sed -e "s|[^( ]*\bsigtool\b|$out/bin/sigtool|g" \ + ${bootstrapTools}/bin/codesign > $out/bin/codesign + chmod a+x $out/bin/codesign + ''; + }; + + print-reexports = stdenv.mkDerivation { + name = "bootstrap-stage0-print-reexports"; + phases = [ "installPhase" ]; + installPhase = '' + mkdir -p $out/bin + ln -s ${bootstrapTools}/bin/print-reexports $out/bin + ''; + }; + + rewrite-tbd = stdenv.mkDerivation { + name = "bootstrap-stage0-rewrite-tbd"; + phases = [ "installPhase" ]; + installPhase = '' + mkdir -p $out/bin + ln -s ${bootstrapTools}/bin/rewrite-tbd $out/bin + ''; + }; + + binutils-unwrapped = { name = "bootstrap-stage0-binutils"; outPath = bootstrapTools; }; + + cctools = { + name = "bootstrap-stage0-cctools"; + outPath = bootstrapTools; + targetPrefix = ""; + }; + + binutils = lib.makeOverridable (import ../../build-support/bintools-wrapper) { + shell = "${bootstrapTools}/bin/bash"; + inherit lib; + inherit (self) stdenvNoCC; + + nativeTools = false; + nativeLibc = false; + inherit (self) buildPackages coreutils gnugrep; + libc = selfDarwin.Libsystem; + bintools = selfDarwin.binutils-unwrapped; + inherit (selfDarwin) postLinkSignHook signingUtils; + }; + } // lib.optionalAttrs (! useAppleSDKLibs) { + CF = stdenv.mkDerivation { + name = "bootstrap-stage0-CF"; + buildCommand = '' + mkdir -p $out/Library/Frameworks + ln -s ${bootstrapTools}/Library/Frameworks/CoreFoundation.framework $out/Library/Frameworks + ''; + }; + Libsystem = stdenv.mkDerivation { name = "bootstrap-stage0-Libsystem"; buildCommand = '' @@ -200,35 +328,12 @@ in rec { ln -s ${bootstrapTools}/include-Libsystem $out/include ''; }; - - darwin-stubs = superDarwin.darwin-stubs.override { inherit (self) stdenvNoCC fetchurl; }; - - dyld = { - name = "bootstrap-stage0-dyld"; - buildCommand = '' - mkdir -p $out - ln -s ${bootstrapTools}/lib $out/lib - ln -s ${bootstrapTools}/include $out/include - ''; - }; - - binutils = lib.makeOverridable (import ../../build-support/bintools-wrapper) { - shell = "${bootstrapTools}/bin/bash"; - inherit lib; - inherit (self) stdenvNoCC; - - nativeTools = false; - nativeLibc = false; - inherit (self) buildPackages coreutils gnugrep; - libc = selfDarwin.Libsystem; - bintools = { name = "bootstrap-stage0-binutils"; outPath = bootstrapTools; }; - }; }); - llvmPackages_7 = { + "${finalLlvmPackages}" = { clang-unwrapped = stdenv.mkDerivation { name = "bootstrap-stage0-clang"; - version = bootstrapClangVersion; + version = bootstrapLlvmVersion; buildCommand = '' mkdir -p $out/lib ln -s ${bootstrapTools}/bin $out/bin @@ -278,36 +383,46 @@ in rec { persistent = self: super: with prevStage; { cmake = super.cmakeMinimal; + inherit pbzx cpio; + python3 = super.python3Minimal; ninja = super.ninja.override { buildDocs = false; }; - llvmPackages_7 = super.llvmPackages_7 // (let - tools = super.llvmPackages_7.tools.extend (_: _: { - inherit (llvmPackages_7) clang-unwrapped; + "${finalLlvmPackages}" = super."${finalLlvmPackages}" // (let + tools = super."${finalLlvmPackages}".tools.extend (_: _: { + inherit (pkgs."${finalLlvmPackages}") clang-unwrapped; }); - libraries = super.llvmPackages_7.libraries.extend (_: _: { - inherit (llvmPackages_7) compiler-rt libcxx libcxxabi; + libraries = super."${finalLlvmPackages}".libraries.extend (_: _: { + inherit (pkgs."${finalLlvmPackages}") compiler-rt libcxx libcxxabi; }); in { inherit tools libraries; } // tools // libraries); darwin = super.darwin.overrideScope (selfDarwin: _: { + inherit (darwin) rewrite-tbd binutils-unwrapped; + + signingUtils = darwin.signingUtils.override { + inherit (selfDarwin) sigtool; + }; + binutils = darwin.binutils.override { coreutils = self.coreutils; libc = selfDarwin.Libsystem; + inherit (selfDarwin) postLinkSignHook signingUtils; }; }); }; in with prevStage; stageFun 1 prevStage { extraPreHook = "export NIX_CFLAGS_COMPILE+=\" -F${bootstrapTools}/Library/Frameworks\""; extraNativeBuildInputs = []; - extraBuildInputs = [ ]; - libcxx = pkgs.libcxx; + extraBuildInputs = [ pkgs.darwin.CF ]; + libcxx = pkgs."${finalLlvmPackages}".libcxx; allowedRequisites = [ bootstrapTools ] ++ - (with pkgs; [ coreutils gnugrep libcxx libcxxabi llvmPackages_7.clang-unwrapped llvmPackages_7.compiler-rt ]) ++ - (with pkgs.darwin; [ darwin-stubs Libsystem ]); + (with pkgs; [ coreutils gnugrep ]) ++ + (with pkgs."${finalLlvmPackages}"; [ libcxx libcxxabi compiler-rt clang-unwrapped ]) ++ + (with pkgs.darwin; [ Libsystem CF ] ++ lib.optional useAppleSDKLibs objc4); overrides = persistent; }; @@ -321,26 +436,30 @@ in rec { findfreetype libssh curl cmake autoconf automake libtool ed cpio coreutils libssh2 nghttp2 libkrb5 ninja brotli; - llvmPackages_7 = super.llvmPackages_7 // (let - tools = super.llvmPackages_7.tools.extend (_: _: { - inherit (llvmPackages_7) clang-unwrapped; + "${finalLlvmPackages}" = super."${finalLlvmPackages}" // (let + tools = super."${finalLlvmPackages}".tools.extend (_: _: { + inherit (pkgs."${finalLlvmPackages}") clang-unwrapped; }); - libraries = super.llvmPackages_7.libraries.extend (_: libSuper: { - inherit (llvmPackages_7) compiler-rt; + libraries = super."${finalLlvmPackages}".libraries.extend (_: libSuper: { + inherit (pkgs."${finalLlvmPackages}") compiler-rt; libcxx = libSuper.libcxx.override { stdenv = overrideCC self.stdenv self.ccNoLibcxx; }; - libcxxabi = libSuper.libcxxabi.override { + libcxxabi = libSuper.libcxxabi.override ({ stdenv = overrideCC self.stdenv self.ccNoLibcxx; + } // lib.optionalAttrs (finalLlvmVersion == "7") { + # TODO: the bootstrapping of llvm packages isn't consistent. + # `standalone` may be redundant if darwin behaves like useLLVM (or + # has useLLVM = true). standalone = true; - }; + }); }); in { inherit tools libraries; } // tools // libraries); darwin = super.darwin.overrideScope (_: _: { inherit (darwin) binutils dyld Libsystem xnu configd ICU libdispatch libclosure - launchd CF darwin-stubs; + launchd CF objc4 darwin-stubs sigtool postLinkSignHook signingUtils; }); }; in with prevStage; stageFun 2 prevStage { @@ -350,16 +469,18 @@ in rec { extraNativeBuildInputs = [ pkgs.xz ]; extraBuildInputs = [ pkgs.darwin.CF ]; - libcxx = pkgs.libcxx; + libcxx = pkgs."${finalLlvmPackages}".libcxx; allowedRequisites = [ bootstrapTools ] ++ (with pkgs; [ - xz.bin xz.out libcxx libcxxabi llvmPackages_7.compiler-rt - llvmPackages_7.clang-unwrapped zlib libxml2.out curl.out brotli.lib openssl.out - libssh2.out nghttp2.lib libkrb5 coreutils gnugrep pcre.out gmp libiconv + xz.bin xz.out zlib libxml2.out curl.out openssl.out libssh2.out + nghttp2.lib coreutils gnugrep pcre.out gmp libiconv brotli.lib + ] ++ lib.optional haveKRB5 libkrb5) ++ + (with pkgs."${finalLlvmPackages}"; [ + libcxx libcxxabi compiler-rt clang-unwrapped ]) ++ - (with pkgs.darwin; [ dyld Libsystem CF ICU locale ]); + (with pkgs.darwin; [ dyld Libsystem CF ICU locale ] ++ lib.optional useAppleSDKLibs objc4); overrides = persistent; }; @@ -376,16 +497,16 @@ in rec { # Avoid pulling in a full python and its extra dependencies for the llvm/clang builds. libxml2 = super.libxml2.override { pythonSupport = false; }; - llvmPackages_7 = super.llvmPackages_7 // (let - libraries = super.llvmPackages_7.libraries.extend (_: _: { - inherit (llvmPackages_7) libcxx libcxxabi; + "${finalLlvmPackages}" = super."${finalLlvmPackages}" // (let + libraries = super."${finalLlvmPackages}".libraries.extend (_: _: { + inherit (pkgs."${finalLlvmPackages}") libcxx libcxxabi; }); in { inherit libraries; } // libraries); darwin = super.darwin.overrideScope (_: _: { inherit (darwin) dyld Libsystem xnu configd libdispatch libclosure launchd libiconv - locale darwin-stubs; + locale darwin-stubs sigtool; }); }; in with prevStage; stageFun 3 prevStage { @@ -397,7 +518,7 @@ in rec { # patches our shebangs back to point at bootstrapTools. This makes sure bash comes first. extraNativeBuildInputs = with pkgs; [ xz ]; extraBuildInputs = [ pkgs.darwin.CF pkgs.bash ]; - libcxx = pkgs.libcxx; + libcxx = pkgs."${finalLlvmPackages}".libcxx; extraPreHook = '' export PATH=${pkgs.bash}/bin:$PATH @@ -407,11 +528,13 @@ in rec { allowedRequisites = [ bootstrapTools ] ++ (with pkgs; [ - xz.bin xz.out bash libcxx libcxx.dev libcxxabi libcxxabi.dev llvmPackages_7.compiler-rt - llvmPackages_7.clang-unwrapped zlib libxml2.out curl.out brotli.lib openssl.out - libssh2.out nghttp2.lib libkrb5 coreutils gnugrep pcre.out gmp libiconv + xz.bin xz.out bash zlib libxml2.out curl.out openssl.out libssh2.out + nghttp2.lib coreutils gnugrep pcre.out gmp libiconv brotli.lib + ] ++ lib.optional haveKRB5 libkrb5) ++ + (with pkgs."${finalLlvmPackages}"; [ + libcxx libcxx.dev libcxxabi libcxxabi.dev compiler-rt clang-unwrapped ]) ++ - (with pkgs.darwin; [ dyld ICU Libsystem locale ]); + (with pkgs.darwin; [ dyld ICU Libsystem locale ] ++ lib.optional useAppleSDKLibs objc4); overrides = persistent; }; @@ -432,20 +555,21 @@ in rec { ]; }); - llvmPackages_7 = super.llvmPackages_7 // (let - tools = super.llvmPackages_7.tools.extend (llvmSelf: _: { - clang-unwrapped-all-outputs = llvmPackages_7.clang-unwrapped-all-outputs.override { llvm = llvmSelf.llvm; }; - libllvm = llvmPackages_7.libllvm.override { inherit libxml2; }; + "${finalLlvmPackages}" = super."${finalLlvmPackages}" // (let + tools = super."${finalLlvmPackages}".tools.extend (llvmSelf: _: { + clang-unwrapped-all-outputs = pkgs."${finalLlvmPackages}".clang-unwrapped-all-outputs.override { llvm = llvmSelf.llvm; }; + libllvm = pkgs."${finalLlvmPackages}".libllvm.override { inherit libxml2; }; }); - libraries = super.llvmPackages_7.libraries.extend (llvmSelf: _: { - inherit (llvmPackages_7) libcxx libcxxabi compiler-rt; + libraries = super."${finalLlvmPackages}".libraries.extend (llvmSelf: _: { + inherit (pkgs."${finalLlvmPackages}") libcxx libcxxabi compiler-rt; }); in { inherit tools libraries; } // tools // libraries); darwin = super.darwin.overrideScope (_: superDarwin: { inherit (darwin) dyld Libsystem libiconv locale darwin-stubs; - CF = superDarwin.CF.override { + # See useAppleSDKLibs in darwin-packages.nix + CF = if useAppleSDKLibs then super.darwin.CF else superDarwin.CF.override { inherit libxml2; python3 = prevStage.python3; }; @@ -455,7 +579,7 @@ in rec { shell = "${pkgs.bash}/bin/bash"; extraNativeBuildInputs = with pkgs; [ xz ]; extraBuildInputs = [ pkgs.darwin.CF pkgs.bash ]; - libcxx = pkgs.libcxx; + libcxx = pkgs."${finalLlvmPackages}".libcxx; extraPreHook = '' export PATH_LOCALE=${pkgs.darwin.locale}/share/locale @@ -464,29 +588,32 @@ in rec { }; stdenvDarwin = prevStage: let + doSign = localSystem.isAarch64; pkgs = prevStage; persistent = self: super: with prevStage; { inherit gnumake gzip gnused bzip2 gawk ed xz patch bash - ncurses libffi zlib llvm gmp pcre gnugrep - coreutils findutils diffutils patchutils; + ncurses libffi zlib gmp pcre gnugrep + coreutils findutils diffutils patchutils pbzx; - llvmPackages_7 = super.llvmPackages_7 // (let - tools = super.llvmPackages_7.tools.extend (_: super: { - inherit (llvmPackages_7) llvm clang-unwrapped; - }); - libraries = super.llvmPackages_7.libraries.extend (_: _: { - inherit (llvmPackages_7) compiler-rt libcxx libcxxabi; - }); - in { inherit tools libraries; } // tools // libraries); - - darwin = super.darwin.overrideScope (_: _: { - inherit (darwin) dyld ICU Libsystem libiconv; + darwin = super.darwin.overrideScope (_: _: { + inherit (darwin) dyld ICU Libsystem Csu libiconv rewrite-tbd; } // lib.optionalAttrs (super.stdenv.targetPlatform == localSystem) { inherit (darwin) binutils binutils-unwrapped cctools; }); } // lib.optionalAttrs (super.stdenv.targetPlatform == localSystem) { + inherit llvm; + # Need to get rid of these when cross-compiling. + "${finalLlvmPackages}" = super."${finalLlvmPackages}" // (let + tools = super."${finalLlvmPackages}".tools.extend (_: super: { + inherit (pkgs."${finalLlvmPackages}") llvm clang-unwrapped; + }); + libraries = super."${finalLlvmPackages}".libraries.extend (_: _: { + inherit (pkgs."${finalLlvmPackages}") compiler-rt libcxx libcxxabi; + }); + in { inherit tools libraries; } // tools // libraries); + inherit binutils binutils-unwrapped; }; in import ../generic rec { @@ -510,11 +637,12 @@ in rec { initialPath = import ../common-path.nix { inherit pkgs; }; shell = "${pkgs.bash}/bin/bash"; - cc = pkgs.llvmPackages.libcxxClang.override { - cc = pkgs.llvmPackages.clang-unwrapped; - }; + cc = pkgs."${finalLlvmPackages}".libcxxClang; + + extraNativeBuildInputs = lib.optionals localSystem.isAarch64 [ + pkgs.updateAutotoolsGnuConfigScriptsHook + ]; - extraNativeBuildInputs = []; extraBuildInputs = [ pkgs.darwin.CF ]; extraAttrs = { @@ -524,19 +652,27 @@ in rec { }; allowedRequisites = (with pkgs; [ - xz.out xz.bin libcxx libcxx.dev libcxxabi libcxxabi.dev gmp.out gnumake findutils bzip2.out - bzip2.bin llvmPackages.llvm llvmPackages.llvm.lib llvmPackages.compiler-rt llvmPackages.compiler-rt.dev + xz.out xz.bin gmp.out gnumake findutils bzip2.out + bzip2.bin zlib.out zlib.dev libffi.out coreutils ed diffutils gnutar gzip ncurses.out ncurses.dev ncurses.man gnused bash gawk - gnugrep llvmPackages.clang-unwrapped - llvmPackages.libclang.dev llvmPackages.libclang.lib - patch pcre.out gettext + gnugrep patch pcre.out gettext binutils.bintools darwin.binutils darwin.binutils.bintools - curl.out brotli.lib openssl.out libssh2.out nghttp2.lib libkrb5 + curl.out openssl.out libssh2.out nghttp2.lib brotli.lib cc.expand-response-params libxml2.out - ]) ++ (with pkgs.darwin; [ + ] ++ lib.optional haveKRB5 libkrb5 + ++ lib.optionals localSystem.isAarch64 [ + pkgs.updateAutotoolsGnuConfigScriptsHook pkgs.gnu-config + ]) + ++ (with pkgs."${finalLlvmPackages}"; [ + libcxx libcxx.dev libcxxabi libcxxabi.dev + llvm llvm.lib compiler-rt compiler-rt.dev + clang-unwrapped libclang.dev libclang.lib + ]) + ++ (with pkgs.darwin; [ dyld Libsystem CF cctools ICU libiconv locale libtapi - ]); + ] ++ lib.optional useAppleSDKLibs objc4 + ++ lib.optionals doSign [ postLinkSignHook sigtool signingUtils ]); overrides = lib.composeExtensions persistent (self: super: { darwin = super.darwin.overrideScope (_: superDarwin: { diff --git a/pkgs/stdenv/darwin/unpack-bootstrap-tools-aarch64.sh b/pkgs/stdenv/darwin/unpack-bootstrap-tools-aarch64.sh new file mode 100644 index 00000000000..63b72972d71 --- /dev/null +++ b/pkgs/stdenv/darwin/unpack-bootstrap-tools-aarch64.sh @@ -0,0 +1,52 @@ +set -euo pipefail + +# Unpack the bootstrap tools tarball. +echo Unpacking the bootstrap tools... +$mkdir $out +$bzip2 -d < $tarball | (cd $out && $cpio -i) + +export PATH=$out/bin + +# Fix codesign wrapper paths +sed -i \ + -e "1c\ +#!$out/bin/bash" \ + -e "s|[^( ]*\bsigtool\b|$out/bin/sigtool|g" \ + $out/bin/codesign + +updateInstallName() { + local path="$1" + + cp "$path" "$path.new" + install_name_tool -id "$path" "$path.new" + codesign -f -i "$(basename "$path")" -s - "$path.new" + mv -f "$path.new" "$path" +} + +find $out + +ln -s bash $out/bin/sh +ln -s bzip2 $out/bin/bunzip2 + +find $out/lib -type f -name '*.dylib' -print0 | while IFS= read -r -d $'\0' lib; do + updateInstallName "$lib" +done + +# Provide a gunzip script. +cat > $out/bin/gunzip < $out/bin/egrep +echo "exec $out/bin/grep -E \"\$@\"" >> $out/bin/egrep +echo "#! $out/bin/sh" > $out/bin/fgrep +echo "exec $out/bin/grep -F \"\$@\"" >> $out/bin/fgrep + +cat >$out/bin/dsymutil << EOF +#!$out/bin/sh +EOF + +chmod +x $out/bin/egrep $out/bin/fgrep $out/bin/dsymutil diff --git a/pkgs/stdenv/default.nix b/pkgs/stdenv/default.nix index d9eadf26804..d6c59573f2a 100644 --- a/pkgs/stdenv/default.nix +++ b/pkgs/stdenv/default.nix @@ -57,6 +57,7 @@ in powerpc64-linux = stagesLinux; powerpc64le-linux = stagesLinux; x86_64-darwin = stagesDarwin; + aarch64-darwin = stagesDarwin; x86_64-solaris = stagesNix; i686-cygwin = stagesNative; x86_64-cygwin = stagesNative; From 33b59b8940c35e849d68b87b36db15941f84e528 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Mon, 7 Dec 2020 23:46:12 -0600 Subject: [PATCH 35/71] flake.nix: add aarch64-darwin --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index 537f91ee5e7..5237cae86f1 100644 --- a/flake.nix +++ b/flake.nix @@ -18,6 +18,7 @@ "aarch64-linux" "armv6l-linux" "armv7l-linux" + "aarch64-darwin" ]; forAllSystems = f: lib.genAttrs systems (system: f system); From a6753d0c4255b1efa6a941efb3d8d7a39ec956e3 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Mon, 7 Dec 2020 23:48:40 -0600 Subject: [PATCH 36/71] lib/systems: add aarch64-darwin to mesaPlatforms --- lib/systems/doubles.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/systems/doubles.nix b/lib/systems/doubles.nix index 6f638be585b..c6d90ba9850 100644 --- a/lib/systems/doubles.nix +++ b/lib/systems/doubles.nix @@ -96,5 +96,5 @@ in { embedded = filterDoubles predicates.isNone; - mesaPlatforms = ["i686-linux" "x86_64-linux" "x86_64-darwin" "armv5tel-linux" "armv6l-linux" "armv7l-linux" "armv7a-linux" "aarch64-linux" "powerpc64-linux" "powerpc64le-linux"]; + mesaPlatforms = ["i686-linux" "x86_64-linux" "x86_64-darwin" "armv5tel-linux" "armv6l-linux" "armv7l-linux" "armv7a-linux" "aarch64-linux" "powerpc64-linux" "powerpc64le-linux" "aarch64-darwin"]; } From 3e7034abb9490e3eff4ec436317f3d6b5f52b8d7 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Wed, 9 Dec 2020 16:48:00 -0600 Subject: [PATCH 37/71] darwin/xcode: provide libc++ from XCode toolchain We could use our own libc++ here, but it is probably best to use the provided one to ensure consistency. This fixes some C++ programs when running aarch64-apple-ios-clang++. --- pkgs/os-specific/darwin/xcode/sdk-pkgs.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/os-specific/darwin/xcode/sdk-pkgs.nix b/pkgs/os-specific/darwin/xcode/sdk-pkgs.nix index ab934d7eaaa..0512d9dd46a 100644 --- a/pkgs/os-specific/darwin/xcode/sdk-pkgs.nix +++ b/pkgs/os-specific/darwin/xcode/sdk-pkgs.nix @@ -41,6 +41,7 @@ rec { mv cc-cflags.tmp $out/nix-support/cc-cflags echo "-target ${targetPlatform.config}" >> $out/nix-support/cc-cflags echo "-isystem ${sdk}/usr/include${lib.optionalString (lib.versionAtLeast "10" sdk.version) " -isystem ${sdk}/usr/include/c++/4.2.1/ -stdlib=libstdc++"}" >> $out/nix-support/cc-cflags + ${lib.optionalString (lib.versionAtLeast sdk.version "14") "echo -isystem ${xcode}/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1 >> $out/nix-support/cc-cflags"} ''; }) // { inherit sdk; From 1a2cb94c825448c03cda778a328f2e743af17443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Fri, 8 Jan 2021 12:21:36 +0100 Subject: [PATCH 38/71] hydra jobset support for aarch64-darwin --- pkgs/top-level/release-lib.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/top-level/release-lib.nix b/pkgs/top-level/release-lib.nix index 411093186a6..ceae00baec9 100644 --- a/pkgs/top-level/release-lib.nix +++ b/pkgs/top-level/release-lib.nix @@ -27,6 +27,7 @@ rec { pkgs_x86_64_linux = packageSet' { system = "x86_64-linux"; }; pkgs_i686_linux = packageSet' { system = "i686-linux"; }; pkgs_aarch64_linux = packageSet' { system = "aarch64-linux"; }; + pkgs_aarch64_darwin = packageSet' { system = "aarch64-darwin"; }; pkgs_armv6l_linux = packageSet' { system = "armv6l-linux"; }; pkgs_armv7l_linux = packageSet' { system = "armv7l-linux"; }; pkgs_x86_64_darwin = packageSet' { system = "x86_64-darwin"; }; @@ -39,6 +40,7 @@ rec { if system == "x86_64-linux" then pkgs_x86_64_linux else if system == "i686-linux" then pkgs_i686_linux else if system == "aarch64-linux" then pkgs_aarch64_linux + else if system == "aarch64-darwin" then pkgs_aarch64_darwin else if system == "armv6l-linux" then pkgs_armv6l_linux else if system == "armv7l-linux" then pkgs_armv7l_linux else if system == "x86_64-darwin" then pkgs_x86_64_darwin From 3a3df3146e244b6b36a5fa10e2c4890a59fce3b2 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Sat, 9 Jan 2021 21:38:45 +0800 Subject: [PATCH 39/71] Add crossPkgs.aarch64-darwin --- lib/systems/examples.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/systems/examples.nix b/lib/systems/examples.nix index d5f2f2068b4..6a8f4e091aa 100644 --- a/lib/systems/examples.nix +++ b/lib/systems/examples.nix @@ -240,6 +240,12 @@ rec { useiOSPrebuilt = true; }; + aarch64-darwin = { + config = "aarch64-apple-darwin"; + xcodePlatform = "MacOSX"; + platform = {}; + }; + # # Windows # From d2c96703397a909fa9108d33a225da87684aea8f Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Fri, 29 Jan 2021 14:39:23 +0900 Subject: [PATCH 40/71] darwin: add CoreFoundation to the build when explicitly required --- .../darwin/apple-sdk-11.0/apple_sdk.nix | 6 +++++- .../darwin/apple-sdk-11.0/cf-setup-hook.sh | 6 ++++++ pkgs/top-level/darwin-packages.nix | 18 +++++++++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 pkgs/os-specific/darwin/apple-sdk-11.0/cf-setup-hook.sh diff --git a/pkgs/os-specific/darwin/apple-sdk-11.0/apple_sdk.nix b/pkgs/os-specific/darwin/apple-sdk-11.0/apple_sdk.nix index 8e464b1d4fc..a4242405b41 100644 --- a/pkgs/os-specific/darwin/apple-sdk-11.0/apple_sdk.nix +++ b/pkgs/os-specific/darwin/apple-sdk-11.0/apple_sdk.nix @@ -129,7 +129,11 @@ in rec { }; }; - overrides = super: {}; + overrides = super: { + CoreFoundation = lib.overrideDerivation super.CoreFoundation (drv: { + setupHook = ./cf-setup-hook.sh; + }); + }; bareFrameworks = ( lib.mapAttrs framework (import ./frameworks.nix { diff --git a/pkgs/os-specific/darwin/apple-sdk-11.0/cf-setup-hook.sh b/pkgs/os-specific/darwin/apple-sdk-11.0/cf-setup-hook.sh new file mode 100644 index 00000000000..3b08c51d196 --- /dev/null +++ b/pkgs/os-specific/darwin/apple-sdk-11.0/cf-setup-hook.sh @@ -0,0 +1,6 @@ +forceLinkCoreFoundationFramework() { + NIX_CFLAGS_COMPILE="-F@out@/Library/Frameworks${NIX_CFLAGS_COMPILE:+ }${NIX_CFLAGS_COMPILE-}" + NIX_LDFLAGS+=" @out@/Library/Frameworks/CoreFoundation.framework/CoreFoundation" +} + +preConfigureHooks+=(forceLinkCoreFoundationFramework) diff --git a/pkgs/top-level/darwin-packages.nix b/pkgs/top-level/darwin-packages.nix index 5c49aecd2a5..a43cdc80a9d 100644 --- a/pkgs/top-level/darwin-packages.nix +++ b/pkgs/top-level/darwin-packages.nix @@ -162,7 +162,23 @@ impure-cmds // appleSourcePackages // chooseLibs // { # TODO: make swift-corefoundation build with apple_sdk_11_0.Libsystem CF = if useAppleSDKLibs - then apple_sdk.frameworks.CoreFoundation + then + # This attribute (CF) is included in extraBuildInputs in the stdenv. This + # is typically the open source project. When a project refers to + # "CoreFoundation" it has an extra setup hook to force impure system + # CoreFoundation into the link step. + # + # In this branch, we only have a single "CoreFoundation" to choose from. + # To be compatible with the existing convention, we define + # CoreFoundation with the setup hook, and CF as the same package but + # with the setup hook removed. + # + # This may seem unimportant, but without it packages (e.g., bacula) will + # fail with linker errors referring ___CFConstantStringClassReference. + # It's not clear to me why some packages need this extra setup. + lib.overrideDerivation apple_sdk.frameworks.CoreFoundation (drv: { + setupHook = null; + }) else callPackage ../os-specific/darwin/swift-corelibs/corefoundation.nix { }; # As the name says, this is broken, but I don't want to lose it since it's a direction we want to go in From 1a45df1f7f0f2ff3f8950b8d81ae7dfb2a563663 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Sat, 5 Dec 2020 15:02:32 +0900 Subject: [PATCH 41/71] ctags: fix build with newer darwin libraries --- pkgs/development/tools/misc/ctags/default.nix | 7 + .../tools/misc/ctags/unused-collision.patch | 246 ++++++++++++++++++ 2 files changed, 253 insertions(+) create mode 100644 pkgs/development/tools/misc/ctags/unused-collision.patch diff --git a/pkgs/development/tools/misc/ctags/default.nix b/pkgs/development/tools/misc/ctags/default.nix index 90825db2a54..fde7307b27d 100644 --- a/pkgs/development/tools/misc/ctags/default.nix +++ b/pkgs/development/tools/misc/ctags/default.nix @@ -15,6 +15,13 @@ stdenv.mkDerivation rec { # don't use $T(E)MP which is set to the build directory configureFlags= [ "--enable-tmpdir=/tmp" ]; + patches = [ + # Library defines an `__unused__` which is a reserved name, and may + # conflict with the standard library definition. One such conflict is with + # macOS headers. + ./unused-collision.patch + ]; + meta = with lib; { description = "A tool for fast source code browsing (exuberant ctags)"; longDescription = '' diff --git a/pkgs/development/tools/misc/ctags/unused-collision.patch b/pkgs/development/tools/misc/ctags/unused-collision.patch new file mode 100644 index 00000000000..595f67a01b5 --- /dev/null +++ b/pkgs/development/tools/misc/ctags/unused-collision.patch @@ -0,0 +1,246 @@ +--- a/c.c (revision 816) ++++ b/c.c (working copy) +@@ -619,7 +619,7 @@ + return name; + } + +-static void __unused__ pt (tokenInfo *const token) ++static void UNUSED pt (tokenInfo *const token) + { + if (isType (token, TOKEN_NAME)) + printf ("type: %-12s: %-13s line: %lu\n", +@@ -634,7 +634,7 @@ + tokenString (token->type), token->lineNumber); + } + +-static void __unused__ ps (statementInfo *const st) ++static void UNUSED ps (statementInfo *const st) + { + unsigned int i; + printf ("scope: %s decl: %s gotName: %s gotParenName: %s\n", +--- a/eiffel.c (revision 816) ++++ b/eiffel.c (working copy) +@@ -807,7 +807,7 @@ + + static boolean parseType (tokenInfo *const token); + +-static void parseGeneric (tokenInfo *const token, boolean declaration __unused__) ++static void parseGeneric (tokenInfo *const token, boolean declaration UNUSED) + { + unsigned int depth = 0; + #ifdef TYPE_REFERENCE_TOOL +--- a/general.h (revision 816) ++++ b/general.h (working copy) +@@ -57,10 +57,10 @@ + * to prevent warnings about unused variables. + */ + #if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)) && !defined (__GNUG__) +-# define __unused__ __attribute__((unused)) ++# define UNUSED __attribute__((unused)) + # define __printf__(s,f) __attribute__((format (printf, s, f))) + #else +-# define __unused__ ++# define UNUSED + # define __printf__(s,f) + #endif + +--- a/lregex.c (revision 816) ++++ b/lregex.c (working copy) +@@ -538,11 +538,11 @@ + #endif /* HAVE_REGEX */ + + extern void addTagRegex ( +- const langType language __unused__, +- const char* const regex __unused__, +- const char* const name __unused__, +- const char* const kinds __unused__, +- const char* const flags __unused__) ++ const langType language UNUSED, ++ const char* const regex UNUSED, ++ const char* const name UNUSED, ++ const char* const kinds UNUSED, ++ const char* const flags UNUSED) + { + #ifdef HAVE_REGEX + Assert (regex != NULL); +@@ -564,10 +564,10 @@ + } + + extern void addCallbackRegex ( +- const langType language __unused__, +- const char* const regex __unused__, +- const char* const flags __unused__, +- const regexCallback callback __unused__) ++ const langType language UNUSED, ++ const char* const regex UNUSED, ++ const char* const flags UNUSED, ++ const regexCallback callback UNUSED) + { + #ifdef HAVE_REGEX + Assert (regex != NULL); +@@ -581,7 +581,7 @@ + } + + extern void addLanguageRegex ( +- const langType language __unused__, const char* const regex __unused__) ++ const langType language UNUSED, const char* const regex UNUSED) + { + #ifdef HAVE_REGEX + if (! regexBroken) +@@ -602,7 +602,7 @@ + */ + + extern boolean processRegexOption (const char *const option, +- const char *const parameter __unused__) ++ const char *const parameter UNUSED) + { + boolean handled = FALSE; + const char* const dash = strchr (option, '-'); +@@ -624,7 +624,7 @@ + return handled; + } + +-extern void disableRegexKinds (const langType language __unused__) ++extern void disableRegexKinds (const langType language UNUSED) + { + #ifdef HAVE_REGEX + if (language <= SetUpper && Sets [language].count > 0) +@@ -639,8 +639,8 @@ + } + + extern boolean enableRegexKind ( +- const langType language __unused__, +- const int kind __unused__, const boolean mode __unused__) ++ const langType language UNUSED, ++ const int kind UNUSED, const boolean mode UNUSED) + { + boolean result = FALSE; + #ifdef HAVE_REGEX +@@ -660,7 +660,7 @@ + return result; + } + +-extern void printRegexKinds (const langType language __unused__, boolean indent __unused__) ++extern void printRegexKinds (const langType language UNUSED, boolean indent UNUSED) + { + #ifdef HAVE_REGEX + if (language <= SetUpper && Sets [language].count > 0) +--- a/lua.c (revision 816) ++++ b/lua.c (working copy) +@@ -37,7 +37,7 @@ + */ + + /* for debugging purposes */ +-static void __unused__ print_string (char *p, char *q) ++static void UNUSED print_string (char *p, char *q) + { + for ( ; p != q; p++) + fprintf (errout, "%c", *p); +--- a/main.c (revision 816) ++++ b/main.c (working copy) +@@ -522,7 +522,7 @@ + * Start up code + */ + +-extern int main (int __unused__ argc, char **argv) ++extern int main (int UNUSED argc, char **argv) + { + cookedArgs *args; + #ifdef VMS +--- a/options.c (revision 816) ++++ b/options.c (working copy) +@@ -730,7 +730,7 @@ + } + + static void processExcludeOption ( +- const char *const option __unused__, const char *const parameter) ++ const char *const option UNUSED, const char *const parameter) + { + const char *const fileName = parameter + 1; + if (parameter [0] == '\0') +@@ -867,7 +867,7 @@ + } + + static void processFilterTerminatorOption ( +- const char *const option __unused__, const char *const parameter) ++ const char *const option UNUSED, const char *const parameter) + { + freeString (&Option.filterTerminator); + Option.filterTerminator = stringCopy (parameter); +@@ -930,8 +930,8 @@ + } + + static void processHelpOption ( +- const char *const option __unused__, +- const char *const parameter __unused__) ++ const char *const option UNUSED, ++ const char *const parameter UNUSED) + { + printProgramIdentification (); + putchar ('\n'); +@@ -1139,8 +1139,8 @@ + } + + static void processLicenseOption ( +- const char *const option __unused__, +- const char *const parameter __unused__) ++ const char *const option UNUSED, ++ const char *const parameter UNUSED) + { + printProgramIdentification (); + puts (""); +@@ -1166,8 +1166,8 @@ + } + + static void processListMapsOption ( +- const char *const __unused__ option, +- const char *const __unused__ parameter) ++ const char *const UNUSED option, ++ const char *const UNUSED parameter) + { + if (parameter [0] == '\0' || strcasecmp (parameter, "all") == 0) + printLanguageMaps (LANG_AUTO); +@@ -1183,8 +1183,8 @@ + } + + static void processListLanguagesOption ( +- const char *const option __unused__, +- const char *const parameter __unused__) ++ const char *const option UNUSED, ++ const char *const parameter UNUSED) + { + printLanguageList (); + exit (0); +@@ -1358,8 +1358,8 @@ + } + + static void processVersionOption ( +- const char *const option __unused__, +- const char *const parameter __unused__) ++ const char *const option UNUSED, ++ const char *const parameter UNUSED) + { + printProgramIdentification (); + exit (0); +--- a/parse.c (revision 816) ++++ b/parse.c (working copy) +@@ -376,7 +376,7 @@ + */ + + extern void processLanguageDefineOption ( +- const char *const option, const char *const parameter __unused__) ++ const char *const option, const char *const parameter UNUSED) + { + #ifdef HAVE_REGEX + if (parameter [0] == '\0') +--- a/routines.c (revision 816) ++++ b/routines.c (working copy) +@@ -526,7 +526,7 @@ + + #if ! defined (HAVE_STAT_ST_INO) + +-static void canonicalizePath (char *const path __unused__) ++static void canonicalizePath (char *const path UNUSED) + { + #if defined (MSDOS_STYLE_PATH) + char *p; From c99904e11307cbade607ad855a29f07694762f37 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 4 Feb 2021 18:29:29 +0900 Subject: [PATCH 42/71] clang_11: revert -fno-common default --- .../compilers/llvm/11/clang/default.nix | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pkgs/development/compilers/llvm/11/clang/default.nix b/pkgs/development/compilers/llvm/11/clang/default.nix index 67b5e0c17fe..f23394a8b75 100644 --- a/pkgs/development/compilers/llvm/11/clang/default.nix +++ b/pkgs/development/compilers/llvm/11/clang/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, llvm_meta, fetch, cmake, libxml2, libllvm, version, clang-tools-extra_src, python3 +{ lib, stdenv, llvm_meta, fetch, fetchpatch, cmake, libxml2, libllvm, version, clang-tools-extra_src, python3 , buildLlvmTools , fixDarwinDylibNames , enableManpages ? false @@ -45,6 +45,18 @@ let ./purity.patch # https://reviews.llvm.org/D51899 ./gnu-install-dirs.patch + # Revert: [Driver] Default to -fno-common for all targets + # https://reviews.llvm.org/D75056 + # + # Maintains compatibility with packages that haven't been fixed yet, and + # matches gcc10's configuration in nixpkgs. + (fetchpatch { + revert = true; + url = "https://github.com/llvm/llvm-project/commit/0a9fc9233e172601e26381810d093e02ef410f65.diff"; + stripLen = 1; + excludes = [ "docs/*" "test/*" ]; + sha256 = "0gxgmi0qbm89mq911dahallhi8m6wa9vpklklqmxafx4rplrr8ph"; + }) ]; postPatch = '' From 23cae56ca720fadb1040e7739a30bff7dbda38c8 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Tue, 9 Feb 2021 15:58:21 +0900 Subject: [PATCH 43/71] lib/systems/platforms: add Apple M1 --- lib/systems/platforms.nix | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/systems/platforms.nix b/lib/systems/platforms.nix index f46e9c826a5..445144439ca 100644 --- a/lib/systems/platforms.nix +++ b/lib/systems/platforms.nix @@ -375,6 +375,13 @@ rec { }; }; + apple-m1 = { + gcc = { + arch = "armv8.3-a+crypto+sha2+aes+crc+fp16+lse+simd+ras+rdm+rcpc"; + cpu = "apple-a13"; + }; + }; + ## ## MIPS ## @@ -495,7 +502,10 @@ rec { else if lib.versionOlder version "6" then sheevaplug else if lib.versionOlder version "7" then raspberrypi else armv7l-hf-multiplatform - else if platform.isAarch64 then aarch64-multiplatform + + else if platform.isAarch64 then + if platform.isDarwin then apple-m1 + else aarch64-multiplatform else if platform.isRiscV then riscv-multiplatform From bac1418031a6c4e9cf891aa7d3e07df0ba008147 Mon Sep 17 00:00:00 2001 From: Ivan Babrou Date: Fri, 5 Feb 2021 09:34:12 -0800 Subject: [PATCH 44/71] xcbuild: allow building arm64 binaries File paths are copied from XCode 12. --- pkgs/development/tools/xcbuild/platforms.nix | 30 ++++++++++---------- pkgs/development/tools/xcbuild/wrapper.nix | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pkgs/development/tools/xcbuild/platforms.nix b/pkgs/development/tools/xcbuild/platforms.nix index e20dc878b53..0108ac8ef69 100644 --- a/pkgs/development/tools/xcbuild/platforms.nix +++ b/pkgs/development/tools/xcbuild/platforms.nix @@ -1,4 +1,4 @@ -{ runCommand, lib, sdks, xcodePlatform, writeText }: +{ stdenv, runCommand, lib, sdks, xcodePlatform, writeText }: let @@ -15,23 +15,23 @@ let }; # These files are all based off of Xcode spec fies found in - # /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Xcode/Speciications/. + # /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Xcode/PrivatePlugIns/IDEOSXSupportCore.ideplugin/Contents/Resources. - # Based off of the MacOSX Architectures.xcpsec file. All i386 stuff - # is removed because NixPkgs only supports darwin-x86_64. + # Based off of the "MacOSX Architectures.xcspec" file. All i386 stuff + # is removed because NixPkgs only supports darwin-x86_64 and darwin-arm64. Architectures = [ { Identifier = "Standard"; Type = "Architecture"; - Name = "Standard Architectures (64-bit Intel)"; - RealArchitectures = [ "x86_64" ]; + Name = "Standard Architectures (Apple Silicon, 64-bit Intel)"; + RealArchitectures = [ "arm64" "x86_64" ]; ArchitectureSetting = "ARCHS_STANDARD"; } { Identifier = "Universal"; Type = "Architecture"; - Name = "Universal (64-bit Intel)"; - RealArchitectures = [ "x86_64" ]; + Name = "Universal (Apple Silicon, 64-bit Intel)"; + RealArchitectures = [ "arm64" "x86_64" ]; ArchitectureSetting = "ARCHS_STANDARD_32_64_BIT"; } { @@ -43,25 +43,25 @@ let { Identifier = "Standard64bit"; Type = "Architecture"; - Name = "64-bit Intel"; - RealArchitectures = [ "x86_64" ]; + Name = "Apple Silicon, 64-bit Intel"; + RealArchitectures = [ "arm64" "x86_64" ]; ArchitectureSetting = "ARCHS_STANDARD_64_BIT"; } { - Identifier = "x86_64"; + Identifier = if stdenv.isAarch64 then "arm64" else "x86_64"; Type = "Architecture"; - Name = "Intel 64-bit"; + Name = "Apple Silicon or Intel 64-bit"; } { Identifier = "Standard_Including_64_bit"; Type = "Architecture"; Name = "Standard Architectures (including 64-bit)"; - RealArchitectures = [ "x86_64" ]; + RealArchitectures = [ "arm64" "x86_64" ]; ArchitectureSetting = "ARCHS_STANDARD_INCLUDING_64_BIT"; } ]; - # Based off of the MacOSX Package Types.xcpsec file. Only keep the + # Based off of the "MacOSX Package Types.xcspec" file. Only keep the # bare minimum needed. PackageTypes = [ { @@ -169,7 +169,7 @@ let } ]; - # Based off of the MacOSX Product Types.xcpsec file. All + # Based off of the "MacOSX Product Types.xcspec" file. All # bundles/wrapper are removed, because we prefer dynamic products in # NixPkgs. ProductTypes = [ diff --git a/pkgs/development/tools/xcbuild/wrapper.nix b/pkgs/development/tools/xcbuild/wrapper.nix index 4f74b093717..ca69bbe907d 100644 --- a/pkgs/development/tools/xcbuild/wrapper.nix +++ b/pkgs/development/tools/xcbuild/wrapper.nix @@ -28,7 +28,7 @@ let }; platforms = callPackage ./platforms.nix { - inherit sdks xcodePlatform; + inherit sdks xcodePlatform stdenv; }; xcconfig = writeText "nix.xcconfig" '' From 2eb97f2ddd3f557c39437c1007b92d51f619628d Mon Sep 17 00:00:00 2001 From: Ivan Babrou Date: Fri, 5 Feb 2021 21:42:42 -0800 Subject: [PATCH 45/71] darwin.developer_cmds: wrap clang -E from clang-wrapped as clang-cpp --- .../apple-source-releases/developer_cmds/default.nix | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkgs/os-specific/darwin/apple-source-releases/developer_cmds/default.nix b/pkgs/os-specific/darwin/apple-source-releases/developer_cmds/default.nix index 77de079e2f0..f2c4ec32146 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/developer_cmds/default.nix +++ b/pkgs/os-specific/darwin/apple-source-releases/developer_cmds/default.nix @@ -1,7 +1,7 @@ -{ lib, appleDerivation, xcbuildHook, llvmPackages }: +{ lib, appleDerivation, xcbuildHook, llvmPackages, makeWrapper }: appleDerivation { - nativeBuildInputs = [ xcbuildHook ]; + nativeBuildInputs = [ xcbuildHook makeWrapper ]; patches = [ # The following copied from @@ -11,8 +11,9 @@ appleDerivation { ]; postPatch = '' + makeWrapper ${llvmPackages.clang}/bin/clang $out/bin/clang-cpp --add-flags "--driver-mode=cpp" substituteInPlace rpcgen/rpc_main.c \ - --replace "/usr/bin/cpp" "${llvmPackages.clang-unwrapped}/bin/clang-cpp" + --replace "/usr/bin/cpp" "$out/bin/clang-cpp" ''; # temporary install phase until xcodebuild has "install" support From da3ae0231aa2433f6f3711e57020456dc27e26e5 Mon Sep 17 00:00:00 2001 From: Ivan Babrou Date: Fri, 5 Feb 2021 23:00:44 -0800 Subject: [PATCH 46/71] apple-source-releases: make it compile on aarch64 --- .../darwin/apple-source-releases/system_cmds/default.nix | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkgs/os-specific/darwin/apple-source-releases/system_cmds/default.nix b/pkgs/os-specific/darwin/apple-source-releases/system_cmds/default.nix index 34d093b7cc0..d42d142ef6e 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/system_cmds/default.nix +++ b/pkgs/os-specific/darwin/apple-source-releases/system_cmds/default.nix @@ -1,5 +1,5 @@ { stdenv, appleDerivation, lib -, Librpcsvc, apple_sdk, pam, CF, openbsm }: +, libutil, Librpcsvc, apple_sdk, pam, CF, openbsm }: appleDerivation { # xcbuild fails with: @@ -7,7 +7,7 @@ appleDerivation { # see issue facebook/xcbuild#188 # buildInputs = [ xcbuild ]; - buildInputs = [ Librpcsvc apple_sdk.frameworks.OpenDirectory pam CF + buildInputs = [ libutil Librpcsvc apple_sdk.frameworks.OpenDirectory pam CF apple_sdk.frameworks.IOKit openbsm ]; # NIX_CFLAGS_COMPILE = lib.optionalString hostPlatform.isi686 "-D__i386__" # + lib.optionalString hostPlatform.isx86_64 "-D__x86_64__" @@ -35,6 +35,11 @@ appleDerivation { --replace bsm/audit_session.h bsm/audit.h substituteInPlace login.tproj/login_audit.c \ --replace bsm/audit_session.h bsm/audit.h + '' + lib.optionalString stdenv.isAarch64 '' + substituteInPlace sysctl.tproj/sysctl.c \ + --replace "GPROF_STATE" "0" + substituteInPlace login.tproj/login.c \ + --replace "defined(__arm__)" "defined(__arm__) || defined(__arm64__)" ''; buildPhase = '' From 6815776cb0b623c3ded838abc00b923838bba55c Mon Sep 17 00:00:00 2001 From: Ivan Babrou Date: Sun, 7 Feb 2021 13:35:53 -0800 Subject: [PATCH 47/71] python3Packages.cryptography: ignore test_openssl_memleak.py on aarch64-darwin The test fails due to dependency on W+X memory, which is forbidden as of 11.2. --- .../python-modules/cryptography/default.nix | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkgs/development/python-modules/cryptography/default.nix b/pkgs/development/python-modules/cryptography/default.nix index 1bf3602a7b1..fd6cbfc512e 100644 --- a/pkgs/development/python-modules/cryptography/default.nix +++ b/pkgs/development/python-modules/cryptography/default.nix @@ -66,8 +66,18 @@ buildPythonPackage rec { pytz ]; + pytestFlags = lib.concatStringsSep " " ([ + "--disable-pytest-warnings" + ] ++ + lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [ + # aarch64-darwin forbids W+X memory, but this tests depends on it: + # * https://cffi.readthedocs.io/en/latest/using.html#callbacks + "--ignore=tests/hazmat/backends/test_openssl_memleak.py" + ] + ); + checkPhase = '' - py.test --disable-pytest-warnings tests + py.test ${pytestFlags} tests ''; # IOKit's dependencies are inconsistent between OSX versions, so this is the best we From f067102afec850febd148fef827acdc6e759a59d Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Mon, 15 Feb 2021 14:55:53 +0900 Subject: [PATCH 48/71] removeReferencesTo: fix code signatures on aarch64-darwin --- .../remove-references-to/darwin-sign-fixup.sh | 5 ++ .../remove-references-to/default.nix | 51 ++++++++++--------- .../remove-references-to.sh | 37 ++++++++++++++ pkgs/top-level/all-packages.nix | 4 +- 4 files changed, 71 insertions(+), 26 deletions(-) create mode 100644 pkgs/build-support/remove-references-to/darwin-sign-fixup.sh create mode 100644 pkgs/build-support/remove-references-to/remove-references-to.sh diff --git a/pkgs/build-support/remove-references-to/darwin-sign-fixup.sh b/pkgs/build-support/remove-references-to/darwin-sign-fixup.sh new file mode 100644 index 00000000000..940c18e5a62 --- /dev/null +++ b/pkgs/build-support/remove-references-to/darwin-sign-fixup.sh @@ -0,0 +1,5 @@ +# Fixup hook for nukeReferences, not stdenv + +source @signingUtils@ + +fixupHooks+=(signIfRequired) diff --git a/pkgs/build-support/remove-references-to/default.nix b/pkgs/build-support/remove-references-to/default.nix index 8b1d05fc230..f022611ef91 100644 --- a/pkgs/build-support/remove-references-to/default.nix +++ b/pkgs/build-support/remove-references-to/default.nix @@ -3,32 +3,33 @@ # non-existent path (/nix/store/eeee...). This is useful for getting rid of # dependencies that you know are not actually needed at runtime. -{ stdenv, writeScriptBin }: +{ lib, stdenvNoCC, signingUtils, shell ? stdenvNoCC.shell }: -writeScriptBin "remove-references-to" '' -#! ${stdenv.shell} -e +let + stdenv = stdenvNoCC; -# References to remove -targets=() -while getopts t: o; do - case "$o" in - t) storeId=$(echo "$OPTARG" | sed -n "s|^$NIX_STORE/\\([a-z0-9]\{32\}\\)-.*|\1|p") - if [ -z "$storeId" ]; then - echo "-t argument must be a Nix store path" - exit 1 - fi - targets+=("$storeId") - esac -done -shift $(($OPTIND-1)) + darwinCodeSign = stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64; +in -# Files to remove the references from -regions=() -for i in "$@"; do - test ! -L "$i" -a -f "$i" && regions+=("$i") -done +stdenv.mkDerivation { + name = "remove-references-to"; -for target in "''${targets[@]}" ; do - sed -i -e "s|$NIX_STORE/$target-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" "''${regions[@]}" -done -'' + dontUnpack = true; + dontConfigure = true; + dontBuild = true; + + installPhase = '' + mkdir -p $out/bin + substituteAll ${./remove-references-to.sh} $out/bin/remove-references-to + chmod a+x $out/bin/remove-references-to + ''; + + postFixup = lib.optionalString darwinCodeSign '' + mkdir -p $out/nix-support + substituteAll ${./darwin-sign-fixup.sh} $out/nix-support/setup-hooks.sh + ''; + + inherit (builtins) storeDir; + shell = lib.getBin shell + (shell.shellPath or ""); + signingUtils = if darwinCodeSign then signingUtils else null; +} diff --git a/pkgs/build-support/remove-references-to/remove-references-to.sh b/pkgs/build-support/remove-references-to/remove-references-to.sh new file mode 100644 index 00000000000..d8d38dbd80a --- /dev/null +++ b/pkgs/build-support/remove-references-to/remove-references-to.sh @@ -0,0 +1,37 @@ +#! @shell@ -e + +fixupHooks=() + +if [ -e @out@/nix-support/setup-hooks.sh ]; then + source @out@/nix-support/setup-hooks.sh +fi + +# References to remove +targets=() +while getopts t: o; do + case "$o" in + t) storeId=$(echo "$OPTARG" | sed -n "s|^@storeDir@/\\([a-z0-9]\{32\}\\)-.*|\1|p") + if [ -z "$storeId" ]; then + echo "-t argument must be a Nix store path" + exit 1 + fi + targets+=("$storeId") + esac +done +shift $(($OPTIND-1)) + +# Files to remove the references from +regions=() +for i in "$@"; do + test ! -L "$i" -a -f "$i" && regions+=("$i") +done + +for target in "${targets[@]}" ; do + sed -i -e "s|@storeDir@/$target-|@storeDir@/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" "${regions[@]}" +done + +for region in "${regions[@]}"; do + for hook in "${fixupHooks[@]}"; do + eval "$hook" "$i" + done +done diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index ba9f9f8d94a..6101cb555f1 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -642,7 +642,9 @@ in referencesByPopularity = callPackage ../build-support/references-by-popularity { }; - removeReferencesTo = callPackage ../build-support/remove-references-to { }; + removeReferencesTo = callPackage ../build-support/remove-references-to { + inherit (darwin) signingUtils; + }; vmTools = callPackage ../build-support/vm { }; From 79e34294bd678f615bf4a3511c0d875891fc8b0b Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Mon, 15 Feb 2021 14:56:21 +0900 Subject: [PATCH 49/71] nukeReferences: fix code signatures on aarch64-darwin --- pkgs/build-support/nuke-references/builder.sh | 29 ---------------- .../nuke-references/darwin-sign-fixup.sh | 5 +++ .../build-support/nuke-references/default.nix | 28 ++++++++++++++-- .../nuke-references/nuke-refs.sh | 33 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 4 ++- 5 files changed, 67 insertions(+), 32 deletions(-) delete mode 100644 pkgs/build-support/nuke-references/builder.sh create mode 100644 pkgs/build-support/nuke-references/darwin-sign-fixup.sh create mode 100644 pkgs/build-support/nuke-references/nuke-refs.sh diff --git a/pkgs/build-support/nuke-references/builder.sh b/pkgs/build-support/nuke-references/builder.sh deleted file mode 100644 index 7da32203218..00000000000 --- a/pkgs/build-support/nuke-references/builder.sh +++ /dev/null @@ -1,29 +0,0 @@ -source $stdenv/setup - -mkdir -p $out/bin -cat > $out/bin/nuke-refs < "\$i.tmp" - if test -x "\$i"; then chmod +x "\$i.tmp"; fi - mv "\$i.tmp" "\$i" - fi -done -EOF -chmod +x $out/bin/nuke-refs diff --git a/pkgs/build-support/nuke-references/darwin-sign-fixup.sh b/pkgs/build-support/nuke-references/darwin-sign-fixup.sh new file mode 100644 index 00000000000..940c18e5a62 --- /dev/null +++ b/pkgs/build-support/nuke-references/darwin-sign-fixup.sh @@ -0,0 +1,5 @@ +# Fixup hook for nukeReferences, not stdenv + +source @signingUtils@ + +fixupHooks+=(signIfRequired) diff --git a/pkgs/build-support/nuke-references/default.nix b/pkgs/build-support/nuke-references/default.nix index d894b56d366..03f6fe53b54 100644 --- a/pkgs/build-support/nuke-references/default.nix +++ b/pkgs/build-support/nuke-references/default.nix @@ -3,11 +3,35 @@ # path (/nix/store/eeee...). This is useful for getting rid of # dependencies that you know are not actually needed at runtime. -{ stdenvNoCC, perl }: +{ lib, stdenvNoCC, perl, signingUtils, shell ? stdenvNoCC.shell }: + +let + stdenv = stdenvNoCC; + + darwinCodeSign = stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64; +in stdenvNoCC.mkDerivation { name = "nuke-references"; - builder = ./builder.sh; + + dontUnpack = true; + dontConfigure = true; + dontBuild = true; + + installPhase = '' + mkdir -p $out/bin + substituteAll ${./nuke-refs.sh} $out/bin/nuke-refs + chmod a+x $out/bin/nuke-refs + ''; + + postFixup = lib.optionalString darwinCodeSign '' + mkdir -p $out/nix-support + substituteAll ${./darwin-sign-fixup.sh} $out/nix-support/setup-hooks.sh + ''; + # FIXME: get rid of perl dependency. inherit perl; + inherit (builtins) storeDir; + shell = lib.getBin shell + (shell.shellPath or ""); + signingUtils = if darwinCodeSign then signingUtils else null; } diff --git a/pkgs/build-support/nuke-references/nuke-refs.sh b/pkgs/build-support/nuke-references/nuke-refs.sh new file mode 100644 index 00000000000..21eb855cbad --- /dev/null +++ b/pkgs/build-support/nuke-references/nuke-refs.sh @@ -0,0 +1,33 @@ +#! @shell@ + +fixupHooks=() + +if [ -e @out@/nix-support/setup-hooks.sh ]; then + source @out@/nix-support/setup-hooks.sh +fi + +excludes="" +while getopts e: o; do + case "$o" in + e) storeId=$(echo "$OPTARG" | @perl@/bin/perl -ne "print \"\$1\" if m|^\Q@storeDir@\E/([a-z0-9]{32})-.*|") + if [ -z "$storeId" ]; then + echo "-e argument must be a Nix store path" + exit 1 + fi + excludes="$excludes(?!$storeId)" + ;; + esac +done +shift $(($OPTIND-1)) + +for i in "$@"; do + if test ! -L "$i" -a -f "$i"; then + cat "$i" | @perl@/bin/perl -pe "s|\Q@storeDir@\E/$excludes[a-z0-9]{32}-|@storeDir@/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" > "$i.tmp" + if test -x "$i"; then chmod +x "$i.tmp"; fi + mv "$i.tmp" "$i" + + for hook in "${fixupHooks[@]}"; do + eval "$hook" "$i" + done + fi +done diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 6101cb555f1..2aa1a7b2751 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -638,7 +638,9 @@ in replaceDependency = callPackage ../build-support/replace-dependency.nix { }; - nukeReferences = callPackage ../build-support/nuke-references { }; + nukeReferences = callPackage ../build-support/nuke-references { + inherit (darwin) signingUtils; + }; referencesByPopularity = callPackage ../build-support/references-by-popularity { }; From 755d980440a9aefba6a0aebfc367621acd892cf6 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Mon, 15 Feb 2021 15:45:37 +0900 Subject: [PATCH 50/71] darwin: use "11.0" as sdk and minimum version on aarch64-darwin --- lib/systems/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/systems/default.nix b/lib/systems/default.nix index 549f01b058f..70ec98b03c1 100644 --- a/lib/systems/default.nix +++ b/lib/systems/default.nix @@ -131,7 +131,7 @@ rec { else null; # The canonical name for this attribute is darwinSdkVersion, but some # platforms define the old name "sdkVer". - darwinSdkVersion = final.sdkVer or "10.12"; + darwinSdkVersion = final.sdkVer or (if final.isAarch64 then "11.0" else "10.12"); darwinMinVersion = final.darwinSdkVersion; darwinMinVersionVariable = if final.isMacOS then "MACOSX_DEPLOYMENT_TARGET" From aadc07a3d9217a002d01bebb661d3a71825928e3 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Fri, 12 Feb 2021 12:11:43 +0900 Subject: [PATCH 51/71] mc: fix code signature on aarch64-darwin --- pkgs/tools/misc/mc/default.nix | 8 +++++++- pkgs/top-level/all-packages.nix | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pkgs/tools/misc/mc/default.nix b/pkgs/tools/misc/mc/default.nix index 12aa477219b..6cbe693fb60 100644 --- a/pkgs/tools/misc/mc/default.nix +++ b/pkgs/tools/misc/mc/default.nix @@ -16,6 +16,7 @@ , openssl , coreutils , autoreconfHook +, autoSignDarwinBinariesHook }: stdenv.mkDerivation rec { @@ -27,7 +28,12 @@ stdenv.mkDerivation rec { sha256 = "sha256-xt6txQWV8tmiLcbCmanyizk+NYNG6/bKREqEadwWbCc="; }; - nativeBuildInputs = [ pkg-config autoreconfHook unzip ]; + nativeBuildInputs = [ pkg-config autoreconfHook unzip ] + # The preFixup hook rewrites the binary, which invaliates the code + # signature. Add the fixup hook to sign the output. + ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) [ + autoSignDarwinBinariesHook + ]; buildInputs = [ file diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 2aa1a7b2751..4d5a9443704 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -6695,7 +6695,9 @@ in mbutil = python3Packages.callPackage ../applications/misc/mbutil { }; - mc = callPackage ../tools/misc/mc { }; + mc = callPackage ../tools/misc/mc { + inherit (darwin) autoSignDarwinBinariesHook; + }; mcabber = callPackage ../applications/networking/instant-messengers/mcabber { }; From 3e4774765769f9e07b9e7249bfc48bb56733967c Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 18 Feb 2021 22:11:19 +0900 Subject: [PATCH 52/71] libxml2: cap MACOSX_DEPLOYMENT_TARGET at 10.16 libxml2 is used in bootstrapping, so the alternates solution of running libtoolize is tricky here. --- pkgs/development/libraries/libxml2/default.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkgs/development/libraries/libxml2/default.nix b/pkgs/development/libraries/libxml2/default.nix index f436528e13c..ca3cbc4a188 100644 --- a/pkgs/development/libraries/libxml2/default.nix +++ b/pkgs/development/libraries/libxml2/default.nix @@ -3,7 +3,7 @@ , pythonSupport ? enableShared && stdenv.buildPlatform == stdenv.hostPlatform , icuSupport ? false, icu ? null , enableShared ? stdenv.hostPlatform.libc != "msvcrt" -, enableStatic ? !enableShared, +, enableStatic ? !enableShared }: stdenv.mkDerivation rec { @@ -53,6 +53,10 @@ stdenv.mkDerivation rec { (lib.withFeatureAs pythonSupport "python" python) ]; + preConfigure = lib.optionalString (lib.versionAtLeast stdenv.hostPlatform.darwinMinVersion "11") '' + MACOSX_DEPLOYMENT_TARGET=10.16 + ''; + enableParallelBuilding = true; # disable test that's problematic with newer pythons: see From 577bcf38f8a7172cab86f3c2dfc5d35268345bb6 Mon Sep 17 00:00:00 2001 From: Ivan Babrou Date: Sat, 6 Feb 2021 12:49:00 -0800 Subject: [PATCH 53/71] darwin.shell_cmds: add missing dependency on launchd --- .../darwin/apple-source-releases/shell_cmds/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/os-specific/darwin/apple-source-releases/shell_cmds/default.nix b/pkgs/os-specific/darwin/apple-source-releases/shell_cmds/default.nix index e2e13a168f0..a8352285c78 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/shell_cmds/default.nix +++ b/pkgs/os-specific/darwin/apple-source-releases/shell_cmds/default.nix @@ -1,7 +1,7 @@ -{ lib, appleDerivation, xcbuildHook }: +{ lib, appleDerivation, xcbuildHook, launchd }: appleDerivation { - nativeBuildInputs = [ xcbuildHook ]; + nativeBuildInputs = [ xcbuildHook launchd ]; patchPhase = '' # NOTE: these hashes must be recalculated for each version change From d0eff87f6873ed244a294a8d6c81ec7a724d4f19 Mon Sep 17 00:00:00 2001 From: Ivan Babrou Date: Wed, 10 Feb 2021 23:51:49 -0800 Subject: [PATCH 54/71] darwin.file_cmds: add missing Libinfo dependency Fixing: ``` /private/tmp/nix-build-file_cmds-264.1.1-osx-10.11.6.drv-0/file_cmds-264.1.1/ls/print.c:56:10: fatal error: 'membershipPriv.h' file not found ^~~~~~~~~~~~~~~~~~ 1 error generated. ``` --- .../darwin/apple-source-releases/file_cmds/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/os-specific/darwin/apple-source-releases/file_cmds/default.nix b/pkgs/os-specific/darwin/apple-source-releases/file_cmds/default.nix index 53f98e2b457..981e1370437 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/file_cmds/default.nix +++ b/pkgs/os-specific/darwin/apple-source-releases/file_cmds/default.nix @@ -1,8 +1,8 @@ -{ lib, appleDerivation, xcbuildHook, zlib, bzip2, xz, ncurses, libutil }: +{ lib, appleDerivation, xcbuildHook, zlib, bzip2, xz, ncurses, libutil, Libinfo }: appleDerivation { nativeBuildInputs = [ xcbuildHook ]; - buildInputs = [ zlib bzip2 xz ncurses libutil ]; + buildInputs = [ zlib bzip2 xz ncurses libutil Libinfo ]; # some commands not working: # mtree: _simple.h not found From 68733c16f52cfc30ee1550fa362f5fb126f0e0a7 Mon Sep 17 00:00:00 2001 From: Ivan Babrou Date: Tue, 9 Feb 2021 13:58:55 -0800 Subject: [PATCH 55/71] darwin.apple_sdk.frameworks: add missing dependencies ``` /nix/store/5mgn511gbldf7xl5kjm27z9lj10xcycl-apple-framework-CoreData-11.0.0/Library/Frameworks/CoreData.framework/Headers/NSPersistentCloudKitContainerOptions.h:10:9: fatal error: 'CloudKit/CKDatabase.h' file not found ^~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. ``` ``` /nix/store/a7k7kqj08602785vsrss0xa85b08hik4-apple-framework-CloudKit-11.0.0/Library/Frameworks/CloudKit.framework/Headers/CKRecord.h:9:9: fatal error: 'CoreLocation/CLLocation.h' file not found ^~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. ``` --- pkgs/os-specific/darwin/apple-sdk-11.0/frameworks.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/os-specific/darwin/apple-sdk-11.0/frameworks.nix b/pkgs/os-specific/darwin/apple-sdk-11.0/frameworks.nix index 0a605c198a1..c8f8ccc4a08 100644 --- a/pkgs/os-specific/darwin/apple-sdk-11.0/frameworks.nix +++ b/pkgs/os-specific/darwin/apple-sdk-11.0/frameworks.nix @@ -26,18 +26,18 @@ CallKit = {}; Carbon = { inherit ApplicationServices CoreServices Foundation IOKit QuartzCore Security libobjc; }; ClassKit = {}; - CloudKit = {}; + CloudKit = { inherit CoreLocation; }; Cocoa = { inherit AppKit CoreData; }; Collaboration = {}; ColorSync = {}; Combine = {}; Contacts = {}; ContactsUI = {}; - CoreAudio = { inherit IOKit; }; + CoreAudio = { inherit IOKit CoreAudioTypes; }; CoreAudioKit = { inherit AudioUnit; }; CoreAudioTypes = {}; CoreBluetooth = {}; - CoreData = {}; + CoreData = { inherit CloudKit; }; CoreDisplay = {}; CoreFoundation = { inherit libobjc; }; CoreGraphics = { inherit Accelerate IOKit IOSurface SystemConfiguration; }; From f9e6eb090ea75b5b0d68e849e94c0298b8a5894f Mon Sep 17 00:00:00 2001 From: Ivan Babrou Date: Tue, 9 Feb 2021 23:31:04 -0800 Subject: [PATCH 56/71] llvmPackages: default to llvmPackages_11 on aarch64-darwin It doesn't make sense to use llvm7, which doesn't work on arm64. --- pkgs/top-level/all-packages.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 4d5a9443704..37606169189 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -11249,7 +11249,7 @@ in # This returns the minimum suported version for the platform. The # assumption is that or any later version is good. choose = platform: - /**/ if platform.isDarwin then 7 + /**/ if platform.isDarwin then (if platform.isAarch64 then 11 else 7) else if platform.isFreeBSD then 7 else if platform.isAndroid then 12 else if platform.isLinux then 7 From ea2e64c5c05f3b09fed2fc94abf355c1cdc278ea Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 25 Feb 2021 12:48:52 +0900 Subject: [PATCH 57/71] libevent: cap MACOSX_DEPLOYMENT_TARGET at 10.16 --- pkgs/development/libraries/libevent/default.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkgs/development/libraries/libevent/default.nix b/pkgs/development/libraries/libevent/default.nix index b33e94114f6..24ded54d8e9 100644 --- a/pkgs/development/libraries/libevent/default.nix +++ b/pkgs/development/libraries/libevent/default.nix @@ -13,6 +13,10 @@ stdenv.mkDerivation rec { sha256 = "1fq30imk8zd26x8066di3kpc5zyfc5z6frr3zll685zcx4dxxrlj"; }; + preConfigure = lib.optionalString (lib.versionAtLeast stdenv.hostPlatform.darwinMinVersion "11") '' + MACOSX_DEPLOYMENT_TARGET=10.16 + ''; + # libevent_openssl is moved into its own output, so that openssl isn't present # in the default closure. outputs = [ "out" "dev" ] From c96c85873c0a16e5db417ee5138a3ae567ae0d36 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 25 Feb 2021 12:48:59 +0900 Subject: [PATCH 58/71] openbsm: cap MACOSX_DEPLOYMENT_TARGET at 10.16 --- pkgs/development/libraries/openbsm/default.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkgs/development/libraries/openbsm/default.nix b/pkgs/development/libraries/openbsm/default.nix index 269b0138091..4719b7fb747 100644 --- a/pkgs/development/libraries/openbsm/default.nix +++ b/pkgs/development/libraries/openbsm/default.nix @@ -13,6 +13,10 @@ stdenv.mkDerivation rec { patches = lib.optional stdenv.isDarwin [ ./bsm-add-audit_token_to_pid.patch ]; + preConfigure = lib.optionalString (lib.versionAtLeast stdenv.hostPlatform.darwinMinVersion "11") '' + MACOSX_DEPLOYMENT_TARGET=10.16 + ''; + configureFlags = [ "ac_cv_file__usr_include_mach_audit_triggers_defs=no" ]; meta = { From e00c4cdc0a72e5739a27e2f5cac576202d10671e Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 25 Feb 2021 12:49:07 +0900 Subject: [PATCH 59/71] openldap: cap MACOSX_DEPLOYMENT_TARGET at 10.16 --- pkgs/development/libraries/openldap/default.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkgs/development/libraries/openldap/default.nix b/pkgs/development/libraries/openldap/default.nix index fe4704341ef..f9e2b3c0b3f 100644 --- a/pkgs/development/libraries/openldap/default.nix +++ b/pkgs/development/libraries/openldap/default.nix @@ -30,6 +30,10 @@ stdenv.mkDerivation rec { "CC=${stdenv.cc.targetPrefix}cc" ]; + preConfigure = lib.optionalString (lib.versionAtLeast stdenv.hostPlatform.darwinMinVersion "11") '' + MACOSX_DEPLOYMENT_TARGET=10.16 + ''; + configureFlags = [ "--enable-overlays" "--disable-dependency-tracking" # speeds up one-time build From 0ec1e50d8b2681717c90aab701c65e717f0b4bdf Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 25 Feb 2021 12:49:15 +0900 Subject: [PATCH 60/71] vde2: cap MACOSX_DEPLOYMENT_TARGET at 10.16 --- pkgs/tools/networking/vde2/default.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkgs/tools/networking/vde2/default.nix b/pkgs/tools/networking/vde2/default.nix index babbd88fd16..bc3be912265 100644 --- a/pkgs/tools/networking/vde2/default.nix +++ b/pkgs/tools/networking/vde2/default.nix @@ -22,6 +22,10 @@ stdenv.mkDerivation rec { }) ]; + preConfigure = lib.optionalString (lib.versionAtLeast stdenv.hostPlatform.darwinMinVersion "11") '' + MACOSX_DEPLOYMENT_TARGET=10.16 + ''; + configureFlags = lib.optional (!withPython) "--disable-python"; buildInputs = [ openssl libpcap ] From 1f0ae937d6862107e947300dbb64189bacd9e204 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Fri, 26 Feb 2021 13:19:11 +0900 Subject: [PATCH 61/71] libtool2: add bootstrapping warning --- pkgs/development/tools/misc/libtool/libtool2.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkgs/development/tools/misc/libtool/libtool2.nix b/pkgs/development/tools/misc/libtool/libtool2.nix index 89018027e6e..44e4c8665c8 100644 --- a/pkgs/development/tools/misc/libtool/libtool2.nix +++ b/pkgs/development/tools/misc/libtool/libtool2.nix @@ -1,6 +1,11 @@ { lib, stdenv, fetchurl, fetchpatch, autoconf, automake, m4, perl, help2man }: +# Note: this package is used for bootstrapping fetchurl, and thus +# cannot use fetchpatch! All mutable patches (generated by GitHub or +# cgit) that are needed here should be included directly in Nixpkgs as +# files. + stdenv.mkDerivation rec { pname = "libtool"; version = "2.4.6"; From 417a96c8beb4563a6d26814d5ff184524fb45726 Mon Sep 17 00:00:00 2001 From: Finn Behrens Date: Sun, 14 Mar 2021 17:51:57 +0100 Subject: [PATCH 62/71] sbcl: update to 2.1.2 and add arm64-darwin (cherry picked from commit 49d2ad093ecd54f40550745f240dda8dbf0ce920) --- pkgs/development/compilers/sbcl/2.0.8.nix | 4 ++-- pkgs/development/compilers/sbcl/bootstrap.nix | 5 +++++ pkgs/development/compilers/sbcl/common.nix | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pkgs/development/compilers/sbcl/2.0.8.nix b/pkgs/development/compilers/sbcl/2.0.8.nix index bbc171a8d98..1784bf672b3 100644 --- a/pkgs/development/compilers/sbcl/2.0.8.nix +++ b/pkgs/development/compilers/sbcl/2.0.8.nix @@ -1,4 +1,4 @@ import ./common.nix { - version = "2.0.8"; - sha256 = "1xwrwvps7drrpyw3wg5h3g2qajmkwqs9gz0fdw1ns9adp7vld390"; + version = "2.1.2"; + sha256 = "sha256-t3EFUJOYVe1JWYxKAUSD7RILaZFliio7avpHcT3OTAs="; } diff --git a/pkgs/development/compilers/sbcl/bootstrap.nix b/pkgs/development/compilers/sbcl/bootstrap.nix index 8bdbbadc9d6..eaf1ff24d3e 100644 --- a/pkgs/development/compilers/sbcl/bootstrap.nix +++ b/pkgs/development/compilers/sbcl/bootstrap.nix @@ -2,6 +2,11 @@ let options = rec { + aarch64-darwin = { + version = "2.1.2"; + system = "arm64-darwin"; + sha256 = "sha256-H0ALigXcWIypdA+fTf7jERscwbb7QIAfcoxCtGDh0RU="; + }; x86_64-darwin = { version = "1.2.11"; system = "x86-64-darwin"; diff --git a/pkgs/development/compilers/sbcl/common.nix b/pkgs/development/compilers/sbcl/common.nix index 11ae960a531..b020eeafc5c 100644 --- a/pkgs/development/compilers/sbcl/common.nix +++ b/pkgs/development/compilers/sbcl/common.nix @@ -2,7 +2,7 @@ { lib, stdenv, fetchurl, writeText, sbclBootstrap , sbclBootstrapHost ? "${sbclBootstrap}/bin/sbcl --disable-debugger --no-userinit --no-sysinit" -, threadSupport ? (stdenv.isi686 || stdenv.isx86_64 || "aarch64-linux" == stdenv.hostPlatform.system) +, threadSupport ? (stdenv.isi686 || stdenv.isx86_64 || "aarch64-linux" == stdenv.hostPlatform.system || "aarch64-darwin" == stdenv.hostPlatform.system) , disableImmobileSpace ? false # Meant for sbcl used for creating binaries portable to non-NixOS via save-lisp-and-die. # Note that the created binaries still need `patchelf --set-interpreter ...` @@ -79,7 +79,7 @@ stdenv.mkDerivation rec { lib.concatStringsSep " " (builtins.map (x: "--with-${x}") enableFeatures ++ builtins.map (x: "--without-${x}") disableFeatures) - } + } ${if stdenv.hostPlatform.system == "aarch64-darwin" then "--arch=arm64" else ""} (cd doc/manual ; make info) runHook postBuild From c022642fec40e38948a1efcd306852f2783c7b15 Mon Sep 17 00:00:00 2001 From: Jonathan del Strother Date: Fri, 19 Mar 2021 09:11:25 +0000 Subject: [PATCH 63/71] imagemagick: support aarch64-darwin --- pkgs/applications/graphics/ImageMagick/6.x.nix | 2 +- pkgs/applications/graphics/ImageMagick/7.0.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/applications/graphics/ImageMagick/6.x.nix b/pkgs/applications/graphics/ImageMagick/6.x.nix index d6e97c5d682..eb86e74adcf 100644 --- a/pkgs/applications/graphics/ImageMagick/6.x.nix +++ b/pkgs/applications/graphics/ImageMagick/6.x.nix @@ -9,7 +9,7 @@ let if stdenv.hostPlatform.system == "i686-linux" then "i686" else if stdenv.hostPlatform.system == "x86_64-linux" || stdenv.hostPlatform.system == "x86_64-darwin" then "x86-64" else if stdenv.hostPlatform.system == "armv7l-linux" then "armv7l" - else if stdenv.hostPlatform.system == "aarch64-linux" then "aarch64" + else if stdenv.hostPlatform.system == "aarch64-linux" || stdenv.hostPlatform.system == "aarch64-darwin" then "aarch64" else if stdenv.hostPlatform.system == "powerpc64le-linux" then "ppc64le" else throw "ImageMagick is not supported on this platform."; in diff --git a/pkgs/applications/graphics/ImageMagick/7.0.nix b/pkgs/applications/graphics/ImageMagick/7.0.nix index c4e1f3406f6..ed1e580cb16 100644 --- a/pkgs/applications/graphics/ImageMagick/7.0.nix +++ b/pkgs/applications/graphics/ImageMagick/7.0.nix @@ -11,7 +11,7 @@ let if stdenv.hostPlatform.system == "i686-linux" then "i686" else if stdenv.hostPlatform.system == "x86_64-linux" || stdenv.hostPlatform.system == "x86_64-darwin" then "x86-64" else if stdenv.hostPlatform.system == "armv7l-linux" then "armv7l" - else if stdenv.hostPlatform.system == "aarch64-linux" then "aarch64" + else if stdenv.hostPlatform.system == "aarch64-linux" || stdenv.hostPlatform.system == "aarch64-darwin" then "aarch64" else if stdenv.hostPlatform.system == "powerpc64le-linux" then "ppc64le" else throw "ImageMagick is not supported on this platform."; in From 3706fe567ba0eaf9af899e6949fb298d4d222c07 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Mon, 19 Apr 2021 13:11:17 +0900 Subject: [PATCH 64/71] darwin.DarwinTools: remove reference to CFPriv.h Fixes build on aarch64-darwin. --- .../darwin/DarwinTools/default.nix | 6 +++++- .../darwin/DarwinTools/sw_vers-CFPriv.patch | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 pkgs/os-specific/darwin/DarwinTools/sw_vers-CFPriv.patch diff --git a/pkgs/os-specific/darwin/DarwinTools/default.nix b/pkgs/os-specific/darwin/DarwinTools/default.nix index 5badf2434d6..588769c7bfc 100644 --- a/pkgs/os-specific/darwin/DarwinTools/default.nix +++ b/pkgs/os-specific/darwin/DarwinTools/default.nix @@ -8,7 +8,11 @@ stdenv.mkDerivation rec { sha256 = "0hh4jl590jv3v830p77r3jcrnpndy7p2b8ajai3ldpnx2913jfhp"; }; - patchPhase = '' + patches = [ + ./sw_vers-CFPriv.patch + ]; + + postPatch = '' substituteInPlace Makefile \ --replace gcc cc ''; diff --git a/pkgs/os-specific/darwin/DarwinTools/sw_vers-CFPriv.patch b/pkgs/os-specific/darwin/DarwinTools/sw_vers-CFPriv.patch new file mode 100644 index 00000000000..6faeaa75025 --- /dev/null +++ b/pkgs/os-specific/darwin/DarwinTools/sw_vers-CFPriv.patch @@ -0,0 +1,19 @@ +--- a/sw_vers.c 2021-04-19 13:06:50.131346864 +0900 ++++ b/sw_vers.c 2021-04-19 13:07:32.481967474 +0900 +@@ -28,7 +28,15 @@ + */ + + #include +-#include ++ ++// Avoid dependency on CoreFoundation/CFPriv, which no longer appears to be ++// part of the upstream sdk. ++ ++CFDictionaryRef _CFCopyServerVersionDictionary(void); ++CFDictionaryRef _CFCopySystemVersionDictionary(void); ++extern CFStringRef _kCFSystemVersionProductNameKey; ++extern CFStringRef _kCFSystemVersionProductVersionKey; ++extern CFStringRef _kCFSystemVersionBuildVersionKey; + + void usage(char *progname) { + fprintf(stderr, "Usage: %s [-productName|-productVersion|-buildVersion]\n", progname); From 92d53249f6155d02515762e86053e5987b161e31 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Mon, 19 Apr 2021 17:31:20 +0900 Subject: [PATCH 65/71] apr: update libtool, fix downstream aprutil on aarch64-darwin --- pkgs/development/libraries/apr/default.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkgs/development/libraries/apr/default.nix b/pkgs/development/libraries/apr/default.nix index c7a1073d137..03b6c9777df 100644 --- a/pkgs/development/libraries/apr/default.nix +++ b/pkgs/development/libraries/apr/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, fetchurl }: +{ lib, stdenv, fetchurl, autoreconfHook }: stdenv.mkDerivation rec { name = "apr-1.7.0"; @@ -36,6 +36,10 @@ stdenv.mkDerivation rec { CPPFLAGS=lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "-DAPR_IOVEC_DEFINED"; + nativeBuildInputs = + # Update libtool for macOS 11 support + lib.optional (stdenv.isDarwin && stdenv.isAarch64) [ autoreconfHook ]; + enableParallelBuilding = true; meta = with lib; { From 7f216a442409bb4b78359cf77bdc94a375271f4d Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Mon, 19 Apr 2021 19:39:19 +0900 Subject: [PATCH 66/71] catch: backport support for Apple Silicon --- pkgs/development/libraries/catch/default.nix | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkgs/development/libraries/catch/default.nix b/pkgs/development/libraries/catch/default.nix index 2aa5c788dc3..c89fbd477c9 100644 --- a/pkgs/development/libraries/catch/default.nix +++ b/pkgs/development/libraries/catch/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, fetchFromGitHub, cmake }: +{ lib, stdenv, fetchFromGitHub, fetchpatch, cmake }: stdenv.mkDerivation rec { pname = "catch"; @@ -14,6 +14,14 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ cmake ]; cmakeFlags = [ "-DUSE_CPP14=ON" ]; + patches = [ + # https://github.com/catchorg/Catch2/pull/2151 + (fetchpatch { + url = "https://github.com/catchorg/Catch2/commit/bb6d08323f23a39eb65dd86671e68f4f5d3f2d6c.patch"; + sha256 = "1vhbzx84nrhhf9zlbl6h5zmg3r5w5v833ihlswsysb9wp2i4isc5"; + }) + ]; + doCheck = true; checkTarget = "test"; From e592d342daf2d1d77abe392b10ef16be5e46ceea Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Tue, 27 Apr 2021 18:36:39 +0900 Subject: [PATCH 67/71] darwin.ICU: avoid platform.darwinMinVersion references on non-darwin This package isn't expected to work outside of darwin, but must still evaluate cleanly. --- pkgs/os-specific/darwin/apple-source-releases/ICU/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/os-specific/darwin/apple-source-releases/ICU/default.nix b/pkgs/os-specific/darwin/apple-source-releases/ICU/default.nix index f2dd63cf2de..cdebfe6d2f7 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/ICU/default.nix +++ b/pkgs/os-specific/darwin/apple-source-releases/ICU/default.nix @@ -59,7 +59,7 @@ appleDerivation { "DATA_INSTALL_DIR=/share/icu/" "DATA_LOOKUP_DIR=$(DSTROOT)$(DATA_INSTALL_DIR)" - + ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ # darwin* platform properties are only defined on darwin # hack to use our lower macos version "MAC_OS_X_VERSION_MIN_REQUIRED=${formatVersionNumeric stdenv.hostPlatform.darwinMinVersion}" "ICU_TARGET_VERSION=-m${stdenv.hostPlatform.darwinPlatform}-version-min=${stdenv.hostPlatform.darwinMinVersion}" From 48519562e3e2107c4aa312939f7d4791f912c693 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Tue, 27 Apr 2021 19:56:59 +0900 Subject: [PATCH 68/71] darwin-packages: avoid exporting attributes that don't exist --- pkgs/top-level/darwin-packages.nix | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pkgs/top-level/darwin-packages.nix b/pkgs/top-level/darwin-packages.nix index a43cdc80a9d..a7f29d67261 100644 --- a/pkgs/top-level/darwin-packages.nix +++ b/pkgs/top-level/darwin-packages.nix @@ -48,13 +48,18 @@ lib.makeScopeWithSplicing splicePackages newScope otherSplices (_: {}) (spliced: # SDK. useAppleSDKLibs = stdenv.hostPlatform.isAarch64; - chooseLibs = { - inherit ( + selectAttrs = attrs: names: + lib.listToAttrs (lib.concatMap (n: if attrs ? "${n}" then [(lib.nameValuePair n attrs."${n}")] else []) names); + + chooseLibs = ( + # There are differences in which libraries are exported. Avoid evaluation + # errors when a package is not provided. + selectAttrs ( if useAppleSDKLibs then apple_sdk else appleSourcePackages - ) Libsystem LibsystemCross libcharset libunwind objc4 configd IOKit; - + ) ["Libsystem" "LibsystemCross" "libcharset" "libunwind" "objc4" "configd" "IOKit"] + ) // { inherit ( if useAppleSDKLibs then apple_sdk.frameworks From 4b569c17d7a58f4f02708aed7349b92c22e257c8 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Wed, 28 Apr 2021 17:21:54 +0900 Subject: [PATCH 69/71] release.nix: add cross-compiled aarch64-darwin bootstrap tools --- pkgs/top-level/release.nix | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkgs/top-level/release.nix b/pkgs/top-level/release.nix index 5fc6e91b311..0b18dd1ecf2 100644 --- a/pkgs/top-level/release.nix +++ b/pkgs/top-level/release.nix @@ -176,6 +176,15 @@ let # Test a full stdenv bootstrap from the bootstrap tools definition inherit (bootstrap.test-pkgs) stdenv; }; + + # Cross compiled bootstrap tools + aarch64-darwin = + let + bootstrap = import ../stdenv/darwin/make-bootstrap-tools.nix { system = "x86_64-darwin"; crossSystem = "aarch64-darwin"; }; + in { + # Distribution only for now + inherit (bootstrap) dist; + }; }; } // (mapTestOn ((packagePlatforms pkgs) // { From c31591cf8b023005488824a2bba68190d337f630 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Sun, 16 May 2021 12:18:47 +0900 Subject: [PATCH 70/71] all-packages.nix: use darwin.LibsystemCross if defined --- pkgs/top-level/all-packages.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 37606169189..b53806f419d 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -14867,7 +14867,7 @@ in else if name == "libSystem" then if stdenv.targetPlatform.useiOSPrebuilt then targetPackages.darwin.iosSdkPkgs.libraries or darwin.iosSdkPkgs.libraries - else throw "don't yet have a `targetPackages.darwin.LibsystemCross`" + else targetPackages.darwin.LibsystemCross or (throw "don't yet have a `targetPackages.darwin.LibsystemCross for ${stdenv.targetPlatform.config}`") else if name == "nblibc" then targetPackages.netbsdCross.libc or netbsdCross.libc else if name == "wasilibc" then targetPackages.wasilibc or wasilibc else if name == "relibc" then targetPackages.relibc or relibc From 56fcbcd1543188fcc855df7e79fee0a8df259681 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Sun, 16 May 2021 13:24:52 +0900 Subject: [PATCH 71/71] llvmPackages_11: darwin cross compilation and bootstrapping --- .../compilers/llvm/11/compiler-rt/default.nix | 17 +++++++++++------ pkgs/development/compilers/llvm/11/default.nix | 12 ++++++------ .../compilers/llvm/11/libcxx/default.nix | 15 ++++++++++++++- .../compilers/llvm/11/libcxxabi/default.nix | 2 +- pkgs/top-level/all-packages.nix | 1 + 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/pkgs/development/compilers/llvm/11/compiler-rt/default.nix b/pkgs/development/compilers/llvm/11/compiler-rt/default.nix index c9f97bacb3e..65f8d575c56 100644 --- a/pkgs/development/compilers/llvm/11/compiler-rt/default.nix +++ b/pkgs/development/compilers/llvm/11/compiler-rt/default.nix @@ -3,6 +3,7 @@ let useLLVM = stdenv.hostPlatform.useLLVM or false; + isDarwin = stdenv.hostPlatform.isDarwin; bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; haveLibc = stdenv.cc.libc != null; inherit (stdenv.hostPlatform) isMusl; @@ -15,7 +16,6 @@ stdenv.mkDerivation { src = fetch "compiler-rt" "0x1j8ngf1zj63wlnns9vlibafq48qcm72p4jpaxkmkb4qw0grwfy"; nativeBuildInputs = [ cmake python3 llvm.dev ]; - buildInputs = lib.optional stdenv.hostPlatform.isDarwin libcxxabi; NIX_CFLAGS_COMPILE = [ "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" @@ -25,19 +25,19 @@ stdenv.mkDerivation { "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" - ] ++ lib.optionals (useLLVM || bareMetal || isMusl) [ + ] ++ lib.optionals (useLLVM || isDarwin || bareMetal || isMusl) [ "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" "-DCOMPILER_RT_BUILD_XRAY=OFF" "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" "-DCOMPILER_RT_BUILD_PROFILE=OFF" - ] ++ lib.optionals ((useLLVM || bareMetal) && !haveLibc) [ + ] ++ lib.optionals ((useLLVM || isDarwin || bareMetal) && !haveLibc) [ "-DCMAKE_C_COMPILER_WORKS=ON" "-DCMAKE_CXX_COMPILER_WORKS=ON" "-DCOMPILER_RT_BAREMETAL_BUILD=ON" "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" - ] ++ lib.optionals (useLLVM && !haveLibc) [ + ] ++ lib.optionals ((useLLVM || isDarwin) && !haveLibc) [ "-DCMAKE_C_FLAGS=-nodefaultlibs" - ] ++ lib.optionals (useLLVM) [ + ] ++ lib.optionals (useLLVM || isDarwin) [ "-DCOMPILER_RT_BUILD_BUILTINS=ON" #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" @@ -61,6 +61,11 @@ stdenv.mkDerivation { ]# ++ lib.optional stdenv.hostPlatform.isMusl ./sanitizers-nongnu.patch ++ lib.optional stdenv.hostPlatform.isAarch32 ./armv7l.patch; + + preConfigure = lib.optionalString isDarwin '' + cmakeFlagsArray+=("-DCMAKE_LIPO=$(command -v ${stdenv.cc.targetPrefix}lipo)") + ''; + # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd @@ -71,7 +76,7 @@ stdenv.mkDerivation { --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' '' + lib.optionalString stdenv.isDarwin '' substituteInPlace cmake/builtin-config-ix.cmake \ - --replace 'set(ARM64 arm64 arm64e)' 'set(ARM64)' + --replace 'foreach(arch ''${ARM64})' 'foreach(arch)' substituteInPlace cmake/config-ix.cmake \ --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' '' + lib.optionalString (useLLVM) '' diff --git a/pkgs/development/compilers/llvm/11/default.nix b/pkgs/development/compilers/llvm/11/default.nix index 21432abe6a3..c260964051f 100644 --- a/pkgs/development/compilers/llvm/11/default.nix +++ b/pkgs/development/compilers/llvm/11/default.nix @@ -213,20 +213,20 @@ let compiler-rt-libc = callPackage ./compiler-rt { inherit llvm_meta; - stdenv = if stdenv.hostPlatform.useLLVM or false + stdenv = if (stdenv.hostPlatform.useLLVM or false) || stdenv.hostPlatform.isDarwin then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc else stdenv; }; compiler-rt-no-libc = callPackage ./compiler-rt { inherit llvm_meta; - stdenv = if stdenv.hostPlatform.useLLVM or false + stdenv = if (stdenv.hostPlatform.useLLVM or false) || stdenv.hostPlatform.isDarwin then overrideCC stdenv buildLlvmTools.clangNoCompilerRt else stdenv; }; # N.B. condition is safe because without useLLVM both are the same. - compiler-rt = if stdenv.hostPlatform.isAndroid + compiler-rt = if stdenv.hostPlatform.isAndroid || (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) then libraries.compiler-rt-libc else libraries.compiler-rt-no-libc; @@ -236,21 +236,21 @@ let libcxx = callPackage ./libcxx { inherit llvm_meta; - stdenv = if stdenv.hostPlatform.useLLVM or false + stdenv = if (stdenv.hostPlatform.useLLVM or false) || stdenv.hostPlatform.isDarwin then overrideCC stdenv buildLlvmTools.clangNoLibcxx else stdenv; }; libcxxabi = callPackage ./libcxxabi { inherit llvm_meta; - stdenv = if stdenv.hostPlatform.useLLVM or false + stdenv = if (stdenv.hostPlatform.useLLVM or false) || stdenv.hostPlatform.isDarwin then overrideCC stdenv buildLlvmTools.clangNoLibcxx else stdenv; }; libunwind = callPackage ./libunwind { inherit llvm_meta; - stdenv = if stdenv.hostPlatform.useLLVM or false + stdenv = if (stdenv.hostPlatform.useLLVM or false) || stdenv.hostPlatform.isDarwin then overrideCC stdenv buildLlvmTools.clangNoLibcxx else stdenv; }; diff --git a/pkgs/development/compilers/llvm/11/libcxx/default.nix b/pkgs/development/compilers/llvm/11/libcxx/default.nix index 7bd4f7e26b7..596d7f9976b 100644 --- a/pkgs/development/compilers/llvm/11/libcxx/default.nix +++ b/pkgs/development/compilers/llvm/11/libcxx/default.nix @@ -46,7 +46,20 @@ stdenv.mkDerivation { "-DLIBCXX_ENABLE_THREADS=OFF" "-DLIBCXX_ENABLE_FILESYSTEM=OFF" "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" - ] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF"; + ] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF" + + # TODO: this is a bit of a hack to cross compile to Apple Silicon. libcxx + # starting with 11 enables CMAKE_BUILD_WITH_INSTALL_NAME_DIR which requires + # platform setup for rpaths. In cmake, this is enabled when macos is newer + # than 10.5. However CMAKE_SYSTEM_VERSION is set to empty (TODO: why?) + # which prevents the conditional configuration, and configure fails. The + # value here corresponds to `uname -r`. If stdenv.hostPlatform.release is + # not null, then this property will be set via mkDerivation (TODO: how can + # we set this?). + ++ lib.optional ( + stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64 && + stdenv.hostPlatform != stdenv.buildPlatform + ) "-DCMAKE_SYSTEM_VERSION=20.1.0"; passthru = { isLLVM = true; diff --git a/pkgs/development/compilers/llvm/11/libcxxabi/default.nix b/pkgs/development/compilers/llvm/11/libcxxabi/default.nix index f555abd8acb..65e0139a591 100644 --- a/pkgs/development/compilers/llvm/11/libcxxabi/default.nix +++ b/pkgs/development/compilers/llvm/11/libcxxabi/default.nix @@ -48,7 +48,7 @@ stdenv.mkDerivation { # the magic combination of necessary CMake variables # if you fancy a try, take a look at # https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling - install_name_tool -id $out/$file $file + ${stdenv.cc.targetPrefix}install_name_tool -id $out/$file $file done make install install -d 755 $out/include diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index b53806f419d..3740e346032 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -14848,6 +14848,7 @@ in inherit (stdenv.targetPlatform) libc; in if libc == "msvcrt" then targetPackages.windows.mingw_w64_headers or windows.mingw_w64_headers else if libc == "nblibc" then targetPackages.netbsdCross.headers or netbsdCross.headers + else if libc == "libSystem" && stdenv.targetPlatform.isAarch64 then targetPackages.darwin.LibsystemCross or darwin.LibsystemCross else null; # We can choose: