diff --git a/pkgs/applications/blockchains/clightning/default.nix b/pkgs/applications/blockchains/clightning/default.nix index cab5a9c42d7b0..b0da3d4f03df7 100644 --- a/pkgs/applications/blockchains/clightning/default.nix +++ b/pkgs/applications/blockchains/clightning/default.nix @@ -1,5 +1,6 @@ { lib , stdenv +, cctools , darwin , fetchurl , autoconf @@ -29,11 +30,11 @@ stdenv.mkDerivation rec { sha256 = "sha256-KQS/4VmUxJkNpvPcxL5Up9f25leiPzvi2AiKuzRQmDo="; }; - # when building on darwin we need dawin.cctools to provide the correct libtool + # when building on darwin we need cctools to provide the correct libtool # as libwally-core detects the host as darwin and tries to add the -static # option to libtool, also we have to add the modified gsed package. nativeBuildInputs = [ autoconf autogen automake gettext libtool lowdown protobuf py3 unzip which ] - ++ lib.optionals stdenv.isDarwin [ darwin.cctools darwin.autoSignDarwinBinariesHook ]; + ++ lib.optionals stdenv.isDarwin [ cctools darwin.autoSignDarwinBinariesHook ]; buildInputs = [ gmp libsodium sqlite zlib ]; diff --git a/pkgs/applications/editors/vim/macvim.nix b/pkgs/applications/editors/vim/macvim.nix index 64aa5b639a9b4..e6dd8d37803ba 100644 --- a/pkgs/applications/editors/vim/macvim.nix +++ b/pkgs/applications/editors/vim/macvim.nix @@ -12,6 +12,7 @@ , luajit , darwin , libiconv +, libunwind , python3 }: @@ -127,7 +128,7 @@ stdenv.mkDerivation { --replace "PERL_CFLAGS =" "PERL_CFLAGS = -I${darwin.libutil}/include" \ --replace " -L${stdenv.cc.libc}/lib" "" \ --replace " -L${darwin.libobjc}/lib" "" \ - --replace " -L${darwin.libunwind}/lib" "" \ + --replace " -L${libunwind}/lib" "" \ --replace " -L${libiconv}/lib" "" # All the libraries we stripped have -osx- in their name as of this time. diff --git a/pkgs/applications/emulators/firebird-emu/default.nix b/pkgs/applications/emulators/firebird-emu/default.nix index 9fd9901461617..48f3647514271 100644 --- a/pkgs/applications/emulators/firebird-emu/default.nix +++ b/pkgs/applications/emulators/firebird-emu/default.nix @@ -19,9 +19,6 @@ stdenv.mkDerivation rec { hash = "sha256-ZptjlnOiF+hKuKYvBFJL95H5YQuR99d4biOco/MVEmE="; }; - # work around https://github.com/NixOS/nixpkgs/issues/19098 - env.NIX_CFLAGS_COMPILE = lib.optionalString (stdenv.cc.isClang && stdenv.isDarwin) "-fno-lto"; - nativeBuildInputs = [ wrapQtAppsHook qmake ]; buildInputs = [ qtbase qtdeclarative qtquickcontrols ]; diff --git a/pkgs/applications/networking/irc/thelounge/default.nix b/pkgs/applications/networking/irc/thelounge/default.nix index 1078f515c69ac..729afb831d579 100644 --- a/pkgs/applications/networking/irc/thelounge/default.nix +++ b/pkgs/applications/networking/irc/thelounge/default.nix @@ -7,7 +7,7 @@ , fixup-yarn-lock , python3 , npmHooks -, darwin +, cctools , sqlite , srcOnly , buildPackages @@ -38,7 +38,7 @@ stdenv.mkDerivation (finalAttrs: { hash = "sha256-MM6SgVT7Pjdu96A4eWRucEzT7uNPxBqUDgHKl8mH2C0="; }; - nativeBuildInputs = [ nodejs yarn fixup-yarn-lock python3 npmHooks.npmInstallHook ] ++ lib.optional stdenv.isDarwin darwin.cctools; + nativeBuildInputs = [ nodejs yarn fixup-yarn-lock python3 npmHooks.npmInstallHook ] ++ lib.optional stdenv.isDarwin cctools; buildInputs = [ sqlite ]; configurePhase = '' diff --git a/pkgs/applications/networking/n8n/node-composition.nix b/pkgs/applications/networking/n8n/node-composition.nix index d9c0daef7834c..f615ffbf296d8 100644 --- a/pkgs/applications/networking/n8n/node-composition.nix +++ b/pkgs/applications/networking/n8n/node-composition.nix @@ -8,7 +8,7 @@ let nodeEnv = import ./node-env.nix { inherit (pkgs) stdenv lib python2 runCommand writeTextFile writeShellScript; inherit pkgs nodejs; - libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null; + libtool = if pkgs.stdenv.isDarwin then pkgs.cctools else null; }; in import ./node-packages.nix { diff --git a/pkgs/applications/science/computer-architecture/timeloop/default.nix b/pkgs/applications/science/computer-architecture/timeloop/default.nix index ec8ec3ed8abc6..7fc5da8dfa89a 100644 --- a/pkgs/applications/science/computer-architecture/timeloop/default.nix +++ b/pkgs/applications/science/computer-architecture/timeloop/default.nix @@ -41,10 +41,6 @@ stdenv.mkDerivation rec { enableParallelBuilding = true; - #link-time optimization fails on darwin - #see https://github.com/NixOS/nixpkgs/issues/19098 - env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isDarwin "-fno-lto"; - postPatch = '' # Fix gcc-13 build failure due to missing includes: sed -e '1i #include ' -i \ diff --git a/pkgs/applications/version-management/git/default.nix b/pkgs/applications/version-management/git/default.nix index d7f738adee514..2d1fbf43c2a0c 100644 --- a/pkgs/applications/version-management/git/default.nix +++ b/pkgs/applications/version-management/git/default.nix @@ -57,6 +57,8 @@ stdenv.mkDerivation (finalAttrs: { ./git-sh-i18n.patch ./git-send-email-honor-PATH.patch ./installCheck-path.patch + # The source-based SDK uses a newer version of AvailabilityMacros.h that causes git to misdetect the SDK version. + ./use-version-based-SDK-check.patch ] ++ lib.optionals withSsh [ ./ssh-path.patch ]; diff --git a/pkgs/applications/version-management/git/use-version-based-SDK-check.patch b/pkgs/applications/version-management/git/use-version-based-SDK-check.patch new file mode 100644 index 0000000000000..a23b8c29dd928 --- /dev/null +++ b/pkgs/applications/version-management/git/use-version-based-SDK-check.patch @@ -0,0 +1,25 @@ +From 619cc16f0395f70315138cadaa16d2cf813a8603 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Tue, 23 Apr 2024 21:36:17 -0400 +Subject: [PATCH] Use version-based SDK check + +--- + compat/fsmonitor/fsm-listen-darwin.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/compat/fsmonitor/fsm-listen-darwin.c b/compat/fsmonitor/fsm-listen-darwin.c +index 2fc67442eb..53851e1789 100644 +--- a/compat/fsmonitor/fsm-listen-darwin.c ++++ b/compat/fsmonitor/fsm-listen-darwin.c +@@ -5,7 +5,7 @@ + #include + #include + +-#ifndef AVAILABLE_MAC_OS_X_VERSION_10_13_AND_LATER ++#if MAC_OS_X_VERSION_MAX_ALLOWED < 101300 + /* + * This enum value was added in 10.13 to: + * +-- +2.42.0 + diff --git a/pkgs/applications/virtualization/rvvm/default.nix b/pkgs/applications/virtualization/rvvm/default.nix index 718446d1ce1f6..335f83cf871ec 100644 --- a/pkgs/applications/virtualization/rvvm/default.nix +++ b/pkgs/applications/virtualization/rvvm/default.nix @@ -38,10 +38,7 @@ stdenv.mkDerivation rec { makeFlags = [ "PREFIX=$(out)" ] ++ lib.optional enableSDL "USE_SDL=2" # Use SDL2 instead of SDL1 - ++ lib.optional (!enableSDL && !enableX11) "USE_FB=0" - - # work around https://github.com/NixOS/nixpkgs/issues/19098 - ++ lib.optional (stdenv.cc.isClang && stdenv.isDarwin) "CFLAGS=-fno-lto"; + ++ lib.optional (!enableSDL && !enableX11) "USE_FB=0"; meta = with lib; { homepage = "https://github.com/LekKit/RVVM"; diff --git a/pkgs/build-support/bintools-wrapper/default.nix b/pkgs/build-support/bintools-wrapper/default.nix index 2a1fe1344e205..f372714f5625a 100644 --- a/pkgs/build-support/bintools-wrapper/default.nix +++ b/pkgs/build-support/bintools-wrapper/default.nix @@ -55,9 +55,6 @@ # - static armv7l, where compilation fails. && !(targetPlatform.isAarch && targetPlatform.isStatic) ) "pie" - -# Darwin code signing support utilities -, postLinkSignHook ? null, signingUtils ? null }: assert propagateDoc -> bintools ? man; @@ -352,7 +349,7 @@ stdenvNoCC.mkDerivation { ## # TODO(@sternenseemann): make a generic strip wrapper? - + optionalString (bintools.isGNU or false) '' + + optionalString (bintools.isGNU or false || bintools.isCCTools or false) '' wrap ${targetPrefix}strip ${./gnu-binutils-strip-wrapper.sh} \ "${bintools_bin}/bin/${targetPrefix}strip" '' @@ -391,24 +388,6 @@ stdenvNoCC.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/build-support/bintools-wrapper/ld-wrapper.sh b/pkgs/build-support/bintools-wrapper/ld-wrapper.sh index dcbe8a4c24948..7e00d02b03742 100644 --- a/pkgs/build-support/bintools-wrapper/ld-wrapper.sh +++ b/pkgs/build-support/bintools-wrapper/ld-wrapper.sh @@ -226,12 +226,6 @@ if [[ "$NIX_DONT_SET_RPATH_@suffixSalt@" != 1 && "$linkType" != static-pie ]]; t fi -# This is outside the DONT_SET_RPATH branch because it's more targeted and we -# usually want it (on Darwin) even if DONT_SET_RPATH is set. -if [ -n "${NIX_COREFOUNDATION_RPATH:-}" ]; then - extraAfter+=(-rpath $NIX_COREFOUNDATION_RPATH) -fi - # Only add --build-id if this is a final link. FIXME: should build gcc # with --enable-linker-build-id instead? # @@ -257,10 +251,13 @@ PATH="$path_backup" # Old bash workaround, see above. if (( "${NIX_LD_USE_RESPONSE_FILE:-@use_response_file_by_default@}" >= 1 )); then - @prog@ @<(printf "%q\n" \ - ${extraBefore+"${extraBefore[@]}"} \ - ${params+"${params[@]}"} \ - ${extraAfter+"${extraAfter[@]}"}) + responseFile=$(mktemp "${TMPDIR:-/tmp}/ld-params.XXXXXX") + trap 'rm -f -- "$responseFile"' EXIT + printf "%q\n" \ + ${extraBefore+"${extraBefore[@]}"} \ + ${params+"${params[@]}"} \ + ${extraAfter+"${extraAfter[@]}"} > "$responseFile" + @prog@ "@$responseFile" else @prog@ \ ${extraBefore+"${extraBefore[@]}"} \ diff --git a/pkgs/build-support/libredirect/default.nix b/pkgs/build-support/libredirect/default.nix index 1ab4a0db827aa..25b5d352fcad3 100644 --- a/pkgs/build-support/libredirect/default.nix +++ b/pkgs/build-support/libredirect/default.nix @@ -1,12 +1,5 @@ -{ lib, stdenv, bintools-unwrapped, llvmPackages, llvmPackages_13, coreutils }: - -let - # aarch64-darwin needs a clang that can build arm64e binaries, so make sure a version of LLVM - # is used that can do that, but prefer the stdenv one if it is new enough. - llvmPkgs = if (lib.versionAtLeast (lib.getVersion llvmPackages.clang) "13") - then llvmPackages - else llvmPackages_13; - in +{ lib, stdenv, bintools-unwrapped, llvmPackages, coreutils }: + if stdenv.hostPlatform.isStatic then throw '' libredirect is not available on static builds. @@ -46,11 +39,11 @@ else stdenv.mkDerivation rec { # and the library search directory for libdl. # We can't build this on x86_64, because the libSystem we point to doesn't # like arm64(e). - PATH=${bintools-unwrapped}/bin:${llvmPkgs.clang-unwrapped}/bin:$PATH \ + PATH=${bintools-unwrapped}/bin:${llvmPackages.clang-unwrapped}/bin:$PATH \ clang -arch x86_64 -arch arm64 -arch arm64e \ - -isystem ${llvmPkgs.clang.libc}/include \ - -isystem ${llvmPkgs.libclang.lib}/lib/clang/*/include \ - -L${llvmPkgs.clang.libc}/lib \ + -isystem ${llvmPackages.clang.libc}/include \ + -isystem ${llvmPackages.libclang.lib}/lib/clang/*/include \ + -L${llvmPackages.clang.libc}/lib \ -Wl,-install_name,$libName \ -Wall -std=c99 -O3 -fPIC libredirect.c \ -shared -o "$libName" diff --git a/pkgs/build-support/node/build-npm-package/default.nix b/pkgs/build-support/node/build-npm-package/default.nix index 1c7bf63e8cd6a..4bcbf3f14f2fe 100644 --- a/pkgs/build-support/node/build-npm-package/default.nix +++ b/pkgs/build-support/node/build-npm-package/default.nix @@ -3,7 +3,7 @@ , fetchNpmDeps , buildPackages , nodejs -, darwin +, cctools } @ topLevelArgs: { name ? "${args.pname}-${args.version}" @@ -76,7 +76,7 @@ stdenv.mkDerivation (args // { (if npmInstallHook != null then npmInstallHook else npmHooks.npmInstallHook) nodejs.python ] - ++ lib.optionals stdenv.isDarwin [ darwin.cctools ]; + ++ lib.optionals stdenv.isDarwin [ cctools ]; buildInputs = buildInputs ++ [ nodejs ]; strictDeps = true; diff --git a/pkgs/by-name/bi/bitwarden-cli/package.nix b/pkgs/by-name/bi/bitwarden-cli/package.nix index 656c1e60ec212..12deace0e4329 100644 --- a/pkgs/by-name/bi/bitwarden-cli/package.nix +++ b/pkgs/by-name/bi/bitwarden-cli/package.nix @@ -4,7 +4,7 @@ , nodejs_18 , fetchFromGitHub , python3 -, darwin +, cctools , nixosTests }: @@ -26,7 +26,7 @@ buildNpmPackage rec { nativeBuildInputs = [ python3 ] ++ lib.optionals stdenv.isDarwin [ - darwin.cctools + cctools ]; makeCacheWritable = true; diff --git a/pkgs/by-name/cc/cctools/0001-Fix-build-issues-with-misc-redo_prebinding.c.patch b/pkgs/by-name/cc/cctools/0001-Fix-build-issues-with-misc-redo_prebinding.c.patch new file mode 100644 index 0000000000000..66f7a2d7c6411 --- /dev/null +++ b/pkgs/by-name/cc/cctools/0001-Fix-build-issues-with-misc-redo_prebinding.c.patch @@ -0,0 +1,53 @@ +From 55b2a5fcc38eb62f53e155bd8c741481690f1c73 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Wed, 10 Apr 2024 19:08:39 -0400 +Subject: [PATCH 1/6] Fix build issues with misc/redo_prebinding.c + +- Add missing headers; and +- Add missing arguments to `writeout`. +--- + misc/redo_prebinding.c | 7 ++++--- + 1 file changed, 4 insertions(+), 3 deletions(-) + +diff --git a/misc/redo_prebinding.c b/misc/redo_prebinding.c +index a5a3c81..9d0f4c8 100644 +--- a/misc/redo_prebinding.c ++++ b/misc/redo_prebinding.c +@@ -83,6 +83,7 @@ + #include + #endif /* defined(LIBRARY_API) */ + ++#import + #import + #import + #import +@@ -106,7 +107,7 @@ + #import + #import + #import +-//#import ++#import + #import + + #include +@@ -918,7 +919,7 @@ char *envp[]) + if(write_to_stdout) + output_file = NULL; + writeout(archs, narchs, output_file, mode, TRUE, FALSE, FALSE, +- FALSE, NULL); ++ FALSE, FALSE, NULL); + if(errors){ + if(write_to_stdout == FALSE) + unlink(output_file); +@@ -928,7 +929,7 @@ char *envp[]) + else{ + output_file = makestr(input_file, ".redo_prebinding", NULL); + writeout(archs, narchs, output_file, mode, TRUE, FALSE, FALSE, +- FALSE, NULL); ++ FALSE, FALSE, NULL); + if(errors){ + unlink(output_file); + return(2); +-- +2.44.0 + diff --git a/pkgs/by-name/cc/cctools/0002-Rely-on-libcd_is_blob_a_linker_signature.patch b/pkgs/by-name/cc/cctools/0002-Rely-on-libcd_is_blob_a_linker_signature.patch new file mode 100644 index 0000000000000..d4a1e6ec0cac1 --- /dev/null +++ b/pkgs/by-name/cc/cctools/0002-Rely-on-libcd_is_blob_a_linker_signature.patch @@ -0,0 +1,47 @@ +From 645c61100ed6cc087237a645c6572931cbcd0d29 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Wed, 10 Apr 2024 20:36:53 -0400 +Subject: [PATCH 2/6] Rely on libcd_is_blob_a_linker_signature + +--- + libstuff/code_directory.c | 17 ----------------- + 1 file changed, 17 deletions(-) + +diff --git a/libstuff/code_directory.c b/libstuff/code_directory.c +index 7c158fa..229e11a 100644 +--- a/libstuff/code_directory.c ++++ b/libstuff/code_directory.c +@@ -146,22 +146,6 @@ static const char* format_version_xyz(uint32_t version) + */ + int codedir_is_linker_signed(const char* data, uint32_t size) + { +-#if 1 +- // HACK: libcodedirectory.h is in both the macOS SDK in /usr/local/include, and in the tool chain at /usr/include. +- // but there is no way to control clang's search path to look in the toolchain first. +- // So, declare newer API locally. Once this new header is in all SDKs we can remove this. +- // Can't use real function name because it returns an enum type and we cannot define the enum +- // here because it will cause a duplicate definition when the header is updated. +- extern int my_libcd_is_blob_a_linker_signature(const uint8_t *buf, size_t buf_len, int *is_linker_signature) __asm("_libcd_is_blob_a_linker_signature"); +- int ret; +- int linker_signed = 0; +- +- ret = my_libcd_is_blob_a_linker_signature((const uint8_t*)data, +- (size_t)size, +- &linker_signed); +- if ( (ret == 0) && linker_signed ) +- return 1; +-#else + enum libcd_signature_query_ret ret = LIBCD_SIGNATURE_QUERY_SUCCESS; + int linker_signed = 0; + +@@ -176,7 +160,6 @@ int codedir_is_linker_signed(const char* data, uint32_t size) + case LIBCD_SIGNATURE_QUERY_NOT_A_SIGNATURE: + ; + } +-#endif + return 0; + } + +-- +2.44.0 + diff --git a/pkgs/by-name/cc/cctools/0003-Fix-utimensat-compatability-with-the-10.12-SDK.patch b/pkgs/by-name/cc/cctools/0003-Fix-utimensat-compatability-with-the-10.12-SDK.patch new file mode 100644 index 0000000000000..6871f6d87086f --- /dev/null +++ b/pkgs/by-name/cc/cctools/0003-Fix-utimensat-compatability-with-the-10.12-SDK.patch @@ -0,0 +1,50 @@ +From ddf67d55c5e193087f59e2b8ee84725172491b69 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Thu, 11 Apr 2024 18:05:34 -0400 +Subject: [PATCH 3/6] Fix utimensat compatability with the 10.12 SDK + +--- + include/compat.h | 3 +++ + libstuff/writeout.c | 2 +- + misc/lipo.c | 2 +- + 3 files changed, 5 insertions(+), 2 deletions(-) + create mode 100644 include/compat.h + +diff --git a/include/compat.h b/include/compat.h +new file mode 100644 +index 0000000..8b1b866 +--- /dev/null ++++ b/include/compat.h +@@ -0,0 +1,3 @@ ++#pragma once ++#include ++extern int utimensat(int dirfd, const char* pathname, const struct timespec times[_Nullable 2], int flags); +diff --git a/libstuff/writeout.c b/libstuff/writeout.c +index f904caa..03fa535 100644 +--- a/libstuff/writeout.c ++++ b/libstuff/writeout.c +@@ -297,7 +297,7 @@ no_throttle: + * have been zeroed out when the library was created. writeout + * will not zero out the modification time in the filesystem. + */ +- if (__builtin_available(macOS 10.12, *)) { ++ if (__builtin_available(macOS 10.13, *)) { + struct timespec times[2] = {0}; + memcpy(×[0], &toc_timespec, sizeof(struct timespec)); + memcpy(×[1], &toc_timespec, sizeof(struct timespec)); +diff --git a/misc/lipo.c b/misc/lipo.c +index 04a3eca..887c049 100644 +--- a/misc/lipo.c ++++ b/misc/lipo.c +@@ -607,7 +607,7 @@ unknown_flag: + if(close(fd) == -1) + system_fatal("can't close output file: %s",output_file); + #ifndef __OPENSTEP__ +- if (__builtin_available(macOS 10.12, *)) { ++ if (__builtin_available(macOS 10.13, *)) { + time_result = utimensat(AT_FDCWD, output_file, + output_times, 0); + } +-- +2.44.0 + diff --git a/pkgs/by-name/cc/cctools/0004-Use-nixpkgs-clang-with-the-assembler-driver.patch b/pkgs/by-name/cc/cctools/0004-Use-nixpkgs-clang-with-the-assembler-driver.patch new file mode 100644 index 0000000000000..c032073d23eed --- /dev/null +++ b/pkgs/by-name/cc/cctools/0004-Use-nixpkgs-clang-with-the-assembler-driver.patch @@ -0,0 +1,81 @@ +From 50654fe57da6fd1513f745c6ed08c735751433d4 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Mon, 15 Apr 2024 20:47:59 -0400 +Subject: [PATCH 4/6] Use nixpkgs clang with the assembler driver + +--- + as/driver.c | 23 +++++------------------ + 1 file changed, 5 insertions(+), 18 deletions(-) + +diff --git a/as/driver.c b/as/driver.c +index a0d49ad..4b70a56 100644 +--- a/as/driver.c ++++ b/as/driver.c +@@ -36,7 +36,6 @@ char **envp) + char *p, c, *arch_name, *as, *as_local; + char **new_argv; + const char *CLANG = "clang"; +- char *prefix, buf[MAXPATHLEN], resolved_name[PATH_MAX]; + uint32_t bufsize; + struct arch_flag arch_flag; + const struct arch_flag *arch_flags, *family_arch_flag; +@@ -53,19 +52,7 @@ char **envp) + /* + * Construct the prefix to the assembler driver. + */ +- bufsize = MAXPATHLEN; +- p = buf; +- i = _NSGetExecutablePath(p, &bufsize); +- if(i == -1){ +- p = allocate(bufsize); +- _NSGetExecutablePath(p, &bufsize); +- } +- prefix = realpath(p, resolved_name); +- if(prefix == NULL) +- system_fatal("realpath(3) for %s failed", p); +- p = rindex(prefix, '/'); +- if(p != NULL) +- p[1] = '\0'; ++ const char *prefix = "@clang-unwrapped@"; + /* + * Process the assembler flags exactly like the assembler would (except + * let the assembler complain about multiple flags, bad combinations of +@@ -365,7 +352,7 @@ char **envp) + /* + * If this assembler exist try to run it else print an error message. + */ +- as = makestr(prefix, LIB, arch_name, AS, NULL); ++ as = makestr(LIB, arch_name, AS, NULL); + new_argv = allocate((argc + 1) * sizeof(char *)); + new_argv[0] = as; + j = 1; +@@ -387,7 +374,7 @@ char **envp) + else + exit(1); + } +- as_local = makestr(prefix, LOCALLIB, arch_name, AS, NULL); ++ as_local = makestr(LOCALLIB, arch_name, AS, NULL); + new_argv[0] = as_local; + if(access(as_local, F_OK) == 0){ + argv[0] = as_local; +@@ -401,7 +388,7 @@ char **envp) + arch_flags = get_arch_flags(); + count = 0; + for(i = 0; arch_flags[i].name != NULL; i++){ +- as = makestr(prefix, LIB, arch_flags[i].name, AS, NULL); ++ as = makestr(LIB, arch_flags[i].name, AS, NULL); + if(access(as, F_OK) == 0){ + if(count == 0) + printf("Installed assemblers are:\n"); +@@ -409,7 +396,7 @@ char **envp) + count++; + } + else{ +- as_local = makestr(prefix, LOCALLIB, arch_flags[i].name, AS, ++ as_local = makestr(LOCALLIB, arch_flags[i].name, AS, + NULL); + if(access(as_local, F_OK) == 0){ + if(count == 0) +-- +2.44.0 + diff --git a/pkgs/by-name/cc/cctools/0005-Find-ld64-in-the-store.patch b/pkgs/by-name/cc/cctools/0005-Find-ld64-in-the-store.patch new file mode 100644 index 0000000000000..f703907929bf2 --- /dev/null +++ b/pkgs/by-name/cc/cctools/0005-Find-ld64-in-the-store.patch @@ -0,0 +1,28 @@ +From 738e97e3e7b02149a6b7ad094db7eaba3bc22702 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Mon, 22 Apr 2024 18:15:53 -0400 +Subject: [PATCH 5/6] Find ld64 in the store + +--- + libstuff/execute.c | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/libstuff/execute.c b/libstuff/execute.c +index 8526ab7..abbbf1b 100644 +--- a/libstuff/execute.c ++++ b/libstuff/execute.c +@@ -149,6 +149,11 @@ char * + cmd_with_prefix( + char *str) + { ++ // Return the path to ld64 in the store. ++ if (strcmp(str, "ld") == 0) { ++ return "@ld64_path@"; ++ } ++ + int i; + char *p; + char *prefix, buf[MAXPATHLEN], resolved_name[PATH_MAX]; +-- +2.44.0 + diff --git a/pkgs/by-name/cc/cctools/0006-Support-target-prefixes-in-ranlib-detection.patch b/pkgs/by-name/cc/cctools/0006-Support-target-prefixes-in-ranlib-detection.patch new file mode 100644 index 0000000000000..9d27005d4679e --- /dev/null +++ b/pkgs/by-name/cc/cctools/0006-Support-target-prefixes-in-ranlib-detection.patch @@ -0,0 +1,30 @@ +From dcf0cc7e1625d0026d9fc7c66f2cf12f44ae46fd Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Thu, 2 May 2024 07:55:05 -0400 +Subject: [PATCH 6/6] Support target prefixes in ranlib detection + +--- + misc/libtool.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/misc/libtool.c b/misc/libtool.c +index 289ec4d..8265d53 100644 +--- a/misc/libtool.c ++++ b/misc/libtool.c +@@ -426,11 +426,11 @@ char **envp) + p++; + else + p = argv[0]; +- if(strncmp(p, "ranlib", sizeof("ranlib") - 1) == 0) { ++ if(strncmp(p, "@targetPrefix@ranlib", sizeof("@targetPrefix@ranlib") - 1) == 0) { + cmd_flags.ranlib = TRUE; + } + else if (getenv("LIBTOOL_FORCE_RANLIB")) { +- progname = "ranlib"; ++ progname = "@targetPrefix@ranlib"; + cmd_flags.ranlib = TRUE; + } + +-- +2.44.0 + diff --git a/pkgs/by-name/cc/cctools/meson.build b/pkgs/by-name/cc/cctools/meson.build new file mode 100644 index 0000000000000..4bdaf95398569 --- /dev/null +++ b/pkgs/by-name/cc/cctools/meson.build @@ -0,0 +1,602 @@ +# Build settings based on the upstream Xcode project. +# See: https://github.com/apple-oss-distributions/cctools/blob/main/cctools.xcodeproj/project.pbxproj + +# Project settings +project( + 'cctools', + 'c', + version : '@version@', + default_options : { + 'c_args': [ + '-DCCTB_MACOS=YES', + '-DCCTB_PROJECT=cctools', + '-DCCTB_PROJVERS=cctools-@version@', + '-DCCTB_VERSION=@version@', + '-DCURRENT_PROJECT_VERSION="@version@"', + '-DCODEDIRECTORY_SUPPORT', + '-DLTO_SUPPORT' + ] + } +) + +fs = import('fs') + +# Dependencies +cc = meson.get_compiler('c') + +libcodedirectory = cc.find_library('codedirectory') +libprunetrie = cc.find_library('prunetrie') +libcxx = cc.find_library('c++', required : false) +if not libcxx.found() + libcxx = cc.find_library('stdc++') +endif + + +# Feature tests +# Add compatibility header for Darwin SDKs that don’t define `utimensat`. +utimensat_test = ''' +#include +#include +int main(int argc, char* argv[]) { + utimensat(AT_FDCWD, NULL, NULL, 0); + return 0; +} +''' +if host_machine.system() == 'darwin' and not cc.compiles(utimensat_test, name : 'supports utimensat') + add_project_arguments('-include', 'compat.h', language : 'c') + add_project_link_arguments('-undefined', 'dynamic_lookup', language : 'c') +endif + + +incdirs = include_directories('include') + +# Static libraries +libstuff = static_library( + 'stuff', + c_args : [ + '-DCPU_TYPE_RISCV32=24', # Per src/abstraction/MachOFileAbstraction.hpp from ld64 + ], + include_directories : [incdirs, 'include/stuff'], + sources : [ + 'libstuff/SymLoc.c', + 'libstuff/align.c', + 'libstuff/allocate.c', + 'libstuff/apple_version.c', + 'libstuff/arch.c', + 'libstuff/arch_usage.c', + 'libstuff/args.c', + 'libstuff/best_arch.c', + 'libstuff/breakout.c', + 'libstuff/bytesex.c', + 'libstuff/checkout.c', + 'libstuff/code_directory.c', + 'libstuff/coff_bytesex.c', + 'libstuff/crc32.c', + 'libstuff/depinfo.c', + 'libstuff/diagnostics.c', + 'libstuff/dylib_roots.c', + 'libstuff/dylib_table.c', + 'libstuff/errors.c', + 'libstuff/execute.c', + 'libstuff/fatal_arch.c', + 'libstuff/fatals.c', + 'libstuff/get_arch_from_host.c', + 'libstuff/get_toc_byte_sex.c', + 'libstuff/guess_short_name.c', + 'libstuff/hash_string.c', + 'libstuff/hppa.c', + 'libstuff/llvm.c', + 'libstuff/lto.c', + 'libstuff/macosx_deployment_target.c', + 'libstuff/ofile.c', + 'libstuff/ofile_error.c', + 'libstuff/ofile_get_word.c', + 'libstuff/print.c', + 'libstuff/reloc.c', + 'libstuff/rnd.c', + 'libstuff/seg_addr_table.c', + 'libstuff/set_arch_flag_name.c', + 'libstuff/swap_headers.c', + 'libstuff/symbol_list.c', + 'libstuff/unix_standard_mode.c', + 'libstuff/version_number.c', + 'libstuff/vm_flush_cache.c', + 'libstuff/write64.c', + 'libstuff/writeout.c', + 'libstuff/xcode.c' + ] +) + + +# Binaries +ar = executable( + '@targetPrefix@ar', + include_directories : incdirs, + install : true, + link_with : [libstuff], + sources : [ + 'ar/append.c', + 'ar/ar.c', + 'ar/archive.c', + 'ar/contents.c', + 'ar/delete.c', + 'ar/extract.c', + 'ar/misc.c', + 'ar/move.c', + 'ar/print.c', + 'ar/replace.c' + ] +) +install_man( + 'ar/ar.1', + 'ar/ar.5' +) + +as = executable( + '@targetPrefix@gas', + include_directories : incdirs, + install : true, + link_with : [libstuff], + sources : ['as/driver.c'] +) + +as_common = files( + 'as/app.c', + 'as/as.c', + 'as/atof-generic.c', + 'as/atof-ieee.c', + 'as/dwarf2dbg.c', + 'as/expr.c', + 'as/fixes.c', + 'as/flonum-const.c', + 'as/flonum-copy.c', + 'as/flonum-mult.c', + 'as/frags.c', + 'as/hash.c', + 'as/hex-value.c', + 'as/input-file.c', + 'as/input-scrub.c', + 'as/layout.c', + 'as/messages.c', + 'as/obstack.c', + 'as/read.c', + 'as/sections.c', + 'as/symbols.c', + 'as/write_object.c', + 'as/xmalloc.c' +) + +as_arm = executable( + 'as-arm', + c_args : [ + '-DARM', + '-DNeXT_MOD' + ], + include_directories : [ + incdirs, + 'as', + 'include/gnu' + ], + install : true, + install_dir : 'libexec/as/arm', + link_with : [libstuff], + sources : [as_common, 'as/arm.c'] +) + +as_i386 = executable( + 'as-i386', + c_args : [ + '-DI386', + '-Di486', + '-Di586', + '-Di686', + '-DNeXT_MOD' + ], + include_directories : [ + incdirs, + 'as', + 'include/gnu' + ], + install : true, + install_dir : 'libexec/as/i386', + link_with : [libstuff], + sources : [as_common, 'as/i386.c'] +) + +as_x86_64 = executable( + 'as-x86_64', + c_args : [ + '-DI386', + '-Di486', + '-Di586', + '-Di686', + '-DARCH64', + '-DNeXT_MOD' + ], + include_directories : [ + incdirs, + 'as', + 'include/gnu' + ], + install : true, + install_dir : 'libexec/as/x86_64', + link_with : [libstuff], + sources : [as_common, 'as/i386.c'] +) + +# # ld # excluded because ld64 is built separately + +bitcode_strip = executable( + '@targetPrefix@bitcode_strip', + dependencies : [libcodedirectory], + include_directories : incdirs, + install : true, + link_with : [libstuff], + sources : ['misc/bitcode_strip.c'] +) +install_man('man/bitcode_strip.1') + +check_dylib = executable( + '@targetPrefix@check_dylib', + include_directories : incdirs, + install : true, + link_with : [libstuff], + sources : ['misc/check_dylib.c'] +) +install_man('man/check_dylib.1') + +checksyms = executable( + '@targetPrefix@checksyms', + include_directories : incdirs, + install : true, + link_with : [libstuff], + sources : ['misc/checksyms.c'] +) +install_man('man/checksyms.1') + +cmpdylib = executable( + '@targetPrefix@cmpdylib', + include_directories : incdirs, + install : true, + link_with : [libstuff], + sources : ['misc/cmpdylib.c'] +) +install_man('man/cmpdylib.1') + +codesign_allocate = executable( + '@targetPrefix@codesign_allocate', + dependencies : [libcodedirectory], + include_directories : incdirs, + install : true, + link_with : [libstuff], + sources : ['misc/codesign_allocate.c'] +) +install_man('man/codesign_allocate.1') + +ctf_insert = executable( + '@targetPrefix@ctf_insert', + dependencies : [libcodedirectory], + include_directories : [incdirs, 'include/stuff'], + install : true, + link_with : [libstuff], + sources : ['misc/ctf_insert.c'] +) +install_man('man/ctf_insert.1') + +depinfo = executable( + '@targetPrefix@depinfo', + include_directories : incdirs, + install : true, + link_with : [libstuff], + sources : ['misc/depinfo.c'] +) +install_man('man/depinfo.1') + +diagtest = executable( + '@targetPrefix@diagtest', + include_directories : incdirs, + install : true, + link_with : [libstuff], + sources : ['misc/diagtest.c'] +) +install_man('man/diagtest.1') + +gprof = executable( + '@targetPrefix@gprof', + include_directories : incdirs, + install : true, + link_with : [libstuff], + sources : [ + 'gprof/arcs.c', + 'gprof/calls.c', + 'gprof/dfn.c', + 'gprof/getnfile.c', + 'gprof/gprof.c', + 'gprof/hertz.c', + 'gprof/lookup.c', + 'gprof/printgprof.c', + 'gprof/printlist.c', + 'gprof/scatter.c' + ] +) +install_man('man/gprof.1') + +# Not supported on 64-bit architectures +# indr = executable( +# '@targetPrefix@indr', +# include_directories : incdirs, +# sources : ['misc/indr.c'] +# ) +# install_man('man/indr.1') + +install_name_tool = executable( + '@targetPrefix@install_name_tool', + dependencies : [libcodedirectory], + include_directories : incdirs, + install : true, + link_with : [libstuff], + sources : ['misc/install_name_tool.c'] +) +install_man('man/install_name_tool.1') + +libtool = executable( + '@targetPrefix@libtool', + include_directories : incdirs, + install : true, + link_with : [libstuff], + sources : ['misc/libtool.c'] +) +install_man('man/libtool.1') + +lipo = executable( + '@targetPrefix@lipo', + include_directories : incdirs, + install : true, + link_with : [libstuff], + sources : ['misc/lipo.c'] +) +install_man('man/lipo.1') + +mtoc = executable( + '@targetPrefix@mtoc', + include_directories : incdirs, + install : true, + link_with : [libstuff], + sources : ['efitools/mtoc.c'] +) +install_man('man/mtoc.1') + +mtor = executable( + '@targetPrefix@mtor', + include_directories : incdirs, + install : true, + link_with : [libstuff], + sources : ['efitools/mtor.c'] +) +install_man('man/mtor.1') + +nm = executable( + '@targetPrefix@nm', + include_directories : incdirs, + install : true, + link_with : [libstuff], + sources : ['misc/nm.c'] +) +install_man('man/nm-classic.1') + +nmedit = executable( + '@targetPrefix@nmedit', + c_args : ['-DNMEDIT'], + dependencies : [libcodedirectory], + include_directories : incdirs, + install : true, + link_with : [libstuff], + sources : ['misc/strip.c'] +) +install_man('man/nmedit.1') + +otool = executable( + '@targetPrefix@otool', + c_args : ['-DEFI_SUPPORT'], + dependencies : [libcxx], + include_directories : incdirs, + install : true, + link_with : [libstuff], + sources : [ + 'otool/arm64_disasm.c', + 'otool/arm_disasm.c', + 'otool/coff_print.c', + 'otool/dyld_bind_info.c', + 'otool/hppa_disasm.c', + 'otool/i386_disasm.c', + 'otool/i860_disasm.c', + 'otool/m68k_disasm.c', + 'otool/m88k_disasm.c', + 'otool/main.c', + 'otool/ofile_print.c', + 'otool/ppc_disasm.c', + 'otool/print_bitcode.c', + 'otool/print_objc.c', + 'otool/print_objc2_32bit.c', + 'otool/print_objc2_64bit.c', + 'otool/print_objc2_util.c', + 'otool/sparc_disasm.c' + ] +) +install_man('man/otool-classic.1') + +pagestuff = executable( + '@targetPrefix@pagestuff', + include_directories : incdirs, + install : true, + link_with : [libstuff], + sources : ['misc/pagestuff.c'] +) +install_man('man/pagestuff.1') + +# ranlib is a symlink to libtool +install_man( + 'man/ranlib.1', + 'man/ranlib.5' +) + +redo_prebinding = executable( + '@targetPrefix@redo_prebinding', + dependencies : [libcodedirectory], + include_directories : incdirs, + install : true, + link_with : [libstuff], + sources : ['misc/redo_prebinding.c'] +) +install_man('man/redo_prebinding.1') + +seg_addr_table = executable( + '@targetPrefix@seg_addr_table', + include_directories : incdirs, + install : true, + link_with : [libstuff], + sources : ['misc/seg_addr_table.c'] +) +install_man('man/seg_addr_table.1') + +seg_hack = executable( + '@targetPrefix@seg_hack', + dependencies : [libcodedirectory], + include_directories : incdirs, + install : true, + link_with : [libstuff], + sources : ['misc/seg_hack.c'] +) + +segedit = executable( + '@targetPrefix@segedit', + include_directories : incdirs, + install : true, + link_with : [libstuff], + sources : ['misc/segedit.c'] +) +install_man('man/segedit.1',) + +size = executable( + '@targetPrefix@size', + include_directories : incdirs, + install : true, + link_with : [libstuff], + sources : ['misc/size.c'] +) +install_man('man/size-classic.1') + +strings = executable( + '@targetPrefix@strings', + include_directories : incdirs, + install : true, + link_with : [libstuff], + sources : ['misc/strings.c'] +) +install_man('man/strings.1') + +strip = executable( + '@targetPrefix@strip', + c_args : ['-DTRIE_SUPPORT'], + dependencies : [libcodedirectory, libcxx, libprunetrie], + include_directories : incdirs, + install : true, + link_with : [libstuff], + sources : ['misc/strip.c'] +) +install_man('man/strip.1',) + +vtool = executable( + '@targetPrefix@vtool', + dependencies : [libcodedirectory], + include_directories : [incdirs, 'include/stuff'], + install : true, + link_with : [libstuff], + sources : ['misc/vtool.c'] +) +install_man('man/vtool.1') + + +# Development files +# Static libraries +libmacho = static_library( + 'macho', + include_directories : incdirs, + sources : [ + 'libmacho/arch.c', + 'libmacho/get_end.c', + 'libmacho/getsecbyname.c', + 'libmacho/getsegbyname.c', + 'libmacho/hppa_swap.c', + 'libmacho/i386_swap.c', + 'libmacho/i860_swap.c', + 'libmacho/m68k_swap.c', + 'libmacho/m88k_swap.c', + 'libmacho/ppc_swap.c', + 'libmacho/slot_name.c', + 'libmacho/sparc_swap.c', + 'libmacho/swap.c' + ] +) + +libredo_prebinding = static_library( + 'redo_prebinding', + c_args : ['-DLIBRARY_API'], + include_directories : incdirs, + sources : ['misc/redo_prebinding.c'] +) +install_man('man/redo_prebinding.3') + + +# Development files +# Based on the contents of the upstream SDK. +install_headers( + 'include/mach-o/arch.h', + 'include/mach-o/fat.h', + 'include/mach-o/getsect.h', + 'include/mach-o/ldsyms.h', + 'include/mach-o/loader.h', + 'include/mach-o/nlist.h', + 'include/mach-o/ranlib.h', + 'include/mach-o/reloc.h', + 'include/mach-o/stab.h', + 'include/mach-o/swap.h', + subdir : 'mach-o' +) + +# Some of these architectures are irrelevant, but the Libsystem derivation expects their headers to be present. +# Not every arch has both headers, so tailor the lists for each that does. +foreach arch : ['arm', 'arm64', 'hppa', 'i860', 'm88k', 'ppc', 'sparc', 'x86_64'] + install_headers( + f'include/mach-o/@arch@/reloc.h', + subdir : f'mach-o/@arch@' + ) +endforeach +foreach arch : ['hppa', 'i386', 'i860', 'm68k', 'm88k', 'ppc', 'sparc'] + install_headers( + f'include/mach-o/@arch@/swap.h', + subdir : f'mach-o/@arch@' + ) +endforeach + +install_data( + 'include/modules/mach-o.modulemap', + install_dir : get_option('includedir'), + rename : 'mach-o/module.map' +) +install_man( + 'man/Mach-O.5', + 'man/NSModule.3', + 'man/NSObjectFileImage.3', + 'man/NSObjectFileImage_priv.3', + 'man/arch.3', + 'man/dyld.3', + 'man/end.3', + 'man/get_end.3', + 'man/getsectbyname.3', + 'man/getsectbynamefromheader.3', + 'man/getsectdata.3', + 'man/getsectdatafromheader.3', + 'man/getsegbyname.3', + 'man/stab.5' +) diff --git a/pkgs/by-name/cc/cctools/package.nix b/pkgs/by-name/cc/cctools/package.nix new file mode 100644 index 0000000000000..4513b78813c1f --- /dev/null +++ b/pkgs/by-name/cc/cctools/package.nix @@ -0,0 +1,142 @@ +{ + lib, + stdenv, + fetchFromGitHub, + buildPackages, + darwin, + ld64, + llvm, + memstreamHook, + meson, + ninja, + gitUpdater, +}: + +let + # The targetPrefix is prepended to binary names to allow multiple binuntils on the PATH to both be usable. + targetPrefix = lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform) "${stdenv.targetPlatform.config}-"; + + # First version with all the required files + xnu = fetchFromGitHub { + name = "xnu-src"; + owner = "apple-oss-distributions"; + repo = "xnu"; + rev = "xnu-7195.50.7.100.1"; + hash = "sha256-uHmAOm6k9ZXWfyqHiDSpm+tZqUbERlr6rXSJ4xNACkM="; + }; +in +stdenv.mkDerivation (finalAttrs: { + pname = "${targetPrefix}cctools"; + version = "1010.6"; + + outputs = [ + "out" + "dev" + "man" + "gas" + ]; + + src = fetchFromGitHub { + owner = "apple-oss-distributions"; + repo = "cctools"; + rev = "cctools-${finalAttrs.version}"; + hash = "sha256-JiKCP6U+xxR4mk4TXWv/mEo9Idg+QQqUYmB/EeRksCE="; + }; + + sourceRoot = "source"; + + postUnpack = '' + unpackFile '${xnu}' + ''; + + patches = [ + # Fix compile errors in redo_prebinding.c + ./0001-Fix-build-issues-with-misc-redo_prebinding.c.patch + # Use libcd_is_blob_a_linker_signature as defined in the libcodedirectory.h header + ./0002-Rely-on-libcd_is_blob_a_linker_signature.patch + # cctools uses availability checks for `utimensat`, but it checks the wrong version. + # Also, provide a definition to avoid implicit function definition errors. + ./0003-Fix-utimensat-compatability-with-the-10.12-SDK.patch + # Use the nixpkgs clang’s path as the prefix. + ./0004-Use-nixpkgs-clang-with-the-assembler-driver.patch + # Make sure cctools can find ld64 in the store + ./0005-Find-ld64-in-the-store.patch + # `ranlib` is a symlink to `libtool`. Make sure its detection works when it is used in cross-compilation. + ./0006-Support-target-prefixes-in-ranlib-detection.patch + ]; + + postPatch = '' + substitute ${./meson.build} meson.build \ + --subst-var-by targetPrefix '${targetPrefix}' \ + --subst-var version + + # Make sure as’s clang driver uses clang from nixpkgs and finds the drivers in the store. + substituteInPlace as/driver.c \ + --subst-var-by clang-unwrapped '${lib.getBin buildPackages.clang.cc}/bin/' \ + --replace '../libexec/as/' '${placeholder "gas"}/libexec/as/' \ + --replace '../local/libexec/as/' '${placeholder "gas"}/libexec/as/' + + # Need to set the path to make sure cctools can find ld64 in the store. + substituteInPlace libstuff/execute.c \ + --subst-var-by ld64_path '${lib.getBin ld64}/bin/ld' + + # Set the target prefix for `ranlib` + substituteInPlace misc/libtool.c \ + --subst-var-by targetPrefix '${targetPrefix}' + + # The version of this file distributed with cctools defines several CPU types missing from the 10.12 SDK. + ln -s machine-cctools.h include/mach/machine.h + + cp ../xnu-src/EXTERNAL_HEADERS/mach-o/fixup-chains.h include/mach-o/fixup-chains.h + ''; + + strictDeps = true; + + nativeBuildInputs = [ + meson + ninja + ]; + + buildInputs = [ + ld64 + llvm + ] + ++ lib.optionals stdenv.isDarwin [ darwin.objc4 ] + ++ lib.optionals (stdenv.isDarwin && stdenv.isx86_64) [ memstreamHook ]; + + mesonBuildType = "release"; + + mesonFlags = [ (lib.mesonOption "b_ndebug" "if-release") ]; + + postInstall = '' + ln -s ${targetPrefix}libtool "$out/bin/${targetPrefix}ranlib" + ln -s nm-classic.1 "''${!outputMan}/share/man/man1/nm.1" + ln -s otool-classic.1 "''${!outputMan}/share/man/man1/otool.1" + ln -s size-classic.1 "''${!outputMan}/share/man/man1/size.1" + + # Move GNU as to its own output to prevent it from being used accidentally. + moveToOutput bin/gas "$gas" + moveToOutput libexec "$gas" + for arch in arm i386 x86_64; do + mv "$gas/libexec/as/$arch/as-$arch" "$gas/libexec/as/$arch/as" + done + ''; + + __structuredAttrs = true; + + passthru = { + inherit targetPrefix; + updateScript = gitUpdater { rev-prefix = "cctools-"; }; + }; + + meta = { + description = "The classic linker for Darwin"; + homepage = "https://opensource.apple.com/releases/"; + license = with lib.licenses; [ + apple-psl20 + gpl2 # GNU as + ]; + maintainers = with lib.maintainers; [ reckenrode ]; + platforms = lib.platforms.darwin; + }; +}) diff --git a/pkgs/by-name/fr/frankenphp/package.nix b/pkgs/by-name/fr/frankenphp/package.nix index 45b0fed97129d..3c6e02ded1d1d 100644 --- a/pkgs/by-name/fr/frankenphp/package.nix +++ b/pkgs/by-name/fr/frankenphp/package.nix @@ -6,6 +6,7 @@ , brotli , testers , frankenphp +, cctools , darwin , libiconv , pkg-config @@ -44,7 +45,7 @@ in buildGoModule rec { vendorHash = "sha256-eNW03oBaON2X5X2ZbM3Ly5T+bJzSDhEYajY5LaZhwdQ="; buildInputs = [ phpUnwrapped brotli ] ++ phpUnwrapped.buildInputs; - nativeBuildInputs = [ makeBinaryWrapper ] ++ lib.optionals stdenv.isDarwin [ pkg-config darwin.cctools darwin.autoSignDarwinBinariesHook ]; + nativeBuildInputs = [ makeBinaryWrapper ] ++ lib.optionals stdenv.isDarwin [ pkg-config cctools darwin.autoSignDarwinBinariesHook ]; subPackages = [ "frankenphp" ]; diff --git a/pkgs/by-name/ld/ld64/0001-Use-std-atomics-and-std-mutex.patch b/pkgs/by-name/ld/ld64/0001-Use-std-atomics-and-std-mutex.patch new file mode 100644 index 0000000000000..386d6eb3d6c71 --- /dev/null +++ b/pkgs/by-name/ld/ld64/0001-Use-std-atomics-and-std-mutex.patch @@ -0,0 +1,181 @@ +From 8b0a9036cdc9b6c43cb86a1a7a8004dbb6aec197 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Sat, 6 Apr 2024 20:29:25 -0400 +Subject: [PATCH 1/6] Use std::atomics and std::mutex + +--- + src/ld/InputFiles.cpp | 13 ++++++------- + src/ld/InputFiles.h | 9 +++++---- + src/ld/OutputFile.cpp | 13 ++++++------- + src/ld/ld.cpp | 11 +++++------ + 4 files changed, 22 insertions(+), 24 deletions(-) + +diff --git a/src/ld/InputFiles.cpp b/src/ld/InputFiles.cpp +index ec53a60..427ab09 100644 +--- a/src/ld/InputFiles.cpp ++++ b/src/ld/InputFiles.cpp +@@ -42,7 +42,6 @@ + #include + #include + #include +-#include + #if HAVE_LIBDISPATCH + #include + #endif +@@ -387,16 +386,16 @@ ld::File* InputFiles::makeFile(const Options::FileInfo& info, bool indirectDylib + + ld::relocatable::File* objResult = mach_o::relocatable::parse(p, len, info.path, info.modTime, info.ordinal, objOpts); + if ( objResult != NULL ) { +- OSAtomicAdd64(len, &_totalObjectSize); +- OSAtomicIncrement32(&_totalObjectLoaded); ++ _totalObjectSize += len; ++ ++_totalObjectLoaded; + return objResult; + } + + // see if it is an llvm object file + objResult = lto::parse(p, len, info.path, info.modTime, info.ordinal, _options.architecture(), _options.subArchitecture(), _options.logAllFiles(), _options.verboseOptimizationHints()); + if ( objResult != NULL ) { +- OSAtomicAdd64(len, &_totalObjectSize); +- OSAtomicIncrement32(&_totalObjectLoaded); ++ _totalObjectSize += len; ++ ++_totalObjectLoaded; + return objResult; + } + +@@ -444,8 +443,8 @@ ld::File* InputFiles::makeFile(const Options::FileInfo& info, bool indirectDylib + ld::archive::File* archiveResult = ::archive::parse(p, len, info.path, info.modTime, info.ordinal, archOpts); + if ( archiveResult != NULL ) { + +- OSAtomicAdd64(len, &_totalArchiveSize); +- OSAtomicIncrement32(&_totalArchivesLoaded); ++ _totalArchiveSize += len; ++ ++_totalArchivesLoaded; + return archiveResult; + } + +diff --git a/src/ld/InputFiles.h b/src/ld/InputFiles.h +index c18ccf8..ffff26b 100644 +--- a/src/ld/InputFiles.h ++++ b/src/ld/InputFiles.h +@@ -46,6 +46,7 @@ + #include + #endif + ++#include + #include + + #include "Options.h" +@@ -78,10 +79,10 @@ public: + size_t count() const { return _inputFiles.size(); } + + // for -print_statistics +- volatile int64_t _totalObjectSize; +- volatile int64_t _totalArchiveSize; +- volatile int32_t _totalObjectLoaded; +- volatile int32_t _totalArchivesLoaded; ++ std::atomic _totalObjectSize; ++ std::atomic _totalArchiveSize; ++ std::atomic _totalObjectLoaded; ++ std::atomic _totalArchivesLoaded; + int32_t _totalDylibsLoaded; + + +diff --git a/src/ld/OutputFile.cpp b/src/ld/OutputFile.cpp +index 5055d1f..ff3d430 100644 +--- a/src/ld/OutputFile.cpp ++++ b/src/ld/OutputFile.cpp +@@ -43,11 +43,10 @@ + #include + #include + #include +-#include + extern "C" { + #include + } +-#include ++#include + #include + #include + #include +@@ -1315,7 +1314,7 @@ void OutputFile::rangeCheckRISCVBranch20(int64_t displacement, ld::Internal& sta + + + #if SUPPORT_ARCH_arm64e +-static os_lock_unfair_s sAuthenticatedFixupDataLock = OS_LOCK_UNFAIR_INIT; // to serialize building of _authenticatedFixupData ++static std::mutex sAuthenticatedFixupDataLock; // to serialize building of _authenticatedFixupData + #endif + + void OutputFile::applyFixUps(ld::Internal& state, uint64_t mhAddress, const ld::Atom* atom, uint8_t* buffer) +@@ -1690,11 +1689,11 @@ void OutputFile::applyFixUps(ld::Internal& state, uint64_t mhAddress, const ld:: + } + else { + auto fixupOffset = (uintptr_t)(fixUpLocation - mhAddress); +- os_lock_lock(&sAuthenticatedFixupDataLock); ++ sAuthenticatedFixupDataLock.lock(); + assert(_authenticatedFixupData.find(fixupOffset) == _authenticatedFixupData.end()); + auto authneticatedData = std::make_pair(authData, accumulator); + _authenticatedFixupData[fixupOffset] = authneticatedData; +- os_lock_unlock(&sAuthenticatedFixupDataLock); ++ sAuthenticatedFixupDataLock.unlock(); + // Zero out this entry which we will expect later. + set64LE(fixUpLocation, 0); + } +@@ -1721,11 +1720,11 @@ void OutputFile::applyFixUps(ld::Internal& state, uint64_t mhAddress, const ld:: + } + else { + auto fixupOffset = (uintptr_t)(fixUpLocation - mhAddress); +- os_lock_lock(&sAuthenticatedFixupDataLock); ++ sAuthenticatedFixupDataLock.lock(); + assert(_authenticatedFixupData.find(fixupOffset) == _authenticatedFixupData.end()); + auto authneticatedData = std::make_pair(authData, accumulator); + _authenticatedFixupData[fixupOffset] = authneticatedData; +- os_lock_unlock(&sAuthenticatedFixupDataLock); ++ sAuthenticatedFixupDataLock.unlock(); + // Zero out this entry which we will expect later. + set64LE(fixUpLocation, 0); + } +diff --git a/src/ld/ld.cpp b/src/ld/ld.cpp +index b7590a3..f1bf9df 100644 +--- a/src/ld/ld.cpp ++++ b/src/ld/ld.cpp +@@ -47,9 +47,8 @@ extern "C" double log2 ( double ); + #include + #include + #include +-#include + +-#include ++#include + #include + #include + #include +@@ -1603,8 +1602,8 @@ int main(int argc, const char* argv[]) + statistics.vmEnd.faults-statistics.vmStart.faults); + fprintf(stderr, "memory active: %lu, wired: %lu\n", statistics.vmEnd.active_count * vm_page_size, statistics.vmEnd.wire_count * vm_page_size); + char temp[40]; +- fprintf(stderr, "processed %3u object files, totaling %15s bytes\n", inputFiles._totalObjectLoaded, commatize(inputFiles._totalObjectSize, temp)); +- fprintf(stderr, "processed %3u archive files, totaling %15s bytes\n", inputFiles._totalArchivesLoaded, commatize(inputFiles._totalArchiveSize, temp)); ++ fprintf(stderr, "processed %3u object files, totaling %15s bytes\n", inputFiles._totalObjectLoaded.load(), commatize(inputFiles._totalObjectSize.load(), temp)); ++ fprintf(stderr, "processed %3u archive files, totaling %15s bytes\n", inputFiles._totalArchivesLoaded.load(), commatize(inputFiles._totalArchiveSize.load(), temp)); + fprintf(stderr, "processed %3u dylib files\n", inputFiles._totalDylibsLoaded); + fprintf(stderr, "wrote output file totaling %15s bytes\n", commatize(out.fileSize(), temp)); + } +@@ -1634,12 +1633,12 @@ int main(int argc, const char* argv[]) + #ifndef NDEBUG + + // now that the linker is multi-threaded, only allow one assert() to be processed +-static os_lock_unfair_s sAssertLock = OS_LOCK_UNFAIR_INIT; ++static std::mutex sAssertLock; + + // implement assert() function to print out a backtrace before aborting + void __assert_rtn(const char* func, const char* file, int line, const char* failedexpr) + { +- os_lock_lock(&sAssertLock); ++ sAssertLock.lock(); + + Snapshot *snapshot = Snapshot::globalSnapshot; + +-- +2.42.0 + diff --git a/pkgs/by-name/ld/ld64/0002-Avoid-UB-when-std-vector-is-empty.patch b/pkgs/by-name/ld/ld64/0002-Avoid-UB-when-std-vector-is-empty.patch new file mode 100644 index 0000000000000..88bd41ecb97c7 --- /dev/null +++ b/pkgs/by-name/ld/ld64/0002-Avoid-UB-when-std-vector-is-empty.patch @@ -0,0 +1,1239 @@ +From e4434c35b2922bbcf1034ccfc985c33cf6afc90b Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Sun, 7 Apr 2024 13:37:58 -0400 +Subject: [PATCH 2/6] Avoid UB when std::vector is empty + +--- + src/ld/LinkEdit.hpp | 2 +- + src/ld/LinkEditClassic.hpp | 6 +-- + src/ld/Options.h | 12 ++--- + src/ld/Resolver.cpp | 4 +- + src/ld/parsers/generic_dylib_file.hpp | 4 +- + src/ld/parsers/lto_file.cpp | 8 ++-- + src/ld/parsers/macho_relocatable_file.cpp | 16 +++---- + src/ld/passes/branch_island.cpp | 16 +++---- + src/ld/passes/branch_shim.cpp | 20 ++++---- + src/ld/passes/code_dedup.cpp | 4 +- + src/ld/passes/compact_unwind.cpp | 8 ++-- + src/ld/passes/dtrace_dof.cpp | 4 +- + src/ld/passes/got.cpp | 6 +-- + src/ld/passes/inits.cpp | 4 +- + src/ld/passes/objc.cpp | 20 ++++---- + src/ld/passes/objc_constants.cpp | 2 +- + src/ld/passes/objc_stubs.cpp | 16 +++---- + src/ld/passes/stubs/stub_arm.hpp | 52 ++++++++++----------- + src/ld/passes/stubs/stub_arm64.hpp | 32 ++++++------- + src/ld/passes/stubs/stub_arm64_32.hpp | 32 ++++++------- + src/ld/passes/stubs/stub_arm64e.hpp | 20 ++++---- + src/ld/passes/stubs/stub_arm_classic.hpp | 12 ++--- + src/ld/passes/stubs/stub_x86.hpp | 32 ++++++------- + src/ld/passes/stubs/stub_x86_64.hpp | 32 ++++++------- + src/ld/passes/stubs/stub_x86_64_classic.hpp | 12 ++--- + src/ld/passes/stubs/stub_x86_classic.hpp | 12 ++--- + src/ld/passes/tlvp.cpp | 2 +- + src/mach_o/ExportsTrie.cpp | 4 +- + 28 files changed, 197 insertions(+), 197 deletions(-) + +diff --git a/src/ld/LinkEdit.hpp b/src/ld/LinkEdit.hpp +index 2d72109..acd3e5c 100644 +--- a/src/ld/LinkEdit.hpp ++++ b/src/ld/LinkEdit.hpp +@@ -56,7 +56,7 @@ public: + std::vector& bytes() { return _data; } + unsigned long size() const { return _data.size(); } + void reserve(unsigned long l) { _data.reserve(l); } +- const uint8_t* start() const { return &_data[0]; } ++ const uint8_t* start() const { return _data.data(); } + + void append_uleb128(uint64_t value) { + uint8_t byte; +diff --git a/src/ld/LinkEditClassic.hpp b/src/ld/LinkEditClassic.hpp +index 9bf8c0b..7add285 100644 +--- a/src/ld/LinkEditClassic.hpp ++++ b/src/ld/LinkEditClassic.hpp +@@ -754,11 +754,11 @@ uint64_t SymbolTableAtom::size() const + template + void SymbolTableAtom::copyRawContent(uint8_t buffer[]) const + { +- memcpy(&buffer[this->_writer._localSymbolsStartIndex*sizeof(macho_nlist

)], &_locals[0], ++ memcpy(&buffer[this->_writer._localSymbolsStartIndex*sizeof(macho_nlist

)], _locals.data(), + this->_writer._localSymbolsCount*sizeof(macho_nlist

)); +- memcpy(&buffer[this->_writer._globalSymbolsStartIndex*sizeof(macho_nlist

)], &_globals[0], ++ memcpy(&buffer[this->_writer._globalSymbolsStartIndex*sizeof(macho_nlist

)], _globals.data(), + this->_writer._globalSymbolsCount*sizeof(macho_nlist

)); +- memcpy(&buffer[this->_writer._importSymbolsStartIndex *sizeof(macho_nlist

)], &_imports[0], ++ memcpy(&buffer[this->_writer._importSymbolsStartIndex *sizeof(macho_nlist

)], _imports.data(), + this->_writer._importSymbolsCount*sizeof(macho_nlist

)); + } + +diff --git a/src/ld/Options.h b/src/ld/Options.h +index 4cf09a1..3900a71 100644 +--- a/src/ld/Options.h ++++ b/src/ld/Options.h +@@ -358,15 +358,15 @@ public: + uint64_t customStackAddr() const { return fStackAddr; } + bool hasExecutableStack() const { return fExecutableStack; } + bool hasNonExecutableHeap() const { return fNonExecutableHeap; } +- UndefinesIterator initialUndefinesBegin() const { return &fInitialUndefines[0]; } +- UndefinesIterator initialUndefinesEnd() const { return &fInitialUndefines[fInitialUndefines.size()]; } ++ UndefinesIterator initialUndefinesBegin() const { return fInitialUndefines.data(); } ++ UndefinesIterator initialUndefinesEnd() const { return fInitialUndefines.data() + fInitialUndefines.size(); } + const std::vector& initialUndefines() const { return fInitialUndefines; } + bool printWhyLive(const char* name) const; + bool printWhyLive() const { return !fWhyLive.empty(); } + uint32_t minimumHeaderPad() const { return fMinimumHeaderPad; } + bool maxMminimumHeaderPad() const { return fMaxMinimumHeaderPad; } +- ExtraSection::const_iterator extraSectionsBegin() const { return &fExtraSections[0]; } +- ExtraSection::const_iterator extraSectionsEnd() const { return &fExtraSections[fExtraSections.size()]; } ++ ExtraSection::const_iterator extraSectionsBegin() const { return fExtraSections.data(); } ++ ExtraSection::const_iterator extraSectionsEnd() const { return fExtraSections.data() + fExtraSections.size(); } + CommonsMode commonsMode() const { return fCommonsMode; } + bool warnCommons() const { return fWarnCommons; } + bool keepRelocations(); +@@ -389,8 +389,8 @@ public: + const char* dTraceScriptName() { return fDtraceScriptName; } + bool dTrace() { return (fDtraceScriptName != NULL); } + unsigned long orderedSymbolsCount() const { return fOrderedSymbols.size(); } +- OrderedSymbolsIterator orderedSymbolsBegin() const { return &fOrderedSymbols[0]; } +- OrderedSymbolsIterator orderedSymbolsEnd() const { return &fOrderedSymbols[fOrderedSymbols.size()]; } ++ OrderedSymbolsIterator orderedSymbolsBegin() const { return fOrderedSymbols.data(); } ++ OrderedSymbolsIterator orderedSymbolsEnd() const { return fOrderedSymbols.data() + fOrderedSymbols.size(); } + uint64_t baseWritableAddress() { return fBaseWritableAddress; } + uint64_t segmentAlignment() const { return fSegmentAlignment; } + uint64_t segPageSize(const char* segName) const; +diff --git a/src/ld/Resolver.cpp b/src/ld/Resolver.cpp +index 063d2b4..9d7d86a 100644 +--- a/src/ld/Resolver.cpp ++++ b/src/ld/Resolver.cpp +@@ -130,8 +130,8 @@ public: + { return _aliasOf.contentHash(ibt); } + virtual bool canCoalesceWith(const ld::Atom& rhs, const class ld::IndirectBindingTable& ibt) const + { return _aliasOf.canCoalesceWith(rhs,ibt); } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup + 1); } + virtual ld::Atom::UnwindInfo::iterator beginUnwind() const { return NULL; } + virtual ld::Atom::UnwindInfo::iterator endUnwind() const { return NULL; } + virtual ld::Atom::LineInfo::iterator beginLineInfo() const { return NULL; } +diff --git a/src/ld/parsers/generic_dylib_file.hpp b/src/ld/parsers/generic_dylib_file.hpp +index f6a38b4..52898e1 100644 +--- a/src/ld/parsers/generic_dylib_file.hpp ++++ b/src/ld/parsers/generic_dylib_file.hpp +@@ -80,8 +80,8 @@ public: + virtual const char* name() const override final { return "import-atom"; } + virtual uint64_t size() const override final { return 0; } + virtual uint64_t objectAddress() const override final { return 0; } +- virtual ld::Fixup::iterator fixupsBegin() const override final { return &_undefs[0]; } +- virtual ld::Fixup::iterator fixupsEnd() const override final { return &_undefs[_undefs.size()]; } ++ virtual ld::Fixup::iterator fixupsBegin() const override final { return _undefs.data(); } ++ virtual ld::Fixup::iterator fixupsEnd() const override final { return _undefs.data() + _undefs.size(); } + virtual void copyRawContent(uint8_t buffer[]) const override final { } + + virtual void setScope(Scope) { } +diff --git a/src/ld/parsers/lto_file.cpp b/src/ld/parsers/lto_file.cpp +index 80e35bf..5318212 100644 +--- a/src/ld/parsers/lto_file.cpp ++++ b/src/ld/parsers/lto_file.cpp +@@ -73,8 +73,8 @@ public: + uint64_t size() const override { return 0; } + uint64_t objectAddress() const override { return 0; } + void copyRawContent(uint8_t buffer[]) const override { } +- ld::Fixup::iterator fixupsBegin() const override { return &_undefs[0]; } +- ld::Fixup::iterator fixupsEnd() const override { return &_undefs[_undefs.size()]; } ++ ld::Fixup::iterator fixupsBegin() const override { return _undefs.data(); } ++ ld::Fixup::iterator fixupsEnd() const override { return _undefs.data() + _undefs.size(); } + + // for adding references to symbols outside bitcode file + void addReference(const char* nm) +@@ -188,9 +188,9 @@ public: + bool canCoalesceWith(const ld::Atom& rhs, const class ld::IndirectBindingTable& ibt) const override + { return (_compiledAtom ? _compiledAtom->canCoalesceWith(rhs,ibt) : false); } + ld::Fixup::iterator fixupsBegin() const override +- { return (_compiledAtom ? _compiledAtom->fixupsBegin() : (ld::Fixup*)&_file._fixupToInternal); } ++ { return (_compiledAtom ? _compiledAtom->fixupsBegin() : &_file._fixupToInternal); } + ld::Fixup::iterator fixupsEnd() const override +- { return (_compiledAtom ? _compiledAtom->fixupsEnd() : &((ld::Fixup*)&_file._fixupToInternal)[1]); } ++ { return (_compiledAtom ? _compiledAtom->fixupsEnd() : (&_file._fixupToInternal + 1)); } + ld::Atom::UnwindInfo::iterator beginUnwind() const override + { return (_compiledAtom ? _compiledAtom->beginUnwind() : NULL); } + ld::Atom::UnwindInfo::iterator endUnwind() const override +diff --git a/src/ld/parsers/macho_relocatable_file.cpp b/src/ld/parsers/macho_relocatable_file.cpp +index 4497169..b9a3694 100644 +--- a/src/ld/parsers/macho_relocatable_file.cpp ++++ b/src/ld/parsers/macho_relocatable_file.cpp +@@ -763,12 +763,12 @@ public: + { if ( _hash == 0 ) _hash = sect().contentHash(this, ind); return _hash; } + virtual bool canCoalesceWith(const ld::Atom& rhs, const ld::IndirectBindingTable& ind) const + { return sect().canCoalesceWith(this, rhs, ind); } +- virtual ld::Fixup::iterator fixupsBegin() const { return &machofile()._fixups[_fixupsStartIndex]; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &machofile()._fixups[_fixupsStartIndex+_fixupsCount]; } +- virtual ld::Atom::UnwindInfo::iterator beginUnwind() const { return &machofile()._unwindInfos[_unwindInfoStartIndex]; } +- virtual ld::Atom::UnwindInfo::iterator endUnwind() const { return &machofile()._unwindInfos[_unwindInfoStartIndex+_unwindInfoCount]; } +- virtual ld::Atom::LineInfo::iterator beginLineInfo() const{ return &machofile()._lineInfos[_lineInfoStartIndex]; } +- virtual ld::Atom::LineInfo::iterator endLineInfo() const { return &machofile()._lineInfos[_lineInfoStartIndex+_lineInfoCount]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return machofile()._fixups.data() + _fixupsStartIndex; } ++ virtual ld::Fixup::iterator fixupsEnd() const { return machofile()._fixups.data() + _fixupsStartIndex + _fixupsCount; } ++ virtual ld::Atom::UnwindInfo::iterator beginUnwind() const { return machofile()._unwindInfos.data() + _unwindInfoStartIndex; } ++ virtual ld::Atom::UnwindInfo::iterator endUnwind() const { return machofile()._unwindInfos.data() + _unwindInfoStartIndex + _unwindInfoCount; } ++ virtual ld::Atom::LineInfo::iterator beginLineInfo() const{ return machofile()._lineInfos.data() + _lineInfoStartIndex; } ++ virtual ld::Atom::LineInfo::iterator endLineInfo() const { return machofile()._lineInfos.data() + _lineInfoStartIndex + _lineInfoCount; } + virtual void setFile(const ld::File* f); + + private: +@@ -993,8 +993,8 @@ public: + virtual uint64_t size() const { return 0; } + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &((ld::Fixup*)&_fixup)[0]; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup + 1); } + + private: + static ld::Section _s_section; +diff --git a/src/ld/passes/branch_island.cpp b/src/ld/passes/branch_island.cpp +index 22976bc..7d6fc2d 100644 +--- a/src/ld/passes/branch_island.cpp ++++ b/src/ld/passes/branch_island.cpp +@@ -85,8 +85,8 @@ public: + OSWriteLittleInt32(buffer, 0, 0x14000000); + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup2)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup2 + 1); } + + private: + const char* _name; +@@ -117,8 +117,8 @@ public: + OSWriteLittleInt32(buffer, 0, 0xEA000000); + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup2)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup2 + 1); } + + private: + const char* _name; +@@ -188,8 +188,8 @@ public: + OSWriteLittleInt32(buffer, 0, 0xf0008000); + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup2)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup2 + 1); } + + private: + const char* _name; +@@ -225,8 +225,8 @@ public: + OSWriteLittleInt16(&buffer[8], 0, 0x4760); // bx r12 + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup5)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup5 + 1); } + + private: + const char* _name; +diff --git a/src/ld/passes/branch_shim.cpp b/src/ld/passes/branch_shim.cpp +index fed4a92..3842f2c 100644 +--- a/src/ld/passes/branch_shim.cpp ++++ b/src/ld/passes/branch_shim.cpp +@@ -73,8 +73,8 @@ public: + } + + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup4)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup4 + 1); } + + private: + const char* _name; +@@ -112,8 +112,8 @@ public: + } + + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup1)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup1 + 1); } + + private: + const char* _name; +@@ -153,8 +153,8 @@ public: + OSWriteLittleInt32(&buffer[12], 0, 0x00000000); // .long target-this + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup4)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup4 + 1); } + + private: + const char* _name; +@@ -196,8 +196,8 @@ public: + OSWriteLittleInt32(&buffer[12], 0, 0); // .long target-this + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup4)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup4 + 1); } + + private: + const char* _name; +@@ -232,8 +232,8 @@ public: + OSWriteLittleInt32(&buffer[ 8], 0, 0); // .long target + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup1)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(const_cast(&_fixup1)); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup1 + 1); } + + private: + const char* _name; +diff --git a/src/ld/passes/code_dedup.cpp b/src/ld/passes/code_dedup.cpp +index be91432..94f4d73 100644 +--- a/src/ld/passes/code_dedup.cpp ++++ b/src/ld/passes/code_dedup.cpp +@@ -64,8 +64,8 @@ public: + virtual uint64_t size() const { return 0; } + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &((ld::Fixup*)&_fixup)[0]; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup + 1); } + + private: + const ld::Atom* _dedupOf; +diff --git a/src/ld/passes/compact_unwind.cpp b/src/ld/passes/compact_unwind.cpp +index a7b696d..7082fcc 100644 +--- a/src/ld/passes/compact_unwind.cpp ++++ b/src/ld/passes/compact_unwind.cpp +@@ -76,8 +76,8 @@ public: + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const; + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixups[0]; } +- virtual ld::Fixup::iterator fixupsEnd() const { return (ld::Fixup*)&_fixups[_fixups.size()]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(_fixups.data()); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(_fixups.data() + _fixups.size()); } + + private: + typedef typename A::P P; +@@ -1022,8 +1022,8 @@ public: + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const; + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixups[0]; } +- virtual ld::Fixup::iterator fixupsEnd() const { return (ld::Fixup*)&_fixups[_fixups.size()]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(_fixups.data()); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(_fixups.data() + _fixups.size()); } + + private: + typedef typename A::P P; +diff --git a/src/ld/passes/dtrace_dof.cpp b/src/ld/passes/dtrace_dof.cpp +index 80e323d..0fbba39 100644 +--- a/src/ld/passes/dtrace_dof.cpp ++++ b/src/ld/passes/dtrace_dof.cpp +@@ -54,8 +54,8 @@ public: + virtual void copyRawContent(uint8_t buffer[]) const + { memcpy(buffer, _content, _size); } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixups[0]; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &_fixups[_fixups.size()]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return _fixups.data(); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return _fixups.data() + _fixups.size(); } + + protected: + friend class File; +diff --git a/src/ld/passes/got.cpp b/src/ld/passes/got.cpp +index 8f702f4..92a12f2 100644 +--- a/src/ld/passes/got.cpp ++++ b/src/ld/passes/got.cpp +@@ -61,7 +61,7 @@ public: + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } + virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } ++ virtual ld::Fixup::iterator fixupsEnd() const { return &_fixup + 1; } + + private: + mutable ld::Fixup _fixup; +@@ -104,8 +104,8 @@ public: + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup2)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } ++ virtual ld::Fixup::iterator fixupsEnd() const { return &_fixup2 + 1; } + + private: + mutable ld::Fixup _fixup1; +diff --git a/src/ld/passes/inits.cpp b/src/ld/passes/inits.cpp +index 8123e05..8b06346 100644 +--- a/src/ld/passes/inits.cpp ++++ b/src/ld/passes/inits.cpp +@@ -57,8 +57,8 @@ public: + virtual uint64_t size() const { return 4; } + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup2)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup2 + 1); } + + protected: + mutable ld::Fixup _fixup1; +diff --git a/src/ld/passes/objc.cpp b/src/ld/passes/objc.cpp +index 826b6a3..76ed67a 100644 +--- a/src/ld/passes/objc.cpp ++++ b/src/ld/passes/objc.cpp +@@ -138,7 +138,7 @@ public: + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } + virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } ++ virtual ld::Fixup::iterator fixupsEnd() const { return &_fixup + 1; } + + private: + mutable ld::Fixup _fixup; +@@ -173,7 +173,7 @@ public: + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } + virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } ++ virtual ld::Fixup::iterator fixupsEnd() const { return &_fixup + 1; } + + private: + mutable ld::Fixup _fixup; +@@ -250,8 +250,8 @@ public: + virtual uint64_t objectAddress() const { return 0; } + virtual void setScope(Scope) { } + virtual void copyRawContent(uint8_t buffer[]) const; +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixups[0]; } +- virtual ld::Fixup::iterator fixupsEnd() const { return (ld::Fixup*)&_fixups[_fixups.size()]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(_fixups.data()); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(_fixups.data() + _fixups.size()); } + + + private: +@@ -297,8 +297,8 @@ public: + bzero(buffer, size()); + A::P::setP(*((pint_t*)(buffer)), _protocolCount); + } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixups[0]; } +- virtual ld::Fixup::iterator fixupsEnd() const { return (ld::Fixup*)&_fixups[_fixups.size()]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(_fixups.data()); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(_fixups.data() + _fixups.size()); } + + private: + typedef typename A::P::uint_t pint_t; +@@ -337,8 +337,8 @@ public: + A::P::E::set32(((uint32_t*)(buffer))[0], 2*sizeof(pint_t)); // sizeof(objc_property) + A::P::E::set32(((uint32_t*)(buffer))[1], _propertyCount); + } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixups[0]; } +- virtual ld::Fixup::iterator fixupsEnd() const { return (ld::Fixup*)&_fixups[_fixups.size()]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(_fixups.data()); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(_fixups.data() + _fixups.size()); } + + private: + typedef typename A::P::uint_t pint_t; +@@ -381,8 +381,8 @@ public: + virtual bool canCoalesceWith(const ld::Atom& rhs, const class ld::IndirectBindingTable& ibt) const + { return _atom->canCoalesceWith(rhs,ibt); } + +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixups[0]; } +- virtual ld::Fixup::iterator fixupsEnd() const { return (ld::Fixup*)&_fixups[_fixups.size()]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(_fixups.data()); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(_fixups.data() + _fixups.size()); } + + protected: + void addFixupAtOffset(uint32_t offset, bool isAuthPtr=false); +diff --git a/src/ld/passes/objc_constants.cpp b/src/ld/passes/objc_constants.cpp +index 3e99538..0ae2d5d 100644 +--- a/src/ld/passes/objc_constants.cpp ++++ b/src/ld/passes/objc_constants.cpp +@@ -60,7 +60,7 @@ public: + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } + virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } ++ virtual ld::Fixup::iterator fixupsEnd() const { return &_fixup + 1; } + + private: + mutable ld::Fixup _fixup; +diff --git a/src/ld/passes/objc_stubs.cpp b/src/ld/passes/objc_stubs.cpp +index 79d8643..fd4b24a 100644 +--- a/src/ld/passes/objc_stubs.cpp ++++ b/src/ld/passes/objc_stubs.cpp +@@ -157,8 +157,8 @@ public: + virtual uint64_t size() const override; + virtual uint64_t objectAddress() const override { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const override; +- virtual ld::Fixup::iterator fixupsBegin() const override { return &_fixups.front(); } +- virtual ld::Fixup::iterator fixupsEnd() const override { return &_fixups.front() + _fixups.size(); } ++ virtual ld::Fixup::iterator fixupsBegin() const override { return _fixups.data(); } ++ virtual ld::Fixup::iterator fixupsEnd() const override { return _fixups.data() + _fixups.size(); } + + private: + void addFixups(const ld::Atom* selector, const ld::Atom* msgSend, uint32_t msgSendSlot); +@@ -300,8 +300,8 @@ public: + virtual uint64_t size() const override { return (_is64 ? 8 : 4); } + virtual uint64_t objectAddress() const override { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const override { } +- virtual ld::Fixup::iterator fixupsBegin() const override { return &_fixup; } +- virtual ld::Fixup::iterator fixupsEnd() const override { return &((ld::Fixup*)&_fixup)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const override { return const_cast(&_fixup); } ++ virtual ld::Fixup::iterator fixupsEnd() const override { return const_cast(&_fixup + 1); } + + private: + mutable ld::Fixup _fixup; +@@ -331,8 +331,8 @@ public: + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup1)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup1 + 1); } + + private: + const ld::Atom& _target; +@@ -363,8 +363,8 @@ public: + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup2)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup2 + 1); } + + private: + const ld::Atom& _target; +diff --git a/src/ld/passes/stubs/stub_arm.hpp b/src/ld/passes/stubs/stub_arm.hpp +index 85bfd5e..6aee106 100644 +--- a/src/ld/passes/stubs/stub_arm.hpp ++++ b/src/ld/passes/stubs/stub_arm.hpp +@@ -41,8 +41,8 @@ public: + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup + 1); } + + private: + ld::Fixup _fixup; +@@ -111,8 +111,8 @@ public: + OSWriteLittleInt32(&buffer[32], 0, 0x00000000); // L2: .long _fast_lazy_bind - (helperhelper+28) + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup8)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup8 + 1); } + + private: + static ld::Atom* compressedImageCache(ld::passes::stubs::Pass& pass) { +@@ -163,8 +163,8 @@ public: + OSWriteLittleInt32(&buffer[8], 0, 0); // .long lazy-info-offset + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup3)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup3 + 1); } + + private: + static ld::Atom* helperHelper(ld::passes::stubs::Pass& pass, StubHelperAtom& stub, bool stubToResolver) { +@@ -216,8 +216,8 @@ public: + OSWriteLittleInt32(&buffer[32], 0, 0x00000000); // .long foo$lazyptr - helper + 20 + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup5)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup5 + 1); } + + private: + const ld::Atom& _stubTo; +@@ -261,8 +261,8 @@ public: + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup2)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup2 + 1); } + + private: + static ld::Section& selectSection(bool close, bool stubToGlobalWeakDef, bool stubToResolver, bool usingDataConst) { +@@ -313,8 +313,8 @@ public: + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup1)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup1 + 1); } + + private: + const ld::Atom& _stubTo; +@@ -360,8 +360,8 @@ public: + OSWriteLittleInt16(&buffer[14], 0, 0x4760); // bx ip + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup8)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup8 + 1); } + + private: + const ld::Atom& _stubTo; +@@ -409,8 +409,8 @@ public: + OSWriteLittleInt32(&buffer[12], 0, 0x00000000); // L1: .long L_foo$lazy_ptr + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup4)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup4 + 1); } + + private: + const ld::Atom& _stubTo; +@@ -446,8 +446,8 @@ public: + OSWriteLittleInt32(&buffer[ 4], 0, 0x00000000); // .long L_foo$lazy_ptr + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup + 1); } + + private: + const ld::Atom& _stubTo; +@@ -486,8 +486,8 @@ public: + OSWriteLittleInt32(&buffer[12], 0, 0x00000000); // .long L_foo$lazy_ptr - (L1$scv + 8) + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup4)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup4 + 1); } + + private: + const ld::Atom& _stubTo; +@@ -526,8 +526,8 @@ public: + OSWriteLittleInt32(&buffer[ 8], 0, 0x00000000); // .long L_foo$lazy_ptr + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup + 1); } + + private: + const ld::Atom& _stubTo; +@@ -562,8 +562,8 @@ public: + OSWriteLittleInt32(&buffer[ 0], 0, 0xE59FF000); // ldr pc, [pc, #foo$lazy_ptr] + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup + 1); } + + private: + const ld::Atom& _stubTo; +@@ -602,8 +602,8 @@ public: + OSWriteLittleInt32(&buffer[12], 0, 0x00000000); // .long L_foo$nonlazy_ptr - (L1$scv + 8) + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup4)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup4 + 1); } + + private: + const ld::Atom& _stubTo; +diff --git a/src/ld/passes/stubs/stub_arm64.hpp b/src/ld/passes/stubs/stub_arm64.hpp +index 6fcbcf4..ba29717 100644 +--- a/src/ld/passes/stubs/stub_arm64.hpp ++++ b/src/ld/passes/stubs/stub_arm64.hpp +@@ -44,8 +44,8 @@ public: + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup + 1); } + + private: + mutable ld::Fixup _fixup; +@@ -113,8 +113,8 @@ public: + OSWriteLittleInt32(&buffer[20], 0, 0xD61F0200); // BR X16 + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup6)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup6 + 1); } + + private: + static ld::Atom* compressedImageCache(ld::passes::stubs::Pass& pass) { +@@ -164,8 +164,8 @@ public: + OSWriteLittleInt32(&buffer[8], 0, 0x00000000); // L0: .long 0 + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup3)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup3 + 1); } + + private: + static ld::Atom* helperHelper(ld::passes::stubs::Pass& pass, StubHelperAtom& stub, bool stubToResolver) { +@@ -232,8 +232,8 @@ public: + OSWriteLittleInt32(&buffer[96], 0, 0xd61f0200); // br x16 + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup3)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup3 + 1); } + + private: + +@@ -277,8 +277,8 @@ public: + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup2)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup2 + 1); } + + private: + static ld::Section& selectSection(bool stubToGlobalWeakDef, bool stubToResolver, bool dataConstUsed) { +@@ -330,8 +330,8 @@ public: + OSWriteLittleInt32(&buffer[8], 0, 0xD61F0200); // BR X16 + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup3)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup3 + 1); } + + private: + const ld::Atom& _stubTo; +@@ -366,8 +366,8 @@ public: + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup1)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup1 + 1); } + + private: + const ld::Atom& _stubTo; +@@ -404,8 +404,8 @@ public: + OSWriteLittleInt32(&buffer[8], 0, 0xD61F0200); // BR X16 + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup2)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup2 + 1); } + + private: + const ld::Atom& _stubTo; +diff --git a/src/ld/passes/stubs/stub_arm64_32.hpp b/src/ld/passes/stubs/stub_arm64_32.hpp +index 958718c..041ea72 100644 +--- a/src/ld/passes/stubs/stub_arm64_32.hpp ++++ b/src/ld/passes/stubs/stub_arm64_32.hpp +@@ -48,8 +48,8 @@ public: + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup + 1); } + + private: + mutable ld::Fixup _fixup; +@@ -117,8 +117,8 @@ public: + OSWriteLittleInt32(&buffer[20], 0, 0xD61F0200); // BR X16 + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup6)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup6 + 1); } + + private: + static ld::Atom* compressedImageCache(ld::passes::stubs::Pass& pass) { +@@ -168,8 +168,8 @@ public: + OSWriteLittleInt32(&buffer[8], 0, 0x00000000); // L0: .long 0 + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup3)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup3 + 1); } + + private: + static ld::Atom* helperHelper(ld::passes::stubs::Pass& pass, StubHelperAtom& stub, bool stubToResolver) { +@@ -236,8 +236,8 @@ public: + OSWriteLittleInt32(&buffer[96], 0, 0xd61f0200); // br x16 + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup3)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup3 + 1); } + + private: + +@@ -280,8 +280,8 @@ public: + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup2)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup2 + 1); } + + private: + const ld::Atom& _stubTo; +@@ -320,8 +320,8 @@ public: + OSWriteLittleInt32(&buffer[8], 0, 0xD61F0200); // BR X16 + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup3)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup3 + 1); } + + private: + const ld::Atom& _stubTo; +@@ -356,8 +356,8 @@ public: + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup1)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup1 + 1); } + + private: + const ld::Atom& _stubTo; +@@ -394,8 +394,8 @@ public: + OSWriteLittleInt32(&buffer[8], 0, 0xD61F0200); // BR X16 + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup2)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup2 + 1); } + + private: + const ld::Atom& _stubTo; +diff --git a/src/ld/passes/stubs/stub_arm64e.hpp b/src/ld/passes/stubs/stub_arm64e.hpp +index d7ac04d..e9fb816 100644 +--- a/src/ld/passes/stubs/stub_arm64e.hpp ++++ b/src/ld/passes/stubs/stub_arm64e.hpp +@@ -76,8 +76,8 @@ public: + } + + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup3)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup3 + 1); } + + private: + +@@ -118,8 +118,8 @@ public: + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup2)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup2 + 1); } + + private: + static ld::Section& selectSection(bool stubToGlobalWeakDef, bool stubToResolver, bool dataConstUsed) { +@@ -170,8 +170,8 @@ public: + OSWriteLittleInt32(&buffer[8], 0, 0xD61F0A1F); // BRAAZ X16 + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup3)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup3 + 1); } + + private: + const ld::Atom& _stubTo; +@@ -207,8 +207,8 @@ public: + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup2)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup2 + 1); } + + private: + const ld::Atom& _stubTo; +@@ -247,8 +247,8 @@ public: + OSWriteLittleInt32(&buffer[12], 0, 0xD71F0A11); // BRAA X16, X17 + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup2)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup2 + 1); } + + private: + const ld::Atom& _stubTo; +diff --git a/src/ld/passes/stubs/stub_arm_classic.hpp b/src/ld/passes/stubs/stub_arm_classic.hpp +index c7967d7..203e702 100644 +--- a/src/ld/passes/stubs/stub_arm_classic.hpp ++++ b/src/ld/passes/stubs/stub_arm_classic.hpp +@@ -46,8 +46,8 @@ public: + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup2)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup2 + 1); } + + private: + const ld::Atom& _stubTo; +@@ -88,8 +88,8 @@ public: + OSWriteLittleInt32(&buffer[12], 0, 0x00000000); // .long L_foo$lazy_ptr - (L1$scv + 8) + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup4)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup4 + 1); } + + private: + const ld::Atom& _stubTo; +@@ -128,8 +128,8 @@ public: + OSWriteLittleInt32(&buffer[ 8], 0, 0x00000000); // .long L_foo$lazy_ptr + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup + 1); } + + private: + const ld::Atom& _stubTo; +diff --git a/src/ld/passes/stubs/stub_x86.hpp b/src/ld/passes/stubs/stub_x86.hpp +index 80570e5..65fcc83 100644 +--- a/src/ld/passes/stubs/stub_x86.hpp ++++ b/src/ld/passes/stubs/stub_x86.hpp +@@ -44,8 +44,8 @@ public: + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup + 1); } + + private: + mutable ld::Fixup _fixup; +@@ -115,8 +115,8 @@ public: + buffer[11] = 0x90; // nop + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup2)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup2 + 1); } + + private: + static ld::Atom* compressedImageCache(ld::passes::stubs::Pass& pass) { +@@ -169,8 +169,8 @@ public: + buffer[9] = 0x00; + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup3)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup3 + 1); } + + private: + static ld::Atom* helperHelper(ld::passes::stubs::Pass& pass, StubHelperAtom& stub, bool stubToResolver) { +@@ -234,8 +234,8 @@ public: + buffer[21] = 0x00; + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup3)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup3 + 1); } + + private: + +@@ -277,8 +277,8 @@ public: + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup2)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup2 + 1); } + + private: + const ld::Atom& _stubTo; +@@ -317,8 +317,8 @@ public: + buffer[5] = 0x00; + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup + 1); } + + private: + const ld::Atom& _stubTo; +@@ -353,8 +353,8 @@ public: + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup1)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup1 + 1); } + + private: + const ld::Atom& _target; +@@ -402,8 +402,8 @@ public: + buffer[13] = 0x20; + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup4)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup4 + 1); } + + private: + const ld::Atom& _target; +diff --git a/src/ld/passes/stubs/stub_x86_64.hpp b/src/ld/passes/stubs/stub_x86_64.hpp +index d6489e5..d903853 100644 +--- a/src/ld/passes/stubs/stub_x86_64.hpp ++++ b/src/ld/passes/stubs/stub_x86_64.hpp +@@ -44,8 +44,8 @@ public: + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup + 1); } + + private: + mutable ld::Fixup _fixup; +@@ -124,8 +124,8 @@ public: + buffer[15] = 0x90; // nop + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup2)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup2 + 1); } + + private: + static ld::Atom* compressedImageCache(ld::passes::stubs::Pass& pass) { +@@ -178,8 +178,8 @@ public: + buffer[9] = 0x00; + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup3)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup3 + 1); } + + private: + static ld::Atom* helperHelper(ld::passes::stubs::Pass& pass, StubHelperAtom& stub, bool stubToResolver) { +@@ -257,8 +257,8 @@ public: + buffer[35] = 0x00; + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup3)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup3 + 1); } + + private: + +@@ -302,8 +302,8 @@ public: + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup2)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup2 + 1); } + + private: + static ld::Section& selectSection(bool stubToGlobalWeakDef, bool stubToResolver, bool dataConstUsed) { +@@ -355,8 +355,8 @@ public: + buffer[5] = 0x00; + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup + 1); } + + private: + const ld::Atom& _stubTo; +@@ -390,8 +390,8 @@ public: + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return (ld::Fixup*)&_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup1)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup1 + 1); } + + private: + const ld::Atom& _stubTo; +@@ -428,8 +428,8 @@ public: + buffer[5] = 0x00; + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup + 1); } + + private: + const ld::Atom& _stubTo; +diff --git a/src/ld/passes/stubs/stub_x86_64_classic.hpp b/src/ld/passes/stubs/stub_x86_64_classic.hpp +index 057ce61..27dcfe9 100644 +--- a/src/ld/passes/stubs/stub_x86_64_classic.hpp ++++ b/src/ld/passes/stubs/stub_x86_64_classic.hpp +@@ -62,8 +62,8 @@ public: + buffer[11] = 0x00; + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup2)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup2 + 1); } + + private: + const ld::Atom& _stubTo; +@@ -98,8 +98,8 @@ public: + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup2)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup2 + 1); } + + private: + const ld::Atom& _stubTo; +@@ -140,8 +140,8 @@ public: + buffer[5] = 0x00; + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup + 1); } + + private: + const ld::Atom& _stubTo; +diff --git a/src/ld/passes/stubs/stub_x86_classic.hpp b/src/ld/passes/stubs/stub_x86_classic.hpp +index 481055d..bccc3cc 100644 +--- a/src/ld/passes/stubs/stub_x86_classic.hpp ++++ b/src/ld/passes/stubs/stub_x86_classic.hpp +@@ -60,8 +60,8 @@ public: + buffer[9] = 0x00; + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup2)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup2 + 1); } + + private: + const ld::Atom& _stubTo; +@@ -96,8 +96,8 @@ public: + virtual uint64_t objectAddress() const { return 0; } + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup1; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup2)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup1); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup2 + 1); } + + private: + const ld::Atom& _stubTo; +@@ -138,8 +138,8 @@ public: + buffer[5] = 0x00; + } + virtual void setScope(Scope) { } +- virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } ++ virtual ld::Fixup::iterator fixupsBegin() const { return const_cast(&_fixup); } ++ virtual ld::Fixup::iterator fixupsEnd() const { return const_cast(&_fixup + 1); } + + private: + const ld::Atom& _stubTo; +diff --git a/src/ld/passes/tlvp.cpp b/src/ld/passes/tlvp.cpp +index 2a163fd..6fa451f 100644 +--- a/src/ld/passes/tlvp.cpp ++++ b/src/ld/passes/tlvp.cpp +@@ -59,7 +59,7 @@ public: + virtual void copyRawContent(uint8_t buffer[]) const { } + virtual void setScope(Scope) { } + virtual ld::Fixup::iterator fixupsBegin() const { return &_fixup; } +- virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; } ++ virtual ld::Fixup::iterator fixupsEnd() const { return &_fixup + 1; } + + private: + mutable ld::Fixup _fixup; +diff --git a/src/mach_o/ExportsTrie.cpp b/src/mach_o/ExportsTrie.cpp +index 2dd4ed2..0364c2f 100644 +--- a/src/mach_o/ExportsTrie.cpp ++++ b/src/mach_o/ExportsTrie.cpp +@@ -98,8 +98,8 @@ void GenericTrie::buildTrieBytes(size_t entriesCount, const std::vector + } + + // set up trie buffer +- _trieStart = &_trieBytes[0]; +- _trieEnd = &_trieBytes[_trieBytes.size()]; ++ _trieStart = _trieBytes.data(); ++ _trieEnd = _trieBytes.data() + _trieBytes.size(); + } + + Error GenericTrie::Node::addEntry(const WriterEntry& newEntry, const std::vector& terminalBuffer, std::vector& allNodes) +-- +2.42.0 + diff --git a/pkgs/by-name/ld/ld64/0003-Support-LTO-in-nixpkgs.patch b/pkgs/by-name/ld/ld64/0003-Support-LTO-in-nixpkgs.patch new file mode 100644 index 0000000000000..e299ead5896b0 --- /dev/null +++ b/pkgs/by-name/ld/ld64/0003-Support-LTO-in-nixpkgs.patch @@ -0,0 +1,48 @@ +From 947b52bec23295878d54ceb9968f7fe9bb5dd784 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Sun, 7 Apr 2024 15:33:36 -0400 +Subject: [PATCH 3/6] Support LTO in nixpkgs + +--- + src/ld/InputFiles.cpp | 11 ++--------- + src/ld/parsers/lto_file.cpp | 2 +- + 2 files changed, 3 insertions(+), 10 deletions(-) + +diff --git a/src/ld/InputFiles.cpp b/src/ld/InputFiles.cpp +index 427ab09..b8a9870 100644 +--- a/src/ld/InputFiles.cpp ++++ b/src/ld/InputFiles.cpp +@@ -464,15 +464,8 @@ ld::File* InputFiles::makeFile(const Options::FileInfo& info, bool indirectDylib + if ( _options.overridePathlibLTO() != NULL ) { + libLTO = _options.overridePathlibLTO(); + } +- else if ( _NSGetExecutablePath(ldPath, &bufSize) != -1 ) { +- if ( realpath(ldPath, tmpPath) != NULL ) { +- char* lastSlash = strrchr(tmpPath, '/'); +- if ( lastSlash != NULL ) +- strcpy(lastSlash, "/../lib/libLTO.dylib"); +- libLTO = tmpPath; +- if ( realpath(tmpPath, libLTOPath) != NULL ) +- libLTO = libLTOPath; +- } ++ else { ++ libLTO = "@libllvm@/lib/libLTO.dylib"; + } + throwf("could not process llvm bitcode object file, because %s could not be loaded", libLTO); + } +diff --git a/src/ld/parsers/lto_file.cpp b/src/ld/parsers/lto_file.cpp +index 5318212..e18e974 100644 +--- a/src/ld/parsers/lto_file.cpp ++++ b/src/ld/parsers/lto_file.cpp +@@ -1807,7 +1807,7 @@ bool optimize( const std::vector& allAtoms, + + }; // namespace lto + +-static const char *sLTODylib = "@rpath/libLTO.dylib"; ++static const char *sLTODylib = "@libllvm@/lib/libLTO.dylib"; + static std::atomic sLTOIsLoaded(false); + + static void *getHandle() { +-- +2.42.0 + diff --git a/pkgs/by-name/ld/ld64/0004-Add-libcd_is_blob_a_linker_signature-implementation.patch b/pkgs/by-name/ld/ld64/0004-Add-libcd_is_blob_a_linker_signature-implementation.patch new file mode 100644 index 0000000000000..13c4f31dc9089 --- /dev/null +++ b/pkgs/by-name/ld/ld64/0004-Add-libcd_is_blob_a_linker_signature-implementation.patch @@ -0,0 +1,113 @@ +From b60c84e0645a4ab20a97aa0350964a469c90c884 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Mon, 8 Apr 2024 22:42:40 -0400 +Subject: [PATCH 4/6] Add libcd_is_blob_a_linker_signature implementation + +--- + compat/libcodedirectory.c | 74 +++++++++++++++++++++++++++++++++++++++ + src/ld/libcodedirectory.h | 8 +++++ + 2 files changed, 82 insertions(+) + create mode 100644 compat/libcodedirectory.c + +diff --git a/compat/libcodedirectory.c b/compat/libcodedirectory.c +new file mode 100644 +index 0000000..e584dfc +--- /dev/null ++++ b/compat/libcodedirectory.c +@@ -0,0 +1,74 @@ ++// SPDX-License-Identifier: APSL-2.0 ++// libcd_is_blob_a_linker_signature implementation written by Randy Eckenrode © 2024 ++ ++#include ++ ++#include ++ ++// References: ++// - https://forums.developer.apple.com/forums/thread/702351 ++// - https://redmaple.tech/blogs/macho-files/#codedirectory-blob ++ ++static inline uint32_t read32be(const uint8_t* data) ++{ ++ return (data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]; ++} ++ ++static inline bool is_embedded_signature(uint32_t magic) { ++ switch (magic) { ++ case CSMAGIC_EMBEDDED_SIGNATURE: ++ case CSMAGIC_EMBEDDED_SIGNATURE_OLD: ++ return true; ++ default: ++ return false; ++ } ++} ++ ++static inline const uint8_t* find_code_directory(const uint8_t* data, size_t size) { ++ const uint8_t* index_ptr = data + offsetof(CS_SuperBlob, index); ++ ++ // There also needs to space for the actual blobs, but there must be at least enough space ++ // for the blob indexes. If there’s not, then something’s wrong, and the blob is invalid. ++ uint32_t count = read32be(data + offsetof(CS_SuperBlob, count)); ++ if (count > ((data + size) - index_ptr) / sizeof(CS_BlobIndex)) { ++ return NULL; ++ } ++ ++ for (uint32_t n = 0; n < count; ++n) { ++ const uint8_t* current_index_ptr = index_ptr + n * sizeof(CS_BlobIndex); ++ uint32_t type = read32be(current_index_ptr + offsetof(CS_BlobIndex, type)); ++ if (type == CSSLOT_CODEDIRECTORY) { ++ uint32_t offset = read32be(current_index_ptr + offsetof(CS_BlobIndex, offset)); ++ if (offset > size - sizeof(CS_CodeDirectory)) { ++ return NULL; ++ } else { ++ return data + offset; ++ } ++ } ++ } ++ return NULL; ++} ++ ++enum libcd_signature_query_ret ++libcd_is_blob_a_linker_signature(const uint8_t* data, size_t size, int* linker_signed) ++{ ++ if (size < sizeof(CS_SuperBlob) + sizeof(CS_BlobIndex) + sizeof(CS_CodeDirectory)) { ++ return LIBCD_SIGNATURE_QUERY_INVALID_ARGUMENT; ++ } ++ ++ if (!is_embedded_signature(read32be(data + offsetof(CS_SuperBlob, magic)))) { ++ return LIBCD_SIGNATURE_QUERY_NOT_A_SIGNATURE; ++ } ++ ++ const uint8_t* cd = find_code_directory(data, size); ++ if (!cd) { ++ return LIBCD_SIGNATURE_QUERY_INVALID_ARGUMENT; ++ } ++ ++ uint32_t flags = read32be(cd + offsetof(CS_CodeDirectory, flags)); ++ if ((flags & CS_LINKER_SIGNED) == CS_LINKER_SIGNED) { ++ *linker_signed = 1; ++ } ++ ++ return LIBCD_SIGNATURE_QUERY_SUCCESS; ++} +diff --git a/src/ld/libcodedirectory.h b/src/ld/libcodedirectory.h +index 0e989a9..7532648 100644 +--- a/src/ld/libcodedirectory.h ++++ b/src/ld/libcodedirectory.h +@@ -116,6 +116,14 @@ enum libcd_set_linkage_ret { + + enum libcd_set_linkage_ret libcd_set_linkage(libcd *s, int linkage_hash_type, uint8_t *linkage_hash); + ++enum libcd_signature_query_ret { ++ LIBCD_SIGNATURE_QUERY_SUCCESS, ++ LIBCD_SIGNATURE_QUERY_INVALID_ARGUMENT, ++ LIBCD_SIGNATURE_QUERY_NOT_A_SIGNATURE, ++}; ++ ++enum libcd_signature_query_ret libcd_is_blob_a_linker_signature(const uint8_t* data, size_t size, int* linker_signed); ++ + __END_DECLS + + #endif // H_LIBCODEDIRECTORY +-- +2.42.0 + diff --git a/pkgs/by-name/ld/ld64/0005-Add-OpenSSL-based-CoreCrypto-digest-functions.patch b/pkgs/by-name/ld/ld64/0005-Add-OpenSSL-based-CoreCrypto-digest-functions.patch new file mode 100644 index 0000000000000..c3a3c1ef84495 --- /dev/null +++ b/pkgs/by-name/ld/ld64/0005-Add-OpenSSL-based-CoreCrypto-digest-functions.patch @@ -0,0 +1,311 @@ +From a1bd7937a1a9d56c62bfaae7ae62842cd2c92c5d Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Tue, 9 Apr 2024 19:28:17 -0400 +Subject: [PATCH 5/6] Add OpenSSL-based CoreCrypto digest functions + +--- + compat/CommonCrypto/CommonDigest.h | 6 +++ + compat/CommonCrypto/CommonDigestSPI.c | 21 +++++++++++ + compat/CommonCrypto/CommonDigestSPI.h | 14 +++++++ + compat/corecrypto/api_defines.h | 10 +++++ + compat/corecrypto/ccdigest.c | 53 +++++++++++++++++++++++++++ + compat/corecrypto/ccdigest.h | 27 ++++++++++++++ + compat/corecrypto/ccdigest_private.h | 19 ++++++++++ + compat/corecrypto/ccsha1.c | 22 +++++++++++ + compat/corecrypto/ccsha1.h | 9 +++++ + compat/corecrypto/ccsha2.c | 22 +++++++++++ + compat/corecrypto/ccsha2.h | 9 +++++ + 11 files changed, 212 insertions(+) + create mode 100644 compat/CommonCrypto/CommonDigest.h + create mode 100644 compat/CommonCrypto/CommonDigestSPI.c + create mode 100644 compat/CommonCrypto/CommonDigestSPI.h + create mode 100644 compat/corecrypto/api_defines.h + create mode 100644 compat/corecrypto/ccdigest.c + create mode 100644 compat/corecrypto/ccdigest.h + create mode 100644 compat/corecrypto/ccdigest_private.h + create mode 100644 compat/corecrypto/ccsha1.c + create mode 100644 compat/corecrypto/ccsha1.h + create mode 100644 compat/corecrypto/ccsha2.c + create mode 100644 compat/corecrypto/ccsha2.h + +diff --git a/compat/CommonCrypto/CommonDigest.h b/compat/CommonCrypto/CommonDigest.h +new file mode 100644 +index 0000000..a60eba7 +--- /dev/null ++++ b/compat/CommonCrypto/CommonDigest.h +@@ -0,0 +1,6 @@ ++// SPDX-License-Identifier: APSL-2.0 ++// CoreCrypto compatibility shims written by Randy Eckenrode © 2024 ++ ++#pragma once ++ ++#define CCSHA256_OUTPUT_SIZE 32 +diff --git a/compat/CommonCrypto/CommonDigestSPI.c b/compat/CommonCrypto/CommonDigestSPI.c +new file mode 100644 +index 0000000..41269fc +--- /dev/null ++++ b/compat/CommonCrypto/CommonDigestSPI.c +@@ -0,0 +1,21 @@ ++// SPDX-License-Identifier: APSL-2.0 ++// CoreCrypto compatibility shims written by Randy Eckenrode © 2024 ++ ++#include "CommonDigestSPI.h" ++ ++#include ++#include ++ ++#include ++ ++void CCDigest(int type, const uint8_t* bytes, size_t count, uint8_t* digest) { ++ if (type != kCCDigestSHA256) { ++ abort(); ++ } ++ const struct ccdigest_info* di = ccsha256_di(); ++ ++ ccdigest_di_decl(_di, ctx); ++ ccdigest_init(di, ctx); ++ ccdigest_update(di, ctx, count, bytes); ++ ccdigest_final(di, ctx, digest); ++} +diff --git a/compat/CommonCrypto/CommonDigestSPI.h b/compat/CommonCrypto/CommonDigestSPI.h +new file mode 100644 +index 0000000..172742a +--- /dev/null ++++ b/compat/CommonCrypto/CommonDigestSPI.h +@@ -0,0 +1,14 @@ ++// SPDX-License-Identifier: APSL-2.0 ++// CoreCrypto compatibility shims written by Randy Eckenrode © 2024 ++ ++#pragma once ++ ++#include ++ ++#include ++#include ++ ++ ++#define kCCDigestSHA256 10 ++ ++EXTERN_C void CCDigest(int type, const uint8_t* bytes, size_t count, uint8_t* digest); +diff --git a/compat/corecrypto/api_defines.h b/compat/corecrypto/api_defines.h +new file mode 100644 +index 0000000..13d1e7a +--- /dev/null ++++ b/compat/corecrypto/api_defines.h +@@ -0,0 +1,10 @@ ++// SPDX-License-Identifier: APSL-2.0 ++// CoreCrypto compatibility shims written by Randy Eckenrode © 2024 ++ ++#pragma once ++ ++#ifdef __cplusplus ++#define EXTERN_C extern "C" ++#else ++#define EXTERN_C ++#endif +diff --git a/compat/corecrypto/ccdigest.c b/compat/corecrypto/ccdigest.c +new file mode 100644 +index 0000000..e29dcb8 +--- /dev/null ++++ b/compat/corecrypto/ccdigest.c +@@ -0,0 +1,53 @@ ++// SPDX-License-Identifier: APSL-2.0 ++// CoreCrypto compatibility shims written by Randy Eckenrode © 2024 ++ ++#include "ccdigest.h" ++#include "ccdigest_private.h" ++ ++#include ++ ++#include ++ ++ ++struct ccdigest_context* _ccdigest_context_new(void) ++{ ++ struct ccdigest_context* ctx = malloc(sizeof(struct ccdigest_context)); ++ ctx->context = EVP_MD_CTX_new(); ++ return ctx; ++} ++ ++struct ccdigest_info* _ccdigest_newprovider(const char* name) ++{ ++ struct ccdigest_info* di = malloc(sizeof(struct ccdigest_info)); ++ di->provider = EVP_MD_fetch(NULL, name, NULL); ++ return di; ++} ++ ++void ccdigest_init(const struct ccdigest_info* di, struct ccdigest_context* ctx) ++{ ++ if (!EVP_DigestInit_ex2(ctx->context, di->provider, NULL)) { ++ ERR_print_errors_fp(stderr); ++ abort(); ++ } ++} ++ ++void ccdigest_update( ++ const struct ccdigest_info* _di, ++ struct ccdigest_context* ctx, ++ size_t count, ++ const void* bytes ++) ++{ ++ if (!EVP_DigestUpdate(ctx->context, bytes, count)) { ++ ERR_print_errors_fp(stderr); ++ abort(); ++ } ++} ++ ++void ccdigest_final(const struct ccdigest_info* _di, struct ccdigest_context* ctx, uint8_t* digest) ++{ ++ if (!EVP_DigestFinal_ex(ctx->context, digest, NULL)) { ++ ERR_print_errors_fp(stderr); ++ abort(); ++ } ++} +diff --git a/compat/corecrypto/ccdigest.h b/compat/corecrypto/ccdigest.h +new file mode 100644 +index 0000000..9af2394 +--- /dev/null ++++ b/compat/corecrypto/ccdigest.h +@@ -0,0 +1,27 @@ ++// SPDX-License-Identifier: APSL-2.0 ++// CoreCrypto compatibility shims written by Randy Eckenrode © 2024 ++ ++#pragma once ++ ++#include ++#include ++ ++#include "api_defines.h" ++ ++ ++struct ccdigest_info; ++struct ccdigest_context; ++ ++EXTERN_C struct ccdigest_context* _ccdigest_context_new(void); ++ ++#define ccdigest_di_decl(_di, ctxvar) \ ++ struct ccdigest_context* (ctxvar) = _ccdigest_context_new() ++ ++EXTERN_C void ccdigest_init(const struct ccdigest_info* di, struct ccdigest_context* ctx); ++EXTERN_C void ccdigest_update( ++ const struct ccdigest_info* _di, ++ struct ccdigest_context* ctx, ++ size_t count, ++ const void* bytes ++); ++EXTERN_C void ccdigest_final(const struct ccdigest_info* _di, struct ccdigest_context* ctx, uint8_t* digest); +diff --git a/compat/corecrypto/ccdigest_private.h b/compat/corecrypto/ccdigest_private.h +new file mode 100644 +index 0000000..0ea9759 +--- /dev/null ++++ b/compat/corecrypto/ccdigest_private.h +@@ -0,0 +1,19 @@ ++// SPDX-License-Identifier: APSL-2.0 ++// CoreCrypto compatibility shims written by Randy Eckenrode © 2024 ++ ++#pragma once ++ ++#include "api_defines.h" ++ ++#include ++ ++ ++struct ccdigest_info { ++ EVP_MD* provider; ++}; ++ ++struct ccdigest_context { ++ EVP_MD_CTX* context; ++}; ++ ++EXTERN_C struct ccdigest_info* _ccdigest_newprovider(const char* name); +diff --git a/compat/corecrypto/ccsha1.c b/compat/corecrypto/ccsha1.c +new file mode 100644 +index 0000000..e02b2b6 +--- /dev/null ++++ b/compat/corecrypto/ccsha1.c +@@ -0,0 +1,22 @@ ++// SPDX-License-Identifier: APSL-2.0 ++// CoreCrypto compatibility shims written by Randy Eckenrode © 2024 ++ ++#include "ccsha1.h" ++ ++#include ++ ++#include ++ ++#include "ccdigest_private.h" ++ ++ ++static struct ccdigest_info* di = NULL; ++ ++const struct ccdigest_info* ccsha1_di(void) ++{ ++ if (!di) { ++ di = _ccdigest_newprovider("SHA-1"); ++ assert(EVP_MD_get_size(di->provider) == CS_SHA1_LEN); ++ } ++ return di; ++} +diff --git a/compat/corecrypto/ccsha1.h b/compat/corecrypto/ccsha1.h +new file mode 100644 +index 0000000..8e3f85f +--- /dev/null ++++ b/compat/corecrypto/ccsha1.h +@@ -0,0 +1,9 @@ ++// SPDX-License-Identifier: APSL-2.0 ++// CoreCrypto compatibility shims written by Randy Eckenrode © 2024 ++ ++#pragma once ++ ++#include ++ ++ ++EXTERN_C const struct ccdigest_info* ccsha1_di(void); +diff --git a/compat/corecrypto/ccsha2.c b/compat/corecrypto/ccsha2.c +new file mode 100644 +index 0000000..6504503 +--- /dev/null ++++ b/compat/corecrypto/ccsha2.c +@@ -0,0 +1,22 @@ ++// SPDX-License-Identifier: APSL-2.0 ++// CoreCrypto compatibility shims written by Randy Eckenrode © 2024 ++ ++#include "ccsha2.h" ++ ++#include ++ ++#include ++ ++#include "ccdigest_private.h" ++ ++ ++static struct ccdigest_info* di = NULL; ++ ++const struct ccdigest_info* ccsha256_di(void) ++{ ++ if (!di) { ++ di = _ccdigest_newprovider("SHA-256"); ++ assert(EVP_MD_get_size(di->provider) == CS_SHA256_LEN); ++ } ++ return di; ++} +diff --git a/compat/corecrypto/ccsha2.h b/compat/corecrypto/ccsha2.h +new file mode 100644 +index 0000000..9f30e03 +--- /dev/null ++++ b/compat/corecrypto/ccsha2.h +@@ -0,0 +1,9 @@ ++// SPDX-License-Identifier: APSL-2.0 ++// CoreCrypto compatibility shims written by Randy Eckenrode © 2024 ++ ++#pragma once ++ ++#include ++ ++ ++EXTERN_C const struct ccdigest_info* ccsha256_di(void); +-- +2.42.0 + diff --git a/pkgs/by-name/ld/ld64/0006-Disable-searching-in-standard-library-locations.patch b/pkgs/by-name/ld/ld64/0006-Disable-searching-in-standard-library-locations.patch new file mode 100644 index 0000000000000..3199a87995eeb --- /dev/null +++ b/pkgs/by-name/ld/ld64/0006-Disable-searching-in-standard-library-locations.patch @@ -0,0 +1,25 @@ +From 2a306d89c06bcbbf009464448cea427795921e10 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Thu, 11 Apr 2024 23:13:29 -0400 +Subject: [PATCH 6/6] Disable searching in standard library locations + +--- + src/ld/Options.cpp | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/ld/Options.cpp b/src/ld/Options.cpp +index 67a9f53..611b583 100644 +--- a/src/ld/Options.cpp ++++ b/src/ld/Options.cpp +@@ -4320,7 +4320,7 @@ bool Options::shouldUseBuildVersion(ld::Platform plat, uint32_t minOSvers) const + + void Options::buildSearchPaths(int argc, const char* argv[]) + { +- bool addStandardLibraryDirectories = true; ++ bool addStandardLibraryDirectories = false; + ld::Platform platform = ld::Platform::unknown; + std::vector libraryPaths; + std::vector frameworkPaths; +-- +2.42.0 + diff --git a/pkgs/by-name/ld/ld64/gen_compile_stubs.py b/pkgs/by-name/ld/ld64/gen_compile_stubs.py new file mode 100644 index 0000000000000..30fe30789a107 --- /dev/null +++ b/pkgs/by-name/ld/ld64/gen_compile_stubs.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python +import sys +from pathlib import Path + +byteseq = (str(int(x)) for x in Path(sys.argv[1]).read_bytes()) + +print("#pragma once") +print(f"static const char compile_stubs[] = {{ {', '.join(byteseq)} }};") diff --git a/pkgs/by-name/ld/ld64/meson.build b/pkgs/by-name/ld/ld64/meson.build new file mode 100644 index 0000000000000..3000b50fb861b --- /dev/null +++ b/pkgs/by-name/ld/ld64/meson.build @@ -0,0 +1,248 @@ +# Build settings based on the upstream Xcode project. +# See: https://github.com/apple-oss-distributions/ld64/blob/main/ld64.xcodeproj/project.pbxproj + +# Project settings +project( + 'ld64', + 'c', 'cpp', + version : '@version@', + default_options : {'cpp_std': 'c++20'} +) + +fs = import('fs') + +# Dependencies +cc = meson.get_compiler('c') +cxx = meson.get_compiler('cpp') +python = find_program('python3') + +libtapi = cxx.find_library('tapi') +openssl = dependency('openssl', version : '>=3.0') +xar = cc.find_library('xar') + + +# Feature tests + +# macOS 10.12 does not support `DISPATCH_APPLY_AUTO`. Fortunately, `DISPATCH_APPLY_CURRENT_ROOT_QUEUE` has the +# same value and was repurposed in subsequent releases as `DISPATCH_APPLY_AUTO`. +dispatch_apply_auto_test = ''' +#include +int main(int argc, char* argv[]) { + dispatch_queue_t queue = DISPATCH_APPLY_AUTO; + return 0; +} +''' +if not cc.compiles( + dispatch_apply_auto_test, + args : '-Wno-unused-command-line-argument', + name : 'supports DISPATCH_APPLY_AUTO' +) + add_project_arguments( + '-include', 'dispatch/private.h', + '-DDISPATCH_APPLY_AUTO=DISPATCH_APPLY_CURRENT_ROOT_QUEUE', + language: ['c', 'cpp'] + ) +endif + +# The return type of `dispatch_get_global_queue` was changed in 10.14. +# Use the older type if the SDK does not support it. +dispatch_queue_global_test = ''' +#include +int main(int argc, char* argv[]) { + dispatch_queue_global_t queue = dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0); + return 0; +} +''' +if not cc.compiles( + dispatch_queue_global_test, + args : '-Wno-unused-command-line-argument', + name : 'supports dispatch_queue_global_t' +) + add_project_arguments('-Ddispatch_queue_global_t=dispatch_queue_t', language : ['c', 'cpp']) +endif + + +# Generated files + +compile_stubs_h = custom_target( + 'compile_stubs.h', + capture : true, + command : [python, '@INPUT0@', '@INPUT1@'], + input : ['gen_compile_stubs.py', 'compile_stubs'], + output : ['compile_stubs.h'] +) + +configure_h = custom_target( + 'configure_h', + command : ['bash', '@INPUT@'], + env : { + 'DERIVED_FILE_DIR' : meson.current_build_dir(), + 'RC_ProjectSourceVersion': '@version@' + }, + input : ['src/create_configure'], + output : ['configure.h'] +) + +incdirs = include_directories( + 'compat', + 'include', + 'src/abstraction', + 'src/ld', + 'src/ld/code-sign-blobs', + 'src/ld/parsers', + 'src/ld/passes', + 'src/mach_o', +) + +# Dynamic libraries +libcodedirectory = library( + 'codedirectory', + dependencies : [openssl], + include_directories : incdirs, + install : true, + sources : [ + 'compat/corecrypto/ccdigest.c', + 'compat/corecrypto/ccsha1.c', + 'compat/corecrypto/ccsha2.c', + 'compat/libcodedirectory.c', + 'src/ld/libcodedirectory.c' + ], + soversion : 1, +) +install_headers( + 'src/ld/cs_blobs.h', + 'src/ld/libcodedirectory.h', +) + + +# Static libraries +libprunetrie = static_library( + 'prunetrie', + include_directories : incdirs, + install : true, + override_options : {'b_lto': false}, + sources : [ + 'src/mach_o/Error.cpp', + 'src/mach_o/ExportsTrie.cpp', + 'src/other/PruneTrie.cpp' + ] +) +install_headers( + 'src/other/prune_trie.h', + subdir : 'mach-o' +) + + +# Binaries +ld64 = executable( + '@targetPrefix@ld', + c_args : ['-DPRIVATE'], + cpp_args : ['-DPRIVATE'], + dependencies : [libtapi, openssl, xar], + include_directories : incdirs, + install : true, + link_args : [ + '-Wl,-exported_symbol,__mh_execute_header', + '-Wl,-stack_size,0x10000000', + '-Wl,-client_name,ld' + ], + link_with : [libcodedirectory], + sources : [ + compile_stubs_h, + configure_h, + 'compat/CommonCrypto/CommonDigestSPI.c', + 'compat/corecrypto/ccdigest.c', + 'compat/corecrypto/ccsha1.c', + 'compat/corecrypto/ccsha2.c', + 'src/ld/FatFile.cpp', + 'src/ld/InputFiles.cpp', + 'src/ld/Mangling.cpp', + 'src/ld/Options.cpp', + 'src/ld/OutputFile.cpp', + 'src/ld/PlatformSupport.cpp', + 'src/ld/Resolver.cpp', + 'src/ld/ResponseFiles.cpp', + 'src/ld/Snapshot.cpp', + 'src/ld/SymbolTable.cpp', + 'src/ld/code-sign-blobs/blob.cpp', + 'src/ld/code-sign-blobs/blob.h', + 'src/ld/debugline.c', + 'src/ld/ld.cpp', + 'src/ld/parsers/archive_file.cpp', + 'src/ld/parsers/generic_dylib_file.cpp', + 'src/ld/parsers/lto_file.cpp', + 'src/ld/parsers/macho_dylib_file.cpp', + 'src/ld/parsers/macho_relocatable_file.cpp', + 'src/ld/parsers/opaque_section_file.cpp', + 'src/ld/parsers/textstub_dylib_file.cpp', + 'src/ld/passes/bitcode_bundle.cpp', + 'src/ld/passes/branch_island.cpp', + 'src/ld/passes/branch_shim.cpp', + 'src/ld/passes/code_dedup.cpp', + 'src/ld/passes/compact_unwind.cpp', + 'src/ld/passes/dtrace_dof.cpp', + 'src/ld/passes/dylibs.cpp', + 'src/ld/passes/got.cpp', + 'src/ld/passes/huge.cpp', + 'src/ld/passes/inits.cpp', + 'src/ld/passes/objc.cpp', + 'src/ld/passes/objc_constants.cpp', + 'src/ld/passes/objc_stubs.cpp', + 'src/ld/passes/order.cpp', + 'src/ld/passes/stubs/stubs.cpp', + 'src/ld/passes/thread_starts.cpp', + 'src/ld/passes/tlvp.cpp', + 'src/mach_o/Error.cpp', + 'src/mach_o/ExportsTrie.cpp', + ] +) +install_man( + 'doc/man/man1/ld-classic.1' +) + +# Extra tools +dwarfdump = executable( + '@targetPrefix@unwinddump', + include_directories : incdirs, + install : true, + sources : [ + configure_h, + 'src/other/UnwindDump.cpp' + ] +) +install_man( + 'doc/man/man1/unwinddump.1' +) + +machocheck = executable( + '@targetPrefix@machocheck', + include_directories : incdirs, + install : true, + sources : [ + configure_h, + 'src/other/machochecker.cpp' + ] +) + +objectdump = executable( + '@targetPrefix@ObjectDump', + include_directories : incdirs, + install : true, + sources : [ + configure_h, + 'src/ld/PlatformSupport.cpp', + 'src/ld/debugline.c', + 'src/ld/parsers/macho_relocatable_file.cpp', + 'src/other/ObjectDump.cpp' + ] +) + +objcimageinfo = executable( + '@targetPrefix@objcimageinfo', + include_directories : incdirs, + install : true, + sources : [ + configure_h, + 'src/other/objcimageinfo.cpp' + ] +) diff --git a/pkgs/by-name/ld/ld64/package.nix b/pkgs/by-name/ld/ld64/package.nix new file mode 100644 index 0000000000000..f75a9ddd6dd9a --- /dev/null +++ b/pkgs/by-name/ld/ld64/package.nix @@ -0,0 +1,184 @@ +{ + lib, + stdenv, + fetchFromGitHub, + fetchurl, + darwin, + libtapi, + libunwind, + llvm, + llvmPackages, + meson, + ninja, + openssl, + pkg-config, + python3, + swiftPackages, + xar, + gitUpdater, +}: + +let + # The targetPrefix is prepended to binary names to allow multiple binuntils on the PATH to both be usable. + targetPrefix = lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform) "${stdenv.targetPlatform.config}-"; + + # ld64 needs CrashReporterClient.h, which is hard to find, but WebKit2 has it. + # Fetch it directly because the Darwin stdenv bootstrap can’t depend on fetchgit. + crashreporter_h = fetchurl { + url = "https://raw.githubusercontent.com/apple-oss-distributions/WebKit2/WebKit2-7605.1.33.0.2/Platform/spi/Cocoa/CrashReporterClientSPI.h"; + hash = "sha256-0ybVcwHuGEdThv0PPjYQc3SW0YVOyrM3/L9zG/l1Vtk="; + }; + # First version with all the required definitions + xnu = fetchFromGitHub { + name = "xnu-src"; + owner = "apple-oss-distributions"; + repo = "xnu"; + rev = "xnu-6153.11.26"; + hash = "sha256-dcnGcp7bIjQxeAn5pXt+mHSYEXb2Ad9Smhd/WUG4kb4="; + }; + # Avoid pulling in all of Swift just to build libdispatch + libdispatch = swiftPackages.Dispatch.override { useSwift = false; }; +in +stdenv.mkDerivation (finalAttrs: { + pname = "ld64"; + version = "951.9"; + + outputs = [ + "out" + "dev" + "lib" + ]; + + src = fetchFromGitHub { + owner = "apple-oss-distributions"; + repo = "ld64"; + rev = "ld64-${finalAttrs.version}"; + hash = "sha256-hLkfqgBwVPlO4gfriYOawTO5E1zSD63ZcNetm1E5I70"; + }; + + sourceRoot = "source"; + + postUnpack = '' + unpackFile '${xnu}' + ''; + + patches = [ + # Use std::atomic for atomics. + ./0001-Use-std-atomics-and-std-mutex.patch + # `&vec[0]` is UB if the vector is empty. vec.data() is a safe replacement as long as + # the pointer is not dereferenced. + ./0002-Avoid-UB-when-std-vector-is-empty.patch + # ld64 assumes the default libLTO.dylib can be found relative to its bindir, which is + # not the case in nixpkgs. Override it to default to `stdenv.cc`’s libLTO.dylib. + ./0003-Support-LTO-in-nixpkgs.patch + # Add implementation of missing function required for code directory support. + ./0004-Add-libcd_is_blob_a_linker_signature-implementation.patch + # Add OpenSSL implementation of CoreCrypto digest functions + ./0005-Add-OpenSSL-based-CoreCrypto-digest-functions.patch + # ld64 will search `/usr/lib`, `/Library/Frameworks`, etc by default. Disable that. + ./0006-Disable-searching-in-standard-library-locations.patch + ]; + + postPatch = '' + substitute ${./meson.build} meson.build \ + --subst-var-by targetPrefix '${targetPrefix}' \ + --subst-var version + + # Copy headers for certain private APIs + mkdir -p include + substitute ${crashreporter_h} include/CrashReporterClient.h \ + --replace-fail 'USE(APPLE_INTERNAL_SDK)' '0' + + # Copy from the source so the headers can be used on Linux and x86_64-darwin + mkdir -p include/System + for dir in arm i386 machine; do + cp -r ../xnu-src/osfmk/$dir include/System/$dir + done + mkdir -p include/sys + cp ../xnu-src/bsd/sys/commpage.h include/sys + + # Match the version format used by upstream. + sed -i src/ld/Options.cpp \ + -e '1iconst char ld_classicVersionString[] = "@(#)PROGRAM:ld PROJECT:ld64-${finalAttrs.version}\\n";' + + # Instead of messing around with trying to extract and run the script from the Xcode project, + # just use our own Python script to generate `compile_stubs.h` + cp ${./gen_compile_stubs.py} gen_compile_stubs.py + + # Enable LTO support using LLVM’s libLTO.dylib by default. + substituteInPlace src/ld/InputFiles.cpp \ + --subst-var-by libllvm '${lib.getLib llvm}' + substituteInPlace src/ld/parsers/lto_file.cpp \ + --subst-var-by libllvm '${lib.getLib llvm}' + + # Use portable includes + substituteInPlace src/ld/code-sign-blobs/endian.h \ + --replace-fail '#include ' '#include ' + ''; + + strictDeps = true; + + nativeBuildInputs = [ + meson + ninja + pkg-config + python3 + ]; + + buildInputs = [ + libtapi + llvm + libunwind + openssl + xar + ] ++ lib.optionals stdenv.isDarwin [ darwin.dyld ] ++ lib.optionals stdenv.isLinux [ libdispatch ]; + + mesonBuildType = "release"; + + mesonFlags = [ + (lib.mesonOption "b_ndebug" "if-release") + (lib.mesonOption "default_library" (if stdenv.hostPlatform.isStatic then "static" else "shared")) + ] ++ lib.optionals finalAttrs.doCheck [ + (lib.mesonBool "b_lto" true) + ]; + + # ld64 has a test suite, but many of the tests fail (even with ld from Xcode). Instead + # of running the test suite, rebuild ld64 using itself to link itself as a check. + preConfigure = lib.optionalString finalAttrs.doCheck '' + pushd . > /dev/null + + meson setup build-bootstrap -Db_lto=false --buildtype=''${mesonBuildType:-plain} + + cd build-bootstrap + ninja ${targetPrefix}ld "-j$NIX_BUILD_CORES" + + # use `$NIX_CFLAGS_COMPILE` to make sure Meson picks up the new linker. + export NIX_CFLAGS_COMPILE+=" --ld-path=$PWD/${targetPrefix}ld" + + popd > /dev/null + ''; + + doCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform; + dontMesonCheck = true; + + postInstall = '' + ln -s '${targetPrefix}unwinddump' "$out/bin/${targetPrefix}dwarfdump" + ln -s unwinddump.1 "$out/share/man/man1/dwarfdump.1" + ln -s ld-classic.1 "$out/share/man/man1/ld.1" + ln -s ld.1 "$out/share/man/man1/ld64.1" + moveToOutput lib/libprunetrie.a "$dev" + ''; + + __structuredAttrs = true; + + passthru.updateScript = gitUpdater { rev-prefix = "ld64-"; }; + + meta = { + description = "The classic linker for Darwin"; + homepage = "https://opensource.apple.com/releases/"; + license = lib.licenses.apple-psl20; + mainProgram = "ld"; + maintainers = with lib.maintainers; [ reckenrode ]; + platforms = lib.platforms.unix; + }; +}) diff --git a/pkgs/by-name/li/libplacebo_5/package.nix b/pkgs/by-name/li/libplacebo_5/package.nix index f307a869e940b..4e1174815340a 100644 --- a/pkgs/by-name/li/libplacebo_5/package.nix +++ b/pkgs/by-name/li/libplacebo_5/package.nix @@ -51,8 +51,6 @@ stdenv.mkDerivation rec { (mesonBool "demos" false) # Don't build and install the demo programs (mesonEnable "d3d11" false) # Disable the Direct3D 11 based renderer (mesonEnable "glslang" false) # rely on shaderc for GLSL compilation instead - ] ++ optionals stdenv.isDarwin [ - (mesonEnable "unwind" false) # libplacebo doesn’t build with `darwin.libunwind` ]; postPatch = '' diff --git a/pkgs/by-name/li/libtapi/0001-Check-for-no_exported_symbols-linker-support.patch b/pkgs/by-name/li/libtapi/0001-Check-for-no_exported_symbols-linker-support.patch new file mode 100644 index 0000000000000..c4cd5085b7a38 --- /dev/null +++ b/pkgs/by-name/li/libtapi/0001-Check-for-no_exported_symbols-linker-support.patch @@ -0,0 +1,37 @@ +From e954aacbc075355419f5fc99db61f68aca1fcfe4 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Fri, 5 Apr 2024 14:16:40 -0400 +Subject: [PATCH 1/3] Check for -no_exported_symbols linker support + +--- + CMakeLists.txt | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/tapi/CMakeLists.txt b/tapi/CMakeLists.txt +index 62affdf..82426de 100644 +--- a/tapi/CMakeLists.txt ++++ b/tapi/CMakeLists.txt +@@ -73,6 +73,9 @@ llvm_check_linker_flag(CXX "-Wl,-no_inits" LINKER_SUPPORTS_NO_INITS) + llvm_check_linker_flag(CXX "-Wl,-iosmac_version_min,13.0" LINKER_SUPPORTS_IOSMAC) + # MARZIPAN RENAME + ++# Older versus of ld64 (e.g., in the Darwin bootstrap) do not support this flag. ++llvm_check_linker_flag(CXX "-Wl,-no_exported_symbols" LINKER_SUPPORTS_NO_EXPORTED_SYMBOLS) ++ + # Check if i386 is supported. + SET(CMAKE_OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) + SET(CMAKE_OLD_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS}) +@@ -160,7 +163,9 @@ endmacro(add_tapi_library) + macro(add_tapi_executable name) + add_llvm_executable(${name} ${ARGN}) + set_target_properties(${name} PROPERTIES FOLDER "Tapi executables") +- target_link_options(${name} PRIVATE "-Wl,-no_exported_symbols") ++ if(LINKER_SUPPORTS_NO_EXPORTED_SYMBOLS) ++ target_link_options(${name} PRIVATE "-Wl,-no_exported_symbols") ++ endif() + endmacro(add_tapi_executable) + + function(tapi_clang_tablegen) +-- +2.42.0 + diff --git a/pkgs/by-name/li/libtapi/0002-Pass-fileType-to-writeToStream.patch b/pkgs/by-name/li/libtapi/0002-Pass-fileType-to-writeToStream.patch new file mode 100644 index 0000000000000..ffcedb0c6f6e1 --- /dev/null +++ b/pkgs/by-name/li/libtapi/0002-Pass-fileType-to-writeToStream.patch @@ -0,0 +1,25 @@ +From 77ca537cfc61765f2109c626757f2da8de602ce0 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Fri, 5 Apr 2024 23:20:32 -0400 +Subject: [PATCH 2/3] Pass fileType to writeToStream + +--- + lib/Core/JSONReaderWriter.cpp | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/tapi/lib/Core/JSONReaderWriter.cpp b/tapi/lib/Core/JSONReaderWriter.cpp +index c040670..c1be85f 100644 +--- a/tapi/lib/Core/JSONReaderWriter.cpp ++++ b/tapi/lib/Core/JSONReaderWriter.cpp +@@ -57,7 +57,7 @@ Error JSONWriter::writeFile(raw_ostream &os, const InterfaceFile *file, + if (file == nullptr) + return errorCodeToError(std::make_error_code(std::errc::invalid_argument)); + +- return TextAPIWriter::writeToStream(os, *file, /*Compact=*/false); ++ return TextAPIWriter::writeToStream(os, *file, fileType, /*Compact=*/false); + } + + TAPI_NAMESPACE_INTERNAL_END +-- +2.42.0 + diff --git a/pkgs/by-name/li/libtapi/0003-Match-designator-order-with-declaration-order.patch b/pkgs/by-name/li/libtapi/0003-Match-designator-order-with-declaration-order.patch new file mode 100644 index 0000000000000..2883af0a52289 --- /dev/null +++ b/pkgs/by-name/li/libtapi/0003-Match-designator-order-with-declaration-order.patch @@ -0,0 +1,28 @@ +From b69038edb2e0ace9128407ab3ee7bc1001ffd751 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Sun, 7 Apr 2024 19:23:24 -0400 +Subject: [PATCH 3/3] Match designator order with declaration order + +--- + lib/Core/Demangler.cpp | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/tapi/lib/Core/Demangler.cpp b/tapi/lib/Core/Demangler.cpp +index d85899a..f5c485a 100644 +--- a/tapi/lib/Core/Demangler.cpp ++++ b/tapi/lib/Core/Demangler.cpp +@@ -30,9 +30,10 @@ bool Demangler::isItaniumEncoding(StringRef mangledName) { + return mangledName.startswith("_Z") || mangledName.startswith("___Z"); + } + ++ + DemangledName Demangler::demangle(StringRef mangledName) { + DemangledName result{ +- .str = mangledName.str(), .isSwift = false, .isItanium = false}; ++ .str = mangledName.str(), .isItanium = false, .isSwift = false}; + char *demangled = nullptr; + + if (isItaniumEncoding(mangledName)) { +-- +2.42.0 + diff --git a/pkgs/by-name/li/libtapi/package.nix b/pkgs/by-name/li/libtapi/package.nix new file mode 100644 index 0000000000000..58c0485ee5880 --- /dev/null +++ b/pkgs/by-name/li/libtapi/package.nix @@ -0,0 +1,178 @@ +{ + lib, + stdenv, + fetchFromGitHub, + fetchpatch, + cmake, + ninja, + python3, + zlib, +}: + +let + # Apple’s LLVM fork uses its own versioning scheme. + # See: https://en.wikipedia.org/wiki/Xcode#Toolchain_versions + # Note: Can’t use a sparse checkout because the Darwin stdenv bootstrap can’t depend on fetchgit. + appleLlvm = { + version = "15.0.0"; # As reported by upstream’s `tapi --version`. + rev = "2b5ff47e44b059c03de5779479d01a133ab4d581"; # Per the TAPI repo. + hash = "sha256-X37zBbpSEWmqtdTXsd1t++gp+0ggA8YtB73fGKNaiR0="; + }; +in +stdenv.mkDerivation (finalAttrs: { + pname = "libtapi"; + version = "1500.0.12.3"; + + outputs = [ + "out" + "bin" + "dev" + ]; + + srcs = [ + (fetchFromGitHub { + name = "tapi-src"; + owner = "apple-oss-distributions"; + repo = "tapi"; + rev = "tapi-${finalAttrs.version}"; + hash = "sha256-YeaA2OeSY1fXYJHPJJ0TrVC1brspSvutBtPMPGX6Y1o="; + }) + # Don’t pull down the entire repo when only a few projects are needed. + (fetchFromGitHub { + name = "apple-llvm-src"; + owner = "apple"; + repo = "llvm-project"; + inherit (appleLlvm) rev hash; + }) + ]; + + patches = [ + # Older versions of ld64 may not support `-no_exported_symbols`, so use it only + # when the linker supports it. + ./0001-Check-for-no_exported_symbols-linker-support.patch + # The recommended upstream revision of Apple’s LLVM fork needs this patch, or + # `tapi stubify` will crash when generating stubs. + (fetchpatch { + url = "https://github.com/apple/llvm-project/commit/455bf3d1ccd6a52df5e38103532c1b8f49924edc.patch"; + hash = "sha256-ujZcfdAls20JPIvjvO2Xv8st8cNTY/XTEQusICKBKSA"; + }) + # Updates `JSONReaderWriter` to work with the API change in the above patch. + ./0002-Pass-fileType-to-writeToStream.patch + # Fix build on Linux. GCC is more picky than clang about the field order. + ./0003-Match-designator-order-with-declaration-order.patch + ]; + + postPatch = + '' + # Enable building on non-Darwin platforms + substituteInPlace tapi/CMakeLists.txt \ + --replace-fail 'message(FATAL_ERROR "Unsupported configuration.")' "" + + # Remove the client limitation on linking to libtapi.dylib. + substituteInPlace tapi/tools/libtapi/CMakeLists.txt \ + --replace-fail '-allowable_client ld' "" + # Replace hard-coded installation paths with standard ones. + declare -A installdirs=( + [bin]=BINDIR + [include]=INCLUDEDIR + [lib]=LIBDIR + [local/bin]=BINDIR + [local/share/man]=MANDIR + [share/man]=MANDIR + ) + for dir in "''${!installdirs[@]}"; do + cmakevar=CMAKE_INSTALL_''${installdirs[$dir]} + for cmakelist in $(grep -rl "DESTINATION $dir" tapi); do + substituteInPlace "$cmakelist" \ + --replace-fail "DESTINATION $dir" "DESTINATION \''${$cmakevar}" + done + done + # Doesn’t seem to exist publically. + substituteInPlace tapi/test/CMakeLists.txt \ + --replace-fail tapi-configs "" + '' + + lib.optionalString stdenv.isLinux '' + # Remove Darwin-specific versioning flags. + substituteInPlace tapi/tools/libtapi/CMakeLists.txt \ + --replace-fail '-current_version ''${DYLIB_VERSION} -compatibility_version 1' "" + ''; + + preUnpack = '' + mkdir source + ''; + + sourceRoot = "source"; + + postUnpack = '' + chmod -R u+w apple-llvm-src tapi-src + mv apple-llvm-src/{clang,cmake,llvm,utils} source + mv tapi-src source/tapi + ''; + + strictDeps = true; + + buildInputs = [ zlib ]; # Upstream links against zlib in their distribution. + + nativeBuildInputs = [ + cmake + ninja + python3 + ]; + + cmakeDir = "../llvm"; + + cmakeFlags = [ + (lib.cmakeFeature "LLVM_ENABLE_PROJECTS" "clang;tapi") + (lib.cmakeFeature "LLVM_EXTERNAL_PROJECTS" "tapi") + (lib.cmakeBool "TAPI_INCLUDE_DOCS" true) + # Matches the verson string format reported by upstream `tapi`. + (lib.cmakeFeature "TAPI_REPOSITORY_STRING" "tapi-${finalAttrs.version}") + (lib.cmakeFeature "TAPI_FULL_VERSION" appleLlvm.version) + # Match the versioning used by Apple’s LLVM fork (primarily used for .so versioning). + (lib.cmakeFeature "LLVM_VERSION_MAJOR" (lib.versions.major appleLlvm.version)) + (lib.cmakeFeature "LLVM_VERSION_MINOR" (lib.versions.minor appleLlvm.version)) + (lib.cmakeFeature "LLVM_VERSION_PATCH" (lib.versions.patch appleLlvm.version)) + (lib.cmakeFeature "LLVM_VERSION_SUFFIX" "") + # Upstream `tapi` does not link against ncurses. Disable it explicitly to make sure + # it is not detected incorrectly from the bootstrap tools tarball. + (lib.cmakeBool "LLVM_ENABLE_TERMINFO" false) + # Disabling the benchmarks avoids a failure during the configure phase because + # the sparse checkout does not include the benchmarks. + (lib.cmakeBool "LLVM_INCLUDE_BENCHMARKS" false) + # tapi’s tests expect to target macOS 13.0 and build both x86_64 and universal + # binaries regardless of the host platform. + (lib.cmakeBool "LLVM_INCLUDE_TESTS" false) + (lib.cmakeBool "TAPI_INCLUDE_TESTS" false) + ]; + + ninjaFlags = [ + "libtapi" + "tapi-sdkdb" + "tapi" + ]; + + installTargets = [ + "install-libtapi" + "install-tapi-docs" + "install-tapi-headers" + "install-tapi-sdkdb" + "install-tapi" + ]; + + postInstall = '' + # The man page is installed for these, but they’re not included in the source release. + rm $bin/share/man/man1/tapi-analyze.1 $bin/share/man/man1/tapi-api-verify.1 + ''; + + meta = { + description = "Replaces the Mach-O Dynamic Library Stub files in Apple's SDKs to reduce the size"; + homepage = "https://github.com/apple-oss-distributions/tapi/"; + license = lib.licenses.ncsa; + mainProgram = "tapi"; + maintainers = with lib.maintainers; [ + matthewbauer + reckenrode + ]; + platforms = lib.platforms.unix; + }; +}) diff --git a/pkgs/by-name/li/live555/package.nix b/pkgs/by-name/li/live555/package.nix index e8fb1309844b8..4dfcae1b96ca6 100644 --- a/pkgs/by-name/li/live555/package.nix +++ b/pkgs/by-name/li/live555/package.nix @@ -1,6 +1,6 @@ { lib, - darwin, + cctools, fetchpatch, fetchurl, openssl, @@ -31,7 +31,7 @@ stdenv.mkDerivation (finalAttrs: { ]; nativeBuildInputs = lib.optionals stdenv.isDarwin [ - darwin.cctools + cctools ]; buildInputs = [ diff --git a/pkgs/by-name/me/meson/007-case-sensitive-fs.patch b/pkgs/by-name/me/meson/007-case-sensitive-fs.patch new file mode 100644 index 0000000000000..54d07d85585c2 --- /dev/null +++ b/pkgs/by-name/me/meson/007-case-sensitive-fs.patch @@ -0,0 +1,87 @@ +From a6fb2c165cda4bbf315424c96165ec9cc7052363 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Wed, 3 Apr 2024 17:35:56 -0400 +Subject: [PATCH] dependencies: find extraframeworks on case-sensitive + filesystems + +Fixes a test failure on case-sensitive filesystems when a CMake +dependency is turned into an Apple framework. +--- + mesonbuild/dependencies/framework.py | 9 +++++++-- + test cases/osx/11 case sensitive apfs/meson.build | 5 +++++ + test cases/osx/11 case sensitive apfs/prog.c | 3 +++ + test cases/osx/11 case sensitive apfs/test.json | 5 +++++ + 4 files changed, 20 insertions(+), 2 deletions(-) + create mode 100644 test cases/osx/11 case sensitive apfs/meson.build + create mode 100644 test cases/osx/11 case sensitive apfs/prog.c + create mode 100644 test cases/osx/11 case sensitive apfs/test.json + +diff --git a/mesonbuild/dependencies/framework.py b/mesonbuild/dependencies/framework.py +index 3c880c7430af..1fbd628235ba 100644 +--- a/mesonbuild/dependencies/framework.py ++++ b/mesonbuild/dependencies/framework.py +@@ -47,6 +47,7 @@ def detect(self, name: str, paths: T.List[str]) -> None: + framework_path = self._get_framework_path(p, name) + if framework_path is None: + continue ++ framework_name = framework_path.stem + # We want to prefer the specified paths (in order) over the system + # paths since these are "extra" frameworks. + # For example, Python2's framework is in /System/Library/Frameworks and +@@ -54,11 +55,15 @@ def detect(self, name: str, paths: T.List[str]) -> None: + # Python.framework. We need to know for sure that the framework was + # found in the path we expect. + allow_system = p in self.system_framework_paths +- args = self.clib_compiler.find_framework(name, self.env, [p], allow_system) ++ args = self.clib_compiler.find_framework(framework_name, self.env, [p], allow_system) + if args is None: + continue + self.link_args = args + self.framework_path = framework_path.as_posix() ++ # The search is done case-insensitively, so the found name may differ ++ # from the one that was requested. Setting the name ensures the correct ++ # one is used when linking on case-sensitive filesystems. ++ self.name = framework_name + self.compile_args = ['-F' + self.framework_path] + # We need to also add -I includes to the framework because all + # cross-platform projects such as OpenGL, Python, Qt, GStreamer, +@@ -74,7 +79,7 @@ def _get_framework_path(self, path: str, name: str) -> T.Optional[Path]: + p = Path(path) + lname = name.lower() + for d in p.glob('*.framework/'): +- if lname == d.name.rsplit('.', 1)[0].lower(): ++ if lname == d.stem.lower(): + return d + return None + +diff --git a/test cases/osx/11 case sensitive apfs/meson.build b/test cases/osx/11 case sensitive apfs/meson.build +new file mode 100644 +index 000000000000..dd566b185f28 +--- /dev/null ++++ b/test cases/osx/11 case sensitive apfs/meson.build +@@ -0,0 +1,5 @@ ++project('case-sensitive APFS with extra frameworks test', 'c') ++ ++dep = dependency('FoUnDaTiOn') ++ ++exe = executable('prog', 'prog.c', install : true, dependencies: dep) +diff --git a/test cases/osx/11 case sensitive apfs/prog.c b/test cases/osx/11 case sensitive apfs/prog.c +new file mode 100644 +index 000000000000..9b6bdc2ec2f0 +--- /dev/null ++++ b/test cases/osx/11 case sensitive apfs/prog.c +@@ -0,0 +1,3 @@ ++int main(void) { ++ return 0; ++} +diff --git a/test cases/osx/11 case sensitive apfs/test.json b/test cases/osx/11 case sensitive apfs/test.json +new file mode 100644 +index 000000000000..a883714eaa27 +--- /dev/null ++++ b/test cases/osx/11 case sensitive apfs/test.json +@@ -0,0 +1,5 @@ ++{ ++ "installed": [ ++ {"type": "file", "file": "usr/bin/prog"} ++ ] ++} diff --git a/pkgs/by-name/me/meson/package.nix b/pkgs/by-name/me/meson/package.nix index 014c461963d90..75f571eef840e 100644 --- a/pkgs/by-name/me/meson/package.nix +++ b/pkgs/by-name/me/meson/package.nix @@ -73,6 +73,10 @@ python3.pkgs.buildPythonApplication rec { # Fix compilation of Meson using Ninja 1.12 # FIXME: remove in the next point release ./007-Allow-building-via-ninja-12.patch + + # Fix extraframework lookup on case-sensitive APFS. + # https://github.com/mesonbuild/meson/pull/13038 + ./007-case-sensitive-fs.patch ]; buildInputs = lib.optionals (python3.pythonOlder "3.9") [ diff --git a/pkgs/by-name/me/meson/setup-hook.sh b/pkgs/by-name/me/meson/setup-hook.sh index 3f3c7ac59fdea..8266645452277 100644 --- a/pkgs/by-name/me/meson/setup-hook.sh +++ b/pkgs/by-name/me/meson/setup-hook.sh @@ -25,10 +25,7 @@ mesonConfigurePhase() { "--buildtype=${mesonBuildType:-plain}" ) - flagsArray+=( - $mesonFlags - "${mesonFlagsArray[@]}" - ) + _accumFlagsArray mesonFlags mesonFlagsArray echoCmd 'mesonConfigurePhase flags' "${flagsArray[@]}" diff --git a/pkgs/by-name/pr/protoc-gen-js/package.nix b/pkgs/by-name/pr/protoc-gen-js/package.nix index 0df0cb62a83e1..6d0af4018eb0a 100644 --- a/pkgs/by-name/pr/protoc-gen-js/package.nix +++ b/pkgs/by-name/pr/protoc-gen-js/package.nix @@ -1,4 +1,4 @@ -{ stdenv, lib, buildBazelPackage, bazel_6, fetchFromGitHub, darwin }: +{ stdenv, lib, buildBazelPackage, bazel_6, fetchFromGitHub, cctools }: buildBazelPackage rec { pname = "protoc-gen-js"; @@ -17,7 +17,7 @@ buildBazelPackage rec { removeRulesCC = false; removeLocalConfigCC = false; - LIBTOOL = lib.optionalString stdenv.isDarwin "${darwin.cctools}/bin/libtool"; + LIBTOOL = lib.optionalString stdenv.isDarwin "${cctools}/bin/libtool"; fetchAttrs.sha256 = "sha256-WOBlZ0XNrl5UxIaSDxZeOfzS2a8ZkrKdTLKHBDC9UNQ="; diff --git a/pkgs/data/fonts/iosevka/default.nix b/pkgs/data/fonts/iosevka/default.nix index 190170ebc28f4..ac577c2613891 100644 --- a/pkgs/data/fonts/iosevka/default.nix +++ b/pkgs/data/fonts/iosevka/default.nix @@ -2,7 +2,7 @@ , lib , buildNpmPackage , fetchFromGitHub -, darwin +, cctools , remarshal , ttfautohint-nox # Custom font set options. @@ -71,7 +71,7 @@ buildNpmPackage rec { ttfautohint-nox ] ++ lib.optionals stdenv.isDarwin [ # libtool - darwin.cctools + cctools ]; buildPlan = diff --git a/pkgs/development/compilers/chez-racket/shared.nix b/pkgs/development/compilers/chez-racket/shared.nix index 46f53204309b2..f9edc5b57a40e 100644 --- a/pkgs/development/compilers/chez-racket/shared.nix +++ b/pkgs/development/compilers/chez-racket/shared.nix @@ -1,5 +1,5 @@ args: -{ stdenv, lib, fetchFromGitHub, coreutils, darwin +{ stdenv, lib, fetchFromGitHub, cctools, coreutils, darwin , ncurses, libiconv, libX11, zlib, lz4 }: @@ -23,7 +23,7 @@ stdenv.mkDerivation (args // { export LZ4="$(find ${lz4.out}/lib -type f | sort | head -n1)" ''; - nativeBuildInputs = lib.optionals stdenv.isDarwin (with darwin; [ cctools autoSignDarwinBinariesHook ]); + nativeBuildInputs = lib.optionals stdenv.isDarwin [ cctools darwin.autoSignDarwinBinariesHook ]; buildInputs = [ libiconv libX11 lz4 ncurses zlib ]; enableParallelBuilding = true; diff --git a/pkgs/development/compilers/dart/default.nix b/pkgs/development/compilers/dart/default.nix index ee10acbdeb7c9..0b21122b035e3 100644 --- a/pkgs/development/compilers/dart/default.nix +++ b/pkgs/development/compilers/dart/default.nix @@ -3,6 +3,7 @@ , fetchurl , unzip , runCommand +, cctools , darwin , sources ? import ./sources.nix {inherit fetchurl;} , version ? sources.versionUsed @@ -41,7 +42,7 @@ stdenv.mkDerivation (finalAttrs: { testCompile = runCommand "dart-test-compile" { nativeBuildInputs = [ finalAttrs.finalPackage ] - ++ lib.optionals stdenv.isDarwin [ darwin.cctools darwin.sigtool ]; + ++ lib.optionals stdenv.isDarwin [ cctools darwin.sigtool ]; } '' HELLO_MESSAGE="Hello, world!" echo "void main() => print('$HELLO_MESSAGE');" > hello.dart diff --git a/pkgs/development/compilers/dotnet/sigtool.nix b/pkgs/development/compilers/dotnet/sigtool.nix index 658ee578ae983..fe5d1ebc6879c 100644 --- a/pkgs/development/compilers/dotnet/sigtool.nix +++ b/pkgs/development/compilers/dotnet/sigtool.nix @@ -1,11 +1,10 @@ -{ darwin +{ cctools +, darwin , fetchFromGitHub , makeWrapper }: -let - cctools = darwin.cctools; -in darwin.sigtool.overrideAttrs (old: { +darwin.sigtool.overrideAttrs (old: { # this is a fork of sigtool that supports -v and --remove-signature, which are # used by the dotnet sdk src = fetchFromGitHub { diff --git a/pkgs/development/compilers/dotnet/vmr.nix b/pkgs/development/compilers/dotnet/vmr.nix index 3638da1117e9b..0b7931cb411dc 100644 --- a/pkgs/development/compilers/dotnet/vmr.nix +++ b/pkgs/development/compilers/dotnet/vmr.nix @@ -17,6 +17,7 @@ , glibcLocales , ensureNewerSourcesForZipFilesHook , darwin +, ld64 , xcbuild , swiftPackages , openssl @@ -42,7 +43,6 @@ let isDarwin buildPlatform targetPlatform; - inherit (darwin) cctools; inherit (swiftPackages) apple_sdk swift; releaseManifest = lib.importJSON releaseManifestFile; @@ -54,13 +54,13 @@ let sigtool = callPackage ./sigtool.nix {}; - # we need dwarfdump from cctools, but can't have e.g. 'ar' overriding stdenv + # we need dwarfdump from ld64 dwarfdump = stdenvNoCC.mkDerivation { name = "dwarfdump-wrapper"; dontUnpack = true; installPhase = '' mkdir -p "$out/bin" - ln -s "${cctools}/bin/dwarfdump" "$out/bin" + ln -s "${ld64}/bin/dwarfdump" "$out/bin" ''; }; diff --git a/pkgs/development/compilers/elm/packages/node/node-composition.nix b/pkgs/development/compilers/elm/packages/node/node-composition.nix index 1f86de75e3578..65452c7617e74 100644 --- a/pkgs/development/compilers/elm/packages/node/node-composition.nix +++ b/pkgs/development/compilers/elm/packages/node/node-composition.nix @@ -8,7 +8,7 @@ let nodeEnv = import ../../../../node-packages/node-env.nix { inherit (pkgs) stdenv lib python2 runCommand writeTextFile writeShellScript; inherit pkgs nodejs; - libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null; + libtool = if pkgs.stdenv.isDarwin then pkgs.cctools else null; }; in import ./node-packages.nix { diff --git a/pkgs/development/compilers/gcc/default.nix b/pkgs/development/compilers/gcc/default.nix index 5e017a21fa1f5..7a8f0342f62a2 100644 --- a/pkgs/development/compilers/gcc/default.nix +++ b/pkgs/development/compilers/gcc/default.nix @@ -33,6 +33,7 @@ , nukeReferences , callPackage , majorMinorVersion +, cctools , darwin # only for gcc<=6.x @@ -454,7 +455,7 @@ pipe ((callFile ./common/builder.nix {}) ({ } // optionalAttrs (!atLeast10 && stdenv.targetPlatform.isDarwin) { # GCC <10 requires default cctools `strip` instead of `llvm-strip` used by Darwin bintools. preBuild = '' - makeFlagsArray+=('STRIP=${getBin darwin.cctools-port}/bin/${stdenv.cc.targetPrefix}strip') + makeFlagsArray+=('STRIP=${getBin cctools}/bin/${stdenv.cc.targetPrefix}strip') ''; } // optionalAttrs (!atLeast8) { doCheck = false; # requires a lot of tools, causes a dependency cycle for stdenv diff --git a/pkgs/development/compilers/gcc/patches/default.nix b/pkgs/development/compilers/gcc/patches/default.nix index 13b4bcbf6f8cd..b2addad4b75a2 100644 --- a/pkgs/development/compilers/gcc/patches/default.nix +++ b/pkgs/development/compilers/gcc/patches/default.nix @@ -275,9 +275,9 @@ in ./6/gnat-glibc234.patch ] -# The clang-based assembler used in darwin.cctools-llvm (LLVM >11) does not support piping input. +# The clang-based assembler used in darwin.binutils does not support piping input. # Fortunately, it does not exhibit the problem GCC has with the cctools assembler. -# This patch can be dropped should darwin.cctools-llvm ever implement support. +# This patch can be dropped should darwin.binutils ever implement support. ++ optional (!atLeast7 && hostPlatform.isDarwin && lib.versionAtLeast (lib.getVersion stdenv.cc) "12") ./4.9/darwin-clang-as.patch # Building libstdc++ with flat namespaces results in trying to link CoreFoundation, which diff --git a/pkgs/development/compilers/ghc/common-hadrian.nix b/pkgs/development/compilers/ghc/common-hadrian.nix index 55cc96dfd3ed9..8e25ab3db1cdd 100644 --- a/pkgs/development/compilers/ghc/common-hadrian.nix +++ b/pkgs/development/compilers/ghc/common-hadrian.nix @@ -257,24 +257,6 @@ let targetCC = builtins.head toolsForTarget; - # Sometimes we have to dispatch between the bintools wrapper and the unwrapped - # derivation for certain tools depending on the platform. - bintoolsFor = { - # GHC needs install_name_tool on all darwin platforms. On aarch64-darwin it is - # part of the bintools wrapper (due to codesigning requirements), but not on - # x86_64-darwin. - install_name_tool = - if stdenv.targetPlatform.isAarch64 - then targetCC.bintools - else targetCC.bintools.bintools; - # Same goes for strip. - strip = - # TODO(@sternenseemann): also use wrapper if linker == "bfd" or "gold" - if stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin - then targetCC.bintools - else targetCC.bintools.bintools; - }; - # Use gold either following the default, or to avoid the BFD linker due to some bugs / perf issues. # But we cannot avoid BFD when using musl libc due to https://sourceware.org/bugzilla/show_bug.cgi?id=23856 # see #84670 and #49071 for more background. @@ -328,10 +310,10 @@ stdenv.mkDerivation ({ export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm" export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib" export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf" - export STRIP="${bintoolsFor.strip}/bin/${bintoolsFor.strip.targetPrefix}strip" + export STRIP="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}strip" '' + lib.optionalString (stdenv.targetPlatform.linker == "cctools") '' export OTOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}otool" - export INSTALL_NAME_TOOL="${bintoolsFor.install_name_tool}/bin/${bintoolsFor.install_name_tool.targetPrefix}install_name_tool" + export INSTALL_NAME_TOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}install_name_tool" '' + lib.optionalString useLLVM '' export LLC="${lib.getBin buildTargetLlvmPackages.llvm}/bin/llc" export OPT="${lib.getBin buildTargetLlvmPackages.llvm}/bin/opt" diff --git a/pkgs/development/compilers/llvm/16/default.nix b/pkgs/development/compilers/llvm/16/default.nix index 79d5f8589044c..13d8018b0c436 100644 --- a/pkgs/development/compilers/llvm/16/default.nix +++ b/pkgs/development/compilers/llvm/16/default.nix @@ -62,6 +62,9 @@ in let llef = callPackage ../common/lldb-plugins/llef.nix {}; }); + isDarwinCross = stdenv.hostPlatform.isDarwin && (stdenv.buildPlatform != stdenv.hostPlatform); + stdenvNoCF = if stdenv.hostPlatform.isDarwin then darwin.stdenvNoCF else stdenv; + tools = lib.makeExtensible (tools: let callPackage = newScope (tools // { inherit stdenv cmake ninja libxml2 python3 release_version version monorepoSrc buildLlvmTools; }); major = lib.versions.major release_version; @@ -375,9 +378,14 @@ in let # ../common/compiler-rt/armv7l-15.patch ]; inherit llvm_meta; - stdenv = if stdenv.hostPlatform.useLLVM or false || (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isStatic) - then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc - else stdenv; + stdenv = + # Darwin requires libc++ to build analyzers. + if stdenv.hostPlatform.isDarwin then + overrideCC stdenv (buildLlvmTools.clangNoCompilerRtWithLibc.override { inherit (targetLlvmLibraries) libcxx; }) + else if stdenv.hostPlatform.useLLVM or false then + overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc + else + stdenv; }; compiler-rt-no-libc = callPackage ../common/compiler-rt { @@ -396,7 +404,7 @@ in let ]; inherit llvm_meta; stdenv = if stdenv.hostPlatform.useLLVM or false - then overrideCC stdenv buildLlvmTools.clangNoCompilerRt + then overrideCC stdenvNoCF buildLlvmTools.clangNoCompilerRt else stdenv; }; @@ -414,7 +422,15 @@ in let # stdenv's compiler. libcxx = callPackage ../common/libcxx { inherit llvm_meta; - stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx; + stdenv = + # Avoid an infinite recursion between libc++ and compiler-rt on Darwin by building without compiler-rt. + if stdenv.hostPlatform.isDarwin then + overrideCC stdenvNoCF (buildLlvmTools.clangNoCompilerRtWithLibc.override { + nixSupport.cc-cflags = [ "-nostdlib" ]; + nixSupport.cc-ldflags = [ "-lSystem" ]; + }) + else + overrideCC stdenv buildLlvmTools.clangNoLibcxx; }; libunwind = callPackage ../common/libunwind { @@ -422,7 +438,7 @@ in let ./libunwind/gnu-install-dirs.patch ]; inherit llvm_meta; - stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx; + stdenv = overrideCC stdenvNoCF buildLlvmTools.clangNoLibcxx; }; openmp = callPackage ../common/openmp { diff --git a/pkgs/development/compilers/llvm/18/default.nix b/pkgs/development/compilers/llvm/18/default.nix index 3c0e551791e54..7c91c22a347af 100644 --- a/pkgs/development/compilers/llvm/18/default.nix +++ b/pkgs/development/compilers/llvm/18/default.nix @@ -57,6 +57,9 @@ in let inherit (import ../common/common-let.nix { inherit lib fetchFromGitHub release_version gitRelease officialRelease monorepoSrc'; }) llvm_meta monorepoSrc; + isDarwinCross = stdenv.hostPlatform.isDarwin && (stdenv.buildPlatform != stdenv.hostPlatform); + stdenvNoCF = if stdenv.hostPlatform.isDarwin then darwin.stdenvNoCF else stdenv; + tools = lib.makeExtensible (tools: let callPackage = newScope (tools // { inherit stdenv cmake ninja libxml2 python3 release_version version monorepoSrc buildLlvmTools; }); major = lib.versions.major release_version; @@ -356,9 +359,14 @@ in let # ../common/compiler-rt/armv7l-15.patch ]; inherit llvm_meta; - stdenv = if stdenv.hostPlatform.useLLVM or false || (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isStatic) - then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc - else stdenv; + stdenv = + # Darwin requires libc++ to build analyzers. + if stdenv.hostPlatform.isDarwin then + overrideCC stdenv (buildLlvmTools.clangNoCompilerRtWithLibc.override { inherit (targetLlvmLibraries) libcxx; }) + else if stdenv.hostPlatform.useLLVM or false then + overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc + else + stdenv; }; compiler-rt-no-libc = callPackage ../common/compiler-rt { @@ -374,7 +382,7 @@ in let ]; inherit llvm_meta; stdenv = if stdenv.hostPlatform.useLLVM or false - then overrideCC stdenv buildLlvmTools.clangNoCompilerRt + then overrideCC stdenvNoCF buildLlvmTools.clangNoCompilerRt else stdenv; }; @@ -396,12 +404,20 @@ in let ./libcxx/0001-darwin-10.12-mbstate_t-fix.patch ]; inherit llvm_meta; - stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx; + stdenv = + # Avoid an infinite recursion between libc++ and compiler-rt on Darwin by building without compiler-rt. + if stdenv.hostPlatform.isDarwin then + overrideCC stdenvNoCF (buildLlvmTools.clangNoCompilerRtWithLibc.override { + nixSupport.cc-cflags = [ "-nostdlib" ]; + nixSupport.cc-ldflags = [ "-lSystem" ]; + }) + else + overrideCC stdenv buildLlvmTools.clangNoLibcxx; }; libunwind = callPackage ../common/libunwind { inherit llvm_meta; - stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx; + stdenv = overrideCC stdenvNoCF buildLlvmTools.clangNoLibcxx; }; openmp = callPackage ../common/openmp { diff --git a/pkgs/development/compilers/llvm/common/compiler-rt/default.nix b/pkgs/development/compilers/llvm/common/compiler-rt/default.nix index 4f44d6396d301..f48ad0d13c2b6 100644 --- a/pkgs/development/compilers/llvm/common/compiler-rt/default.nix +++ b/pkgs/development/compilers/llvm/common/compiler-rt/default.nix @@ -22,7 +22,8 @@ let useLLVM = stdenv.hostPlatform.useLLVM or false; bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; haveLibc = stdenv.cc.libc != null; - isDarwinStatic = stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isStatic && lib.versionAtLeast release_version "16"; + isDarwinStatic = stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isStatic; + inherit (stdenv.hostPlatform) isMusl isAarch64; baseName = "compiler-rt"; @@ -81,7 +82,7 @@ stdenv.mkDerivation ({ "-DCOMPILER_RT_BUILD_ORC=OFF" # may be possible to build with musl if necessary ] ++ lib.optionals (useLLVM || bareMetal) [ "-DCOMPILER_RT_BUILD_PROFILE=OFF" - ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal || isDarwinStatic) [ + ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal) [ "-DCMAKE_CXX_COMPILER_WORKS=ON" ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal) [ "-DCMAKE_C_COMPILER_WORKS=ON" diff --git a/pkgs/development/compilers/llvm/common/libunwind/default.nix b/pkgs/development/compilers/llvm/common/libunwind/default.nix index 515914e6acb64..87e1c3b0c7109 100644 --- a/pkgs/development/compilers/llvm/common/libunwind/default.nix +++ b/pkgs/development/compilers/llvm/common/libunwind/default.nix @@ -46,7 +46,17 @@ let cd ../runtimes ''; - postInstall = lib.optionalString (enableShared && !stdenv.hostPlatform.isDarwin) '' + postInstall = '' + # GNU libunwind ships pkg-config files, which some packages expect to use to find libunwind. + # Upstream issue: https://github.com/llvm/llvm-project/issues/84662 + mkdir -p ''${!outputDev}/lib/pkgconfig + substitute ${./libunwind.pc} ''${!outputDev}/lib/pkgconfig/libunwind.pc \ + --subst-var version \ + --subst-var-by CMAKE_INSTALL_PREFIX $out \ + --subst-var-by CMAKE_INSTALL_FULL_INCLUDEDIR ''${!outputDev}/include \ + --subst-var-by CMAKE_INSTALL_FULL_LIBDIR ''${!outputLib}/lib + '' + + lib.optionalString ((lib.versionAtLeast release_version "15") && enableShared && !stdenv.hostPlatform.isDarwin) '' # libcxxabi wants to link to libunwind_shared.so (?). ln -s $out/lib/libunwind.so $out/lib/libunwind_shared.so ''; @@ -82,6 +92,6 @@ stdenv.mkDerivation (rec { ''; }; } // (if postUnpack != "" then { inherit postUnpack; } else {}) - // (if (lib.versionAtLeast release_version "15") then { inherit postInstall; } else {}) + // (if postInstall != "" then { inherit postInstall; } else {}) // (if prePatch != "" then { inherit prePatch; } else {}) // (if postPatch != "" then { inherit postPatch; } else {})) diff --git a/pkgs/development/compilers/llvm/common/libunwind/libunwind.pc b/pkgs/development/compilers/llvm/common/libunwind/libunwind.pc new file mode 100644 index 0000000000000..440f48eae0196 --- /dev/null +++ b/pkgs/development/compilers/llvm/common/libunwind/libunwind.pc @@ -0,0 +1,10 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ +libdir=@CMAKE_INSTALL_FULL_LIBDIR@ + +Name: libunwind +Description: An implementation of the HP libunwind interface +Version: @version@ +Cflags: -I${includedir} +Libs: -L${libdir} -lunwind diff --git a/pkgs/development/compilers/ponyc/default.nix b/pkgs/development/compilers/ponyc/default.nix index c7008ec22a8aa..740ff702acd30 100644 --- a/pkgs/development/compilers/ponyc/default.nix +++ b/pkgs/development/compilers/ponyc/default.nix @@ -13,6 +13,7 @@ , substituteAll , which , z3 +, cctools , darwin }: @@ -36,7 +37,7 @@ stdenv.mkDerivation (rec { }; nativeBuildInputs = [ cmake makeWrapper which python3 ] - ++ lib.optionals (stdenv.isDarwin) [ darwin.cctools ]; + ++ lib.optionals (stdenv.isDarwin) [ cctools ]; buildInputs = [ libxml2 z3 ]; # Sandbox disallows network access, so disabling problematic networking tests diff --git a/pkgs/development/compilers/rgbds/default.nix b/pkgs/development/compilers/rgbds/default.nix index 7cec0eb0ddbb8..21999825c0004 100644 --- a/pkgs/development/compilers/rgbds/default.nix +++ b/pkgs/development/compilers/rgbds/default.nix @@ -11,7 +11,6 @@ stdenv.mkDerivation rec { }; nativeBuildInputs = [ bison flex pkg-config ]; buildInputs = [ libpng ]; - env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isDarwin "-fno-lto"; installFlags = [ "PREFIX=${placeholder "out"}" ]; meta = with lib; { diff --git a/pkgs/development/compilers/swift/default.nix b/pkgs/development/compilers/swift/default.nix index 2a56a03766b95..9de3a01c34e0f 100644 --- a/pkgs/development/compilers/swift/default.nix +++ b/pkgs/development/compilers/swift/default.nix @@ -58,7 +58,7 @@ let xcbuild = xcodebuild; swift-unwrapped = callPackage ./compiler { - inherit (darwin) DarwinTools cctools sigtool; + inherit (darwin) DarwinTools sigtool; inherit (apple_sdk) MacOSX-SDK CLTools_Executables; inherit (apple_sdk.frameworks) CoreServices Foundation Combine; }; @@ -85,7 +85,7 @@ let }; swiftpm = callPackage ./swiftpm { - inherit (darwin) DarwinTools cctools; + inherit (darwin) DarwinTools; inherit (apple_sdk.frameworks) CryptoKit LocalAuthentication; swift = swiftNoSwiftDriver; }; diff --git a/pkgs/development/interpreters/cyclone/default.nix b/pkgs/development/interpreters/cyclone/default.nix index 7364cf7d4400c..d61af16b5d22e 100644 --- a/pkgs/development/interpreters/cyclone/default.nix +++ b/pkgs/development/interpreters/cyclone/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, fetchFromGitHub, libck, darwin }: +{ lib, stdenv, fetchFromGitHub, libck, cctools }: let version = "0.34.0"; @@ -15,7 +15,7 @@ let enableParallelBuilding = true; - nativeBuildInputs = lib.optionals stdenv.isDarwin [ darwin.cctools ]; + nativeBuildInputs = lib.optionals stdenv.isDarwin [ cctools ]; buildInputs = [ libck ]; @@ -36,7 +36,7 @@ stdenv.mkDerivation { enableParallelBuilding = true; nativeBuildInputs = [ bootstrap ] - ++ lib.optionals stdenv.isDarwin [ darwin.cctools ]; + ++ lib.optionals stdenv.isDarwin [ cctools ]; buildInputs = [ libck ]; diff --git a/pkgs/development/interpreters/python/cpython/default.nix b/pkgs/development/interpreters/python/cpython/default.nix index 37b9d19fe88d9..625291fa46b7c 100644 --- a/pkgs/development/interpreters/python/cpython/default.nix +++ b/pkgs/development/interpreters/python/cpython/default.nix @@ -70,8 +70,7 @@ , enableNoSemanticInterposition ? true # enabling LTO on 32bit arch causes downstream packages to fail when linking -# enabling LTO on *-darwin causes python3 to fail when linking. -, enableLTO ? stdenv.is64bit && stdenv.isLinux +, enableLTO ? stdenv.is64bit && (stdenv.isLinux || stdenv.isDarwin) # enable asserts to ensure the build remains reproducible , reproducibleBuild ? false @@ -441,7 +440,7 @@ in with passthru; stdenv.mkDerivation (finalAttrs: { # Never even try to use lchmod on linux, # don't rely on detecting glibc-isms. "ac_cv_func_lchmod=no" - ] ++ optionals static [ + ] ++ optionals (static && !stdenv.hostPlatform.isDarwin) [ "LDFLAGS=-static" ]; diff --git a/pkgs/development/interpreters/python/default.nix b/pkgs/development/interpreters/python/default.nix index 86eaf142d9205..b3434524ebfc9 100644 --- a/pkgs/development/interpreters/python/default.nix +++ b/pkgs/development/interpreters/python/default.nix @@ -142,7 +142,6 @@ in { db = db.override { dbmSupport = !stdenv.isDarwin; }; python = __splicedPackages.pythonInterpreters.pypy27_prebuilt; inherit passthruFun; - inherit (darwin) libunwind; inherit (darwin.apple_sdk.frameworks) Security; }; @@ -159,7 +158,6 @@ in { db = db.override { dbmSupport = !stdenv.isDarwin; }; python = __splicedPackages.pypy27; inherit passthruFun; - inherit (darwin) libunwind; inherit (darwin.apple_sdk.frameworks) Security; }; diff --git a/pkgs/development/libraries/SDL2/0001-Use-version-checks-with-SDK-macros.patch b/pkgs/development/libraries/SDL2/0001-Use-version-checks-with-SDK-macros.patch new file mode 100644 index 0000000000000..bc700f388115a --- /dev/null +++ b/pkgs/development/libraries/SDL2/0001-Use-version-checks-with-SDK-macros.patch @@ -0,0 +1,76 @@ +From aa8302edc15e28d26ea0ba69a51b4b66c6569c05 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Tue, 23 Apr 2024 22:17:02 -0400 +Subject: [PATCH] Use version checks with SDK macros + +--- + src/audio/coreaudio/SDL_coreaudio.h | 2 +- + src/render/metal/SDL_render_metal.m | 4 ++-- + src/video/cocoa/SDL_cocoamodes.m | 2 +- + src/video/cocoa/SDL_cocoamouse.m | 2 +- + 4 files changed, 5 insertions(+), 5 deletions(-) + +diff --git a/src/audio/coreaudio/SDL_coreaudio.h b/src/audio/coreaudio/SDL_coreaudio.h +index d5d11ca51..a3b25a5ab 100644 +--- a/src/audio/coreaudio/SDL_coreaudio.h ++++ b/src/audio/coreaudio/SDL_coreaudio.h +@@ -42,7 +42,7 @@ + /* Things named "Master" were renamed to "Main" in macOS 12.0's SDK. */ + #ifdef MACOSX_COREAUDIO + #include +-#ifndef MAC_OS_VERSION_12_0 ++#if MAC_OS_X_VERSION_MAX_ALLOWED < 120000 + #define kAudioObjectPropertyElementMain kAudioObjectPropertyElementMaster + #endif + #endif +diff --git a/src/render/metal/SDL_render_metal.m b/src/render/metal/SDL_render_metal.m +index ee6b88209..0f10fc7b1 100644 +--- a/src/render/metal/SDL_render_metal.m ++++ b/src/render/metal/SDL_render_metal.m +@@ -1536,7 +1536,7 @@ static void *METAL_GetMetalCommandEncoder(SDL_Renderer * renderer) + + static int METAL_SetVSync(SDL_Renderer * renderer, const int vsync) + { +-#if (defined(__MACOSX__) && defined(MAC_OS_X_VERSION_10_13)) || TARGET_OS_MACCATALYST ++#if (defined(__MACOSX__) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 101300)) || TARGET_OS_MACCATALYST + if (@available(macOS 10.13, *)) { + METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata; + if (vsync) { +@@ -1826,7 +1826,7 @@ static SDL_Renderer *METAL_CreateRenderer(SDL_Window * window, Uint32 flags) + + renderer->always_batch = SDL_TRUE; + +-#if (defined(__MACOSX__) && defined(MAC_OS_X_VERSION_10_13)) || TARGET_OS_MACCATALYST ++#if (defined(__MACOSX__) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 101300)) || TARGET_OS_MACCATALYST + if (@available(macOS 10.13, *)) { + data.mtllayer.displaySyncEnabled = (flags & SDL_RENDERER_PRESENTVSYNC) != 0; + if (data.mtllayer.displaySyncEnabled) { +diff --git a/src/video/cocoa/SDL_cocoamodes.m b/src/video/cocoa/SDL_cocoamodes.m +index d1ef99e9c..393d06eca 100644 +--- a/src/video/cocoa/SDL_cocoamodes.m ++++ b/src/video/cocoa/SDL_cocoamodes.m +@@ -34,7 +34,7 @@ + /* This gets us MAC_OS_X_VERSION_MIN_REQUIRED... */ + #include + +-#ifndef MAC_OS_X_VERSION_10_13 ++#if MAC_OS_X_VERSION_MAX_ALLOWED < 101300 + #define NSAppKitVersionNumber10_12 1504 + #endif + #if (IOGRAPHICSTYPES_REV < 40) +diff --git a/src/video/cocoa/SDL_cocoamouse.m b/src/video/cocoa/SDL_cocoamouse.m +index c14f9abdc..e14512b60 100644 +--- a/src/video/cocoa/SDL_cocoamouse.m ++++ b/src/video/cocoa/SDL_cocoamouse.m +@@ -119,7 +119,7 @@ static NSCursor *LoadHiddenSystemCursor(NSString *cursorName, SEL fallback) + } + + if (frames > 1) { +- #ifdef MAC_OS_VERSION_12_0 /* same value as deprecated symbol. */ ++ #if MAC_OS_X_VERSION_MAX_ALLOWED < 120000 /* same value as deprecated symbol. */ + const NSCompositingOperation operation = NSCompositingOperationCopy; + #else + const NSCompositingOperation operation = NSCompositeCopy; +-- +2.42.0 + diff --git a/pkgs/development/libraries/SDL2/default.nix b/pkgs/development/libraries/SDL2/default.nix index 0096f3b265b64..57b9cb74c7eaa 100644 --- a/pkgs/development/libraries/SDL2/default.nix +++ b/pkgs/development/libraries/SDL2/default.nix @@ -76,6 +76,8 @@ stdenv.mkDerivation (finalAttrs: { # but on NixOS they're spread across different paths. # This patch + the setup-hook will ensure that `sdl2-config --cflags` works correctly. ./find-headers.patch + # The source-based SDK uses a newer version of AvailabilityMacros.h that causes SDK2 to misdetect the SDK version. + ./0001-Use-version-checks-with-SDK-macros.patch ]; postPatch = '' diff --git a/pkgs/development/libraries/abseil-cpp/202206.nix b/pkgs/development/libraries/abseil-cpp/202206.nix index 5dda078a3a901..e354140a7dcb4 100644 --- a/pkgs/development/libraries/abseil-cpp/202206.nix +++ b/pkgs/development/libraries/abseil-cpp/202206.nix @@ -23,6 +23,13 @@ stdenv.mkDerivation rec { ./cmake-core-foundation.patch ]; + # abseil-cpp tries to build for both aarch64 and x86_64, which fails due to passing unrecognized flags. + # Only build for the host platform instead. + postPatch = lib.optionalString stdenv.isDarwin '' + substituteInPlace absl/copts/AbseilConfigureCopts.cmake \ + --replace-fail 'APPLE AND CMAKE_CXX_COMPILER_ID MATCHES [[Clang]]' 'false' + ''; + cmakeFlags = [ "-DBUILD_SHARED_LIBS=${if static then "OFF" else "ON"}" ] ++ lib.optionals (cxxStandard != null) [ diff --git a/pkgs/development/libraries/abseil-cpp/202301.nix b/pkgs/development/libraries/abseil-cpp/202301.nix index b2d4f437473f3..374eb9f123117 100644 --- a/pkgs/development/libraries/abseil-cpp/202301.nix +++ b/pkgs/development/libraries/abseil-cpp/202301.nix @@ -24,6 +24,13 @@ stdenv.mkDerivation (finalAttrs: { ./cmake-core-foundation.patch ]; + # abseil-cpp tries to build for both aarch64 and x86_64, which fails due to passing unrecognized flags. + # Only build for the host platform instead. + postPatch = lib.optionalString stdenv.isDarwin '' + substituteInPlace absl/copts/AbseilConfigureCopts.cmake \ + --replace-fail 'APPLE AND CMAKE_CXX_COMPILER_ID MATCHES [[Clang]]' 'false' + ''; + cmakeFlags = [ "-DABSL_BUILD_TEST_HELPERS=ON" "-DABSL_USE_EXTERNAL_GOOGLETEST=ON" diff --git a/pkgs/development/libraries/abseil-cpp/202308.nix b/pkgs/development/libraries/abseil-cpp/202308.nix index f3aac7d1388bd..01b73f34f8c35 100644 --- a/pkgs/development/libraries/abseil-cpp/202308.nix +++ b/pkgs/development/libraries/abseil-cpp/202308.nix @@ -18,6 +18,13 @@ stdenv.mkDerivation (finalAttrs: { hash = "sha256-wW7dCqiiHyBHiizyV0+M6p17itwTpzHv/T0/mcXyYWE="; }; + # abseil-cpp tries to build for both aarch64 and x86_64, which fails due to passing unrecognized flags. + # Only build for the host platform instead. + postPatch = lib.optionalString stdenv.isDarwin '' + substituteInPlace absl/copts/AbseilConfigureCopts.cmake \ + --replace-fail 'APPLE AND CMAKE_CXX_COMPILER_ID MATCHES [[Clang]]' 'false' + ''; + cmakeFlags = [ "-DABSL_BUILD_TEST_HELPERS=ON" "-DABSL_USE_EXTERNAL_GOOGLETEST=ON" diff --git a/pkgs/development/libraries/abseil-cpp/202401.nix b/pkgs/development/libraries/abseil-cpp/202401.nix index 73e663b0d0c6f..a68db64555863 100644 --- a/pkgs/development/libraries/abseil-cpp/202401.nix +++ b/pkgs/development/libraries/abseil-cpp/202401.nix @@ -18,6 +18,13 @@ stdenv.mkDerivation (finalAttrs: { hash = "sha256-eA2/dZpNOlex1O5PNa3XSZhpMB3AmaIoHzVDI9TD/cg="; }; + # abseil-cpp tries to build for both aarch64 and x86_64, which fails due to passing unrecognized flags. + # Only build for the host platform instead. + postPatch = lib.optionalString stdenv.isDarwin '' + substituteInPlace absl/copts/AbseilConfigureCopts.cmake \ + --replace-fail 'APPLE AND CMAKE_CXX_COMPILER_ID MATCHES [[Clang]]' 'false' + ''; + cmakeFlags = [ "-DABSL_BUILD_TEST_HELPERS=ON" "-DABSL_USE_EXTERNAL_GOOGLETEST=ON" diff --git a/pkgs/development/libraries/boost/generic.nix b/pkgs/development/libraries/boost/generic.nix index 3db9b77bf05d5..c9be84a3d4a0b 100644 --- a/pkgs/development/libraries/boost/generic.nix +++ b/pkgs/development/libraries/boost/generic.nix @@ -178,6 +178,8 @@ stdenv.mkDerivation { cat << EOF >> user-config.jam using clang-darwin : : ${stdenv.cc.targetPrefix}c++ : "-rpath $out/lib/" + $AR + $RANLIB ; EOF '' diff --git a/pkgs/development/libraries/catboost/default.nix b/pkgs/development/libraries/catboost/default.nix index b4fa78a125265..3824cf046b95a 100644 --- a/pkgs/development/libraries/catboost/default.nix +++ b/pkgs/development/libraries/catboost/default.nix @@ -2,7 +2,7 @@ , config , fetchFromGitHub , cmake -, darwin +, cctools , libiconv , llvmPackages , ninja @@ -60,7 +60,7 @@ stdenv.mkDerivation (finalAttrs: { ragel yasm ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ - darwin.cctools + cctools ] ++ lib.optionals cudaSupport (with cudaPackages; [ cuda_nvcc ]); diff --git a/pkgs/development/libraries/freeimage/default.nix b/pkgs/development/libraries/freeimage/default.nix index 245ea93f63e40..4f5f42582c57c 100644 --- a/pkgs/development/libraries/freeimage/default.nix +++ b/pkgs/development/libraries/freeimage/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, fetchsvn, darwin, libtiff +{ lib, stdenv, fetchsvn, cctools, libtiff , libpng, zlib, libwebp, libraw, openexr, openjpeg , libjpeg, jxrlib, pkg-config , fixDarwinDylibNames, autoSignDarwinBinariesHook }: @@ -38,7 +38,7 @@ stdenv.mkDerivation (finalAttrs: { nativeBuildInputs = [ pkg-config ] ++ lib.optionals stdenv.isDarwin [ - darwin.cctools + cctools fixDarwinDylibNames ] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [ autoSignDarwinBinariesHook diff --git a/pkgs/development/libraries/gstreamer/core/default.nix b/pkgs/development/libraries/gstreamer/core/default.nix index eb9231155b80a..27c8820f61c79 100644 --- a/pkgs/development/libraries/gstreamer/core/default.nix +++ b/pkgs/development/libraries/gstreamer/core/default.nix @@ -66,9 +66,9 @@ stdenv.mkDerivation (finalAttrs: { buildInputs = [ bash-completion + libunwind ] ++ lib.optionals stdenv.isLinux [ libcap - libunwind ] ++ lib.optionals (lib.meta.availableOn stdenv.hostPlatform elfutils) [ elfutils ] ++ lib.optionals stdenv.isDarwin [ @@ -85,8 +85,6 @@ stdenv.mkDerivation (finalAttrs: { "-Dexamples=disabled" # requires many dependencies and probably not useful for our users (lib.mesonEnable "doc" enableDocumentation) ] ++ lib.optionals stdenv.isDarwin [ - # darwin.libunwind doesn't have pkg-config definitions so meson doesn't detect it. - "-Dlibunwind=disabled" "-Dlibdw=disabled" ]; diff --git a/pkgs/development/libraries/http-parser/default.nix b/pkgs/development/libraries/http-parser/default.nix index 65ac1fe92c130..837ad22b0b83a 100644 --- a/pkgs/development/libraries/http-parser/default.nix +++ b/pkgs/development/libraries/http-parser/default.nix @@ -30,7 +30,7 @@ stdenv.mkDerivation rec { "DESTDIR=" "PREFIX=$(out)" "BINEXT=${stdenv.hostPlatform.extensions.executable}" - "Platform=${lib.toLower stdenv.hostPlatform.uname.system}" + "PLATFORM=${lib.toLower stdenv.hostPlatform.uname.system}" "AEXT=${lib.strings.removePrefix "." stdenv.hostPlatform.extensions.staticLibrary}" "ENABLE_SHARED=${if enableShared then "1" else "0"}" "ENABLE_STATIC=${if enableStatic then "1" else "0"}" diff --git a/pkgs/development/libraries/libmcrypt/default.nix b/pkgs/development/libraries/libmcrypt/default.nix index 672ba730be12b..6a4b0adfefb4f 100644 --- a/pkgs/development/libraries/libmcrypt/default.nix +++ b/pkgs/development/libraries/libmcrypt/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, fetchurl, darwin, disablePosixThreads ? false }: +{ lib, stdenv, fetchurl, cctools, disablePosixThreads ? false }: stdenv.mkDerivation rec { pname = "libmcrypt"; @@ -9,7 +9,7 @@ stdenv.mkDerivation rec { sha256 = "0gipgb939vy9m66d3k8il98rvvwczyaw2ixr8yn6icds9c3nrsz4"; }; - buildInputs = lib.optional stdenv.isDarwin darwin.cctools; + buildInputs = lib.optional stdenv.isDarwin cctools; configureFlags = lib.optionals disablePosixThreads [ "--disable-posix-threads" ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ diff --git a/pkgs/development/libraries/libplacebo/default.nix b/pkgs/development/libraries/libplacebo/default.nix index 5759d9bed505b..4a33828f81fec 100644 --- a/pkgs/development/libraries/libplacebo/default.nix +++ b/pkgs/development/libraries/libplacebo/default.nix @@ -59,8 +59,6 @@ stdenv.mkDerivation rec { (mesonEnable "glslang" false) # rely on shaderc for GLSL compilation instead (mesonEnable "vk-proc-addr" vulkanSupport) (mesonOption "vulkan-registry" "${vulkan-headers}/share/vulkan/registry/vk.xml") - ] ++ optionals stdenv.isDarwin [ - (mesonEnable "unwind" false) # libplacebo doesn’t build with `darwin.libunwind` ]; postPatch = '' diff --git a/pkgs/development/libraries/libpsl/default.nix b/pkgs/development/libraries/libpsl/default.nix index a8fcd2581caa5..dea39d2c29eb9 100644 --- a/pkgs/development/libraries/libpsl/default.nix +++ b/pkgs/development/libraries/libpsl/default.nix @@ -3,6 +3,7 @@ , autoreconfHook , docbook_xsl , docbook_xml_dtd_43 +, gettext , gtk-doc , lzip , libidn2 @@ -38,6 +39,7 @@ stdenv.mkDerivation rec { ]; buildInputs = [ + gettext libidn2 libunistring libxslt diff --git a/pkgs/development/libraries/librsvg/default.nix b/pkgs/development/libraries/librsvg/default.nix index a682b39bbcd80..b2108411aa540 100644 --- a/pkgs/development/libraries/librsvg/default.nix +++ b/pkgs/development/libraries/librsvg/default.nix @@ -113,9 +113,8 @@ stdenv.mkDerivation (finalAttrs: { ${lib.optionalString (stdenv.hostPlatform.emulatorAvailable buildPackages) (stdenv.hostPlatform.emulator buildPackages)} ${lib.getDev gdk-pixbuf}/bin/gdk-pixbuf-query-loaders ''; - # librsvg only links Foundation, but it also requiers libobjc. The Framework.tbd in the 11.0 SDK - # reexports libobjc, but the one in the 10.12 SDK does not, so link it manually. - env = lib.optionalAttrs (stdenv.isDarwin && stdenv.isx86_64) { + # librsvg only links Foundation, but it also requiers libobjc. + env = lib.optionalAttrs stdenv.isDarwin { NIX_LDFLAGS = "-lobjc"; }; diff --git a/pkgs/development/libraries/nss/generic.nix b/pkgs/development/libraries/nss/generic.nix index cab8a0ff2bc10..ab47134e244dc 100644 --- a/pkgs/development/libraries/nss/generic.nix +++ b/pkgs/development/libraries/nss/generic.nix @@ -7,7 +7,7 @@ , zlib , sqlite , ninja -, darwin +, cctools , fixDarwinDylibNames , buildPackages , useP11kit ? true @@ -36,7 +36,7 @@ stdenv.mkDerivation rec { depsBuildBuild = [ buildPackages.stdenv.cc ]; nativeBuildInputs = [ perl ninja (buildPackages.python3.withPackages (ps: with ps; [ gyp ])) ] - ++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.cctools fixDarwinDylibNames ]; + ++ lib.optionals stdenv.hostPlatform.isDarwin [ cctools fixDarwinDylibNames ]; buildInputs = [ zlib sqlite ]; diff --git a/pkgs/development/libraries/qt-5/5.15/default.nix b/pkgs/development/libraries/qt-5/5.15/default.nix index a8885fc5647bc..4269d451599c2 100644 --- a/pkgs/development/libraries/qt-5/5.15/default.nix +++ b/pkgs/development/libraries/qt-5/5.15/default.nix @@ -325,8 +325,8 @@ let rm -r src/3rdparty/chromium/third_party/catapult cp -r ${srcs.catapult} src/3rdparty/chromium/third_party/catapult ''; - inherit (darwin) cctools xnu; - inherit (darwin.apple_sdk_11_0) libpm libunwind; + inherit (darwin) xnu; + inherit (darwin.apple_sdk_11_0) libpm; inherit (darwin.apple_sdk_11_0.libs) sandbox; inherit (darwin.apple_sdk_11_0.frameworks) ApplicationServices AVFoundation Foundation ForceFeedback GameController AppKit ImageCaptureCore CoreBluetooth IOBluetooth CoreWLAN Quartz Cocoa LocalAuthentication diff --git a/pkgs/development/libraries/qt-6/default.nix b/pkgs/development/libraries/qt-6/default.nix index c724bd21d11ff..b4241bbca26c5 100644 --- a/pkgs/development/libraries/qt-6/default.nix +++ b/pkgs/development/libraries/qt-6/default.nix @@ -152,8 +152,8 @@ let qtwayland = callPackage ./modules/qtwayland.nix { }; qtwebchannel = callPackage ./modules/qtwebchannel.nix { }; qtwebengine = callPackage ./modules/qtwebengine.nix { - inherit (darwin) autoSignDarwinBinariesHook bootstrap_cmds cctools xnu; - inherit (darwin.apple_sdk_11_0) libpm libunwind; + inherit (darwin) autoSignDarwinBinariesHook bootstrap_cmds xnu; + inherit (darwin.apple_sdk_11_0) libpm; inherit (darwin.apple_sdk_11_0.libs) sandbox; inherit (darwin.apple_sdk_11_0.frameworks) AGL AVFoundation Accelerate Cocoa CoreLocation CoreML ForceFeedback diff --git a/pkgs/development/libraries/science/math/mkl/default.nix b/pkgs/development/libraries/science/math/mkl/default.nix index 90e6c05da77d0..607b6c89e40d1 100644 --- a/pkgs/development/libraries/science/math/mkl/default.nix +++ b/pkgs/development/libraries/science/math/mkl/default.nix @@ -5,7 +5,7 @@ , fetchurl , rpmextract , _7zz -, darwin +, cctools , validatePkgConfig , enableStatic ? stdenv.hostPlatform.isStatic }: @@ -72,7 +72,7 @@ in stdenvNoCC.mkDerivation ({ nativeBuildInputs = [ validatePkgConfig ] ++ (if stdenvNoCC.isDarwin then - [ _7zz darwin.cctools ] + [ _7zz cctools ] else [ rpmextract ]); diff --git a/pkgs/development/libraries/science/math/petsc/default.nix b/pkgs/development/libraries/science/math/petsc/default.nix index c07250c660a33..bc5f7fe14a9be 100644 --- a/pkgs/development/libraries/science/math/petsc/default.nix +++ b/pkgs/development/libraries/science/math/petsc/default.nix @@ -1,7 +1,7 @@ { lib , stdenv , fetchurl -, darwin +, cctools , gfortran , python3 , blas @@ -43,7 +43,7 @@ stdenv.mkDerivation rec { prePatch = lib.optionalString stdenv.isDarwin '' substituteInPlace config/install.py \ - --replace /usr/bin/install_name_tool ${darwin.cctools}/bin/install_name_tool + --replace /usr/bin/install_name_tool ${cctools}/bin/install_name_tool ''; # Both OpenMPI and MPICH get confused by the sandbox environment and spew errors like this (both to stdout and stderr): diff --git a/pkgs/development/node-packages/composition.nix b/pkgs/development/node-packages/composition.nix index d9c0daef7834c..f615ffbf296d8 100644 --- a/pkgs/development/node-packages/composition.nix +++ b/pkgs/development/node-packages/composition.nix @@ -8,7 +8,7 @@ let nodeEnv = import ./node-env.nix { inherit (pkgs) stdenv lib python2 runCommand writeTextFile writeShellScript; inherit pkgs nodejs; - libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null; + libtool = if pkgs.stdenv.isDarwin then pkgs.cctools else null; }; in import ./node-packages.nix { diff --git a/pkgs/development/python-modules/cffi/default.nix b/pkgs/development/python-modules/cffi/default.nix index 7d03ab82c7bca..41d632d90393c 100644 --- a/pkgs/development/python-modules/cffi/default.nix +++ b/pkgs/development/python-modules/cffi/default.nix @@ -12,6 +12,9 @@ pythonAtLeast, }: +let + ccVersion = lib.getVersion stdenv.cc; +in if isPyPy then null else @@ -39,9 +42,9 @@ else # ./darwin-use-libffi-closures.diff ] - ++ lib.optionals (stdenv.cc.isClang && lib.versionAtLeast (lib.getVersion stdenv.cc) "13") [ + ++ lib.optionals (stdenv.cc.isClang && (ccVersion == "boot" || lib.versionAtLeast (lib.getVersion stdenv.cc) "13")) [ # -Wnull-pointer-subtraction is enabled with -Wextra. Suppress it to allow the following tests - # to run and pass when cffi is built with newer versions of clang: + # to run and pass when cffi is built with newer versions of clang (including the bootstrap tools clang on Darwin): # - testing/cffi1/test_verify1.py::test_enum_usage # - testing/cffi1/test_verify1.py::test_named_pointer_as_argument ./clang-pointer-substraction-warning.diff diff --git a/pkgs/development/python-modules/cocotb/default.nix b/pkgs/development/python-modules/cocotb/default.nix index f65b11c81ce2b..6e6410b4ab465 100644 --- a/pkgs/development/python-modules/cocotb/default.nix +++ b/pkgs/development/python-modules/cocotb/default.nix @@ -45,11 +45,6 @@ buildPythonPackage rec { # remove circular dependency cocotb-bus from setup.py substituteInPlace setup.py --replace "'cocotb-bus<1.0'" "" - '' - + lib.optionalString stdenv.isDarwin '' - # disable lto on darwin - # https://github.com/NixOS/nixpkgs/issues/19098 - substituteInPlace cocotb_build_libs.py --replace "-flto" "" ''; patches = [ diff --git a/pkgs/development/python-modules/levenshtein/default.nix b/pkgs/development/python-modules/levenshtein/default.nix index a7913fd5b0970..4f04a810bd5e5 100644 --- a/pkgs/development/python-modules/levenshtein/default.nix +++ b/pkgs/development/python-modules/levenshtein/default.nix @@ -37,12 +37,6 @@ buildPythonPackage rec { buildInputs = [ rapidfuzz-cpp ]; - env.NIX_CFLAGS_COMPILE = toString ( - lib.optionals (stdenv.cc.isClang && stdenv.isDarwin) [ - "-fno-lto" # work around https://github.com/NixOS/nixpkgs/issues/19098 - ] - ); - dependencies = [ rapidfuzz ]; nativeCheckInputs = [ pytestCheckHook ]; diff --git a/pkgs/development/python-modules/rapidfuzz/default.nix b/pkgs/development/python-modules/rapidfuzz/default.nix index 747611f2b17b0..08cfc8113db4c 100644 --- a/pkgs/development/python-modules/rapidfuzz/default.nix +++ b/pkgs/development/python-modules/rapidfuzz/default.nix @@ -59,12 +59,6 @@ buildPythonPackage rec { export CMAKE_ARGS="-DCMAKE_CXX_COMPILER_AR=$AR -DCMAKE_CXX_COMPILER_RANLIB=$RANLIB" ''; - env.NIX_CFLAGS_COMPILE = toString ( - lib.optionals (stdenv.cc.isClang && stdenv.isDarwin) [ - "-fno-lto" # work around https://github.com/NixOS/nixpkgs/issues/19098 - ] - ); - passthru.optional-dependencies = { full = [ numpy ]; }; diff --git a/pkgs/development/r-modules/default.nix b/pkgs/development/r-modules/default.nix index 8d4004d7580f3..2f3e03b2512f5 100644 --- a/pkgs/development/r-modules/default.nix +++ b/pkgs/development/r-modules/default.nix @@ -1294,7 +1294,7 @@ let pbdZMQ = old.pbdZMQ.overrideAttrs (attrs: { postPatch = lib.optionalString stdenv.isDarwin '' for file in R/*.{r,r.in}; do - sed -i 's#system("which \(\w\+\)"[^)]*)#"${pkgs.darwin.cctools}/bin/\1"#g' $file + sed -i 's#system("which \(\w\+\)"[^)]*)#"${pkgs.cctools}/bin/\1"#g' $file done ''; }); diff --git a/pkgs/development/ruby-modules/gem-config/default.nix b/pkgs/development/ruby-modules/gem-config/default.nix index 3a64f7d2fd9d1..9601169c69f07 100644 --- a/pkgs/development/ruby-modules/gem-config/default.nix +++ b/pkgs/development/ruby-modules/gem-config/default.nix @@ -783,10 +783,7 @@ in substituteInPlace lib/sassc/native.rb \ --replace 'gem_root = spec.gem_dir' 'gem_root = File.join(__dir__, "../../")' ''; - } // (lib.optionalAttrs stdenv.isDarwin { - # https://github.com/NixOS/nixpkgs/issues/19098 - buildFlags = [ "--disable-lto" ]; - }); + }; sass-embedded = attrs: { # Patch the Rakefile to use our dart-sass and not try to fetch anything. diff --git a/pkgs/development/tools/boost-build/default.nix b/pkgs/development/tools/boost-build/default.nix index 6b485b80ea1c0..72d927de42c5d 100644 --- a/pkgs/development/tools/boost-build/default.nix +++ b/pkgs/development/tools/boost-build/default.nix @@ -39,6 +39,9 @@ stdenv.mkDerivation { postPatch = '' substituteInPlace src/build-system.jam \ --replace "default-toolset = darwin" "default-toolset = clang-darwin" + # Upstream uses arm64, but nixpkgs uses aarch64. + substituteInPlace src/tools/clang.jam \ + --replace-fail 'arch = arm64' 'arch = aarch64' '' + lib.optionalString (useBoost ? version && lib.versionAtLeast useBoost.version "1.82") '' patchShebangs --build src/engine/build.sh ''; diff --git a/pkgs/development/tools/build-managers/bazel/bazel_7/cpp-test.nix b/pkgs/development/tools/build-managers/bazel/bazel_7/cpp-test.nix index 1761358c263e6..52cb24397b4a8 100644 --- a/pkgs/development/tools/build-managers/bazel/bazel_7/cpp-test.nix +++ b/pkgs/development/tools/build-managers/bazel/bazel_7/cpp-test.nix @@ -3,7 +3,8 @@ , bazel-examples , bazelTest , callPackage -, darwin +, cctools +, ld64 , distDir , extraBazelArgs ? "" , Foundation ? null @@ -37,8 +38,8 @@ let #! ${runtimeShell} export CXX='${stdenv.cc}/bin/clang++' - export LD='${darwin.cctools}/bin/ld' - export LIBTOOL='${darwin.cctools}/bin/libtool' + export LD='${ld64}/bin/ld' + export LIBTOOL='${cctools}/bin/libtool' export CC='${stdenv.cc}/bin/clang' # XXX: hack for macosX, this flags disable bazel usage of xcode diff --git a/pkgs/development/tools/build-managers/bazel/bazel_7/java-test.nix b/pkgs/development/tools/build-managers/bazel/bazel_7/java-test.nix index 2b231dc52a6e7..119554da42a1e 100644 --- a/pkgs/development/tools/build-managers/bazel/bazel_7/java-test.nix +++ b/pkgs/development/tools/build-managers/bazel/bazel_7/java-test.nix @@ -4,7 +4,8 @@ , stdenv , symlinkJoin , callPackage -, darwin +, cctools +, ld64 , extraBazelArgs ? "" , lib , openjdk8 @@ -38,8 +39,8 @@ let #! ${runtimeShell} export CXX='${stdenv.cc}/bin/clang++' - export LD='${darwin.cctools}/bin/ld' - export LIBTOOL='${darwin.cctools}/bin/libtool' + export LD='${ld64}/bin/ld' + export LIBTOOL='${cctools}/bin/libtool' export CC='${stdenv.cc}/bin/clang' # XXX: hack for macosX, this flags disable bazel usage of xcode diff --git a/pkgs/development/tools/build-managers/bazel/bazel_7/protobuf-test.nix b/pkgs/development/tools/build-managers/bazel/bazel_7/protobuf-test.nix index 6658c0d5b0ed5..84d28d9d2faa3 100644 --- a/pkgs/development/tools/build-managers/bazel/bazel_7/protobuf-test.nix +++ b/pkgs/development/tools/build-managers/bazel/bazel_7/protobuf-test.nix @@ -2,7 +2,8 @@ , Foundation , bazelTest , callPackage -, darwin +, cctools +, ld64 , distDir , extraBazelArgs ? "" , fetchFromGitHub @@ -98,8 +99,8 @@ let #! ${runtimeShell} export CXX='${stdenv.cc}/bin/clang++' - export LD='${darwin.cctools}/bin/ld' - export LIBTOOL='${darwin.cctools}/bin/libtool' + export LD='${ld64}/bin/ld' + export LIBTOOL='${cctools}/bin/libtool' export CC='${stdenv.cc}/bin/clang' # XXX: hack for macosX, this flags disable bazel usage of xcode diff --git a/pkgs/development/tools/build-managers/bazel/cpp-test.nix b/pkgs/development/tools/build-managers/bazel/cpp-test.nix index 7b0e2a5d01bf3..1d06ca02d6988 100644 --- a/pkgs/development/tools/build-managers/bazel/cpp-test.nix +++ b/pkgs/development/tools/build-managers/bazel/cpp-test.nix @@ -3,7 +3,8 @@ , bazelTest , bazel-examples , stdenv -, darwin +, cctools +, ld64 , extraBazelArgs ? "" , lib , runLocal @@ -20,8 +21,8 @@ let #! ${runtimeShell} export CXX='${stdenv.cc}/bin/clang++' - export LD='${darwin.cctools}/bin/ld' - export LIBTOOL='${darwin.cctools}/bin/libtool' + export LD='${ld64}/bin/ld' + export LIBTOOL='${cctools}/bin/libtool' export CC='${stdenv.cc}/bin/clang' # XXX: hack for macosX, this flags disable bazel usage of xcode diff --git a/pkgs/development/tools/build-managers/bazel/java-test.nix b/pkgs/development/tools/build-managers/bazel/java-test.nix index ed4711f4027f9..418a470e89085 100644 --- a/pkgs/development/tools/build-managers/bazel/java-test.nix +++ b/pkgs/development/tools/build-managers/bazel/java-test.nix @@ -2,7 +2,8 @@ , bazelTest , bazel-examples , stdenv -, darwin +, cctools +, ld64 , extraBazelArgs ? "" , lib , openjdk8 @@ -20,8 +21,8 @@ let #! ${runtimeShell} export CXX='${stdenv.cc}/bin/clang++' - export LD='${darwin.cctools}/bin/ld' - export LIBTOOL='${darwin.cctools}/bin/libtool' + export LD='${ld64}/bin/ld' + export LIBTOOL='${cctools}/bin/libtool' export CC='${stdenv.cc}/bin/clang' # XXX: hack for macosX, this flags disable bazel usage of xcode diff --git a/pkgs/development/tools/build-managers/bazel/protobuf-test.nix b/pkgs/development/tools/build-managers/bazel/protobuf-test.nix index 963bad679c50c..a142fec4b30b2 100644 --- a/pkgs/development/tools/build-managers/bazel/protobuf-test.nix +++ b/pkgs/development/tools/build-managers/bazel/protobuf-test.nix @@ -4,7 +4,8 @@ , fetchFromGitHub , fetchurl , stdenv -, darwin +, cctools +, ld64 , lib , openjdk8 , jdk11_headless @@ -134,8 +135,8 @@ let #! ${runtimeShell} export CXX='${stdenv.cc}/bin/clang++' - export LD='${darwin.cctools}/bin/ld' - export LIBTOOL='${darwin.cctools}/bin/libtool' + export LD='${ld64}/bin/ld' + export LIBTOOL='${cctools}/bin/libtool' export CC='${stdenv.cc}/bin/clang' # XXX: hack for macosX, this flags disable bazel usage of xcode diff --git a/pkgs/development/tools/build-managers/bazel/python-bin-path-test.nix b/pkgs/development/tools/build-managers/bazel/python-bin-path-test.nix index 2538a2ae074ad..c948f15c9548b 100644 --- a/pkgs/development/tools/build-managers/bazel/python-bin-path-test.nix +++ b/pkgs/development/tools/build-managers/bazel/python-bin-path-test.nix @@ -2,7 +2,8 @@ bazel , bazelTest , stdenv -, darwin +, cctools +, ld64 , extraBazelArgs ? "" , lib , runLocal @@ -17,8 +18,8 @@ let #! ${runtimeShell} export CXX='${stdenv.cc}/bin/clang++' - export LD='${darwin.cctools}/bin/ld' - export LIBTOOL='${darwin.cctools}/bin/libtool' + export LD='${ld64}/bin/ld' + export LIBTOOL='${cctools}/bin/libtool' export CC='${stdenv.cc}/bin/clang' # XXX: hack for macosX, this flags disable bazel usage of xcode diff --git a/pkgs/development/tools/build-managers/gn/generic.nix b/pkgs/development/tools/build-managers/gn/generic.nix index dab03ebfb7581..20021ccabb31c 100644 --- a/pkgs/development/tools/build-managers/gn/generic.nix +++ b/pkgs/development/tools/build-managers/gn/generic.nix @@ -1,4 +1,4 @@ -{ stdenv, lib, fetchgit, darwin, writeText +{ stdenv, lib, fetchgit, cctools, darwin, writeText , ninja, python3 , ... }: diff --git a/pkgs/development/tools/nodehun/default.nix b/pkgs/development/tools/nodehun/default.nix index cef41d9187912..08e7e05b04bc1 100644 --- a/pkgs/development/tools/nodehun/default.nix +++ b/pkgs/development/tools/nodehun/default.nix @@ -1,4 +1,5 @@ { buildNpmPackage +, cctools , darwin , fetchFromGitHub , lib @@ -31,7 +32,7 @@ buildNpmPackage { buildInputs = lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.CoreServices ]; nativeBuildInputs = [ nodePackages.node-gyp python3 ] - ++ lib.optionals stdenv.isDarwin [ darwin.cctools ]; + ++ lib.optionals stdenv.isDarwin [ cctools ]; postInstall = '' # Only keep the necessary parts of build/Release to reduce closure size diff --git a/pkgs/development/tools/rcodesign/default.nix b/pkgs/development/tools/rcodesign/default.nix index e3999ebff952d..c1874168434b2 100644 --- a/pkgs/development/tools/rcodesign/default.nix +++ b/pkgs/development/tools/rcodesign/default.nix @@ -31,6 +31,10 @@ rustPlatform.buildRustPackage rec { checkFlags = [ # Does network IO "--skip=ticket_lookup::test::lookup_ticket" + # Impurely access system Xcode installations + "--skip=parsed_sdk::test::find_all_sdks" + "--skip=simple_sdk::test::find_all_sdks" + "--skip=test::find_all_platform_directories" ]; meta = with lib; { diff --git a/pkgs/development/tools/tracy/default.nix b/pkgs/development/tools/tracy/default.nix index 4c86ea2fb9cbe..bc0582811be28 100644 --- a/pkgs/development/tools/tracy/default.nix +++ b/pkgs/development/tools/tracy/default.nix @@ -49,9 +49,7 @@ stdenv.mkDerivation rec { # ../../../server/TracyView.cpp:649:34, preventing building. ++ lib.optional stdenv.isDarwin "-Wno-format-security" ++ lib.optional stdenv.isLinux "-ltbb" - ++ lib.optional stdenv.cc.isClang "-faligned-allocation" - # workaround issue #19098 - ++ lib.optional (stdenv.cc.isClang && stdenv.isDarwin) "-fno-lto"); + ++ lib.optional stdenv.cc.isClang "-faligned-allocation"); buildPhase = '' runHook preBuild diff --git a/pkgs/development/tools/xcbuild/toolchains.nix b/pkgs/development/tools/xcbuild/toolchains.nix index e0abf90847fc8..a5e8ed28ce1e5 100644 --- a/pkgs/development/tools/xcbuild/toolchains.nix +++ b/pkgs/development/tools/xcbuild/toolchains.nix @@ -60,7 +60,7 @@ runCommand "Toolchains" {} ('' ln -s ${buildPackages.indent}/bin/indent $toolchain/bin/indent ln -s ${buildPackages.ctags}/bin/ctags $toolchain/bin/ctags '' + optionalString stdenv.isDarwin '' - for bin in ${getBin buildPackages.darwin.cctools}/bin/*; do + for bin in ${getBin buildPackages.cctools}/bin/*; do if ! [ -e "$toolchain/bin/$(basename $bin)" ]; then ln -s $bin $toolchain/bin fi diff --git a/pkgs/development/web/netlify-cli/composition.nix b/pkgs/development/web/netlify-cli/composition.nix index d9c0daef7834c..f615ffbf296d8 100644 --- a/pkgs/development/web/netlify-cli/composition.nix +++ b/pkgs/development/web/netlify-cli/composition.nix @@ -8,7 +8,7 @@ let nodeEnv = import ./node-env.nix { inherit (pkgs) stdenv lib python2 runCommand writeTextFile writeShellScript; inherit pkgs nodejs; - libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null; + libtool = if pkgs.stdenv.isDarwin then pkgs.cctools else null; }; in import ./node-packages.nix { diff --git a/pkgs/development/web/playwright-test/default.nix b/pkgs/development/web/playwright-test/default.nix index d9c0daef7834c..f615ffbf296d8 100644 --- a/pkgs/development/web/playwright-test/default.nix +++ b/pkgs/development/web/playwright-test/default.nix @@ -8,7 +8,7 @@ let nodeEnv = import ./node-env.nix { inherit (pkgs) stdenv lib python2 runCommand writeTextFile writeShellScript; inherit pkgs nodejs; - libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null; + libtool = if pkgs.stdenv.isDarwin then pkgs.cctools else null; }; in import ./node-packages.nix { diff --git a/pkgs/games/eduke32/default.nix b/pkgs/games/eduke32/default.nix index 5bb9966602d85..740d0bc47ea75 100644 --- a/pkgs/games/eduke32/default.nix +++ b/pkgs/games/eduke32/default.nix @@ -83,9 +83,6 @@ in stdenv.mkDerivation (finalAttrs: { makeFlags = [ "SDLCONFIG=${SDL2}/bin/sdl2-config" - ] ++ lib.optionals stdenv.isDarwin [ - # broken, see: https://github.com/NixOS/nixpkgs/issues/19098 - "LTO=0" ]; buildFlags = [ diff --git a/pkgs/games/stockfish/default.nix b/pkgs/games/stockfish/default.nix index 74eff702add19..2e6d142b7148a 100644 --- a/pkgs/games/stockfish/default.nix +++ b/pkgs/games/stockfish/default.nix @@ -30,12 +30,6 @@ stdenv.mkDerivation rec { sha256 = "sha256-ASy2vIP94lnSKgxixK1GoC84yAysaJpxeyuggV4MrP4="; }; - # This addresses a linker issue with Darwin - # https://github.com/NixOS/nixpkgs/issues/19098 - preBuild = lib.optionalString stdenv.isDarwin '' - sed -i.orig '/^\#\#\# 3.*Link Time Optimization/,/^\#\#\# 3/d' Makefile - ''; - postUnpack = '' sourceRoot+=/src echo ${nnue} diff --git a/pkgs/misc/base16-builder/node-packages.nix b/pkgs/misc/base16-builder/node-packages.nix index 2bf491c2e6652..50fc38ae90e94 100644 --- a/pkgs/misc/base16-builder/node-packages.nix +++ b/pkgs/misc/base16-builder/node-packages.nix @@ -12,7 +12,7 @@ let nodeEnv = import ../../development/node-packages/node-env.nix { inherit (pkgs) stdenv lib python2 runCommand writeTextFile writeShellScript; inherit pkgs nodejs; - libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null; + libtool = if pkgs.stdenv.isDarwin then pkgs.cctools else null; }; in import ./node-packages-generated.nix { diff --git a/pkgs/os-specific/bsd/netbsd/default.nix b/pkgs/os-specific/bsd/netbsd/default.nix index e0d03108960c0..f30bf945c8415 100644 --- a/pkgs/os-specific/bsd/netbsd/default.nix +++ b/pkgs/os-specific/bsd/netbsd/default.nix @@ -60,7 +60,7 @@ makeScopeWithSplicing' { compat = self.callPackage ./pkgs/compat/package.nix { inherit (buildPackages) coreutils; - inherit (buildPackages.darwin) cctools-port; + inherit (buildPackages) cctools; inherit (buildPackages.buildPackages) rsync; inherit (buildPackages.netbsd) makeMinimal; inherit (self) diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/compat/package.nix b/pkgs/os-specific/bsd/netbsd/pkgs/compat/package.nix index 4c149e95c1ae6..b31dcd6946497 100644 --- a/pkgs/os-specific/bsd/netbsd/pkgs/compat/package.nix +++ b/pkgs/os-specific/bsd/netbsd/pkgs/compat/package.nix @@ -5,7 +5,7 @@ zlib, defaultMakeFlags, coreutils, - cctools-port, + cctools, include, libc, libutil, @@ -76,7 +76,7 @@ mkDerivation ( ++ lib.optionals stdenv.hostPlatform.isDarwin [ # GNU objcopy produces broken .a libs which won't link into dependers. # Makefiles only invoke `$OBJCOPY -x/-X`, so cctools strip works here. - "OBJCOPY=${cctools-port}/bin/strip" + "OBJCOPY=${cctools}/bin/strip" ]; RENAME = "-D"; 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 fdc3bd45e55ee..0521e681deb83 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 @@ -214,10 +214,6 @@ in rec { # Overrides for framework derivations. overrides = super: { - CoreFoundation = lib.overrideDerivation super.CoreFoundation (drv: { - setupHook = ./cf-setup-hook.sh; - }); - # This framework doesn't exist in newer SDKs (somewhere around 10.13), but # there are references to it in nixpkgs. QuickTime = throw "QuickTime framework not available"; 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 deleted file mode 100644 index b64eb95f2ded7..0000000000000 --- a/pkgs/os-specific/darwin/apple-sdk-11.0/cf-setup-hook.sh +++ /dev/null @@ -1,6 +0,0 @@ -forceLinkCoreFoundationFramework() { - NIX_CFLAGS_COMPILE="-F@out@/Library/Frameworks${NIX_CFLAGS_COMPILE:+ }${NIX_CFLAGS_COMPILE-}" - NIX_LDFLAGS+=" @out@/Library/Frameworks/CoreFoundation.framework/CoreFoundation.tbd" -} - -preConfigureHooks+=(forceLinkCoreFoundationFramework) diff --git a/pkgs/os-specific/darwin/apple-sdk-11.0/default.nix b/pkgs/os-specific/darwin/apple-sdk-11.0/default.nix index 238c1b7e460b0..e246512ecef21 100644 --- a/pkgs/os-specific/darwin/apple-sdk-11.0/default.nix +++ b/pkgs/os-specific/darwin/apple-sdk-11.0/default.nix @@ -90,6 +90,11 @@ let packages = stdenvs // { inherit (callPackage ./apple_sdk.nix { }) frameworks libs; + libunwind = ( + pkgs.darwin.libunwind + or lib.throw "darwin.apple_sdk_11_0.libunwind has been removed, please use libunwind instead" + ); + # 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 CLTools_Executables; @@ -98,7 +103,6 @@ let LibsystemCross = pkgs.darwin.Libsystem; libcharset = callPackage ./libcharset.nix { }; libcompression = callPackage ./libcompression.nix { }; - libunwind = callPackage ./libunwind.nix { }; libnetwork = callPackage ./libnetwork.nix { }; libpm = callPackage ./libpm.nix { }; # Avoid introducing a new objc4 if stdenv already has one, to prevent @@ -137,7 +141,6 @@ let Security configd libcharset - libunwind objc4 ; apple_sdk = prev.darwin.apple_sdk_11_0; diff --git a/pkgs/os-specific/darwin/apple-sdk-11.0/libSystem.nix b/pkgs/os-specific/darwin/apple-sdk-11.0/libSystem.nix index b661da75febe6..9f212f069b61e 100644 --- a/pkgs/os-specific/darwin/apple-sdk-11.0/libSystem.nix +++ b/pkgs/os-specific/darwin/apple-sdk-11.0/libSystem.nix @@ -1,4 +1,11 @@ -{ stdenvNoCC, buildPackages, MacOSX-SDK }: +{ stdenvNoCC +, MacOSX-SDK +, buildPackages +# These are included for compatibility with the 10.12 SDK Libsystem derivation, so that the +# bootstrap stdenv can override these unconditionally. +, withCsu ? null +, withLibresolv ? null +}: stdenvNoCC.mkDerivation { pname = "libSystem"; diff --git a/pkgs/os-specific/darwin/apple-sdk-11.0/libunwind.nix b/pkgs/os-specific/darwin/apple-sdk-11.0/libunwind.nix deleted file mode 100644 index 885780eba75cd..0000000000000 --- a/pkgs/os-specific/darwin/apple-sdk-11.0/libunwind.nix +++ /dev/null @@ -1,24 +0,0 @@ -{ 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/cf-setup-hook.sh b/pkgs/os-specific/darwin/apple-sdk/cf-setup-hook.sh deleted file mode 100644 index 5d0f58f48b481..0000000000000 --- a/pkgs/os-specific/darwin/apple-sdk/cf-setup-hook.sh +++ /dev/null @@ -1,9 +0,0 @@ -linkSystemCoreFoundationFramework() { - NIX_CFLAGS_COMPILE="-F@out@/Library/Frameworks${NIX_CFLAGS_COMPILE:+ }${NIX_CFLAGS_COMPILE-}" - # gross! many symbols (such as _OBJC_CLASS_$_NSArray) are defined in system CF, but not - # in the opensource release - # if the package needs private headers, we assume they also want to link with system CF - NIX_LDFLAGS+=" @out@/Library/Frameworks/CoreFoundation.framework/CoreFoundation.tbd" -} - -preConfigureHooks+=(linkSystemCoreFoundationFramework) diff --git a/pkgs/os-specific/darwin/apple-sdk/default.nix b/pkgs/os-specific/darwin/apple-sdk/default.nix index a3d1df0867a9a..f5d0bca3504c2 100644 --- a/pkgs/os-specific/darwin/apple-sdk/default.nix +++ b/pkgs/os-specific/darwin/apple-sdk/default.nix @@ -1,8 +1,8 @@ -{ stdenv, fetchurl, cpio, pbzx, pkgs, lib, darwin-stubs, print-reexports }: +{ stdenvNoCC, fetchurl, cpio, pbzx, pkgs, lib, darwin-stubs, print-reexports }: let # sadly needs to be exported because security_tool needs it - sdk = stdenv.mkDerivation rec { + sdk = stdenvNoCC.mkDerivation rec { pname = "MacOS_SDK"; version = "10.12"; @@ -55,7 +55,7 @@ let substArgs = lib.concatMap (x: [ "--subst-var-by" x deps'."${x}" ]) (lib.attrNames deps'); in lib.escapeShellArgs substArgs; - framework = name: deps: stdenv.mkDerivation { + framework = name: deps: stdenvNoCC.mkDerivation { name = "apple-framework-${name}"; dontUnpack = true; @@ -163,9 +163,6 @@ let propagatedBuildInputs = builtins.attrValues deps; - # don't use pure CF for dylibs that depend on frameworks - setupHook = ./framework-setup-hook.sh; - # Not going to be more specific than this for now __propagatedImpureHostDeps = lib.optionals (name != "Kernel") [ # The setup-hook ensures that everyone uses the impure CoreFoundation who uses these SDK frameworks, so let's expose it @@ -181,7 +178,7 @@ let }; }; - tbdOnlyFramework = name: { private ? true }: stdenv.mkDerivation { + tbdOnlyFramework = name: { private ? true }: stdenvNoCC.mkDerivation { name = "apple-framework-${name}"; dontUnpack = true; installPhase = '' @@ -207,7 +204,7 @@ let }; in rec { libs = { - xpc = stdenv.mkDerivation { + xpc = stdenvNoCC.mkDerivation { name = "apple-lib-xpc"; dontUnpack = true; @@ -220,7 +217,7 @@ in rec { ''; }; - Xplugin = stdenv.mkDerivation { + Xplugin = stdenvNoCC.mkDerivation { name = "apple-lib-Xplugin"; dontUnpack = true; @@ -239,7 +236,7 @@ in rec { ''; }; - utmp = stdenv.mkDerivation { + utmp = stdenvNoCC.mkDerivation { name = "apple-lib-utmp"; dontUnpack = true; @@ -252,7 +249,7 @@ in rec { ''; }; - sandbox = stdenv.mkDerivation { + sandbox = stdenvNoCC.mkDerivation { name = "apple-lib-sandbox"; dontUnpack = true; @@ -276,10 +273,6 @@ in rec { extraTBDFiles = [ "Versions/A/Frameworks/HTMLRendering.framework/Versions/A/HTMLRendering.tbd" ]; }); - CoreFoundation = lib.overrideDerivation super.CoreFoundation (drv: { - setupHook = ./cf-setup-hook.sh; - }); - CoreMedia = lib.overrideDerivation super.CoreMedia (drv: { __propagatedImpureHostDeps = drv.__propagatedImpureHostDeps or [] ++ [ "/System/Library/Frameworks/CoreImage.framework" diff --git a/pkgs/os-specific/darwin/apple-sdk/framework-setup-hook.sh b/pkgs/os-specific/darwin/apple-sdk/framework-setup-hook.sh deleted file mode 100644 index b0d5915fc1fcf..0000000000000 --- a/pkgs/os-specific/darwin/apple-sdk/framework-setup-hook.sh +++ /dev/null @@ -1,42 +0,0 @@ -# On macOS, frameworks are linked to the system CoreFoundation but -# dynamic libraries built with nix use a pure version of CF this -# causes segfaults for binaries that depend on it at runtime. This -# can be solved in two ways. -# 1. Rewrite references to the pure CF using this setup hook, this -# works for the simple case but this can still cause problems if other -# dependencies (eg. python) use the pure CF. -# 2. Create a wrapper for the binary that sets DYLD_FRAMEWORK_PATH to -# /System/Library/Frameworks. This will make everything load the -# system's CoreFoundation framework while still keeping the -# dependencies pure for other packages. - -fixupOutputHooks+=('fixDarwinFrameworksIn $prefix') - -fixDarwinFrameworks() { - local systemPrefix='/System/Library/Frameworks' - - for fn in "$@"; do - if [ -L "$fn" ]; then continue; fi - echo "$fn: fixing dylib" - - for framework in $(otool -L "$fn" | awk '/CoreFoundation\.framework/ {print $1}'); do - install_name_tool -change "$framework" "$systemPrefix/CoreFoundation.framework/Versions/A/CoreFoundation" "$fn" >&2 - done - done -} - -fixDarwinFrameworksIn() { - local dir="$1" - fixDarwinFrameworks $(find "$dir" -name "*.dylib") -} - - -# This configures the stdenv to use /System/Library/Frameworks/CoreFoundation.framework -# instead of the nix version by including the system frameworks path -# as an rpath entry when creating binaries. - -useSystemCoreFoundationFramework () { - export NIX_COREFOUNDATION_RPATH=/System/Library/Frameworks -} - -addEnvHooks "$hostOffset" useSystemCoreFoundationFramework diff --git a/pkgs/os-specific/darwin/apple-sdk/sdkRoot.nix b/pkgs/os-specific/darwin/apple-sdk/sdkRoot.nix index 67d9cbe031059..01af2635cd805 100644 --- a/pkgs/os-specific/darwin/apple-sdk/sdkRoot.nix +++ b/pkgs/os-specific/darwin/apple-sdk/sdkRoot.nix @@ -41,18 +41,14 @@ runCommand "sdkroot-${sdkVersion}" { } '' install -D '${../../../build-support/setup-hooks/role.bash}' "$out/nix-support/setup-hook" cat >> "$out/nix-support/setup-hook" <<-hook - # - # See comments in cc-wrapper's setup hook. This works exactly the same way. - # - [[ -z \''${strictDeps-} ]] || (( "\$hostOffset" < 0 )) || return 0 - sdkRootHook() { # See ../../../build-support/setup-hooks/role.bash local role_post getHostRoleEnvHook # Only set the SDK root if one has not been set via this hook or some other means. - if [[ ! \$NIX_CFLAGS_COMPILE =~ isysroot ]]; then + local cflagsVar=NIX_CFLAGS_COMPILE\''${role_post} + if [[ ! \''${!cflagsVar} =~ isysroot ]]; then export NIX_CFLAGS_COMPILE\''${role_post}+=' -isysroot $out/${sdkName}.sdk' fi } @@ -60,9 +56,9 @@ runCommand "sdkroot-${sdkVersion}" { } '' # See ../../../build-support/setup-hooks/role.bash getTargetRole - addEnvHooks "\$targetOffset" sdkRootHook + addEnvHooks "\$hostOffset" sdkRootHook # No local scope in sourced file - unset -v role_post + unset -v cflagsVar role_post hook '' diff --git a/pkgs/os-specific/darwin/apple-source-releases/AvailabilityVersions/default.nix b/pkgs/os-specific/darwin/apple-source-releases/AvailabilityVersions/default.nix new file mode 100644 index 0000000000000..290d79135aa8f --- /dev/null +++ b/pkgs/os-specific/darwin/apple-source-releases/AvailabilityVersions/default.nix @@ -0,0 +1,39 @@ +{ + lib, + stdenvNoCC, + appleDerivation', + cmake, + ninja, + python3, + unifdef, +}: + +appleDerivation' stdenvNoCC { + nativeBuildInputs = [ cmake ninja python3 unifdef ]; + + postPatch = '' + substituteInPlace CMakeLists.txt \ + --replace-fail '/usr' "" + patchShebangs . + ''; + + cmakeFlags = [ + (lib.cmakeFeature "DSTROOT" (placeholder "out")) + ]; + + preConfigure = '' + cmakeFlagsArray+=("-DOBJROOT=$PWD/build" "-DSRCROOT=$PWD") + ''; + + postInstall = '' + # Remove internal and private headers + rm -rf "$out/AppleInternal" "$out/local" + # `__ENVIRONMENT_OS_VERSION_MIN_REQUIRED__` is only defined by clang 17+, so define it for older versions. + sed -e '/#ifndef __MAC_OS_X_VERSION_MIN_REQUIRED/{ + i#ifndef __ENVIRONMENT_OS_VERSION_MIN_REQUIRED__ + i#define __ENVIRONMENT_OS_VERSION_MIN_REQUIRED__ __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ + i#endif + }' \ + -i "$out/include/AvailabilityInternal.h" + ''; +} diff --git a/pkgs/os-specific/darwin/apple-source-releases/Csu/default.nix b/pkgs/os-specific/darwin/apple-source-releases/Csu/default.nix index 8cb478d0874ce..f72c2d459716d 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/Csu/default.nix +++ b/pkgs/os-specific/darwin/apple-source-releases/Csu/default.nix @@ -1,7 +1,10 @@ -{ lib, appleDerivation', stdenv }: - -appleDerivation' stdenv { +{ lib +, Libsystem +, stdenvBootstrap +, appleDerivation' +}: +appleDerivation' stdenvBootstrap { prePatch = '' substituteInPlace Makefile \ --replace /usr/lib /lib \ @@ -9,12 +12,7 @@ appleDerivation' stdenv { --replace /usr/bin "" \ --replace /bin/ "" \ --replace "CC = " "#" \ - --replace "SDK_DIR = " "SDK_DIR = . #" \ - - # Mac OS didn't support rpaths back before 10.5, but we don't care about it. - substituteInPlace Makefile \ - --replace -mmacosx-version-min=10.4 -mmacosx-version-min=10.6 \ - --replace -mmacosx-version-min=10.5 -mmacosx-version-min=10.6 + --replace "SDK_DIR = " "SDK_DIR = . #" ''; installFlags = [ "DSTROOT=$(out)" ]; diff --git a/pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix b/pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix index 87fb8512fb646..e9277fccefd60 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix +++ b/pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix @@ -1,9 +1,10 @@ -{ lib, stdenv, buildPackages, fetchzip, fetchFromGitHub -, appleDerivation', xnu, Libc, Libm, libdispatch, Libinfo +{ lib, stdenvNoCC, buildPackages, fetchzip, fetchFromGitHub +, appleDerivation', AvailabilityVersions, xnu, Libc, Libm, libdispatch, Libinfo , dyld, Csu, architecture, libclosure, CarbonHeaders, ncurses, CommonCrypto , copyfile, removefile, libresolvHeaders, libresolv, Libnotify, libmalloc, libplatform, libpthread , mDNSResponder, launchd, libutilHeaders, hfsHeaders, darwin-stubs , headersOnly ? false +, withCsu ? !headersOnly , withLibresolv ? !headersOnly }: @@ -29,7 +30,7 @@ let hash = "sha256-tXLW/TNsluhO1X9Rv3FANyzyOe5TE/hZz0gVo7JGvHA="; }; in -appleDerivation' stdenv { +appleDerivation' stdenvNoCC { dontBuild = true; dontFixup = true; @@ -48,18 +49,28 @@ appleDerivation' stdenv { # Set up our include directories (cd ${xnu}/include && find . -name '*.h' -or -name '*.defs' | copyHierarchy $out/include) - cp ${xnu}/Library/Frameworks/Kernel.framework/Versions/A/Headers/Availability*.h $out/include cp ${xnu}/Library/Frameworks/Kernel.framework/Versions/A/Headers/stdarg.h $out/include + # These headers are from a newer SDK, but they’re more compatible with GCC (and still work with older SDKs). + cp ${AvailabilityVersions}/include/Availability*.h $out/include + cp -r ${AvailabilityVersions}/include/os $out/include + # But make sure the max version is set correctly for the current SDK. + # TODO: Make this replacement be independent of SDK version. + substituteInPlace $out/include/AvailabilityInternal.h \ + --replace-fail '__MAC_OS_X_VERSION_MAX_ALLOWED __MAC_15_0' '__MAC_OS_X_VERSION_MAX_ALLOWED __MAC_10_12_4' + substituteInPlace $out/include/AvailabilityMacros.h \ + --replace-fail 'MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_VERSION_14_0' 'MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_12_4' \ + --replace-fail 'MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_VERSION_14_0' 'MAC_OS_X_VERSION_MAX_ALLOWED __MAC_10_12_4' + for dep in ${Libc} ${Libm} ${Libinfo} ${dyld} ${architecture} \ - ${libclosure} ${CarbonHeaders} ${libdispatch} ${ncurses.dev} \ + ${libclosure} ${CarbonHeaders} ${libdispatch} \ ${CommonCrypto} ${copyfile} ${removefile} ${libresolvHeaders} \ ${Libnotify} ${libplatform} ${mDNSResponder} ${launchd} \ ${libutilHeaders} ${libmalloc} ${libpthread} ${hfsHeaders}; do (cd $dep/include && find . -name '*.h' | copyHierarchy $out/include) done - (cd ${buildPackages.darwin.cctools.dev}/include/mach-o && find . -name '*.h' | copyHierarchy $out/include/mach-o) + (cd ${lib.getDev buildPackages.cctools}/include/mach-o && find . -name '*.h' | copyHierarchy $out/include/mach-o) for header in pthread.h pthread_impl.h pthread_spis.h sched.h; do ln -s "$out/include/pthread/$header" "$out/include/$header" @@ -74,27 +85,6 @@ appleDerivation' stdenv { cp ${darling.src}/src/libc/os/log.h $out/include/os cp ${darling.src}/src/duct/include/os/trace.h $out/include/os - cat < $out/include/os/availability.h - #ifndef __OS_AVAILABILITY__ - #define __OS_AVAILABILITY__ - #include - - #if defined(__has_feature) && defined(__has_attribute) && __has_attribute(availability) - #define API_AVAILABLE(...) __API_AVAILABLE_GET_MACRO(__VA_ARGS__, __API_AVAILABLE4, __API_AVAILABLE3, __API_AVAILABLE2, __API_AVAILABLE1)(__VA_ARGS__) - #define API_DEPRECATED(...) __API_DEPRECATED_MSG_GET_MACRO(__VA_ARGS__, __API_DEPRECATED_MSG5, __API_DEPRECATED_MSG4, __API_DEPRECATED_MSG3, __API_DEPRECATED_MSG2, __API_DEPRECATED_MSG1)(__VA_ARGS__) - #define API_DEPRECATED_WITH_REPLACEMENT(...) __API_DEPRECATED_REP_GET_MACRO(__VA_ARGS__, __API_DEPRECATED_REP5, __API_DEPRECATED_REP4, __API_DEPRECATED_REP3, __API_DEPRECATED_REP2, __API_DEPRECATED_REP1)(__VA_ARGS__) - #define API_UNAVAILABLE(...) __API_UNAVAILABLE_GET_MACRO(__VA_ARGS__, __API_UNAVAILABLE3, __API_UNAVAILABLE2, __API_UNAVAILABLE1)(__VA_ARGS__) - #else - - #define API_AVAILABLE(...) - #define API_DEPRECATED(...) - #define API_DEPRECATED_WITH_REPLACEMENT(...) - #define API_UNAVAILABLE(...) - - #endif - #endif - EOF - cat < $out/include/TargetConditionals.h #ifndef __TARGETCONDITIONALS__ #define __TARGETCONDITIONALS__ @@ -132,35 +122,25 @@ appleDerivation' stdenv { #endif /* __TARGETCONDITIONALS__ */ EOF '' + lib.optionalString (!headersOnly) '' - - # The startup object files - cp ${Csu}/lib/* $out/lib - cp -vr \ ${darwin-stubs}/usr/lib/libSystem.B.tbd \ ${darwin-stubs}/usr/lib/system \ $out/lib substituteInPlace $out/lib/libSystem.B.tbd \ - --replace "/usr/lib/system/" "$out/lib/system/" + --replace-fail "/usr/lib/system/" "$out/lib/system/" ln -s libSystem.B.tbd $out/lib/libSystem.tbd # Set up links to pretend we work like a conventional unix (Apple's design, not mine!) for name in c dbm dl info m mx poll proc pthread rpcsvc util gcc_s.10.4 gcc_s.10.5; do ln -s libSystem.tbd $out/lib/lib$name.tbd done + '' + lib.optionalString withCsu '' + # The startup object files + cp ${Csu}/lib/* $out/lib '' + lib.optionalString withLibresolv '' - # This probably doesn't belong here, but we want to stay similar to glibc, which includes resolv internally... - cp ${libresolv}/lib/libresolv.9.dylib $out/lib/libresolv.9.dylib - resolv_libSystem=$(${stdenv.cc.bintools.targetPrefix}otool -L "$out/lib/libresolv.9.dylib" | tail -n +3 | grep -o "$NIX_STORE.*-\S*") || true - echo $libs - - chmod +w $out/lib/libresolv.9.dylib - ${stdenv.cc.bintools.targetPrefix}install_name_tool \ - -id $out/lib/libresolv.9.dylib \ - -change "$resolv_libSystem" /usr/lib/libSystem.dylib \ - $out/lib/libresolv.9.dylib + ln -s ${lib.getLib libresolv}/lib/libresolv.9.dylib $out/lib ln -s libresolv.9.dylib $out/lib/libresolv.dylib ''; diff --git a/pkgs/os-specific/darwin/apple-source-releases/Libsystem/headers.txt b/pkgs/os-specific/darwin/apple-source-releases/Libsystem/headers.txt index b6e608f81ebf5..7ecbc03ad28a3 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/Libsystem/headers.txt +++ b/pkgs/os-specific/darwin/apple-source-releases/Libsystem/headers.txt @@ -1,7 +1,9 @@ AssertMacros.h Availability.h AvailabilityInternal.h +AvailabilityInternalLegacy.h AvailabilityMacros.h +AvailabilityVersions.h Block.h Block_private.h CommonCrypto/CommonBaseXX.h @@ -458,13 +460,6 @@ corpses/task_corpse.h cpio.h crt_externs.h ctype.h -curses.h -cursesapp.h -cursesf.h -cursesm.h -cursesp.h -cursesw.h -cursslk.h db.h default_pager/default_pager_types.h device/device.defs @@ -501,14 +496,11 @@ dns_sd.h dns_util.h err.h errno.h -eti.h -etip.h execinfo.h fcntl.h fenv.h fmtmsg.h fnmatch.h -form.h fsproperties.h fstab.h fts.h @@ -946,7 +938,6 @@ math.h membership.h membershipPriv.h memory.h -menu.h miscfs/devfs/devfs.h miscfs/specfs/specdev.h miscfs/union/union.h @@ -956,9 +947,6 @@ monitor.h mpool.h msgcat.h nameser.h -nc_tparm.h -ncurses.h -ncurses_dll.h ndbm.h net/bpf.h net/dlil.h @@ -1050,8 +1038,6 @@ os/overflow.h os/semaphore_private.h os/trace.h os/tsd.h -os/voucher_activity_private.h -os/voucher_private.h osfmk/UserNotification/KUNCUserNotifications.h osfmk/UserNotification/UNDReply.defs osfmk/UserNotification/UNDRequest.defs @@ -1352,7 +1338,6 @@ osfmk/vm/vm_protos.h osfmk/vm/vm_shared_region.h osfmk/voucher/ipc_pthread_priority_types.h osfmk/x86_64/machine_kpc.h -panel.h paths.h pexpert/boot.h pexpert/i386/boot.h @@ -1678,12 +1663,8 @@ sys/xattr.h sysexits.h syslog.h tar.h -term.h -term_entry.h -termcap.h termios.h thread_data.h -tic.h time.h timeconv.h ttyent.h @@ -1692,7 +1673,6 @@ tzlink.h tzlink_internal.h ucontext.h ulimit.h -unctrl.h unistd.h util.h utime.h diff --git a/pkgs/os-specific/darwin/apple-source-releases/configd/default.nix b/pkgs/os-specific/darwin/apple-source-releases/configd/default.nix index 998bc867e757f..ae795b0218be7 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/configd/default.nix +++ b/pkgs/os-specific/darwin/apple-source-releases/configd/default.nix @@ -1,19 +1,35 @@ -{ lib, stdenv, runCommand, appleDerivation', launchd, bootstrap_cmds, swift-corelibs-foundation, xnu, xpc, ppp, IOKit, eap8021x, Security +{ lib, stdenvBootstrap, stdenvNoCC, appleDerivation', CF, launchd, bootstrap_cmds, swift-corelibs-foundation, xnu, xpc, ppp, IOKit, eap8021x, Security , headersOnly ? false }: let - privateHeaders = runCommand "swift-corelibs-foundation-private" { } '' - mkdir -p $out/include/CoreFoundation - - cp ${swift-corelibs-foundation}/Library/Frameworks/CoreFoundation.framework/PrivateHeaders/* \ - $out/include/CoreFoundation - ''; + # Copy the headers out of CF instead of building it to avoid an infinite recursion. + privateHeaders = stdenvNoCC.mkDerivation { + pname = "swift-corelibs-foundation-private"; + inherit (swift-corelibs-foundation) version src; + + buildCommand = '' + unpackFile "$src" + + mkdir -p "$out/include/CoreFoundation" + + declare -a privateHeaders=( + Base.subproj/CFRuntime.h + PlugIn.subproj/CFBundlePriv.h + RunLoop.subproj/CFRunLoop.h + String.subproj/CFStringDefaultEncoding.h + ) + + for header in "''${privateHeaders[@]}"; do + cp source/CoreFoundation/$header $out/include/CoreFoundation + done + ''; + }; in -appleDerivation' stdenv { - meta.broken = stdenv.cc.nativeLibc; +appleDerivation' stdenvBootstrap { + meta.broken = stdenvBootstrap.cc.nativeLibc; nativeBuildInputs = lib.optionals (!headersOnly) [ bootstrap_cmds ]; - buildInputs = lib.optionals (!headersOnly) [ privateHeaders launchd ppp xpc IOKit eap8021x ]; + buildInputs = lib.optionals (!headersOnly) [ CF privateHeaders launchd ppp xpc IOKit eap8021x ]; propagatedBuildInputs = lib.optionals (!headersOnly) [ Security ]; diff --git a/pkgs/os-specific/darwin/apple-source-releases/default.nix b/pkgs/os-specific/darwin/apple-source-releases/default.nix index c34268fd41927..92cfb72465624 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/default.nix +++ b/pkgs/os-specific/darwin/apple-source-releases/default.nix @@ -6,6 +6,9 @@ let # a stdenv out of something like this. With some care we can probably get rid of this, but for # now it's staying here. versions = { + "macos-14.4" = { + AvailabilityVersions = "140.1"; + }; "macos-14.3" = { system_cmds = "970.0.4"; }; @@ -26,12 +29,14 @@ let libplatform = "126.50.8"; mDNSResponder = "765.50.9"; libutil = "47.30.1"; - libunwind = "35.3"; Libc = "1158.50.2"; dtrace = "209.50.12"; libpthread = "218.60.3"; hfs = "366.70.1"; }; + "osx-10.12.4" = { + libdispatch = "703.50.37"; + }; "osx-10.11.6" = { PowerManagement = "572.50.1"; dtrace = "168"; @@ -63,7 +68,6 @@ let IOKit = ""; libutil = "43"; - libunwind = "35.3"; Librpcsvc = "26"; developer_cmds= "62"; network_cmds = "481.20.1"; @@ -245,6 +249,7 @@ developerToolsPackages_11_3_1 // macosPackages_11_0_1 // { inherit (adv_cmds-boot) ps locale; architecture = applePackage "architecture" "osx-10.11.6" "sha256-cUKeMx6mOAxBSRHIdfzsrR65Qv86m7+20XvpKqVfwVI=" {}; + AvailabilityVersions = applePackage "AvailabilityVersions" "macos-14.4" "sha256-O9/EOsbK5ZXxh6iDSTwGWWrY5GX/viUwdfG3tdvZwcQ=" {}; bsdmake = applePackage "bsdmake" "dev-tools-3.2.6" "sha256-CW8zP5QZMhWTGp+rhrm8oHE/vSLsRlv1VRAGe1OUDmI=" {}; CarbonHeaders = applePackage "CarbonHeaders" "osx-10.6.2" "sha256-UNaHvxzYzEBnYYuoMLqWUVprZa6Wqn/3XleoSCco050=" {}; CommonCrypto = applePackage "CommonCrypto" "osx-10.12.6" "sha256-FLgODBrfv+XsGaAjddncYAm/BIJJYw6LcwX/z7ncKFM=" {}; @@ -269,7 +274,7 @@ developerToolsPackages_11_3_1 // macosPackages_11_0_1 // { }; }; libclosure = applePackage "libclosure" "osx-10.11.6" "sha256-L5rQ+UBpf3B+W1U+gZKk7fXulslHsc8lxnCsplV+nr0=" {}; - libdispatch = applePackage "libdispatch" "osx-10.10.5" "sha256-jfAEk0OLrJa9AIZVikIoHomd+l+4rCfc320Xh50qK5M=" {}; + libdispatch = applePackage "libdispatch" "osx-10.12.4" "sha256-xUqoG5JK4P3nXeoVUOBzodVK9fjH/I3xJ6WRtM39bdw=" {}; Libinfo = applePackage "Libinfo" "osx-10.11.6" "sha256-6F7wiwerv4nz/xXHtp1qCHSaFzZgzcRN+jbmXA5oWOQ=" {}; Libm = applePackage "Libm" "osx-10.7.4" "sha256-KjMETfT4qJm0m0Ux/F6Rq8bI4Q4UVnFx6IKbKxXd+Es=" {}; Libnotify = applePackage "Libnotify" "osx-10.12.6" "sha256-6wvMBxAUfiYcQtmlfYCj1d3kFmFM/jdboTd7hRvi3e4=" {}; @@ -283,7 +288,6 @@ developerToolsPackages_11_3_1 // macosPackages_11_0_1 // { libresolv = applePackage "libresolv" "osx-10.12.6" "sha256-FtvwjJKSFX6j9APYPC8WLXVOjbHLZa1Gcoc8yxLy8qE=" {}; Libsystem = applePackage "Libsystem" "osx-10.12.6" "sha256-zvRdCP//TjKCGAqm/5nJXPppshU1cv2fg/L/yK/olGQ=" {}; libutil = applePackage "libutil" "osx-10.12.6" "sha256-4PFuk+CTLwvd/Ll9GLBkiIM0Sh/CVaiKwh5m1noheRs=" {}; - libunwind = applePackage "libunwind" "osx-10.12.6" "sha256-CC0sndP/mKYe3dZu3v7fjuDASV4V4w7dAcnWMvpoquE=" {}; mDNSResponder = applePackage "mDNSResponder" "osx-10.12.6" "sha256-ddZr6tropkpdMJhq/kUlm3OwO8b0yxtkrMpwec8R4FY=" {}; objc4 = applePackage "objc4" "osx-10.12.6" "sha256-ZsxRpdsfv3Dxs7yBBCkjbKXKR6aXwkEpxc1XYXz7ueM=" {}; ppp = applePackage "ppp" "osx-10.12.6" "sha256-M1zoEjjeKIDUEP6ACbpUJk3OXjobw4g/qzUmxGdX1J0=" {}; diff --git a/pkgs/os-specific/darwin/apple-source-releases/libdispatch/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libdispatch/default.nix index 176cb8646f1e5..335115f8fea6f 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/libdispatch/default.nix +++ b/pkgs/os-specific/darwin/apple-source-releases/libdispatch/default.nix @@ -1,13 +1,12 @@ -{ appleDerivation', stdenvNoCC }: +{ lib, appleDerivation', stdenvNoCC }: -appleDerivation' stdenvNoCC { +appleDerivation' stdenvNoCC (finalAttrs: { dontConfigure = true; dontBuild = true; installPhase = '' mkdir -p $out/include/dispatch $out/include/os # Move these headers so CF can find - mv private/voucher*.h $out/include/os cp -r private/*.h $out/include/dispatch cp -r dispatch/*.h $out/include/dispatch @@ -15,7 +14,7 @@ appleDerivation' stdenvNoCC { # gcc compatibility. Source: https://stackoverflow.com/a/28014302/3714556 substituteInPlace $out/include/dispatch/object.h \ - --replace 'typedef void (^dispatch_block_t)(void);' \ + --replace-fail 'typedef void (^dispatch_block_t)(void);' \ '#ifdef __clang__ typedef void (^dispatch_block_t)(void); #else @@ -46,9 +45,14 @@ appleDerivation' stdenvNoCC { dispatch/source.h dispatch/source_private.h dispatch/time.h + '' + + lib.optionalString (lib.versionAtLeast "1271.40.12" finalAttrs.version) '' + dispatch/time_private.h + dispatch/workloop.h + dispatch/workloop_private.h + '' + + '' os/object.h os/object_private.h - os/voucher_activity_private.h - os/voucher_private.h ''; -} +}) diff --git a/pkgs/os-specific/darwin/apple-source-releases/libresolv/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libresolv/default.nix index 2a8a609472a20..1a5e29b474ee6 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/libresolv/default.nix +++ b/pkgs/os-specific/darwin/apple-source-releases/libresolv/default.nix @@ -1,8 +1,15 @@ -{ lib, appleDerivation', stdenv, stdenvNoCC, Libinfo, configdHeaders, mDNSResponder +{ lib +, Libsystem +, stdenvNoCC +, stdenvBootstrap +, appleDerivation' +, Libinfo +, configdHeaders +, mDNSResponder , headersOnly ? false }: -appleDerivation' (if headersOnly then stdenvNoCC else stdenv) { +appleDerivation' (if headersOnly then stdenvNoCC else stdenvBootstrap) { buildInputs = lib.optionals (!headersOnly) [ Libinfo configdHeaders mDNSResponder ]; buildPhase = lib.optionalString (!headersOnly) '' diff --git a/pkgs/os-specific/darwin/apple-source-releases/libunwind/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libunwind/default.nix deleted file mode 100644 index df3c5650452de..0000000000000 --- a/pkgs/os-specific/darwin/apple-source-releases/libunwind/default.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ lib, appleDerivation }: - -appleDerivation { - dontBuild = true; - - # install headers only - installPhase = '' - mkdir -p $out/lib - cp -R include $out/include - ''; - - meta = with lib; { - maintainers = with maintainers; [ copumpkin lnl7 ]; - platforms = platforms.darwin; - license = licenses.apple-psl20; - }; -} diff --git a/pkgs/os-specific/darwin/apple-source-releases/macos-11.0.1.nix b/pkgs/os-specific/darwin/apple-source-releases/macos-11.0.1.nix index 2de90a0236761..6f93e10081919 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/macos-11.0.1.nix +++ b/pkgs/os-specific/darwin/apple-source-releases/macos-11.0.1.nix @@ -31,7 +31,6 @@ libmalloc = applePackage' "libmalloc" "317.40.8" "macos-11.0.1" "sha256-Tdhb0mq3 libplatform = applePackage' "libplatform" "254.40.4" "macos-11.0.1" "1qf3ri0yd8b1xjln1j1gyx7ks6k3a2jhd63blyvfby75y9s7flky" {}; libpthread = applePackage' "libpthread" "454.40.3" "macos-11.0.1" "0zljbw8mpb80n1if65hhi9lkgwbgjr8vc9wvf7q1nl3mzyl35f8p" {}; libresolv = applePackage' "libresolv" "68" "macos-11.0.1" "045ahh8nvaam9whryc2f5g5xagwp7d187r80kcff82snp5p66aq1" {}; -libunwind = applePackage' "libunwind" "200.10" "macos-11.0.1" "0wa4ssr7skn5j0ncm1rigd56qmbs982zvwr3qpjn28krwp8wvigd" {}; libutil = applePackage' "libutil" "58.40.2" "macos-11.0.1" "11s0vizk7bg0k0yjx21j8vaji4j4vk57131qbp07i9lpksb3bcy4" {}; mDNSResponder = applePackage' "mDNSResponder" "1310.40.42" "macos-11.0.1" "0xxrqqbqsf0pagfs1yzwfbwf7lhr0sns97k18y7kh4ri0p09h44c" {}; network_cmds = applePackage' "network_cmds" "606.40.2" "macos-11.0.1" "1jsy13nraarafq6wmgh3wyir8wrwfra148xsjns7cw7q5xn40a1w" {}; diff --git a/pkgs/os-specific/darwin/apple-source-releases/objc4/default.nix b/pkgs/os-specific/darwin/apple-source-releases/objc4/default.nix index 315f0fb06219b..b45b7ef6165d9 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/objc4/default.nix +++ b/pkgs/os-specific/darwin/apple-source-releases/objc4/default.nix @@ -1,6 +1,10 @@ -{ appleDerivation, darwin-stubs }: +{ lib +, appleDerivation' +, stdenvNoCF +, darwin-stubs +}: -appleDerivation { +appleDerivation' stdenvNoCF { # Not strictly necessary, since libSystem depends on it, but it's nice to be explicit so we # can easily find out what's impure. __propagatedImpureHostDeps = [ diff --git a/pkgs/os-specific/darwin/apple-source-releases/xnu/default.nix b/pkgs/os-specific/darwin/apple-source-releases/xnu/default.nix index 14ede7949d0f9..91289ce0d75ac 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/xnu/default.nix +++ b/pkgs/os-specific/darwin/apple-source-releases/xnu/default.nix @@ -1,16 +1,39 @@ -{ appleDerivation', lib, stdenv, stdenvNoCC, buildPackages -, bootstrap_cmds, bison, flex -, gnum4, unifdef, perl, python3 +{ lib +, pkgsBuildBuild +, buildPackages +, appleDerivation' +, stdenvNoCC +, stdenv +, bison +, flex +, gnum4 +, unifdef +, perl +, python3 +, bootstrap_cmds , headersOnly ? true }: appleDerivation' (if headersOnly then stdenvNoCC else stdenv) ( - let arch = if stdenv.isx86_64 then "x86_64" else "arm64"; + let + inherit (stdenv) hostPlatform targetPlatform; + arch = stdenv.hostPlatform.darwinArch; + targetPrefix = lib.optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-"; + + # Take advantage of the fact that every clang is a cross-compiler. mig doesn’t need to be able to + # link, so there’s no need to re-wrap the clang. + migcc = stdenvNoCC.mkDerivation { + name = "migcc"; + version = lib.getVersion pkgsBuildBuild.clang; + buildCommand = '' + mkdir -p $out/bin + ln -s '${pkgsBuildBuild.clang.cc}/bin/clang' "$out/bin/${stdenvNoCC.targetPlatform.config}-cc" + ''; + }; in { depsBuildBuild = [ buildPackages.stdenv.cc ]; - - nativeBuildInputs = [ bootstrap_cmds bison flex gnum4 unifdef perl python3 ]; + nativeBuildInputs = [ bison flex gnum4 unifdef perl python3 bootstrap_cmds migcc ]; patches = lib.optionals stdenv.isx86_64 [ ./python3.patch ]; @@ -56,27 +79,39 @@ appleDerivation' (if headersOnly then stdenvNoCC else stdenv) ( --replace '--def $<' '> $@; echo' ''; - PLATFORM = "MacOSX"; - SDKVERSION = "10.11"; - CC = "${stdenv.cc.targetPrefix or ""}cc"; - CXX = "${stdenv.cc.targetPrefix or ""}c++"; - MIG = "mig"; - MIGCOM = "migcom"; - STRIP = "${stdenv.cc.bintools.targetPrefix or ""}strip"; - RANLIB = "${stdenv.cc.bintools.targetPrefix or ""}ranlib"; - NM = "${stdenv.cc.bintools.targetPrefix or ""}nm"; - UNIFDEF = "unifdef"; - DSYMUTIL = "dsymutil"; - HOST_OS_VERSION = "10.10"; - HOST_CC = "${buildPackages.stdenv.cc.targetPrefix or ""}cc"; - HOST_FLEX = "flex"; - HOST_BISON = "bison"; - HOST_GM4 = "m4"; - MIGCC = "cc"; - ARCHS = arch; - ARCH_CONFIGS = arch; - - env.NIX_CFLAGS_COMPILE = "-Wno-error"; + env = { + PLATFORM = "MacOSX"; + SDKVERSION = "10.11"; + MIG = "mig"; + MIGCOM = "migcom"; + UNIFDEF = "unifdef"; + DSYMUTIL = "dsymutil"; + HOST_OS_VERSION = "10.10"; + HOST_FLEX = "flex"; + HOST_BISON = "bison"; + HOST_GM4 = "m4"; + MIGCC = "${stdenvNoCC.targetPlatform.config}-cc"; + ARCHS = arch; + ARCH_CONFIGS = arch; + CC = "${targetPrefix}cc"; + CXX = "${targetPrefix}c++"; + STRIP = "${targetPrefix}strip"; + RANLIB = "${targetPrefix}ranlib"; + NM = "${targetPrefix}nm"; + HOST_CC = "${targetPrefix}cc"; + HOST_LD = "${targetPrefix}ld"; + NIX_CFLAGS_COMPILE = "-Wno-error"; + } // lib.optionalAttrs headersOnly { + HOST_CODESIGN = "echo"; + HOST_CODESIGN_ALLOCATE = "echo"; + LIPO = "echo"; + LIBTOOL = "echo"; + CTFCONVERT = "echo"; + CTFMERGE = "echo"; + CTFINSERT = "echo"; + NMEDIT = "echo"; + IIG = "echo"; + }; preBuild = let macosVersion = "10.0 10.1 10.2 10.3 10.4 10.5 10.6 10.7 10.8 10.9 10.10 10.11" + @@ -151,14 +186,4 @@ appleDerivation' (if headersOnly then stdenvNoCC else stdenv) ( ''; appleHeaders = builtins.readFile (./. + "/headers-${arch}.txt"); -} // lib.optionalAttrs headersOnly { - HOST_CODESIGN = "echo"; - HOST_CODESIGN_ALLOCATE = "echo"; - LIPO = "echo"; - LIBTOOL = "echo"; - CTFCONVERT = "echo"; - CTFMERGE = "echo"; - CTFINSERT = "echo"; - NMEDIT = "echo"; - IIG = "echo"; }) diff --git a/pkgs/os-specific/darwin/binutils/default.nix b/pkgs/os-specific/darwin/binutils/default.nix index 78c510f7da4cd..91fedae9feaf7 100644 --- a/pkgs/os-specific/darwin/binutils/default.nix +++ b/pkgs/os-specific/darwin/binutils/default.nix @@ -1,108 +1,119 @@ -{ lib, stdenv, makeWrapper, binutils-unwrapped, cctools, llvm, clang-unwrapped, dualAs ? false }: - -# Make sure both underlying packages claim to have prepended their binaries -# with the same targetPrefix. -assert binutils-unwrapped.targetPrefix == cctools.targetPrefix; +{ + lib, + stdenvNoCC, + cctools, + clang-unwrapped, + ld64, + llvm, + llvm-manpages, + makeWrapper, + enableManpages ? stdenvNoCC.targetPlatform == stdenvNoCC.hostPlatform, +}: let - inherit (binutils-unwrapped) targetPrefix; - cmds = [ - "ar" "ranlib" "as" "install_name_tool" - "ld" "strip" "otool" "lipo" "nm" "strings" "size" + inherit (stdenvNoCC) targetPlatform hostPlatform; + targetPrefix = lib.optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-"; + + llvm_cmds = [ + "addr2line" + "ar" + "c++filt" + "dsymutil" + "nm" + "objcopy" + "objdump" + "otool" + "size" + "strings" + "strip" + ]; + + cctools_cmds = [ "codesign_allocate" + "gprof" + "ranlib" + # Use the cctools versions because the LLVM ones can crash or fail when the cctools ones don’t. + # Revisit when LLVM is updated to LLVM 18 on Darwin. + "lipo" + "install_name_tool" ]; - isCCToolsLLVM = lib.getName cctools == "cctools-llvm"; -in -# TODO: loop over targetPrefixed binaries too -stdenv.mkDerivation { - pname = "${targetPrefix}cctools-binutils-darwin" + lib.optionalString dualAs "-dualas"; + linkManPages = + pkg: source: target: + lib.optionalString enableManpages '' + sourcePath=${pkg}/share/man/man1/${source}.1.gz + targetPath=''${!outputMan}/share/man/man1/${target}.1.gz + + if [ -f "$sourcePath" ]; then + mkdir -p "$(dirname "$targetPath")" + ln -s "$sourcePath" "$targetPath" + fi + ''; +in +stdenvNoCC.mkDerivation { + pname = "${targetPrefix}cctools-binutils-darwin"; inherit (cctools) version; - outputs = [ "out" "man" ]; + + outputs = [ "out" ] ++ lib.optional enableManpages "man"; + + strictDeps = true; + + nativeBuildInputs = [ makeWrapper ]; + buildCommand = '' mkdir -p $out/bin $out/include - ln -s ${binutils-unwrapped.out}/bin/${targetPrefix}c++filt $out/bin/${targetPrefix}c++filt - - # We specifically need: - # - ld: binutils doesn't provide it on darwin - # - as: as above - # - ar: the binutils one produces .a files that the cctools ld doesn't like - # - ranlib: for compatibility with ar - # - otool: we use it for some of our name mangling - # - install_name_tool: we use it to rewrite stuff in our bootstrap tools - # - strip: the binutils one seems to break mach-o files - # - lipo: gcc build assumes it exists - # - nm: the gnu one doesn't understand many new load commands - for i in ${lib.concatStringsSep " " (map (e: targetPrefix + e) cmds)}; do - ln -sf "${cctools}/bin/$i" "$out/bin/$i" - done + for tool in ${toString llvm_cmds}; do + # Translate between LLVM and traditional tool names (e.g., `c++filt` versus `cxxfilt`). + cctoolsTool=''${tool//-/_} + llvmTool=''${tool//++/xx} - ln -s ${llvm}/bin/dsymutil $out/bin/dsymutil + # Some tools aren’t prefixed (like `dsymutil`). + llvmPath="${lib.getBin llvm}/bin" + if [ -e "$llvmPath/llvm-$llvmTool" ]; then + llvmTool=llvm-$llvmTool + elif [ -e "$llvmPath/${targetPrefix}$llvmTool" ]; then + llvmTool=${targetPrefix}$llvmTool + fi - ln -s ${binutils-unwrapped.out}/share $out/share + ln -s "$llvmPath/$llvmTool" "$out/bin/${targetPrefix}$cctoolsTool" + ${linkManPages llvm-manpages "$llvmTool" "$cctoolsTool"} + done - mkdir -p "$man"/share/man/man{1,5} - for i in ${lib.concatStringsSep " " cmds}; do - for path in "${cctools.man}"/share/man/man?/$i.*; do - dest_path="$man''${path#${cctools.man}}" - ln -sv "$path" "$dest_path" - done + for tool in ${toString cctools_cmds}; do + ln -s "${lib.getBin cctools}/bin/${targetPrefix}$tool" "$out/bin/${targetPrefix}$tool" + ${linkManPages (lib.getMan cctools) "$tool" "$tool"} done - '' - + lib.optionalString (!isCCToolsLLVM) ( - # cctools-port has a `libexec` folder for `as`, but cctools-llvm uses the clang - # assembler on both platforms. Only link it when cctools is cctools-port. - '' - ln -s ${cctools}/libexec $out/libexec - '' - # cctools-llvm uses the LLVM assembler on both architectures, so use the assembler - # from that instead of relinking it. - # - # On aarch64-darwin we must use clang, because "as" from cctools just doesn't - # handle the arch. Proxying calls to clang produces quite a bit of warnings, - # and using clang directly here is a better option than relying on cctools. - # On x86_64-darwin the Clang version is too old to support this mode. - + lib.optionalString stdenv.isAarch64 '' - rm $out/bin/${targetPrefix}as - makeWrapper "${clang-unwrapped}/bin/clang" "$out/bin/${targetPrefix}as" \ - --add-flags "-x assembler -integrated-as -c" - '' - # x86-64 Darwin gnat-bootstrap emits assembly - # with MOVQ as the mnemonic for quadword interunit moves - # such as `movq %rbp, %xmm0`. - # The clang integrated assembler recognises this as valid, - # but unfortunately the cctools-port GNU assembler does not; - # it instead uses MOVD as the mnemonic. - # The assembly that a GCC build emits is determined at build time - # and cannot be changed afterwards. - # - # To build GNAT on x86-64 Darwin, therefore, - # we need both the clang _and_ the cctools-port assemblers to be available: - # the former to build at least the stage1 compiler, - # and the latter at least to be detectable - # as the target for the final compiler. - # - # We choose to match the Aarch64 case above, - # wrapping the clang integrated assembler as `as`. - # It then seems sensible to wrap the cctools GNU assembler as `gas`. - # - + lib.optionalString (stdenv.isx86_64 && dualAs) '' - mv $out/bin/${targetPrefix}as $out/bin/${targetPrefix}gas - makeWrapper "${clang-unwrapped}/bin/clang" "$out/bin/${targetPrefix}as" \ - --add-flags "-x assembler -integrated-as -c" - '' - ); - - nativeBuildInputs = lib.optionals (!isCCToolsLLVM && (stdenv.isAarch64 || dualAs)) [ makeWrapper ]; + ${ + # These unprefixed because some tools expect to invoke them without it when cross-compiling to Darwin: + # - clang needs `dsymutil` when building with debug information; + # - meson needs `lipo` when cross-compiling to Darwin; and + # - meson also needs `install_name_tool` and `otool` when performing rpath cleanup on installation. + lib.optionalString (targetPrefix != "") '' + for bintool in dsymutil install_name_tool lipo otool; do + ln -s "$out/bin/${targetPrefix}$bintool" "$out/bin/$bintool" + done + '' + } + # Use the clang-integrated assembler. `as` in cctools is deprecated upstream and no longer built in nixpkgs. + makeWrapper "${lib.getBin clang-unwrapped}/bin/clang" "$out/bin/${targetPrefix}as" \ + --add-flags "-x assembler -integrated-as -c" + + ln -s '${lib.getBin ld64}/bin/${targetPrefix}ld' "$out/bin/${targetPrefix}ld" + ${linkManPages (lib.getMan ld64) "ld" "ld"} + ${linkManPages (lib.getMan ld64) "ld-classic" "ld-classic"} + ${linkManPages (lib.getMan ld64) "ld64" "ld64"} + ''; + + __structuredAttrs = true; passthru = { - inherit targetPrefix; - isCCTools = true; + inherit cctools_cmds llvm_cmds targetPrefix; + isCCTools = true; # The fact ld64 is used instead of lld is why this isn’t `isLLVM`. }; meta = { - maintainers = with lib.maintainers; [ matthewbauer ]; + maintainers = with lib.maintainers; [ reckenrode ]; priority = 10; }; } diff --git a/pkgs/os-specific/darwin/cctools/apple.nix b/pkgs/os-specific/darwin/cctools/apple.nix deleted file mode 100644 index dee4e20062560..0000000000000 --- a/pkgs/os-specific/darwin/cctools/apple.nix +++ /dev/null @@ -1,122 +0,0 @@ -{ lib, stdenv, fetchFromGitHub, symlinkJoin, xcbuildHook, tcsh, libobjc, libtapi, libunwind, llvm, memstreamHook, xar }: - -let - -cctools = stdenv.mkDerivation rec { - pname = "cctools"; - version = "973.0.1"; - - src = fetchFromGitHub { - owner = "apple-oss-distributions"; - repo = "cctools"; - rev = "${pname}-${version}"; - hash = "sha256-0NlDqy3zeg4D0MbDipx0sMYDfzYa63Jxfsckzz/928o="; - }; - - patches = [ - ./cctools-add-missing-vtool-libstuff-dep.patch - ]; - - postPatch = '' - for file in libstuff/writeout.c misc/libtool.c misc/lipo.c; do - substituteInPlace "$file" \ - --replace '__builtin_available(macOS 10.12, *)' '0' - done - substituteInPlace libmacho/swap.c \ - --replace '#ifndef RLD' '#if 1' - ''; - - nativeBuildInputs = [ xcbuildHook memstreamHook ]; - buildInputs = [ libobjc llvm ]; - - xcbuildFlags = [ - "MACOSX_DEPLOYMENT_TARGET=10.12" - ]; - - doCheck = true; - checkPhase = '' - runHook preCheck - - Products/Release/libstuff_test - rm Products/Release/libstuff_test - - runHook postCheck - ''; - - installPhase = '' - runHook preInstall - - rm -rf "$out/usr" - mkdir -p "$out/bin" - find Products/Release -maxdepth 1 -type f -perm 755 -exec cp {} "$out/bin/" \; - cp -r include "$out/" - - ln -s ./nm-classic "$out"/bin/nm - ln -s ./otool-classic "$out"/bin/otool - - runHook postInstall - ''; -}; - -ld64 = stdenv.mkDerivation rec { - pname = "ld64"; - version = "609"; - - src = fetchFromGitHub { - owner = "apple-oss-distributions"; - repo = "ld64"; - rev = "${pname}-${version}"; - hash = "sha256-WAaphem6NS4eCHL/pISlDXnO1CDYTgSrVGzcothh4/Q="; - }; - - postPatch = '' - substituteInPlace ld64.xcodeproj/project.pbxproj \ - --replace "/bin/csh" "${tcsh}/bin/tcsh" \ - --replace 'F9E8D4BE07FCAF2A00FD5801 /* PBXBuildRule */,' "" \ - --replace 'F9E8D4BD07FCAF2000FD5801 /* PBXBuildRule */,' "" - - sed -i src/ld/Options.cpp -e '1iconst char ldVersionString[] = "${version}";' - ''; - - nativeBuildInputs = [ xcbuildHook ]; - buildInputs = [ - libtapi - libunwind - llvm - xar - ]; - - installPhase = '' - runHook preInstall - - mkdir -p "$out/bin" - find Products/Release-assert -maxdepth 1 -type f -perm 755 -exec cp {} "$out/bin/" \; - - runHook postInstall - ''; -}; - -in - -symlinkJoin rec { - name = "cctools-${version}"; - version = "${cctools.version}-${ld64.version}"; - - paths = [ - cctools - ld64 - ]; - - # workaround for the fetch-tarballs script - passthru = { - inherit (cctools) src; - ld64_src = ld64.src; - }; - - meta = with lib; { - description = "MacOS Compiler Tools"; - homepage = "http://www.opensource.apple.com/source/cctools/"; - license = licenses.apple-psl20; - platforms = platforms.darwin; - }; -} diff --git a/pkgs/os-specific/darwin/cctools/cctools-add-missing-vtool-libstuff-dep.patch b/pkgs/os-specific/darwin/cctools/cctools-add-missing-vtool-libstuff-dep.patch deleted file mode 100644 index 1cd65ec6bcf19..0000000000000 --- a/pkgs/os-specific/darwin/cctools/cctools-add-missing-vtool-libstuff-dep.patch +++ /dev/null @@ -1,11 +0,0 @@ -diff -ru a/cctools.xcodeproj/project.pbxproj b/cctools.xcodeproj/project.pbxproj ---- a/cctools.xcodeproj/project.pbxproj 2021-02-24 20:30:55.000000000 -0500 -+++ b/cctools.xcodeproj/project.pbxproj 2022-01-31 20:01:09.000000000 -0500 -@@ -2558,6 +2558,7 @@ - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( -+ DE97E92421F3B86100C7947D /* libstuff.a in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; diff --git a/pkgs/os-specific/darwin/cctools/darwin-memstream.patch b/pkgs/os-specific/darwin/cctools/darwin-memstream.patch deleted file mode 100644 index 3e0d0a43ba8d0..0000000000000 --- a/pkgs/os-specific/darwin/cctools/darwin-memstream.patch +++ /dev/null @@ -1,17 +0,0 @@ ---- a/cctools/include/stuff/diagnostics.h -+++ b/cctools/include/stuff/diagnostics.h -@@ -60,13 +60,6 @@ void diagnostics_log_msg(enum diagnostic_level level, const char* message); - */ - void diagnostics_write(void); - --#if defined(__APPLE__ ) && defined(__has_builtin) --# if __has_builtin(__builtin_available) --# define HAVE_OPENMEMSTREAM_RUNTIME __builtin_available(macOS 10.13, *) --# endif --#endif --#ifndef HAVE_OPENMEMSTREAM_RUNTIME --# define HAVE_OPENMEMSTREAM_RUNTIME 1 --#endif -+#define HAVE_OPENMEMSTREAM_RUNTIME 1 - - #endif /* diagnostics_h */ diff --git a/pkgs/os-specific/darwin/cctools/ld-ignore-rpath-link.patch b/pkgs/os-specific/darwin/cctools/ld-ignore-rpath-link.patch deleted file mode 100644 index fc87f69ac32d0..0000000000000 --- a/pkgs/os-specific/darwin/cctools/ld-ignore-rpath-link.patch +++ /dev/null @@ -1,16 +0,0 @@ -diff --git a/cctools/ld64/src/ld/Options.cpp b/cctools/ld64/src/ld/Options.cpp -index 2565518..9250016 100644 ---- a/cctools/ld64/src/ld/Options.cpp -+++ b/cctools/ld64/src/ld/Options.cpp -@@ -2522,6 +2522,11 @@ void Options::parse(int argc, const char* argv[]) - throw "missing argument to -rpath"; - fRPaths.push_back(path); - } -+ else if ( strcmp(arg, "-rpath-link") == 0 ) { -+ const char* path = argv[++i]; -+ if ( path == NULL ) -+ throw "missing argument to -rpath-link"; -+ } - else if ( strcmp(arg, "-read_only_stubs") == 0 ) { - fReadOnlyx86Stubs = true; - } diff --git a/pkgs/os-specific/darwin/cctools/ld-rpath-nonfinal.patch b/pkgs/os-specific/darwin/cctools/ld-rpath-nonfinal.patch deleted file mode 100644 index 17ad9053f3bd6..0000000000000 --- a/pkgs/os-specific/darwin/cctools/ld-rpath-nonfinal.patch +++ /dev/null @@ -1,29 +0,0 @@ -diff --git a/cctools/ld64/src/ld/Options.cpp b/cctools/ld64/src/ld/Options.cpp -index e4b37ec..4189ebc 100644 ---- a/cctools/ld64/src/ld/Options.cpp -+++ b/cctools/ld64/src/ld/Options.cpp -@@ -5800,24 +5800,6 @@ void Options::checkIllegalOptionCombinations() - if ( fDeadStrip && (fOutputKind == Options::kObjectFile) ) - throw "-r and -dead_strip cannot be used together"; - -- // can't use -rpath unless targeting 10.5 or later -- if ( fRPaths.size() > 0 ) { -- if ( !platforms().minOS(ld::version2008) ) -- throw "-rpath can only be used when targeting Mac OS X 10.5 or later"; -- switch ( fOutputKind ) { -- case Options::kDynamicExecutable: -- case Options::kDynamicLibrary: -- case Options::kDynamicBundle: -- break; -- case Options::kStaticExecutable: -- case Options::kObjectFile: -- case Options::kDyld: -- case Options::kPreload: -- case Options::kKextBundle: -- throw "-rpath can only be used when creating a dynamic final linked image"; -- } -- } -- - if ( fPositionIndependentExecutable ) { - switch ( fOutputKind ) { - case Options::kDynamicExecutable: diff --git a/pkgs/os-specific/darwin/cctools/llvm.nix b/pkgs/os-specific/darwin/cctools/llvm.nix deleted file mode 100644 index f2986bf872f76..0000000000000 --- a/pkgs/os-specific/darwin/cctools/llvm.nix +++ /dev/null @@ -1,113 +0,0 @@ -# Create a cctools-compatible bintools that uses equivalent tools from LLVM in place of the ones -# from cctools when possible. - -{ lib, stdenv, makeWrapper, cctools-port, llvmPackages, enableManpages ? stdenv.targetPlatform == stdenv.hostPlatform }: - -let - inherit (stdenv) targetPlatform hostPlatform; - - cctoolsVersion = lib.getVersion cctools-port; - llvmVersion = llvmPackages.release_version; - - # `bitcode_strip` is not available until LLVM 12. - useLLVMBitcodeStrip = lib.versionAtLeast llvmVersion "12"; - - # A compatible implementation of `otool` was not added until LLVM 13. - useLLVMOtool = lib.versionAtLeast llvmVersion "13"; - - # Older versions of `strip` cause problems for the version of `codesign_allocate` available in - # the version of cctools in nixpkgs. The version of `codesign_allocate` in cctools-1005.2 does - # not appear to have issues, but the source is not available yet (as of June 2023). - useLLVMStrip = lib.versionAtLeast llvmVersion "15" || lib.versionAtLeast cctoolsVersion "1005.2"; - - # Clang 11 performs an optimization on x86_64 that is sensitive to the presence of debug info. - # This causes GCC to fail to bootstrap due to object file differences between stages 2 and 3. - useClangAssembler = lib.versionAtLeast llvmVersion "12" || !stdenv.isx86_64; - - llvm_bins = [ - "dwarfdump" - "nm" - "objdump" - "size" - "strings" - ] - ++ lib.optional useLLVMBitcodeStrip "bitcode-strip" - ++ lib.optional useLLVMOtool "otool" - ++ lib.optional useLLVMStrip "strip"; - - # Only include the tools that LLVM doesn’t provide and that are present normally on Darwin. - # The only exceptions are the following tools, which should be reevaluated when LLVM is bumped. - # - install_name_tool (llvm-objcopy): unrecognized linker commands when building open source CF; - # - libtool (llvm-libtool-darwin): not fully compatible when used with xcbuild; and - # - lipo (llvm-lipo): crashes when running the LLVM test suite. - cctools_bins = [ - "cmpdylib" - "codesign_allocate" - "ctf_insert" - "install_name_tool" - "ld" - "libtool" - "lipo" - "nmedit" - "pagestuff" - "ranlib" - "segedit" - "vtool" - ] - ++ lib.optional (!useLLVMBitcodeStrip) "bitcode_strip" - ++ lib.optional (!useLLVMOtool) "otool" - ++ lib.optional (!useLLVMStrip) "strip" - ++ lib.optional (!useClangAssembler) "as"; - - targetPrefix = lib.optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-"; - - linkManPages = pkg: source: target: lib.optionalString enableManpages '' - sourcePath=${pkg}/share/man/man1/${source}.1.gz - targetPath=$man/share/man/man1/${target}.1.gz - - if [ -f "$sourcePath" ]; then - mkdir -p "$(dirname "$targetPath")" - ln -s "$sourcePath" "$targetPath" - fi - ''; -in -stdenv.mkDerivation { - pname = "cctools-llvm"; - version = "${llvmVersion}-${cctoolsVersion}"; - - nativeBuildInputs = [ makeWrapper ]; - - # The `man` output has to be included unconditionally because darwin.binutils expects it. - outputs = [ "out" "dev" "man" ]; - - buildCommand = '' - mkdir -p "$out/bin" "$man" - ln -s ${lib.getDev cctools-port} "$dev" - - '' + lib.optionalString useClangAssembler '' - # Use the clang-integrated assembler instead of using `as` from cctools. - makeWrapper "${lib.getBin llvmPackages.clang-unwrapped}/bin/clang" "$out/bin/${targetPrefix}as" \ - --add-flags "-x assembler -integrated-as -c" - - '' + '' - ln -s "${lib.getBin llvmPackages.bintools-unwrapped}/bin/${targetPrefix}llvm-ar" "$out/bin/${targetPrefix}ar" - ${linkManPages llvmPackages.llvm-manpages "llvm-ar" "ar"} - - for tool in ${toString llvm_bins}; do - cctoolsTool=''${tool/-/_} - ln -s "${lib.getBin llvmPackages.llvm}/bin/llvm-$tool" "$out/bin/${targetPrefix}$cctoolsTool" - ${linkManPages llvmPackages.llvm-manpages "llvm-$tool" "$cctoolsTool"} - done - - for tool in ${toString cctools_bins}; do - ln -s "${lib.getBin cctools-port}/bin/${targetPrefix}$tool" "$out/bin/${targetPrefix}$tool" - ${linkManPages (lib.getMan cctools-port) "$tool" "$tool"} - done - - ${linkManPages (lib.getMan cctools-port) "ld64" "ld64"} - ${lib.optionalString (!useLLVMOtool) # The actual man page for otool in cctools is llvm-otool - (linkManPages (lib.getMan cctools-port) "llvm-otool" "llvm-otool")} - ''; - - passthru = { inherit targetPrefix; }; -} diff --git a/pkgs/os-specific/darwin/cctools/port.nix b/pkgs/os-specific/darwin/cctools/port.nix deleted file mode 100644 index 377d84d9bf731..0000000000000 --- a/pkgs/os-specific/darwin/cctools/port.nix +++ /dev/null @@ -1,192 +0,0 @@ -{ lib, stdenv, fetchFromGitHub, autoconf, automake, libtool, autoreconfHook, memstreamHook -, installShellFiles -, libuuid -, libobjc ? null, maloader ? null -, enableTapiSupport ? true, libtapi -, fetchpatch -}: - -let - - # The targetPrefix prepended to binary names to allow multiple binuntils on the - # PATH to both be usable. - targetPrefix = lib.optionalString - (stdenv.targetPlatform != stdenv.hostPlatform) - "${stdenv.targetPlatform.config}-"; -in - -# Non-Darwin alternatives -assert (!stdenv.hostPlatform.isDarwin) -> maloader != null; - -stdenv.mkDerivation { - pname = "${targetPrefix}cctools-port"; - version = "973.0.1"; - - src = fetchFromGitHub { - owner = "tpoechtrager"; - repo = "cctools-port"; - # This is the commit before: https://github.com/tpoechtrager/cctools-port/pull/114 - # That specific change causes trouble for us (see the PR discussion), but - # is also currently the last commit on master at the time of writing, so we - # can just go back one step. - rev = "457dc6ddf5244ebf94f28e924e3a971f1566bd66"; - sha256 = "0ns12q7vg9yand4dmdsps1917cavfbw67yl5q7bm6kb4ia5kkx13"; - }; - - outputs = [ "out" "dev" "man" ]; - - nativeBuildInputs = [ autoconf automake libtool autoreconfHook installShellFiles ] - ++ lib.optionals (stdenv.isDarwin && stdenv.isx86_64) [ memstreamHook ]; - buildInputs = [ libuuid ] - ++ lib.optionals stdenv.isDarwin [ libobjc ] - ++ lib.optional enableTapiSupport libtapi; - - patches = [ - ./ld-ignore-rpath-link.patch - ./ld-rpath-nonfinal.patch - (fetchpatch { - url = "https://github.com/tpoechtrager/cctools-port/commit/4a734070cd2838e49658464003de5b92271d8b9e.patch"; - hash = "sha256-72KaJyu7CHXxJJ1GNq/fz+kW1RslO3UaKI91LhBtiXA="; - }) - (fetchpatch { - url = "https://github.com/MercuryTechnologies/cctools-port/commit/025899b7b3593dedb0c681e689e57c0e7bbd9b80.patch"; - hash = "sha256-SWVUzFaJHH2fu9y8RcU3Nx/QKx60hPE5zFx0odYDeQs="; - }) - # Always use `open_memstream`. This is provided by memstream via hook on x86_64-darwin. - ./darwin-memstream.patch - ]; - - __propagatedImpureHostDeps = [ - # As far as I can tell, otool from cctools is the only thing that depends on these two, and we should fix them - "/usr/lib/libobjc.A.dylib" - "/usr/lib/libobjc.dylib" - ]; - - enableParallelBuilding = true; - - # TODO(@Ericson2314): Always pass "--target" and always targetPrefix. - configurePlatforms = [ "build" "host" ] - ++ lib.optional (stdenv.targetPlatform != stdenv.hostPlatform) "target"; - configureFlags = [ "--disable-clang-as" ] - ++ lib.optionals enableTapiSupport [ - "--enable-tapi-support" - "--with-libtapi=${libtapi}" - ]; - - postPatch = lib.optionalString stdenv.hostPlatform.isDarwin '' - substituteInPlace cctools/Makefile.am --replace libobjc2 "" - '' + '' - sed -i -e 's/addStandardLibraryDirectories = true/addStandardLibraryDirectories = false/' cctools/ld64/src/ld/Options.cpp - - # FIXME: there are far more absolute path references that I don't want to fix right now - substituteInPlace cctools/configure.ac \ - --replace "-isystem /usr/local/include -isystem /usr/pkg/include" "" \ - --replace "-L/usr/local/lib" "" \ - - # Appears to use new libdispatch API not available in macOS SDK 10.12. - substituteInPlace cctools/ld64/src/ld/libcodedirectory.c \ - --replace "#define LIBCD_PARALLEL 1" "" - - patchShebangs tools - sed -i -e 's/which/type -P/' tools/*.sh - - cd cctools - ''; - - preInstall = '' - installManPage ar/ar.{1,5} - - # The makefile rules for installing headers are missing in 973.0.1. - # The below is derived from 949.0.1. - mkdir -p $dev/include/mach-o/i386 - mkdir -p $dev/include/mach-o/ppc - mkdir -p $dev/include/mach-o/x86_64 - mkdir -p $dev/include/mach-o/arm - mkdir -p $dev/include/mach-o/arm64 - mkdir -p $dev/include/mach-o/m68k - mkdir -p $dev/include/mach-o/sparc - mkdir -p $dev/include/mach-o/hppa - mkdir -p $dev/include/mach-o/i860 - mkdir -p $dev/include/mach-o/m88k - mkdir -p $dev/include/dyld - mkdir -p $dev/include/cbt - - pushd include/mach-o - install -c -m 444 arch.h ldsyms.h reloc.h \ - stab.h loader.h fat.h swap.h getsect.h nlist.h \ - ranlib.h $dev/include/mach-o - popd - - pushd include/mach-o/i386 - install -c -m 444 swap.h \ - $dev/include/mach-o/i386 - popd - - pushd include/mach-o/ppc - install -c -m 444 reloc.h swap.h \ - $dev/include/mach-o/ppc - popd - - pushd include/mach-o/x86_64 - install -c -m 444 reloc.h \ - $dev/include/mach-o/x86_64 - popd - - pushd include/mach-o/arm - install -c -m 444 reloc.h \ - $dev/include/mach-o/arm - popd - - pushd include/mach-o/arm64 - install -c -m 444 reloc.h \ - $dev/include/mach-o/arm64 - popd - - pushd include/mach-o/m68k - install -c -m 444 swap.h \ - $dev/include/mach-o/m68k - popd - - pushd include/mach-o/sparc - install -c -m 444 reloc.h swap.h \ - $dev/include/mach-o/sparc - popd - - pushd include/mach-o/hppa - install -c -m 444 reloc.h swap.h \ - $dev/include/mach-o/hppa - popd - - pushd include/mach-o/i860 - install -c -m 444 reloc.h swap.h \ - $dev/include/mach-o/i860 - popd - - pushd include/mach-o/m88k - install -c -m 444 reloc.h swap.h \ - $dev/include/mach-o/m88k - popd - - pushd include/stuff - install -c -m 444 bool.h \ - $dev/include/dyld - popd - - pushd include/cbt - install -c -m 444 libsyminfo.h \ - $dev/include/cbt - popd - ''; - - passthru = { - inherit targetPrefix; - }; - - meta = { - broken = !stdenv.targetPlatform.isDarwin; # Only supports darwin targets - homepage = "http://www.opensource.apple.com/source/cctools/"; - description = "MacOS Compiler Tools (cross-platform port)"; - license = lib.licenses.apple-psl20; - maintainers = with lib.maintainers; [ matthewbauer ]; - }; -} diff --git a/pkgs/os-specific/darwin/swift-corelibs/0006-System-CF-framework-compatibility.patch b/pkgs/os-specific/darwin/swift-corelibs/0006-System-CF-framework-compatibility.patch index 248cb5f600370..33fe5b298a0f1 100644 --- a/pkgs/os-specific/darwin/swift-corelibs/0006-System-CF-framework-compatibility.patch +++ b/pkgs/os-specific/darwin/swift-corelibs/0006-System-CF-framework-compatibility.patch @@ -65,11 +65,13 @@ diff -u a/CoreFoundation/cmake/modules/CoreFoundationAddFramework.cmake b/CoreFo endif() add_custom_target(${NAME}_POPULATE_HEADERS DEPENDS -@@ -51,13 +57,15 @@ +@@ -51,13 +57,22 @@ set_target_properties(${NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY - ${CMAKE_BINARY_DIR}/${NAME}.framework) ++ ${CMAKE_BINARY_DIR}/${NAME}.framework/Versions/Current ++ ARCHIVE_OUTPUT_DIRECTORY + ${CMAKE_BINARY_DIR}/${NAME}.framework/Versions/Current) target_compile_options(${NAME} PRIVATE @@ -77,7 +79,12 @@ diff -u a/CoreFoundation/cmake/modules/CoreFoundationAddFramework.cmake b/CoreFo -I;${CMAKE_BINARY_DIR}/${NAME}.framework/PrivateHeaders) add_dependencies(${NAME} ${NAME}_POPULATE_HEADERS) -+ file(CREATE_LINK Versions/Current/${NAME} ${CMAKE_BINARY_DIR}/${NAME}.framework/${NAME} SYMBOLIC) ++ if(${AF_TYPE} STREQUAL STATIC) ++ set(LIBRARY_NAME ${CMAKE_STATIC_LIBRARY_PREFIX}${NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}) ++ else() ++ set(LIBRARY_NAME ${NAME}) ++ endif() ++ file(CREATE_LINK Versions/Current/${LIBRARY_NAME} ${CMAKE_BINARY_DIR}/${NAME}.framework/${NAME} SYMBOLIC) + if(AF_FRAMEWORK_DIRECTORY) set(${AF_FRAMEWORK_DIRECTORY} ${CMAKE_BINARY_DIR}/${NAME}.framework PARENT_SCOPE) diff --git a/pkgs/os-specific/darwin/swift-corelibs/corefoundation.nix b/pkgs/os-specific/darwin/swift-corelibs/corefoundation.nix index 5c593b1488e29..992db9bb68930 100644 --- a/pkgs/os-specific/darwin/swift-corelibs/corefoundation.nix +++ b/pkgs/os-specific/darwin/swift-corelibs/corefoundation.nix @@ -1,4 +1,18 @@ -{ lib, stdenv, fetchFromGitHub, fetchurl, makeSetupHook, cmake, pkg-config, launchd, libdispatch, python3Minimal, libxml2, objc4, icu }: +{ lib +, stdenvNoCF +, fetchurl +, fetchFromGitHub +, cmake +, ninja +, pkg-config +, python3Minimal +, launchd +, libdispatch +, libxml2 +, objc4 +, icu +, enableShared ? !stdenvNoCF.hostPlatform.isStatic +}: let # 10.12 adds a new sysdir.h that our version of CF in the main derivation depends on, but @@ -8,9 +22,11 @@ let url = "https://raw.githubusercontent.com/apple/swift-corelibs-foundation/9a5d8420f7793e63a8d5ec1ede516c4ebec939f0/CoreFoundation/Base.subproj/CFSystemDirectories.c"; sha256 = "0krfyghj4f096arvvpf884ra5czqlmbrgf8yyc0b3avqmb613pcc"; }; + + inherit (stdenvNoCF.cc.bintools) targetPrefix; in -stdenv.mkDerivation { +stdenvNoCF.mkDerivation { pname = "swift-corefoundation"; version = "unstable-2018-09-14"; @@ -74,18 +90,13 @@ stdenv.mkDerivation { "-DINCLUDE_OBJC=1" ]; - cmakeFlags = [ - "-DBUILD_SHARED_LIBS=ON" - "-DCF_ENABLE_LIBDISPATCH=OFF" - ]; + cmakeFlags = [ "-DCF_ENABLE_LIBDISPATCH=OFF" ] + ++ lib.optionals enableShared [ "-DBUILD_SHARED_LIBS=ON" ]; enableParallelBuilding = true; - postInstall = '' - install_name_tool -id '@rpath/CoreFoundation.framework/Versions/A/CoreFoundation' \ + postInstall = lib.optionalString enableShared '' + ${targetPrefix}install_name_tool -id '@rpath/CoreFoundation.framework/Versions/A/CoreFoundation' \ "$out/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation" - - mkdir -p "$out/nix-support" - substituteAll ${./pure-corefoundation-hook.sh} "$out/nix-support/setup-hook" ''; } diff --git a/pkgs/os-specific/darwin/swift-corelibs/pure-corefoundation-hook.sh b/pkgs/os-specific/darwin/swift-corelibs/pure-corefoundation-hook.sh deleted file mode 100644 index d5539f50861a4..0000000000000 --- a/pkgs/os-specific/darwin/swift-corelibs/pure-corefoundation-hook.sh +++ /dev/null @@ -1,7 +0,0 @@ -usePureCoreFoundation() { -# Avoid overriding value set by the impure CF - if [ -z "${NIX_COREFOUNDATION_RPATH:-}" ]; then - export NIX_COREFOUNDATION_RPATH=@out@/Library/Frameworks - fi -} -addEnvHooks "$hostOffset" usePureCoreFoundation diff --git a/pkgs/servers/mx-puppet-discord/node-composition.nix b/pkgs/servers/mx-puppet-discord/node-composition.nix index bd96f550554b2..13549251a85b9 100644 --- a/pkgs/servers/mx-puppet-discord/node-composition.nix +++ b/pkgs/servers/mx-puppet-discord/node-composition.nix @@ -8,7 +8,7 @@ let nodeEnv = import ../../development/node-packages/node-env.nix { inherit (pkgs) stdenv lib python2 runCommand writeTextFile writeShellScript; inherit pkgs nodejs; - libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null; + libtool = if pkgs.stdenv.isDarwin then pkgs.cctools else null; }; in import ./node-packages.nix { diff --git a/pkgs/servers/sql/mariadb/default.nix b/pkgs/servers/sql/mariadb/default.nix index 3ff31ba1d3abe..60f71f2894680 100644 --- a/pkgs/servers/sql/mariadb/default.nix +++ b/pkgs/servers/sql/mariadb/default.nix @@ -250,28 +250,24 @@ in # Supported until 2025-06-24 version = "10.5.23"; hash = "sha256-P3wzsgjLeZ2wFKh09WcY6t/yLulXgfo2Cqa8aWEJrP4="; - inherit (self.darwin) cctools; inherit (self.darwin.apple_sdk.frameworks) CoreServices; }; mariadb_106 = self.callPackage generic { # Supported until 2026-07-06 version = "10.6.16"; hash = "sha256-Xvg4Q+eW3Nqa6keyRpDd9thI9D9D4R+dmgzCHHj7uc8="; - inherit (self.darwin) cctools; inherit (self.darwin.apple_sdk.frameworks) CoreServices; }; mariadb_1011 = self.callPackage generic { # Supported until 2028-02-16 version = "10.11.6"; hash = "sha256-HAFjRj6Y1x9HgHQWEaQJge7ivETTkmAcpJu/lI0E3Wc="; - inherit (self.darwin) cctools; inherit (self.darwin.apple_sdk.frameworks) CoreServices; }; mariadb_110 = self.callPackage generic { # Supported until 2024-06-07 version = "11.0.4"; hash = "sha256-J2ls3zEVnyJUEOtchmW4VkWhxZmBzlr2vP9sll/u3ms="; - inherit (self.darwin) cctools; inherit (self.darwin.apple_sdk.frameworks) CoreServices; }; } diff --git a/pkgs/servers/web-apps/ethercalc/node-packages.nix b/pkgs/servers/web-apps/ethercalc/node-packages.nix index 22b4c99d08aef..ac7a58a6d0643 100644 --- a/pkgs/servers/web-apps/ethercalc/node-packages.nix +++ b/pkgs/servers/web-apps/ethercalc/node-packages.nix @@ -8,7 +8,7 @@ let nodeEnv = import ../../../development/node-packages/node-env.nix { inherit (pkgs) stdenv lib python2 runCommand writeTextFile writeShellScript; inherit pkgs nodejs; - libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null; + libtool = if pkgs.stdenv.isDarwin then pkgs.cctools else null; }; in import ./node-packages-generated.nix { diff --git a/pkgs/servers/x11/xorg/darwin/libunwind.patch b/pkgs/servers/x11/xorg/darwin/libunwind.patch new file mode 100644 index 0000000000000..af63f325d0001 --- /dev/null +++ b/pkgs/servers/x11/xorg/darwin/libunwind.patch @@ -0,0 +1,53 @@ +diff -ur a/os/backtrace.c b/os/backtrace.c +--- a/os/backtrace.c 2024-04-12 13:17:00.000000000 -0400 ++++ b/os/backtrace.c 2024-05-17 21:02:02.049859348 -0400 +@@ -40,6 +40,40 @@ + #endif + #include + ++static const char* unw_strerror(int error_code) ++{ ++ switch (error_code) { ++ case UNW_ESUCCESS: ++ return "no error"; ++ case UNW_EUNSPEC: ++ return "unspecified (general) error"; ++ case UNW_ENOMEM: ++ return "out of memory"; ++ case UNW_EBADREG: ++ return "bad register number"; ++ case UNW_EREADONLYREG: ++ return "attempt to write read-only register"; ++ case UNW_ESTOPUNWIND: ++ return "stop unwinding"; ++ case UNW_EINVALIDIP: ++ return "invalid IP"; ++ case UNW_EBADFRAME: ++ return "bad frame"; ++ case UNW_EINVAL: ++ return "unsupported operation or bad value"; ++ case UNW_EBADVERSION: ++ return "unwind info has unsupported version"; ++ case UNW_ENOINFO: ++ return "no unwind info found"; ++#if defined(_LIBUNWIND_TARGET_AARCH64) && !defined(_LIBUNWIND_IS_NATIVE_ONLY) ++ case UNW_ECROSSRASIGNING: ++ return "cross unwind with return address signing"; ++#endif ++ default: ++ return "unknown error occurred"; ++ } ++} ++ + void + xorg_backtrace(void) + { +@@ -53,7 +87,7 @@ + const char *filename; + Dl_info dlinfo; + +- pip.unwind_info = NULL; ++ pip.unwind_info = 0; + ret = unw_getcontext(&context); + if (ret) { + ErrorFSigSafe("unw_getcontext failed: %s [%d]\n", unw_strerror(ret), diff --git a/pkgs/servers/x11/xorg/overrides.nix b/pkgs/servers/x11/xorg/overrides.nix index a6d7d7e6a7f0c..8033c0668fc60 100644 --- a/pkgs/servers/x11/xorg/overrides.nix +++ b/pkgs/servers/x11/xorg/overrides.nix @@ -864,6 +864,8 @@ self: super: }) ./darwin/bundle_main.patch ./darwin/stub.patch + # Fixes incompatibility with LLVM libunwind + ./darwin/libunwind.patch ]; postPatch = attrs.postPatch + '' diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix index 2304b3289b7eb..06acfa4b88350 100644 --- a/pkgs/stdenv/adapters.nix +++ b/pkgs/stdenv/adapters.nix @@ -129,8 +129,6 @@ rec { # Best effort static binaries. Will still be linked to libSystem, # but more portable than Nix store binaries. makeStaticDarwin = stdenv: stdenv.override (old: { - # extraBuildInputs are dropped in cross.nix, but darwin still needs them - extraBuildInputs = [ pkgs.buildPackages.darwin.CF ]; mkDerivationFromStdenv = withOldMkDerivation old (stdenv: mkDerivationSuper: args: (mkDerivationSuper args).overrideAttrs (prevAttrs: { NIX_CFLAGS_LINK = toString (prevAttrs.NIX_CFLAGS_LINK or "") diff --git a/pkgs/stdenv/cross/default.nix b/pkgs/stdenv/cross/default.nix index 1cbbfeb6d2025..74600510b00b8 100644 --- a/pkgs/stdenv/cross/default.nix +++ b/pkgs/stdenv/cross/default.nix @@ -51,13 +51,16 @@ in lib.init bootStages ++ [ hostPlatform = crossSystem; targetPlatform = crossSystem; - # 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 - ++ lib.optionals hostPlatform.isDarwin [ buildPackages.targetPackages.darwin.apple_sdk.frameworks.CoreFoundation ] - ; - allowedRequisites = null; + # 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 + ++ lib.optionals hostPlatform.isDarwin [ + buildPackages.targetPackages.darwin.apple_sdk.frameworks.CoreFoundation + buildPackages.targetPackages.darwin.apple_sdk.sdkRoot + ] + ; + allowedRequisites = null; hasCC = !targetPlatform.isGhcjs; diff --git a/pkgs/stdenv/darwin/default.nix b/pkgs/stdenv/darwin/default.nix index 45cc6742c7205..50dfd90d0e181 100644 --- a/pkgs/stdenv/darwin/default.nix +++ b/pkgs/stdenv/darwin/default.nix @@ -93,7 +93,7 @@ let extraBuildCommands = let - inherit (prevStage.llvmPackages) clang-unwrapped compiler-rt release_version; + inherit (prevStage.llvmPackages) clang-unwrapped compiler-rt; in '' function clangResourceRootIncludePath() { @@ -138,9 +138,8 @@ let inherit config; - extraBuildInputs = [ prevStage.darwin.CF ]; - extraNativeBuildInputs = extraNativeBuildInputs - ++ [ prevStage.darwin.apple_sdk.sdkRoot ]; + extraBuildInputs = [ prevStage.darwin.CF prevStage.darwin.apple_sdk.sdkRoot ]; + extraNativeBuildInputs = extraNativeBuildInputs; preHook = lib.optionalString (!isBuiltByNixpkgsCompiler bash) '' # Don't patch #!/interpreter because it leads to retained @@ -174,9 +173,6 @@ let overrides = self: super: (overrides self super) // { fetchurl = thisStdenv.fetchurlBoot; fetchpatch = super.fetchpatch.override { inherit (self) fetchurl; }; - fetchgit = super.fetchgit.override { - git = super.git.override { curl = bootstrapTools; }; - }; fetchzip = super.fetchzip.override { inherit (self) fetchurl; }; }; }; @@ -192,6 +188,9 @@ in ({}: { __raw = true; + cctools = true; + ld64 = true; + coreutils = null; gnugrep = null; @@ -202,7 +201,6 @@ in apple_sdk.sdkRoot = null; binutils = null; binutils-unwrapped = null; - cctools = null; print-reexports = null; rewrite-tbd = null; sigtool = null; @@ -233,21 +231,111 @@ in # stage should only access the stage that came before it. ccWrapperStdenv = self.stdenv; - bash = bootstrapTools; + bash = bootstrapTools // { + shellPath = "/bin/bash"; + }; + coreutils = bootstrapTools; cpio = bootstrapTools; gnugrep = bootstrapTools; pbzx = bootstrapTools; + cctools = super.stdenv.mkDerivation { + pname = "bootstrap-stage0-cctools"; + version = "boot"; + + buildCommand = '' + declare -a cctools=( + ar + bitcode_strip + check_dylib + checksyms + cmpdylib + codesign_allocate + ctf_insert + depinfo + diagtest + gas + gprof + install_name_tool + libtool + lipo + mtoc + mtor + nm + nmedit + otool + pagestuff + ranlib + redo_prebinding + seg_addr_table + seg_hack + segedit + size + strings + strip + vtool + ) + + mkdir -p "$out/bin" + for tool in "''${cctools[@]}"; do + toolsrc="${bootstrapTools}/bin/$tool" + if [ -e "$toolsrc" ]; then + ln -s "$toolsrc" "$out/bin" + fi + done + + # Copy only the required headers to avoid accidentally linking headers that belong to other packages, + # which can cause problems when building Libsystem in the source-based SDK. + declare -a machohdrs=( + arch.h + fat.h + fixup-chains.h + getsect.h + ldsyms.h + loader.h + nlist.h + ranlib.h + reloc.h + stab.h + swap.h + arm + arm64 + hppa + i386 + i860 + m68k + m88k + ppc + sparc + x86_64 + ) + + mkdir -p "$out/include/mach-o" + for header in "''${machohdrs[@]}"; do + machosrc="${bootstrapTools}/include-Libsystem/mach-o/$header" + if [ -e "$machosrc" ]; then + cp -r "$machosrc" "$out/include/mach-o/$header" + fi + done + ''; + + passthru = { + isFromBootstrapFiles = true; + targetPrefix = ""; + }; + }; + + ld64 = bootstrapTools // { + targetPrefix = ""; + version = "boot"; + }; + darwin = super.darwin.overrideScope (selfDarwin: superDarwin: { # Prevent CF from being propagated to the initial stdenv. Packages that require it # will have to manually add it to their build inputs. CF = null; - binutils-unwrapped = bootstrapTools // { - version = "boot"; - }; - binutils = super.wrapBintoolsWith { name = "bootstrap-stage0-binutils-wrapper"; @@ -263,14 +351,29 @@ in bintools = selfDarwin.binutils-unwrapped; - inherit (selfDarwin) postLinkSignHook signingUtils; + # Bootstrap tools cctools needs the hook and wrappers to make sure things are signed properly. + # This can be dropped once the bootstrap tools cctools has been updated to 1010.6. + extraBuildCommands = '' + echo 'source ${selfDarwin.postLinkSignHook}' >> $out/nix-support/post-link-hook + + export signingUtils=${selfDarwin.signingUtils} + + wrap \ + install_name_tool ${../../build-support/bintools-wrapper/darwin-install_name_tool-wrapper.sh} \ + "${selfDarwin.binutils-unwrapped}/bin/install_name_tool" + + wrap \ + strip ${../../build-support/bintools-wrapper/darwin-strip-wrapper.sh} \ + "${selfDarwin.binutils-unwrapped}/bin/strip" + ''; }; - cctools = bootstrapTools // { - targetPrefix = ""; + binutils-unwrapped = (superDarwin.binutils-unwrapped.overrideAttrs (old: { version = "boot"; - man = bootstrapTools; - }; + passthru = (old.passthru or { }) // { + isFromBootstrapFiles = true; + }; + })).override { enableManpages = false; }; locale = self.stdenv.mkDerivation { name = "bootstrap-stage0-locale"; @@ -285,6 +388,11 @@ in sigtool = bootstrapTools; } // lib.optionalAttrs (! useAppleSDKLibs) { + Csu = bootstrapTools // { + name = "bootstrap-stage0-Csu"; + passthru.isFromBootstrapFiles = true; + }; + Libsystem = self.stdenv.mkDerivation { name = "bootstrap-stage0-Libsystem"; buildCommand = '' @@ -300,12 +408,20 @@ in ln -s libSystem.tbd $out/lib/lib$name.tbd done - ln -s ${bootstrapTools}/lib/*.o $out/lib + ln -s ${selfDarwin.libresolv}/lib/* $out/lib + ln -s ${selfDarwin.Csu}/lib/*.o $out/lib + ln -s ${bootstrapTools}/include-Libsystem $out/include + ''; + passthru.isFromBootstrapFiles = true; + }; + + libresolv = self.stdenv.mkDerivation { + name = "bootstrap-stage0-libresolv"; + buildCommand = '' + mkdir -p $out/lib ln -s ${bootstrapTools}/lib/libresolv.9.dylib $out/lib ln -s libresolv.9.dylib $out/lib/libresolv.dylib - - ln -s ${bootstrapTools}/include-Libsystem $out/include ''; passthru.isFromBootstrapFiles = true; }; @@ -330,19 +446,21 @@ in hardeningUnsupportedFlags = [ "fortify3" "zerocallusedregs" ]; }; }; - clang-unwrapped = selfTools.libclang; libllvm = self.stdenv.mkDerivation { name = "bootstrap-stage0-llvm"; outputs = [ "out" "lib" ]; buildCommand = '' mkdir -p $out/bin $out/lib ln -s $out $lib - ln -s ${bootstrapTools}/bin/strip $out/bin/llvm-strip - ln -s ${bootstrapTools}/lib/libLLVM* $out/lib + for tool in ${toString super.darwin.binutils-unwrapped.llvm_cmds}; do + cctoolsTool=''${tool//-/_} + ln -s ${bootstrapTools}/bin/$cctoolsTool $out/bin/llvm-$tool + done + ln -s ${bootstrapTools}/bin/dsymutil $out/bin/dsymutil + ln -s ${bootstrapTools}/lib/libLLVM* $out/lib ''; passthru.isFromBootstrapFiles = true; }; - llvm = selfTools.libllvm; }); libraries = super.llvmPackages.libraries.extend (_: _: { libcxx = self.stdenv.mkDerivation { @@ -380,30 +498,20 @@ in ''; }) - # This stage is primarily responsible for building the linker and setting up versions of - # certain dependencies needed by the rest of the build process. It is necessary to rebuild the - # linker because the `compiler-rt` build process checks the version and attempts to manually - # run `codesign` if it detects a version of `ld64` it considers too old. If that happens, the - # build process will fail for a few different reasons: - # - sigtool is too old and does not accept the `--sign` argument; - # - sigtool is new enough to accept the `--sign` argument, but it aborts when it is invoked on a - # binary that is already signed; or - # - compiler-rt attempts to invoke `codesign` on x86_64-darwin, but `sigtool` is not currently - # part of the x86_64-darwin bootstrap tools. - # - # This stage also builds CF and Libsystem to simplify assertions and assumptions for later by - # making sure both packages are present on x86_64-darwin and aarch64-darwin. + # This stage is primarily responsible for setting up versions of certain dependencies needed + # by the rest of the build process. This stage also builds CF and Libsystem to simplify assertions + # and assumptions for later by making sure both packages are present on x86_64-darwin and aarch64-darwin. (prevStage: # previous stage0 stdenv: assert lib.all isFromBootstrapFiles ( - with prevStage; [ bash coreutils cpio gnugrep ] ++ lib.optionals useAppleSDKLibs [ pbzx ] + with prevStage; [ bash cctools coreutils cpio gnugrep ld64 ] ++ lib.optionals useAppleSDKLibs [ pbzx ] ); assert lib.all isFromBootstrapFiles (with prevStage.darwin; [ - binutils-unwrapped cctools print-reexports rewrite-tbd sigtool + binutils-unwrapped print-reexports rewrite-tbd sigtool ]); - assert (! useAppleSDKLibs) -> lib.all isFromBootstrapFiles (with prevStage.darwin; [ Libsystem ]); + assert (! useAppleSDKLibs) -> lib.all isFromBootstrapFiles (with prevStage.darwin; [ Libsystem libresolv ]); assert useAppleSDKLibs -> lib.all isFromNixpkgs (with prevStage.darwin; [ Libsystem ]); assert lib.all isFromNixpkgs (with prevStage.darwin; [ dyld launchd xnu ]); assert (with prevStage.darwin; (! useAppleSDKLibs) -> CF == null); @@ -417,7 +525,10 @@ in overrides = self: super: { inherit (prevStage) ccWrapperStdenv - coreutils gnugrep; + cctools coreutils gnugrep ld64; + + binutils-unwrapped = builtins.throw "nothing in the bootstrap should depend on GNU binutils"; + curl = builtins.throw "nothing in the bootstrap can depend on curl"; # Use this stage’s CF to build CMake. It’s required but can’t be included in the stdenv. cmake = self.cmakeMinimal; @@ -436,18 +547,20 @@ in ninja = super.ninja.override { buildDocs = false; }; - # Use this stage’s CF to build Python. It’s required but can’t be included in the stdenv. + # Use this stage’s CF to build Python. It’s required, but it can’t be included in the stdenv. python3 = self.python3Minimal; - python3Minimal = super.python3Minimal.overrideAttrs (old: { - buildInputs = old.buildInputs ++ [ self.darwin.CF ]; + python3Minimal = (super.python3Minimal.override { + self = self.python3Minimal; + }).overrideAttrs (old: { + buildInputs = old.buildInputs or [ ] ++ [ self.darwin.CF ]; }); darwin = super.darwin.overrideScope (selfDarwin: superDarwin: { apple_sdk = superDarwin.apple_sdk // { - inherit (prevStage.darwin.apple_sdk) sdkRoot; + inherit (prevStage.darwin.apple_sdk) binutils-unwrapped sdkRoot; }; - # Use this stage’s CF to build configd. It’s required but can’t be included in the stdenv. + # Use this stage’s CF to build configd. It’s required, but it can’t be included in the stdenv. configd = superDarwin.configd.overrideAttrs (old: { buildInputs = old.buildInputs or [ ] ++ [ self.darwin.CF ]; }); @@ -460,21 +573,37 @@ in inherit (selfDarwin) sigtool; }; + # Rewrap binutils with the real Libsystem binutils = superDarwin.binutils.override { inherit (self) coreutils; - inherit (selfDarwin) postLinkSignHook signingUtils; - bintools = selfDarwin.binutils-unwrapped; libc = selfDarwin.Libsystem; + # TODO(@sternenseemann): can this be removed? runtimeShell = "${bootstrapTools}/bin/bash"; + + # Bootstrap tools cctools needs the hook to make sure things are signed properly. + # This can be dropped once the bootstrap tools cctools has been updated to 1010.6. + extraBuildCommands = '' + echo 'source ${selfDarwin.postLinkSignHook}' >> $out/nix-support/post-link-hook + + export signingUtils=${selfDarwin.signingUtils} + + wrap \ + install_name_tool ${../../build-support/bintools-wrapper/darwin-install_name_tool-wrapper.sh} \ + "${selfDarwin.binutils-unwrapped}/bin/install_name_tool" + + wrap \ + strip ${../../build-support/bintools-wrapper/darwin-strip-wrapper.sh} \ + "${selfDarwin.binutils-unwrapped}/bin/strip" + ''; }; + # Avoid building unnecessary Python dependencies due to building LLVM manpages. binutils-unwrapped = superDarwin.binutils-unwrapped.override { - inherit (selfDarwin) cctools; + inherit (self) cctools ld64; + enableManpages = false; }; - - cctools = selfDarwin.cctools-port; }); llvmPackages = super.llvmPackages // ( @@ -500,34 +629,29 @@ in extraPreHook = '' stripAllFlags=" " # the cctools "strip" command doesn't know "-s" stripDebugFlags="-S" # the cctools "strip" command does something odd with "-p" - - # Don’t assume the ld64 in bootstrap tools supports response files. Only recent versions do. - export NIX_LD_USE_RESPONSE_FILE=0 ''; }) - # Build cctools, Python, and sysctl for use by LLVM’s check phase. They must be built in - # their stage to prevent infinite recursions and to make sure the stdenv used to build - # LLVM has the newly built cctools instead of the one from the bootstrap tools. + # Build sysctl for use by LLVM’s check phase. It must be built separately to avoid an infinite recursion. (prevStage: # previous stage1 stdenv: - assert lib.all isFromBootstrapFiles (with prevStage; [ coreutils gnugrep ]); + assert lib.all isFromBootstrapFiles (with prevStage; [ cctools coreutils gnugrep ld64 ]); assert lib.all isBuiltByBootstrapFilesCompiler (with prevStage; [ - autoconf automake bash binutils-unwrapped bison brotli cmake cpio cyrus_sasl db + autoconf automake bash bison brotli cmake cpio cyrus_sasl db ed expat flex gettext gmp groff icu libedit libffi libiconv libidn2 libkrb5 libssh2 libtool libunistring libxml2 m4 ncurses nghttp2 ninja openldap openssh openssl - patchutils pbzx perl pkg-config.pkg-config python3 python3Minimal scons serf sqlite + patchutils pbzx perl pkg-config.pkg-config python3Minimal scons serf sqlite subversion texinfo unzip which xz zlib zstd ]); assert lib.all isBuiltByBootstrapFilesCompiler (with prevStage.darwin; [ - binutils-unwrapped cctools locale libtapi print-reexports rewrite-tbd sigtool + locale print-reexports rewrite-tbd sigtool ]); - assert (! useAppleSDKLibs) -> lib.all isBuiltByBootstrapFilesCompiler (with prevStage.darwin; [ Libsystem configd ]); + assert (! useAppleSDKLibs) -> lib.all isBuiltByBootstrapFilesCompiler (with prevStage.darwin; [ configd libresolv ]); assert (! useAppleSDKLibs) -> lib.all isFromNixpkgs (with prevStage.darwin; [ CF ]); - assert useAppleSDKLibs -> lib.all isFromNixpkgs (with prevStage.darwin; [ CF Libsystem libobjc]); - assert lib.all isFromNixpkgs (with prevStage.darwin; [ dyld launchd xnu ]); + assert useAppleSDKLibs -> lib.all isFromNixpkgs (with prevStage.darwin; [ CF libobjc]); + assert lib.all isFromNixpkgs (with prevStage.darwin; [ Libsystem binutils-unwrapped dyld launchd xnu ]); assert lib.all isFromBootstrapFiles (with prevStage.llvmPackages; [ clang-unwrapped libclang libllvm llvm compiler-rt libcxx @@ -540,40 +664,30 @@ in overrides = self: super: { inherit (prevStage) ccWrapperStdenv - autoconf automake bash binutils binutils-unwrapped bison brotli cmake cmakeMinimal - coreutils cpio cyrus_sasl db ed expat flex gettext gmp gnugrep groff icu + autoconf automake bash binutils binutils-unwrapped bison brotli cctools cmake cmakeMinimal + coreutils curl cpio cyrus_sasl db ed expat flex gettext gmp gnugrep groff icu ld64 libedit libffi libidn2 libkrb5 libssh2 libtool libunistring libxml2 m4 ncurses nghttp2 ninja openldap openssh openssl patchutils pbzx perl pkg-config python3Minimal scons sed serf sharutils sqlite subversion texinfo unzip which xz zlib zstd; - # Support for the SystemConfiguration framework is required to run the LLVM tests, but trying - # to override python3Minimal does not appear to work. - python3 = (super.python3.override { - inherit (self) libffi; - inherit (self.darwin) configd; - openssl = null; - readline = null; - ncurses = null; - gdbm = null; - sqlite = null; - tzdata = null; - stripConfig = true; - stripIdlelib = true; - stripTests = true; - stripTkinter = true; - rebuildBytecode = false; - stripBytecode = true; - includeSiteCustomize = false; - enableOptimizations = false; + # Avoid pulling in openldap just to run Meson’s tests. + meson = super.meson.overrideAttrs { + doInstallCheck = false; + }; + + # The bootstrap Python needs its own `pythonAttr` to make sure the override works properly. + python3 = self.python3-bootstrap; + python3-bootstrap = super.python3.override { + self = self.python3-bootstrap; + pythonAttr = "python3-bootstrap"; enableLTO = false; - mimetypesSupport = false; - }).overrideAttrs (_: { pname = "python3-minimal-scproxy"; }); + }; darwin = super.darwin.overrideScope (_: superDarwin: { inherit (prevStage.darwin) - CF sdkRoot Libsystem binutils-unwrapped cctools cctools-port configd darwin-stubs dyld - launchd libclosure libdispatch libobjc locale objc4 postLinkSignHook + CF sdkRoot Libsystem binutils binutils-unwrapped configd darwin-stubs dyld + launchd libclosure libdispatch libobjc libresolv locale objc4 postLinkSignHook print-reexports rewrite-tbd signingUtils sigtool; apple_sdk = superDarwin.apple_sdk // { @@ -600,10 +714,8 @@ in prevStage.gnu-config ]; - # Until LLVM is rebuilt, assume `strip` is the one from cctools. extraPreHook = '' - stripAllFlags=" " # the cctools "strip" command doesn't know "-s" - stripDebugFlags="-S" # the cctools "strip" command does something odd with "-p" + stripDebugFlags="-S" # llvm-strip does not support "-p" for Mach-O ''; }) @@ -612,66 +724,71 @@ in # but those libraries will be used in the final stdenv. # # Rebuild coreutils and gnugrep to avoid unwanted references to the bootstrap tools on `PATH`. + # + # The first build of cctools is deferred until this stage because it depends on LLVM headers + # that are not included in the bootstrap tools tarball. (prevStage: # previous stage-sysctl stdenv: - assert lib.all isFromBootstrapFiles (with prevStage; [ coreutils gnugrep ]); + assert lib.all isFromBootstrapFiles (with prevStage; [ cctools coreutils gnugrep ld64 ]); assert lib.all isBuiltByBootstrapFilesCompiler (with prevStage; [ - atf autoconf automake bash binutils-unwrapped bison brotli cmake cpio cyrus_sasl db + atf autoconf automake bash bison brotli cmake cpio cyrus_sasl db ed expat flex gettext gmp groff icu kyua libedit libffi libiconv libidn2 libkrb5 libssh2 - libtool libunistring libxml2 m4 ncurses nghttp2 ninja openldap openssh openssl + libtapi libtool libunistring libxml2 m4 meson ncurses nghttp2 ninja openldap openssh openssl patchutils pbzx perl pkg-config.pkg-config python3 python3Minimal scons serf sqlite subversion sysctl.provider texinfo unzip which xz zlib zstd ]); assert lib.all isBuiltByBootstrapFilesCompiler (with prevStage.darwin; [ - binutils-unwrapped cctools locale libtapi print-reexports rewrite-tbd sigtool + locale print-reexports rewrite-tbd sigtool ]); - assert (! useAppleSDKLibs) -> lib.all isBuiltByBootstrapFilesCompiler (with prevStage.darwin; [ Libsystem configd ]); + assert (! useAppleSDKLibs) -> lib.all isBuiltByBootstrapFilesCompiler (with prevStage.darwin; [ configd libresolv ]); assert (! useAppleSDKLibs) -> lib.all isFromNixpkgs (with prevStage.darwin; [ CF ]); - assert useAppleSDKLibs -> lib.all isFromNixpkgs (with prevStage.darwin; [ CF Libsystem libobjc ]); - assert lib.all isFromNixpkgs (with prevStage.darwin; [ dyld launchd xnu ]); + assert useAppleSDKLibs -> lib.all isFromNixpkgs (with prevStage.darwin; [ CF libobjc]); + assert lib.all isFromNixpkgs (with prevStage.darwin; [ Libsystem binutils-unwrapped dyld launchd xnu ]); assert lib.all isFromBootstrapFiles (with prevStage.llvmPackages; [ clang-unwrapped libclang libllvm llvm compiler-rt libcxx ]); - assert lib.getVersion prevStage.stdenv.cc.bintools.bintools == lib.getVersion prevStage.darwin.cctools-port; - stageFun prevStage { name = "bootstrap-stage-xclang"; overrides = self: super: { inherit (prevStage) ccWrapperStdenv atf autoconf automake bash binutils binutils-unwrapped bison brotli cmake cmakeMinimal - cpio cyrus_sasl db ed expat flex gettext gmp groff icu kyua libedit libffi libiconv - libidn2 libkrb5 libssh2 libtool libunistring libxml2 m4 ncurses nghttp2 ninja + cpio curl cyrus_sasl db ed expat flex gettext gmp groff icu kyua libedit libffi libiconv + libidn2 libkrb5 libssh2 libtool libunistring libxml2 m4 meson ncurses nghttp2 ninja openldap openssh openssl patchutils pbzx perl pkg-config python3 python3Minimal scons sed serf sharutils sqlite subversion sysctl texinfo unzip which xz zlib zstd; - # Switch from cctools-port to cctools-llvm now that LLVM has been built. - darwin = super.darwin.overrideScope (_: superDarwin: { + ld64 = super.ld64.overrideAttrs { doCheck = false; }; + + darwin = super.darwin.overrideScope (selfDarwin: superDarwin: { inherit (prevStage.darwin) - CF Libsystem configd darwin-stubs dyld launchd libclosure libdispatch libobjc + CF Libsystem configd darwin-stubs dyld launchd libclosure libdispatch libobjc libresolv locale objc4 postLinkSignHook print-reexports rewrite-tbd signingUtils sigtool; apple_sdk = superDarwin.apple_sdk // { inherit (prevStage.darwin.apple_sdk) sdkRoot; }; + binutils = superDarwin.binutils.override { + inherit (prevStage) expand-response-params; + libc = selfDarwin.Libsystem; + }; + # Avoid building unnecessary Python dependencies due to building LLVM manpages. - cctools-llvm = superDarwin.cctools-llvm.override { enableManpages = false; }; + binutils-unwrapped = superDarwin.binutils-unwrapped.override { enableManpages = false; }; }); llvmPackages = super.llvmPackages // ( let - llvmMajor = lib.versions.major super.llvmPackages.release_version; - # libc++, and libc++abi do not need CoreFoundation. Avoid propagating the CF from prior # stages to the final stdenv via rpath by dropping it from `extraBuildInputs`. stdenvNoCF = self.stdenv.override { - extraBuildInputs = [ ]; + extraBuildInputs = [ prevStage.darwin.apple_sdk.sdkRoot ]; }; libcxxBootstrapStdenv = self.overrideCC stdenvNoCF (self.llvmPackages.clangNoCompilerRtWithLibc.override { @@ -679,14 +796,30 @@ in nixSupport.cc-ldflags = [ "-lSystem" ]; }); + tools = super.llvmPackages.tools.extend (selfTools: superTools: { + # Disable checks in the first build of LLVM, which requires Python 3 and take a lot of time. + libllvm = superTools.libllvm.override { doCheck = false; }; + }); + libraries = super.llvmPackages.libraries.extend (selfLib: superLib: { compiler-rt = null; libcxx = superLib.libcxx.override ({ stdenv = libcxxBootstrapStdenv; }); + # Not ideal, but use the old bintools to link libunwind. Otherwise, it will cause an infinite recursion + # when libunwind depends on bintools depends on ld64 depends on libunwind. + libunwind = superLib.libunwind.override ({ + stdenv = libcxxBootstrapStdenv.override (old: { + cc = old.cc.override { + bintools = prevStage.stdenv.cc.bintools.override { + inherit (old.cc) libc; + }; + }; + }); + }); }); in - { inherit libraries; } // libraries + { inherit tools libraries; } // tools // libraries ); }; @@ -696,18 +829,16 @@ in ]; extraPreHook = '' - stripAllFlags=" " # the cctools "strip" command doesn't know "-s" - stripDebugFlags="-S" # the cctools "strip" command does something odd with "-p" + stripDebugFlags="-S" # llvm-strip does not support "-p" for Mach-O ''; }) - # This stage rebuilds Libsystem. It also rebuilds bash, which will be needed in later stages - # to use in patched shebangs (e.g., to make sure `icu-config` uses bash from nixpkgs). + # This stage rebuilds CF, Libsystem, and bash, which is needed in later stages to patch shebangs. (prevStage: # previous stage-xclang stdenv: assert lib.all isBuiltByBootstrapFilesCompiler (with prevStage; [ - atf autoconf automake bash binutils-unwrapped bison cmake cmakeMinimal coreutils cpio - cyrus_sasl db ed expat flex gettext gmp gnugrep groff icu kyua libedit libtool m4 ninja + atf autoconf automake bash bison cctools cmake cmakeMinimal coreutils cpio + cyrus_sasl db ed expat flex gettext gmp gnugrep groff icu kyua ld64 libedit libtapi libtool m4 meson ninja openbsm openldap openpam openssh patchutils pbzx perl pkg-config.pkg-config python3 python3Minimal scons serf sqlite subversion sysctl.provider texinfo unzip which xz ]); @@ -718,31 +849,31 @@ in ]); assert lib.all isBuiltByBootstrapFilesCompiler (with prevStage.darwin; [ - binutils-unwrapped cctools locale libtapi print-reexports rewrite-tbd sigtool + locale print-reexports rewrite-tbd sigtool ]); - assert (! useAppleSDKLibs) -> lib.all isBuiltByBootstrapFilesCompiler (with prevStage.darwin; [ Libsystem configd ]); + assert (! useAppleSDKLibs) -> lib.all isBuiltByBootstrapFilesCompiler (with prevStage.darwin; [ configd libresolv ]); assert (! useAppleSDKLibs) -> lib.all isFromNixpkgs (with prevStage.darwin; [ CF ]); - assert useAppleSDKLibs -> lib.all isFromNixpkgs (with prevStage.darwin; [ CF Libsystem libobjc ]); - assert lib.all isFromNixpkgs (with prevStage.darwin; [ dyld launchd libclosure libdispatch xnu ]); + assert useAppleSDKLibs -> lib.all isFromNixpkgs (with prevStage.darwin; [ CF libobjc]); + assert lib.all isFromNixpkgs (with prevStage.darwin; [ + Libsystem binutils-unwrapped dyld launchd libclosure libdispatch xnu + ]); assert lib.all isBuiltByBootstrapFilesCompiler (with prevStage.llvmPackages; [ clang-unwrapped libclang libllvm llvm ]); - assert lib.all isBuiltByNixpkgsCompiler (with prevStage.llvmPackages; [ libcxx ]); + assert lib.all isBuiltByNixpkgsCompiler (with prevStage.llvmPackages; [ libcxx libunwind ]); assert prevStage.llvmPackages.compiler-rt == null; - assert lib.getVersion prevStage.stdenv.cc.bintools.bintools == lib.getVersion prevStage.darwin.cctools-port; - stageFun prevStage { - name = "bootstrap-stage2-Libsystem"; + name = "bootstrap-stage2"; overrides = self: super: { inherit (prevStage) ccWrapperStdenv - atf autoconf automake binutils-unwrapped bison brotli cmake cmakeMinimal coreutils - cpio cyrus_sasl db ed expat flex gettext gmp gnugrep groff icu kyua libedit libffi - libiconv libidn2 libkrb5 libssh2 libtool libunistring libxml2 m4 ncurses nghttp2 + atf autoconf automake binutils binutils-unwrapped bison brotli cctools cmake cmakeMinimal coreutils + cpio curl cyrus_sasl db ed expat flex gettext gmp gnugrep groff icu kyua ld64 libedit libffi + libiconv libidn2 libkrb5 libssh2 libtapi libtool libunistring libxml2 m4 meson ncurses nghttp2 ninja openbsm openldap openpam openssh openssl patchutils pbzx perl pkg-config python3 python3Minimal scons serf sqlite subversion sysctl texinfo unzip which xz zlib zstd; @@ -755,108 +886,12 @@ in darwin = super.darwin.overrideScope (selfDarwin: superDarwin: { inherit (prevStage.darwin) - CF binutils-unwrapped cctools configd darwin-stubs launchd libobjc libtapi locale - objc4 print-reexports rewrite-tbd signingUtils sigtool; + binutils-unwrapped configd darwin-stubs launchd locale postLinkSignHook + print-reexports rewrite-tbd signingUtils sigtool; apple_sdk = superDarwin.apple_sdk // { inherit (prevStage.darwin.apple_sdk) sdkRoot; }; - }); - - llvmPackages = super.llvmPackages // ( - let - tools = super.llvmPackages.tools.extend (_: _: { - inherit (prevStage.llvmPackages) clang-unwrapped clangNoCompilerRtWithLibc libclang libllvm llvm; - }); - - libraries = super.llvmPackages.libraries.extend (selfLib: superLib: { - inherit (prevStage.llvmPackages) compiler-rt libcxx; - }); - in - { inherit tools libraries; inherit (prevStage.llvmPackages) release_version; } // tools // libraries - ); - - # Don’t link anything in this stage against CF to prevent propagating CF from prior stages to - # the final stdenv, which happens because of the rpath hook. - stdenv = - let - stdenvNoCF = super.stdenv.override { - extraBuildInputs = [ ]; - }; - in - self.overrideCC stdenvNoCF (self.llvmPackages.clangNoCompilerRtWithLibc.override { - inherit (self.llvmPackages) libcxx; - }); - }; - - extraNativeBuildInputs = lib.optionals localSystem.isAarch64 [ - prevStage.updateAutotoolsGnuConfigScriptsHook - prevStage.gnu-config - ]; - - extraPreHook = '' - stripDebugFlags="-S" # llvm-strip does not support "-p" for Mach-O - ''; - }) - - # This stage rebuilds CF, compiler-rt, and the sdkRoot derivation. - # - # CF requires: - # - aarch64-darwin: libobjc (due to being apple_sdk.frameworks.CoreFoundation instead of swift-corefoundation) - # - x86_64-darwin: libiconv libxml2 icu zlib - (prevStage: - # previous stage2-Libsystem stdenv: - assert lib.all isBuiltByBootstrapFilesCompiler (with prevStage; [ - atf autoconf automake binutils-unwrapped bison brotli cmake cmakeMinimal coreutils - cpio cyrus_sasl db ed expat flex gettext gmp gnugrep groff icu kyua libedit libidn2 - libkrb5 libssh2 libtool libunistring m4 nghttp2 ninja openbsm openldap openpam openssh - openssl patchutils pbzx perl pkg-config.pkg-config python3 python3Minimal scons serf - sqlite subversion sysctl.provider texinfo unzip which xz zstd - ]); - - assert lib.all isBuiltByNixpkgsCompiler (with prevStage; [ bash ]); - - assert lib.all isBuiltByBootstrapFilesCompiler (with prevStage; [ - libffi libiconv libxml2 ncurses zlib zstd - ]); - - assert lib.all isBuiltByBootstrapFilesCompiler (with prevStage.darwin; [ - binutils-unwrapped cctools locale libtapi print-reexports rewrite-tbd sigtool - ]); - - assert (! useAppleSDKLibs) -> lib.all isBuiltByBootstrapFilesCompiler (with prevStage.darwin; [ configd ]); - assert (! useAppleSDKLibs) -> lib.all isBuiltByNixpkgsCompiler (with prevStage.darwin; [ Libsystem ]); - assert (! useAppleSDKLibs) -> lib.all isFromNixpkgs (with prevStage.darwin; [ CF ]); - assert useAppleSDKLibs -> lib.all isFromNixpkgs (with prevStage.darwin; [ CF Libsystem libobjc ]); - assert lib.all isFromNixpkgs (with prevStage.darwin; [ dyld launchd libclosure libdispatch xnu ]); - - assert lib.all isBuiltByBootstrapFilesCompiler (with prevStage.llvmPackages; [ - clang-unwrapped libclang libllvm llvm - ]); - assert lib.all isBuiltByNixpkgsCompiler (with prevStage.llvmPackages; [ libcxx ]); - assert prevStage.llvmPackages.compiler-rt == null; - - assert lib.getVersion prevStage.stdenv.cc.bintools.bintools == lib.getVersion prevStage.darwin.cctools-llvm; - - stageFun prevStage { - - name = "bootstrap-stage2-CF"; - - overrides = self: super: { - inherit (prevStage) ccWrapperStdenv - atf autoconf automake bash bison brotli cmake cmakeMinimal coreutils cpio - cyrus_sasl db ed expat flex gettext gmp gnugrep groff kyua libedit libidn2 libkrb5 - libssh2 libtool libunistring m4 ncurses nghttp2 ninja openbsm openldap openpam - openssh openssl patchutils pbzx perl pkg-config python3 python3Minimal scons serf - sqlite subversion sysctl texinfo unzip which xz zstd; - - # Avoid pulling in a full python and its extra dependencies for the llvm/clang builds. - libxml2 = super.libxml2.override { pythonSupport = false; }; - - darwin = super.darwin.overrideScope (selfDarwin: superDarwin: { - inherit (prevStage.darwin) - Libsystem configd darwin-stubs launchd locale print-reexports rewrite-tbd - signingUtils sigtool; # Rewrap binutils so it uses the rebuilt Libsystem. binutils = superDarwin.binutils.override { @@ -865,27 +900,23 @@ in } // { passthru = { inherit (prevStage.bintools.passthru) isFromBootstrapFiles; }; }; - - # Avoid building unnecessary Python dependencies due to building LLVM manpages. - cctools-llvm = superDarwin.cctools-llvm.override { enableManpages = false; }; }); llvmPackages = super.llvmPackages // ( let tools = super.llvmPackages.tools.extend (_: _: { - inherit (prevStage.llvmPackages) clang-unwrapped clangNoCompilerRtWithLibc libclang lld libllvm llvm; - clang = prevStage.stdenv.cc; + inherit (prevStage.llvmPackages) clang-unwrapped clangNoCompilerRt clangNoCompilerRtWithLibc libclang libllvm llvm; }); libraries = super.llvmPackages.libraries.extend (selfLib: superLib: { - inherit (prevStage.llvmPackages) libcxx; + inherit (prevStage.llvmPackages) libcxx libunwind; # Make sure compiler-rt is linked against the CF from this stage, which can be # propagated to the final stdenv. CF is required by ASAN. compiler-rt = superLib.compiler-rt.override ({ inherit (self.llvmPackages) libllvm; stdenv = self.stdenv.override { - extraBuildInputs = [ self.darwin.CF ]; + extraBuildInputs = [ self.darwin.CF prevStage.darwin.apple_sdk.sdkRoot ]; }; }); }); @@ -894,22 +925,15 @@ in ); # Don’t link anything in this stage against CF to prevent propagating CF from prior stages to - # the final stdenv, which happens because of the rpath hook. Also don’t use a stdenv with - # compiler-rt because it needs to be built in this stage. + # the final stdenv, which happens because of the rpath hook. stdenv = let stdenvNoCF = super.stdenv.override { - extraBuildInputs = [ ]; + extraBuildInputs = [ prevStage.darwin.apple_sdk.sdkRoot ]; }; in self.overrideCC stdenvNoCF (self.llvmPackages.clangNoCompilerRtWithLibc.override { inherit (self.llvmPackages) libcxx; - - # Make sure the stdenv is using the Libsystem that will be propagated to the final stdenv. - libc = self.darwin.Libsystem; - bintools = self.llvmPackages.clangNoCompilerRtWithLibc.bintools.override { - libc = self.darwin.Libsystem; - }; }); }; @@ -925,40 +949,35 @@ in # Rebuild LLVM with LLVM. This stage also rebuilds certain dependencies needed by LLVM. # - # LLVM requires: libcxx libffi libiconv libxml2 ncurses zlib + # LLVM requires: libcxx libffi libiconv libxml2 ncurses python3 zlib (prevStage: - # previous stage2-CF stdenv: + # previous stage2 stdenv: assert lib.all isBuiltByBootstrapFilesCompiler (with prevStage; [ - autoconf automake bison brotli cmake cmakeMinimal coreutils cpio cyrus_sasl - db ed expat flex gettext gmp gnugrep groff libedit libidn2 libkrb5 libssh2 libtool - libunistring m4 ncurses nghttp2 ninja openbsm openldap openpam openssh openssl + autoconf automake bison brotli cctools cmake cmakeMinimal coreutils cpio cyrus_sasl + db ed expat flex gettext gmp gnugrep groff icu ld64 libiconv libedit libffi libidn2 libkrb5 libssh2 + libtapi libtool libunistring libxml2 m4 ncurses nghttp2 meson ninja openbsm openldap openpam openssh openssl patchutils pbzx perl pkg-config.pkg-config python3 python3Minimal scons serf sqlite - subversion sysctl.provider texinfo unzip which xz zstd - ]); - assert lib.all isBuiltByNixpkgsCompiler (with prevStage; [ - bash binutils-unwrapped icu libffi libiconv libxml2 zlib + subversion sysctl.provider texinfo unzip which xz zstd zlib ]); + assert lib.all isBuiltByNixpkgsCompiler (with prevStage; [ bash ]); assert lib.all isBuiltByBootstrapFilesCompiler (with prevStage.darwin; [ locale print-reexports rewrite-tbd sigtool ]); - assert lib.all isBuiltByNixpkgsCompiler (with prevStage.darwin; [ - binutils-unwrapped cctools libtapi - ]); assert (! useAppleSDKLibs) -> lib.all isBuiltByBootstrapFilesCompiler (with prevStage.darwin; [ configd ]); - assert (! useAppleSDKLibs) -> lib.all isBuiltByNixpkgsCompiler (with prevStage.darwin; [ Libsystem ]); + assert (! useAppleSDKLibs) -> lib.all isBuiltByNixpkgsCompiler (with prevStage.darwin; [ libresolv ]); assert (! useAppleSDKLibs) -> lib.all isFromNixpkgs (with prevStage.darwin; [ CF ]); - assert useAppleSDKLibs -> lib.all isFromNixpkgs (with prevStage.darwin; [ CF Libsystem libobjc ]); - assert lib.all isFromNixpkgs (with prevStage.darwin; [ dyld launchd libclosure libdispatch xnu ]); + assert useAppleSDKLibs -> lib.all isFromNixpkgs (with prevStage.darwin; [ CF libobjc ]); + assert lib.all isFromNixpkgs (with prevStage.darwin; [ + Libsystem binutils-unwrapped dyld launchd libclosure libdispatch xnu + ]); assert lib.all isBuiltByBootstrapFilesCompiler (with prevStage.llvmPackages; [ clang-unwrapped libclang libllvm llvm ]); assert lib.all isBuiltByNixpkgsCompiler (with prevStage.llvmPackages; [ libcxx ]); - assert lib.getVersion prevStage.stdenv.cc.bintools.bintools == lib.getVersion prevStage.darwin.cctools-llvm; - stageFun prevStage { name = "bootstrap-stage3"; @@ -966,21 +985,21 @@ in overrides = self: super: { inherit (prevStage) ccWrapperStdenv autoconf automake bash binutils binutils-unwrapped bison brotli cmake cmakeMinimal - coreutils cpio cyrus_sasl db ed expat flex gettext gmp gnugrep groff libedit - libidn2 libkrb5 libssh2 libtool libunistring m4 nghttp2 ninja openbsm openldap - openpam openssh openssl patchutils pbzx perl pkg-config python3 python3Minimal scons - sed serf sharutils sqlite subversion sysctl texinfo unzip which xz zstd - - # CF dependencies - don’t rebuild them. - icu libiconv libiconv-darwin libxml2 zlib; + coreutils cpio curl cyrus_sasl db ed expat flex gettext gmp gnugrep groff libedit + libidn2 libkrb5 libssh2 libtool libunistring m4 meson nghttp2 ninja python3 python3Minimal openbsm openldap + openpam openssh openssl patchutils pbzx perl pkg-config scons + sed serf sharutils sqlite subversion sysctl texinfo unzip which xz zstd; # Disable tests because they use dejagnu, which fails to run. libffi = super.libffi.override { doCheck = false; }; + # Avoid pulling in a full python and its extra dependencies for the llvm/clang builds. + libxml2 = super.libxml2.override { pythonSupport = false; }; + darwin = super.darwin.overrideScope (selfDarwin: superDarwin: { inherit (prevStage.darwin) - CF Libsystem binutils binutils-unwrapped cctools cctools-llvm cctools-port configd - darwin-stubs dyld launchd libclosure libdispatch libobjc libtapi locale objc4 + CF Libsystem binutils binutils-unwrapped configd + darwin-stubs dyld launchd libclosure libdispatch libobjc libresolv locale objc4 postLinkSignHook print-reexports rewrite-tbd signingUtils sigtool; apple_sdk = superDarwin.apple_sdk // { @@ -991,7 +1010,7 @@ in llvmPackages = super.llvmPackages // ( let libraries = super.llvmPackages.libraries.extend (_: _: { - inherit (prevStage.llvmPackages) compiler-rt libcxx; + inherit (prevStage.llvmPackages) compiler-rt libcxx libunwind; }); in { inherit libraries; } // libraries @@ -1015,43 +1034,40 @@ in assert lib.all isBuiltByBootstrapFilesCompiler (with prevStage; [ autoconf automake bison brotli cmake cmakeMinimal coreutils cpio cyrus_sasl db ed expat flex gettext gmp gnugrep groff libedit libidn2 libkrb5 libssh2 libtool - libunistring m4 nghttp2 ninja openbsm openldap openpam openssh openssl patchutils pbzx + libunistring m4 meson nghttp2 ninja openbsm openldap openpam openssh openssl patchutils pbzx perl pkg-config.pkg-config python3 python3Minimal scons serf sqlite subversion sysctl.provider texinfo unzip which xz zstd ]); assert lib.all isBuiltByNixpkgsCompiler (with prevStage; [ - bash binutils-unwrapped icu libffi libiconv libxml2 zlib + bash cctools icu ld64 libtapi libffi libiconv libxml2 zlib ]); assert lib.all isBuiltByBootstrapFilesCompiler (with prevStage.darwin; [ locale print-reexports rewrite-tbd sigtool ]); - assert lib.all isBuiltByNixpkgsCompiler (with prevStage.darwin; [ - binutils-unwrapped cctools libtapi - ]); assert (! useAppleSDKLibs) -> lib.all isBuiltByBootstrapFilesCompiler (with prevStage.darwin; [ configd ]); - assert (! useAppleSDKLibs) -> lib.all isBuiltByNixpkgsCompiler (with prevStage.darwin; [ Libsystem ]); + assert (! useAppleSDKLibs) -> lib.all isBuiltByNixpkgsCompiler (with prevStage.darwin; [ libresolv ]); assert (! useAppleSDKLibs) -> lib.all isFromNixpkgs (with prevStage.darwin; [ CF ]); - assert useAppleSDKLibs -> lib.all isFromNixpkgs (with prevStage.darwin; [ CF Libsystem libobjc ]); - assert lib.all isFromNixpkgs (with prevStage.darwin; [ dyld launchd libclosure libdispatch xnu ]); + assert useAppleSDKLibs -> lib.all isFromNixpkgs (with prevStage.darwin; [ CF libobjc ]); + assert lib.all isFromNixpkgs (with prevStage.darwin; [ + Libsystem binutils-unwrapped dyld launchd libclosure libdispatch xnu + ]); assert lib.all isBuiltByNixpkgsCompiler (with prevStage.llvmPackages; [ - clang-unwrapped libclang libllvm llvm compiler-rt libcxx + clang-unwrapped libclang libllvm llvm compiler-rt libcxx libunwind ]); - assert lib.getVersion prevStage.stdenv.cc.bintools.bintools == lib.getVersion prevStage.darwin.cctools-llvm; - stageFun prevStage { name = "bootstrap-stage4"; overrides = self: super: { inherit (prevStage) ccWrapperStdenv - autoconf automake bash bison cmake cmakeMinimal cyrus_sasl db expat flex groff - libedit libtool m4 ninja openldap openssh patchutils perl pkg-config python3 scons - serf sqlite subversion sysctl texinfo unzip which + autoconf automake bash binutils binutils-unwrapped bison cmake cmakeMinimal curl cyrus_sasl + db expat flex groff libedit libtool m4 meson ninja openldap openssh patchutils perl pkg-config python3 + python3Minimal scons serf sqlite subversion sysctl texinfo unzip which # CF dependencies - don’t rebuild them. icu @@ -1062,7 +1078,9 @@ in darwin = super.darwin.overrideScope (selfDarwin: superDarwin: { inherit (prevStage.darwin) dyld CF Libsystem darwin-stubs # CF dependencies - don’t rebuild them. - libobjc objc4; + libobjc objc4 + # Libsystem dependencies - don’t rebuild them + libresolv; apple_sdk = superDarwin.apple_sdk // { inherit (prevStage.darwin.apple_sdk) sdkRoot; @@ -1079,26 +1097,19 @@ in libc = selfDarwin.Libsystem; }; - # cctools needs to build the LLVM man pages, which requires sphinx. Sphinx + # binutils-unwrapped needs to build the LLVM man pages, which requires sphinx. Sphinx # has hatch-vcs as a transitive dependency, which pulls in git (and curl). # Disabling the tests for hatch-vcs allows the stdenv bootstrap to avoid having # any dependency on curl other than the one provided in the bootstrap tools. - cctools-llvm = superDarwin.cctools-llvm.override (old: { - llvmPackages = - let - tools = old.llvmPackages.tools.extend (_: superTools: { - llvm-manpages = superTools.llvm-manpages.override { - python3Packages = prevStage.python3Packages.overrideScope (_: superPython: { - hatch-vcs = (superPython.hatch-vcs.override { - git = null; - pytestCheckHook = null; - }); - }); - }; + binutils-unwrapped = superDarwin.binutils-unwrapped.override (old: { + llvm-manpages = super.llvmPackages.llvm-manpages.override { + python3Packages = prevStage.python3.pkgs.overrideScope (_: superPython: { + hatch-vcs = (superPython.hatch-vcs.override { + git = null; + pytestCheckHook = null; }); - inherit (old.llvmPackages) libraries release_version; - in - { inherit tools libraries release_version; } // tools // libraries; + }); + }; }); }); @@ -1151,7 +1162,7 @@ in }; }); libraries = super.llvmPackages.libraries.extend (_: _:{ - inherit (prevStage.llvmPackages) compiler-rt libcxx; + inherit (prevStage.llvmPackages) compiler-rt libcxx libunwind; }); in { inherit tools libraries; } // tools // libraries @@ -1177,36 +1188,34 @@ in (prevStage: # previous stage4 stdenv: assert lib.all isBuiltByNixpkgsCompiler (with prevStage; [ - bash binutils-unwrapped brotli bzip2 cpio diffutils ed file findutils gawk - gettext gmp gnugrep gnumake gnused gnutar gzip icu libffi libiconv libidn2 libkrb5 - libssh2 libunistring libxml2 libyaml ncurses nghttp2 openbsm openpam openssl patch - pbzx pcre python3Minimal xar xz zlib zstd + bash brotli bzip2 cctools cpio diffutils ed file findutils gawk + gettext gmp gnugrep gnumake gnused gnutar gzip icu ld64 libffi libiconv libidn2 libkrb5 + libssh2 libtapi libunistring libxml2 libyaml ncurses nghttp2 openbsm openpam openssl patch + pbzx pcre xar xz zlib zstd ]); assert lib.all isBuiltByNixpkgsCompiler (with prevStage.darwin; [ - binutils-unwrapped cctools libtapi locale print-reexports rewrite-tbd sigtool + locale print-reexports rewrite-tbd sigtool ]); - assert (! useAppleSDKLibs) -> lib.all isBuiltByNixpkgsCompiler (with prevStage.darwin; [ Libsystem configd ]); + assert (! useAppleSDKLibs) -> lib.all isBuiltByNixpkgsCompiler (with prevStage.darwin; [ configd libresolv ]); assert (! useAppleSDKLibs) -> lib.all isFromNixpkgs (with prevStage.darwin; [ CF ]); - assert useAppleSDKLibs -> lib.all isFromNixpkgs (with prevStage.darwin; [ CF Libsystem libobjc ]); - assert lib.all isFromNixpkgs (with prevStage.darwin; [ dyld launchd libclosure libdispatch xnu ]); + assert useAppleSDKLibs -> lib.all isFromNixpkgs (with prevStage.darwin; [ CF libobjc ]); + assert lib.all isFromNixpkgs (with prevStage.darwin; [ + Libsystem binutils-unwrapped dyld launchd libclosure libdispatch xnu + ]); assert lib.all isBuiltByNixpkgsCompiler (with prevStage.llvmPackages; [ - clang-unwrapped libclang libllvm llvm compiler-rt libcxx + clang-unwrapped libclang libllvm llvm compiler-rt libcxx libunwind ]); assert lib.all isBuiltByBootstrapFilesCompiler (with prevStage; [ autoconf automake bison cmake cmakeMinimal cyrus_sasl db expat flex groff libedit - libtool m4 ninja openldap openssh patchutils perl pkg-config.pkg-config python3 scons + libtool m4 ninja openldap openssh patchutils perl pkg-config.pkg-config python3 python3Minimal scons serf sqlite subversion sysctl.provider texinfo unzip which ]); - assert prevStage.darwin.cctools == prevStage.darwin.cctools-llvm; - let - doSign = localSystem.isAarch64; - cc = prevStage.llvmPackages.clang; in { @@ -1230,9 +1239,9 @@ in extraNativeBuildInputs = lib.optionals localSystem.isAarch64 [ prevStage.updateAutotoolsGnuConfigScriptsHook - ] ++ [ prevStage.darwin.apple_sdk.sdkRoot ]; + ]; - extraBuildInputs = [ prevStage.darwin.CF ]; + extraBuildInputs = [ prevStage.darwin.CF prevStage.darwin.apple_sdk.sdkRoot ]; inherit cc; @@ -1255,11 +1264,13 @@ in allowedRequisites = (with prevStage; [ bash - binutils.bintools - binutils.bintools.lib bzip2.bin bzip2.out cc.expand-response-params + cctools + ld64.out + ld64.lib + libtapi.out coreutils darwin.binutils darwin.binutils.bintools @@ -1286,13 +1297,14 @@ in ncurses.out openbsm openpam + openssl.out patch + xar xz.bin xz.out zlib.dev zlib.out - ] - ++ lib.optionals doSign [ openssl.out ]) + ]) ++ lib.optionals localSystem.isAarch64 [ prevStage.updateAutotoolsGnuConfigScriptsHook prevStage.gnu-config @@ -1312,37 +1324,35 @@ in ++ (with prevStage.darwin; [ CF Libsystem - cctools-llvm - cctools-port dyld - libtapi + libresolv locale apple_sdk.sdkRoot ] - ++ lib.optional useAppleSDKLibs [ objc4 ] - ++ lib.optionals doSign [ postLinkSignHook sigtool signingUtils ]); + ++ lib.optionals useAppleSDKLibs [ objc4 ]); __stdenvImpureHostDeps = commonImpureHostDeps; __extraImpureHostDeps = commonImpureHostDeps; overrides = self: super: { inherit (prevStage) - bash binutils brotli bzip2 coreutils cpio diffutils ed file findutils gawk + bash brotli bzip2 coreutils cpio diffutils ed file findutils gawk gettext gmp gnugrep gnumake gnused gnutar gzip icu libffi libiconv libiconv-darwin libidn2 libssh2 libunistring libxml2 libyaml ncurses nghttp2 openbsm openpam openssl patch pbzx pcre python3Minimal xar xz zlib zstd; darwin = super.darwin.overrideScope (_: superDarwin: { inherit (prevStage.darwin) - CF ICU Libsystem darwin-stubs dyld locale libobjc libtapi rewrite-tbd xnu; + CF ICU Libsystem darwin-stubs dyld locale libobjc libresolv libtapi rewrite-tbd xnu; apple_sdk = superDarwin.apple_sdk // { inherit (prevStage.darwin.apple_sdk) sdkRoot; }; } // lib.optionalAttrs (super.stdenv.targetPlatform == localSystem) { - inherit (prevStage.darwin) binutils binutils-unwrapped cctools-llvm cctools-port; + inherit (prevStage.darwin) binutils binutils-unwrapped; }); } // lib.optionalAttrs (super.stdenv.targetPlatform == localSystem) { + inherit (prevStage) cctools ld64 libtapi; inherit (prevStage.llvmPackages) clang llvm; # Need to get rid of these when cross-compiling. @@ -1352,32 +1362,46 @@ in inherit (prevStage.llvmPackages) clang clang-unwrapped libclang libllvm llvm; }); libraries = super.llvmPackages.libraries.extend (_: _: { - inherit (prevStage.llvmPackages) compiler-rt libcxx; + inherit (prevStage.llvmPackages) compiler-rt libcxx libunwind; }); in { inherit tools libraries; } // tools // libraries ); - inherit (prevStage) binutils binutils-unwrapped; + binutils-unwrapped = super.binutils-unwrapped.override { + # GNU binutils tries to avoid causing a rebuild of LLVM by using its source from a previous stage, + # which results in an evaluation error when binutils is disabled in the bootstrap. + # Removing it from `__bootPackages` prevents an evaluation error. + stdenv = self.stdenv // { + __bootPackages = builtins.removeAttrs self.stdenv.__bootPackages [ "binutils-unwrapped" ]; + }; + }; }; }; }) - # This "no-op" stage is just a place to put the assertions about stage6. + # This "no-op" stage is just a place to put the assertions about the final stage. (prevStage: # previous final stage stdenv: + assert isBuiltByNixpkgsCompiler prevStage.cctools; + assert isBuiltByNixpkgsCompiler prevStage.ld64; assert isBuiltByNixpkgsCompiler prevStage.darwin.sigtool; - assert isBuiltByNixpkgsCompiler prevStage.darwin.binutils-unwrapped; assert isBuiltByNixpkgsCompiler prevStage.darwin.print-reexports; assert isBuiltByNixpkgsCompiler prevStage.darwin.rewrite-tbd; - assert isBuiltByNixpkgsCompiler prevStage.darwin.cctools; assert isFromNixpkgs prevStage.darwin.CF; assert isFromNixpkgs prevStage.darwin.Libsystem; + assert isFromNixpkgs prevStage.darwin.binutils-unwrapped; assert isBuiltByNixpkgsCompiler prevStage.llvmPackages.clang-unwrapped; assert isBuiltByNixpkgsCompiler prevStage.llvmPackages.libllvm; assert isBuiltByNixpkgsCompiler prevStage.llvmPackages.libcxx; assert isBuiltByNixpkgsCompiler prevStage.llvmPackages.compiler-rt; + + # Make sure these evaluate since they were disabled explicitly in the bootstrap. + assert isBuiltByNixpkgsCompiler prevStage.binutils-unwrapped; + assert isFromNixpkgs prevStage.binutils-unwrapped.src; + assert isBuiltByNixpkgsCompiler prevStage.curl; + { inherit (prevStage) config overlays stdenv; }) ] diff --git a/pkgs/stdenv/darwin/make-bootstrap-tools.nix b/pkgs/stdenv/darwin/make-bootstrap-tools.nix index bacad15a68bc7..a355e0e2a3310 100644 --- a/pkgs/stdenv/darwin/make-bootstrap-tools.nix +++ b/pkgs/stdenv/darwin/make-bootstrap-tools.nix @@ -40,7 +40,7 @@ rec { NIX_LDFLAGS = (oa.NIX_LDFLAGS or "") + " -headerpad_max_install_names"; }); - cctools_ = darwin.cctools; + bintools_ = darwin.binutils-unwrapped; # Avoid messing with libkrb5 and libnghttp2. curl_ = curlMinimal.override (args: { @@ -112,7 +112,7 @@ rec { # Copy binutils. for i in as ld ar ranlib nm strip otool install_name_tool lipo codesign_allocate; do - cp ${getBin cctools_}/bin/$i $out/bin + cp ${getBin bintools_}/bin/$i $out/bin done # Copy coreutils, bash, etc. @@ -175,7 +175,7 @@ rec { # copy sigtool cp -d ${getBin darwin.sigtool}/bin/{codesign,sigtool} $out/bin - cp -d ${getLib darwin.libtapi}/lib/libtapi*.dylib $out/lib + cp -d ${getLib libtapi}/lib/libtapi*.dylib $out/lib # tools needed to unpack bootstrap archive mkdir -p unpack/bin unpack/lib diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix index 2cda43d5632f2..2cbd2636a4630 100644 --- a/pkgs/stdenv/generic/default.nix +++ b/pkgs/stdenv/generic/default.nix @@ -114,14 +114,9 @@ let export NIX_NO_SELF_RPATH=1 '' + lib.optionalString (hostPlatform.isDarwin && hostPlatform.isMacOS) '' export MACOSX_DEPLOYMENT_TARGET=${hostPlatform.darwinMinVersion} - '' - # TODO this should be uncommented, but it causes stupid mass rebuilds. I - # think the best solution would just be to fixup linux RPATHs so we don't - # need to set `-rpath` anywhere. - # + lib.optionalString targetPlatform.isDarwin '' - # export NIX_DONT_SET_RPATH_FOR_TARGET=1 - # '' - ; + '' + lib.optionalString targetPlatform.isDarwin '' + export NIX_DONT_SET_RPATH_FOR_TARGET=1 + ''; inherit initialPath shell defaultNativeBuildInputs defaultBuildInputs; diff --git a/pkgs/tools/admin/balena-cli/default.nix b/pkgs/tools/admin/balena-cli/default.nix index 5b45b78835f08..df1f34193e092 100644 --- a/pkgs/tools/admin/balena-cli/default.nix +++ b/pkgs/tools/admin/balena-cli/default.nix @@ -8,6 +8,7 @@ , nodePackages , python3 , udev +, cctools , darwin }: @@ -38,7 +39,7 @@ in buildNpmPackage' rec { nodePackages.node-gyp python3 ] ++ lib.optionals stdenv.isDarwin [ - darwin.cctools + cctools ]; buildInputs = lib.optionals stdenv.isLinux [ diff --git a/pkgs/tools/audio/dl-librescore/default.nix b/pkgs/tools/audio/dl-librescore/default.nix index 3f9a652bde47e..4c3a11b07f031 100644 --- a/pkgs/tools/audio/dl-librescore/default.nix +++ b/pkgs/tools/audio/dl-librescore/default.nix @@ -3,7 +3,7 @@ , buildNpmPackage , fetchFromGitHub , python3 -, darwin +, cctools }: buildNpmPackage rec { @@ -31,7 +31,7 @@ buildNpmPackage rec { nativeBuildInputs = [ python3 ] ++ lib.optionals stdenv.isDarwin [ - darwin.cctools + cctools ]; meta = { diff --git a/pkgs/tools/backup/bacula/default.nix b/pkgs/tools/backup/bacula/default.nix index f8ec672710f5b..3abf2ef5796ce 100644 --- a/pkgs/tools/backup/bacula/default.nix +++ b/pkgs/tools/backup/bacula/default.nix @@ -1,5 +1,5 @@ { lib, stdenv, fetchurl, sqlite, postgresql, zlib, acl, ncurses, openssl, readline -, CoreFoundation, IOKit +, gettext, CoreFoundation, IOKit, Kerberos }: stdenv.mkDerivation rec { @@ -19,8 +19,10 @@ stdenv.mkDerivation rec { buildInputs = [ postgresql sqlite zlib ncurses openssl readline ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ + gettext # bacula requires CoreFoundation, but its `configure` script will only link it when it detects libintl. CoreFoundation IOKit + Kerberos ] # acl relies on attr, which I can't get to build on darwin ++ lib.optional (!stdenv.isDarwin) acl; @@ -31,7 +33,13 @@ stdenv.mkDerivation rec { "--with-logdir=/var/log/bacula" "--with-working-dir=/var/lib/bacula" "--mandir=\${out}/share/man" - ] ++ lib.optional (stdenv.buildPlatform != stdenv.hostPlatform) "ac_cv_func_setpgrp_void=yes"; + ] ++ lib.optional (stdenv.buildPlatform != stdenv.hostPlatform) "ac_cv_func_setpgrp_void=yes" + ++ lib.optionals stdenv.isDarwin [ + # bacula’s `configure` script fails to detect CoreFoundation correctly, + # but these symbols are available in the nixpkgs CoreFoundation framework. + "gt_cv_func_CFLocaleCopyCurrent=yes" + "gt_cv_func_CFPreferencesCopyAppValue=yes" + ]; installFlags = [ "logdir=\${out}/logdir" diff --git a/pkgs/tools/misc/hsd/default.nix b/pkgs/tools/misc/hsd/default.nix index a1e82076cca4e..44100e15283c2 100644 --- a/pkgs/tools/misc/hsd/default.nix +++ b/pkgs/tools/misc/hsd/default.nix @@ -4,7 +4,7 @@ , fetchFromGitHub , python3 , unbound -, darwin +, cctools }: buildNpmPackage rec { @@ -23,7 +23,7 @@ buildNpmPackage rec { nativeBuildInputs = [ python3 ] ++ lib.optionals stdenv.isDarwin [ - darwin.cctools + cctools ]; buildInputs = [ diff --git a/pkgs/tools/misc/moreutils/default.nix b/pkgs/tools/misc/moreutils/default.nix index 7d7dd80d7e7a7..28ca691254ee9 100644 --- a/pkgs/tools/misc/moreutils/default.nix +++ b/pkgs/tools/misc/moreutils/default.nix @@ -8,7 +8,7 @@ , perlPackages , makeWrapper , perl # for pod2man -, darwin +, cctools , gitUpdater }: @@ -28,7 +28,7 @@ stdenv.mkDerivation rec { strictDeps = true; nativeBuildInputs = [ makeWrapper perl libxml2 libxslt docbook-xsl docbook_xml_dtd_44 ]; - buildInputs = lib.optional stdenv.isDarwin darwin.cctools; + buildInputs = lib.optional stdenv.isDarwin cctools; propagatedBuildInputs = with perlPackages; [ perl IPCRun TimeDate TimeDuration ]; diff --git a/pkgs/tools/networking/curl-impersonate/default.nix b/pkgs/tools/networking/curl-impersonate/default.nix index 8f7b659d19b58..b4fb1ca7019cf 100644 --- a/pkgs/tools/networking/curl-impersonate/default.nix +++ b/pkgs/tools/networking/curl-impersonate/default.nix @@ -16,7 +16,7 @@ , autoconf , automake , libtool -, darwin +, cctools , cacert , unzip , go @@ -63,7 +63,7 @@ let nativeBuildInputs = lib.optionals stdenv.isDarwin [ # Must come first so that it shadows the 'libtool' command but leaves 'libtoolize' - darwin.cctools + cctools ] ++ [ installShellFiles cmake diff --git a/pkgs/tools/networking/curl/default.nix b/pkgs/tools/networking/curl/default.nix index 0bd65a307b0b7..aa4ac2ebd890a 100644 --- a/pkgs/tools/networking/curl/default.nix +++ b/pkgs/tools/networking/curl/default.nix @@ -217,7 +217,7 @@ stdenv.mkDerivation (finalAttrs: { maintainers = with maintainers; [ lovek323 ]; platforms = platforms.all; # Fails to link against static brotli or gss - broken = (stdenv.hostPlatform.isStatic && (brotliSupport || gssSupport || stdenv.hostPlatform.system == "x86_64-darwin")) || rustlsSupport; + broken = (stdenv.hostPlatform.isStatic && (brotliSupport || gssSupport )) || rustlsSupport; pkgConfigModules = [ "libcurl" ]; mainProgram = "curl"; }; diff --git a/pkgs/tools/security/onlykey/onlykey.nix b/pkgs/tools/security/onlykey/onlykey.nix index 22e8b62607378..01fc2df3aa83f 100644 --- a/pkgs/tools/security/onlykey/onlykey.nix +++ b/pkgs/tools/security/onlykey/onlykey.nix @@ -8,7 +8,7 @@ let nodeEnv = import ../../../development/node-packages/node-env.nix { inherit (pkgs) stdenv lib python2 runCommand writeTextFile writeShellScript; inherit pkgs nodejs; - libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null; + libtool = if pkgs.stdenv.isDarwin then pkgs.cctools else null; }; in import ./node-packages.nix { diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 8cc14fbf94781..bd6ab9a8463e4 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -1072,7 +1072,7 @@ with pkgs; mya = callPackage ../applications/misc/mya { }; mysql-shell = callPackage ../development/tools/mysql-shell { - inherit (darwin) cctools DarwinTools; + inherit (darwin) DarwinTools; inherit (darwin.apple_sdk.frameworks) CoreServices; antlr = antlr4_10; boost = boost177; # Configure checks for specific version. @@ -1081,7 +1081,7 @@ with pkgs; }; mysql-shell-innovation = callPackage ../development/tools/mysql-shell/innovation.nix { - inherit (darwin) cctools DarwinTools; + inherit (darwin) DarwinTools; inherit (darwin.apple_sdk.frameworks) CoreServices; antlr = antlr4_10; icu = icu73; @@ -1380,7 +1380,9 @@ with pkgs; fixDarwinDylibNames = makeSetupHook { name = "fix-darwin-dylib-names-hook"; - substitutions = { inherit (binutils) targetPrefix; }; + substitutions = { + targetPrefix = lib.optionalString (stdenv.hostPlatform != stdenv.targetPlatform) "${stdenv.targetPlatform.config}-"; + }; meta.platforms = lib.platforms.darwin; } ../build-support/setup-hooks/fix-darwin-dylib-names.sh; @@ -3849,9 +3851,7 @@ with pkgs; glyr = callPackage ../tools/audio/glyr { }; - google-amber = callPackage ../tools/graphics/amber { - inherit (darwin) cctools; - }; + google-amber = callPackage ../tools/graphics/amber { }; hakrawler = callPackage ../tools/security/hakrawler { }; @@ -5492,7 +5492,6 @@ with pkgs; hocr-tools = with python3Packages; toPythonApplication hocr-tools; homepage-dashboard = callPackage ../servers/homepage-dashboard { - inherit (darwin) cctools; inherit (darwin.apple_sdk.frameworks) IOKit; }; @@ -6400,7 +6399,7 @@ with pkgs; }; bacula = callPackage ../tools/backup/bacula { - inherit (darwin.apple_sdk.frameworks) CoreFoundation IOKit; + inherit (darwin.apple_sdk.frameworks) CoreFoundation IOKit Kerberos; }; bacon = callPackage ../development/tools/bacon { @@ -7997,7 +7996,7 @@ with pkgs; lpd8editor = libsForQt5.callPackage ../applications/audio/lpd8editor {}; lp_solve = callPackage ../applications/science/math/lp_solve { - inherit (darwin) cctools autoSignDarwinBinariesHook; + inherit (darwin) autoSignDarwinBinariesHook; }; fabric-installer = callPackage ../tools/games/minecraft/fabric-installer { }; @@ -10467,7 +10466,7 @@ with pkgs; bubblemail = callPackage ../applications/networking/mailreaders/bubblemail { }; mailpit = callPackage ../servers/mail/mailpit { - libtool = if stdenv.isDarwin then darwin.cctools else libtool; + libtool = if stdenv.isDarwin then cctools else libtool; }; mailsend = callPackage ../tools/networking/mailsend { }; @@ -12785,9 +12784,7 @@ with pkgs; selectdefaultapplication = libsForQt5.callPackage ../applications/misc/selectdefaultapplication { }; - semantic-release = callPackage ../development/tools/semantic-release { - inherit (darwin) cctools; - }; + semantic-release = callPackage ../development/tools/semantic-release { }; semgrep = python3.pkgs.callPackage ../tools/security/semgrep { }; semgrep-core = callPackage ../tools/security/semgrep/semgrep-core.nix { }; @@ -14405,7 +14402,6 @@ with pkgs; unicorn = callPackage ../development/libraries/unicorn { inherit (darwin.apple_sdk.frameworks) IOKit; - inherit (darwin) cctools; }; unittest-cpp = callPackage ../development/libraries/unittest-cpp { }; @@ -15228,9 +15224,7 @@ with pkgs; stdenv = gccStdenv; }; - chez = callPackage ../development/compilers/chez { - inherit (darwin) cctools; - }; + chez = callPackage ../development/compilers/chez { }; chez-racket = callPackage ../development/compilers/chez-racket { }; @@ -17022,7 +17016,6 @@ with pkgs; noLibc = (self.libc == null); inherit bintools libc; - inherit (darwin) postLinkSignHook signingUtils; } // extraArgs; in self); yaml-language-server = callPackage ../development/tools/language-servers/yaml-language-server { }; @@ -17574,7 +17567,7 @@ with pkgs; inherit (darwin) libobjc; }; defaultGemConfig = callPackage ../development/ruby-modules/gem-config { - inherit (darwin) DarwinTools cctools autoSignDarwinBinariesHook; + inherit (darwin) DarwinTools autoSignDarwinBinariesHook; inherit (darwin.apple_sdk.frameworks) CoreServices; }; bundix = callPackage ../development/ruby-modules/bundix { }; @@ -17597,7 +17590,7 @@ with pkgs; }; inherit (callPackage ../development/interpreters/ruby { - inherit (darwin) libobjc libunwind; + inherit (darwin) libobjc; inherit (darwin.apple_sdk.frameworks) Foundation; }) mkRubyVersion @@ -18065,7 +18058,7 @@ with pkgs; bazel = bazel_6; bazel_5 = callPackage ../development/tools/build-managers/bazel/bazel_5 { - inherit (darwin) cctools sigtool; + inherit (darwin) sigtool; inherit (darwin.apple_sdk.frameworks) CoreFoundation CoreServices Foundation; buildJdk = jdk11_headless; runJdk = jdk11_headless; @@ -18076,7 +18069,7 @@ with pkgs; }; bazel_6 = darwin.apple_sdk_11_0.callPackage ../development/tools/build-managers/bazel/bazel_6 { - inherit (darwin) cctools sigtool; + inherit (darwin) sigtool; inherit (darwin.apple_sdk_11_0.frameworks) CoreFoundation CoreServices Foundation; buildJdk = jdk11_headless; runJdk = jdk11_headless; @@ -18088,7 +18081,7 @@ with pkgs; }; bazel_7 = darwin.apple_sdk_11_0.callPackage ../development/tools/build-managers/bazel/bazel_7 { - inherit (darwin) cctools sigtool; + inherit (darwin) sigtool; inherit (darwin.apple_sdk_11_0.frameworks) CoreFoundation CoreServices Foundation IOKit; buildJdk = jdk17_headless; runJdk = jdk17_headless; @@ -19808,7 +19801,7 @@ with pkgs; jhiccup = callPackage ../development/tools/java/jhiccup { }; valgrind = callPackage ../development/tools/analysis/valgrind { - inherit (buildPackages.darwin) xnu bootstrap_cmds cctools; + inherit (buildPackages.darwin) xnu bootstrap_cmds; }; valgrind-light = res.valgrind.override { gdb = null; }; @@ -20994,7 +20987,7 @@ with pkgs; inherit (stdenv.targetPlatform) libc; in if stdenv.targetPlatform.isMinGW 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 if libc == "libSystem" then targetPackages.darwin.LibsystemCross else null; # We can choose: @@ -21108,7 +21101,6 @@ with pkgs; gobject-introspection-unwrapped = callPackage ../development/libraries/gobject-introspection { nixStoreDir = config.nix.storeDir or builtins.storeDir; - inherit (darwin) cctools; }; goocanvas = callPackage ../development/libraries/goocanvas { }; @@ -22967,7 +22959,7 @@ with pkgs; }; libunwind = - if stdenv.isDarwin then darwin.libunwind + if stdenv.isDarwin then llvmPackages.libunwind else if stdenv.hostPlatform.system == "riscv32-linux" then llvmPackages_14.libunwind else callPackage ../development/libraries/libunwind { }; @@ -23167,7 +23159,7 @@ with pkgs; lirc = callPackage ../development/libraries/lirc { }; liquid-dsp = callPackage ../development/libraries/liquid-dsp { - inherit (darwin) autoSignDarwinBinariesHook cctools; + inherit (darwin) autoSignDarwinBinariesHook; }; liquidfun = callPackage ../development/libraries/liquidfun { }; @@ -26161,14 +26153,12 @@ with pkgs; mongodb-5_0 = callPackage ../servers/nosql/mongodb/5.0.nix { sasl = cyrus_sasl; boost = boost179.override { enableShared = false; }; - inherit (darwin) cctools; inherit (darwin.apple_sdk.frameworks) CoreFoundation Security; }; mongodb-6_0 = darwin.apple_sdk_11_0.callPackage ../servers/nosql/mongodb/6.0.nix { sasl = cyrus_sasl; boost = boost178.override { enableShared = false; }; - inherit (darwin) cctools; inherit (darwin.apple_sdk.frameworks) CoreFoundation Security; stdenv = if stdenv.isDarwin then darwin.apple_sdk_11_0.stdenv.override (old: { @@ -26192,7 +26182,7 @@ with pkgs; influxdb2 = callPackage ../servers/nosql/influxdb2/combined.nix { }; mysql80 = callPackage ../servers/sql/mysql/8.0.x.nix { - inherit (darwin) cctools developer_cmds DarwinTools; + inherit (darwin) developer_cmds DarwinTools; inherit (darwin.apple_sdk.frameworks) CoreServices; boost = boost177; # Configure checks for specific version. icu = icu69; @@ -26480,7 +26470,7 @@ with pkgs; rethinkdb = callPackage ../servers/nosql/rethinkdb { stdenv = clangStdenv; - libtool = darwin.cctools; + libtool = cctools; protobuf = protobuf_21; }; @@ -29096,7 +29086,7 @@ with pkgs; session-desktop = callPackage ../applications/networking/instant-messengers/session-desktop { }; shaderc = callPackage ../development/compilers/shaderc { - inherit (darwin) autoSignDarwinBinariesHook cctools; + inherit (darwin) autoSignDarwinBinariesHook; }; shades-of-gray-theme = callPackage ../data/themes/shades-of-gray { }; @@ -32592,7 +32582,7 @@ with pkgs; mac = callPackage ../development/libraries/mac { }; - macdylibbundler = callPackage ../development/tools/misc/macdylibbundler { inherit (darwin) cctools; }; + macdylibbundler = callPackage ../development/tools/misc/macdylibbundler { }; magic-wormhole = with python3Packages; toPythonApplication magic-wormhole; @@ -35306,14 +35296,12 @@ with pkgs; openvscode-server = callPackage ../servers/openvscode-server { nodejs = nodejs_18; inherit (darwin.apple_sdk.frameworks) AppKit Cocoa Security; - inherit (darwin) cctools; inherit (nodePackages) node-gyp; }; code-server = callPackage ../servers/code-server { nodejs = nodejs_18; inherit (darwin.apple_sdk.frameworks) AppKit Cocoa CoreServices Security; - inherit (darwin) cctools; inherit (nodePackages) node-gyp; }; @@ -36729,9 +36717,7 @@ with pkgs; garden-of-coloured-lights = callPackage ../games/garden-of-coloured-lights { allegro = allegro4; }; - gargoyle = callPackage ../games/gargoyle { - inherit (darwin) cctools; - }; + gargoyle = callPackage ../games/gargoyle { }; gav = callPackage ../games/gav { }; @@ -37211,7 +37197,6 @@ with pkgs; scid-vs-pc = callPackage ../games/scid-vs-pc { }; scummvm = callPackage ../games/scummvm { - inherit (darwin) cctools; inherit (darwin.apple_sdk.frameworks) Cocoa AudioToolbox Carbon CoreMIDI AudioUnit; }; @@ -40644,7 +40629,7 @@ with pkgs; check-uptime = callPackage ../servers/monitoring/plugins/uptime.nix { }; - ghc-standalone-archive = callPackage ../os-specific/darwin/ghc-standalone-archive { inherit (darwin) cctools; }; + ghc-standalone-archive = callPackage ../os-specific/darwin/ghc-standalone-archive { }; vdr = callPackage ../applications/video/vdr { }; vdrPlugins = recurseIntoAttrs (callPackage ../applications/video/vdr/plugins.nix { }); diff --git a/pkgs/top-level/darwin-aliases.nix b/pkgs/top-level/darwin-aliases.nix index 78e29d9f1a598..c008bea3102f5 100644 --- a/pkgs/top-level/darwin-aliases.nix +++ b/pkgs/top-level/darwin-aliases.nix @@ -51,6 +51,13 @@ mapAliases ({ builder = throw "'darwin.builder' has been changed and renamed to 'darwin.linux-builder'. The default ssh port is now 31022. Please update your configuration or override the port back to 22. See https://nixos.org/manual/nixpkgs/unstable/#sec-darwin-builder"; # added 2023-07-06 + ### C ### + + cctools = pkgs.cctools; # added 2024-05-15 + cctools-apple = pkgs.cctools; # added 2024-05-15 + cctools-port = pkgs.cctools; # added 2024-05-15 + cctools-llvm = self.binutils-unwrapped; # added 2024-05-15 + ### I ### insert_dylib = throw "'darwin.insert_dylib' has been renamed to 'insert-dylib'"; # added 2024-04-04 @@ -58,6 +65,8 @@ mapAliases ({ ### L ### libiconv = pkgs.libiconv; # 2024-03-27 + libtapi = pkgs.libtapi; # added 2024-05-15 + libunwind = pkgs.libunwind; # added 2024-05-15 ### O ### diff --git a/pkgs/top-level/darwin-packages.nix b/pkgs/top-level/darwin-packages.nix index cca74e047dbdd..cc3388b6dca0e 100644 --- a/pkgs/top-level/darwin-packages.nix +++ b/pkgs/top-level/darwin-packages.nix @@ -2,6 +2,7 @@ , buildPackages, pkgs, targetPackages , generateSplicesForMkScope, makeScopeWithSplicing' , stdenv +, overrideCC , preLibcCrossHeaders , config }: @@ -64,13 +65,15 @@ makeScopeWithSplicing' { if useAppleSDKLibs then apple_sdk else appleSourcePackages - ) ["Libsystem" "LibsystemCross" "libcharset" "libunwind" "objc4" "configd" "IOKit"] + ) ["Libsystem" "LibsystemCross" "libcharset" "objc4" "configd" "IOKit"] ) // { inherit ( if useAppleSDKLibs then apple_sdk.frameworks else appleSourcePackages ) Security; + } // lib.optionalAttrs (!useAppleSDKLibs) { + LibsystemCross = self.Libsystem; }; in @@ -79,14 +82,82 @@ impure-cmds // appleSourcePackages // chooseLibs // { inherit apple_sdk apple_sdk_10_12 apple_sdk_11_0; stdenvNoCF = stdenv.override { - extraBuildInputs = []; + extraBuildInputs = [ apple_sdk.sdkRoot ]; }; + # Rewrapping clang is necessary to avoid infinite recursions while overriding Libsystem. + # This is used for building dependencies of Libsystem that require a working clang. + stdenvBootstrap = overrideCC buildPackages.targetPackages.darwin.stdenvNoCF (import ../build-support/cc-wrapper ( + let + LibsystemNoResolv = buildPackages.targetPackages.darwin.Libsystem.override { + withCsu = false; + withLibresolv = false; + }; + in + { + inherit lib; + inherit (buildPackages) stdenvNoCC coreutils gnugrep runtimeShell; + + expand-response-params = ""; + + nativeTools = false; + nativeLibc = false; + + cc = buildPackages.llvmPackages.clang-unwrapped; + libc = LibsystemNoResolv; + + bintools = import ../build-support/bintools-wrapper { + inherit lib; + inherit (buildPackages) stdenvNoCC coreutils gnugrep runtimeShell; + + expand-response-params = ""; + + libc = LibsystemNoResolv; + + bintools = buildPackages.darwin.binutils-unwrapped; + + nativeTools = false; + nativeLibc = false; + }; + + # Can’t rely on `release_version` because this may be used with the bootstrap compiler, + # which does not necessarily provide a correct `release_version`. + extraBuildCommands = '' + function clangResourceRootIncludePath() { + clangLib="$1/lib/clang" + if (( $(ls "$clangLib" | wc -l) > 1 )); then + echo "Multiple LLVM versions were found at "$clangLib", but there must only be one used when building the stdenv." >&2 + exit 1 + fi + echo "$clangLib/$(ls -1 "$clangLib")/include" + } + + rsrc="$out/resource-root" + mkdir "$rsrc" + ln -s "$(clangResourceRootIncludePath "${buildPackages.llvmPackages.clang-unwrapped.lib}")" "$rsrc" + echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags + ''; + }) + ); + binutils-unwrapped = callPackage ../os-specific/darwin/binutils { - inherit (pkgs) binutils-unwrapped; - inherit (pkgs.llvmPackages) llvm clang-unwrapped; + inherit (pkgs.llvmPackages) clang-unwrapped llvm llvm-manpages; }; + # x86-64 Darwin gnat-bootstrap emits assembly + # with MOVQ as the mnemonic for quadword interunit moves + # such as `movq %rbp, %xmm0`. + # The clang integrated assembler recognises this as valid, + # but unfortunately the cctools^gas GNU assembler does not; + # it instead uses MOVD as the mnemonic. + # The assembly that a GCC build emits is determined at build time + # and cannot be changed afterwards. + # + # To build GNAT on x86-64 Darwin, therefore, + # we need both the clang _and_ the cctools^gas assemblers to be available: + # the former to build at least the stage1 compiler, + # and the latter at least to be detectable + # as the target for the final compiler. binutils = pkgs.wrapBintoolsWith { libc = if stdenv.targetPlatform != stdenv.hostPlatform @@ -95,17 +166,15 @@ impure-cmds // appleSourcePackages // chooseLibs // { bintools = self.binutils-unwrapped; }; - binutilsDualAs-unwrapped = callPackage ../os-specific/darwin/binutils { - inherit (pkgs) binutils-unwrapped; - inherit (pkgs.llvmPackages) llvm clang-unwrapped; - dualAs = true; + binutilsDualAs-unwrapped = pkgs.buildEnv { + name = "${lib.getName self.binutils-unwrapped}-dualas-${lib.getVersion self.binutils-unwrapped}"; + paths = [ + self.binutils-unwrapped + (lib.getOutput "gas" pkgs.cctools) + ]; }; - binutilsDualAs = pkgs.wrapBintoolsWith { - libc = - if stdenv.targetPlatform != stdenv.hostPlatform - then pkgs.libcCross - else pkgs.stdenv.cc.libc; + binutilsDualAs = self.binutils.override { bintools = self.binutilsDualAs-unwrapped; }; @@ -114,20 +183,6 @@ impure-cmds // appleSourcePackages // chooseLibs // { bintools = self.binutils-unwrapped; }; - cctools = self.cctools-llvm; - - cctools-apple = callPackage ../os-specific/darwin/cctools/apple.nix { - stdenv = if stdenv.isDarwin then stdenv else pkgs.libcxxStdenv; - }; - - cctools-llvm = callPackage ../os-specific/darwin/cctools/llvm.nix { - stdenv = if stdenv.isDarwin then stdenv else pkgs.libcxxStdenv; - }; - - cctools-port = callPackage ../os-specific/darwin/cctools/port.nix { - stdenv = if stdenv.isDarwin then stdenv else pkgs.libcxxStdenv; - }; - # TODO(@connorbaker): See https://github.com/NixOS/nixpkgs/issues/229389. cf-private = self.apple_sdk.frameworks.CoreFoundation; @@ -195,26 +250,8 @@ impure-cmds // appleSourcePackages // chooseLibs // { inherit (apple_sdk) darwin-stubs; }; - # TODO: Remove the CF hook if a solution to the crashes is not found. - CF = - # CF used to refer to the open source version of CoreFoundation from the Swift - # project. As of macOS 14, the rpath-based approach allowing packages to choose - # which version to use no longer seems to work reliably. Sometimes they works, - # but sometimes they crash with the error (in the system crash logs): - # CF objects must have a non-zero isa. - # See https://developer.apple.com/forums/thread/739355 for more on that error. - # - # 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; - }); + # TODO: Move stdenv to use apple_sdk.frameworks.CoreFoundation and deprecate darwin.CF. + CF = apple_sdk.frameworks.CoreFoundation; # Formerly the CF attribute. Use this is you need the open source release. swift-corelibs-foundation = callPackage ../os-specific/darwin/swift-corelibs/corefoundation.nix { }; diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 34a33f42bf42a..9deb7c43afc66 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -6028,7 +6028,6 @@ self: super: with self; { }; jaxlib-build = callPackage ../development/python-modules/jaxlib rec { - inherit (pkgs.darwin) cctools; # Some platforms don't have `cudaSupport` defined, hence the need for 'or false'. inherit (pkgs.config) cudaSupport; IOKit = pkgs.darwin.apple_sdk_11_0.IOKit; @@ -7481,9 +7480,7 @@ self: super: with self; { minio = callPackage ../development/python-modules/minio { }; - miniupnpc = callPackage ../development/python-modules/miniupnpc { - inherit (pkgs.darwin) cctools; - }; + miniupnpc = callPackage ../development/python-modules/miniupnpc { }; mip = callPackage ../development/python-modules/mip { }; @@ -14933,7 +14930,6 @@ self: super: with self; { }; in callPackage ../development/python-modules/tensorflow { - inherit (pkgs.darwin) cctools; inherit (pkgs.config) cudaSupport; inherit (pkgs.darwin.apple_sdk.frameworks) Foundation Security; flatbuffers-core = pkgs.flatbuffers; @@ -14960,9 +14956,7 @@ self: super: with self; { tensorflow-metadata = callPackage ../development/python-modules/tensorflow-metadata { }; - tensorflow-probability = callPackage ../development/python-modules/tensorflow-probability { - inherit (pkgs.darwin) cctools; - }; + tensorflow-probability = callPackage ../development/python-modules/tensorflow-probability { }; tensorflow = self.tensorflow-build;