From ce857cfef51de132dc92c6cf8f03753c8b9cc04e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Kochen?= Date: Tue, 19 Jul 2022 15:20:53 +0200 Subject: [PATCH 1/4] darwin.apple_sdk_11_0: use stdenv objc4 Stdenv on aarch64-darwin pulls in (bootstrap-stage4) objc4, unlike x86_64. However derivations that otherwise depend on objc4 would use a a different objc4 derivation on top of the final stdenv. Because this library defines an LLVM module, having multiple instances of it in the import path will interfere with builds. --- pkgs/os-specific/darwin/apple-sdk-11.0/default.nix | 4 +++- pkgs/stdenv/darwin/default.nix | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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 b29a36177a825..4565f698d26c5 100644 --- a/pkgs/os-specific/darwin/apple-sdk-11.0/default.nix +++ b/pkgs/os-specific/darwin/apple-sdk-11.0/default.nix @@ -50,7 +50,9 @@ let libcharset = callPackage ./libcharset.nix {}; libunwind = callPackage ./libunwind.nix {}; libnetwork = callPackage ./libnetwork.nix {}; - objc4 = callPackage ./libobjc.nix {}; + # Avoid introducing a new objc4 if stdenv already has one, to prevent + # conflicting LLVM modules. + objc4 = if stdenv ? objc4 then stdenv.objc4 else callPackage ./libobjc.nix {}; # questionable aliases configd = pkgs.darwin.apple_sdk.frameworks.SystemConfiguration; diff --git a/pkgs/stdenv/darwin/default.nix b/pkgs/stdenv/darwin/default.nix index ff56f1de02261..9a7cd9aa9dee5 100644 --- a/pkgs/stdenv/darwin/default.nix +++ b/pkgs/stdenv/darwin/default.nix @@ -698,6 +698,11 @@ rec { libc = pkgs.darwin.Libsystem; shellPackage = pkgs.bash; inherit bootstrapTools; + } // lib.optionalAttrs useAppleSDKLibs { + # This objc4 will be propagated to all builds using the final stdenv, + # and we shouldn't mix different builds, because they would be + # conflicting LLVM modules. Export it here so we can grab it later. + inherit (pkgs.darwin) objc4; }; allowedRequisites = (with pkgs; [ From 2c2aad7b90404a352e19d8062748a611c0089e24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Kochen?= Date: Tue, 19 Jul 2022 21:14:58 +0200 Subject: [PATCH 2/4] IOSurface: remove xpc dependency --- pkgs/os-specific/darwin/apple-sdk-11.0/frameworks.nix | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkgs/os-specific/darwin/apple-sdk-11.0/frameworks.nix b/pkgs/os-specific/darwin/apple-sdk-11.0/frameworks.nix index e9121b0211641..fbfc673a1a9ec 100644 --- a/pkgs/os-specific/darwin/apple-sdk-11.0/frameworks.nix +++ b/pkgs/os-specific/darwin/apple-sdk-11.0/frameworks.nix @@ -89,9 +89,7 @@ IOBluetooth = { inherit CoreBluetooth IOKit; }; IOBluetoothUI = { inherit IOBluetooth; }; IOKit = {}; - # `IOSurface` should depend on `Libsystem` (in place of `xpc`) but this currently causes build - # issues due to incompatibility issues between `Libsystem` and `libcxx`. - IOSurface = { inherit IOKit xpc; }; + IOSurface = { inherit IOKit; }; IOUSBHost = {}; IdentityLookup = {}; ImageCaptureCore = {}; From a275cfe1db655259a92652b49e6dd5c9fa6e9fbc Mon Sep 17 00:00:00 2001 From: Theodore Ni <3806110+tjni@users.noreply.github.com> Date: Fri, 16 Sep 2022 08:29:19 -0700 Subject: [PATCH 3/4] apple_sdk: clean up unused Libsystem parameter --- pkgs/os-specific/darwin/apple-sdk-11.0/apple_sdk.nix | 2 +- pkgs/os-specific/darwin/apple-sdk-11.0/frameworks.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 05340642f8d04..b7666fe31cdb1 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 @@ -168,7 +168,7 @@ in rec { bareFrameworks = ( lib.mapAttrs framework (import ./frameworks.nix { inherit frameworks libs; - inherit (pkgs.darwin.apple_sdk_11_0) libnetwork Libsystem; + inherit (pkgs.darwin.apple_sdk_11_0) libnetwork; libobjc = pkgs.darwin.apple_sdk_11_0.objc4; }) ) // ( diff --git a/pkgs/os-specific/darwin/apple-sdk-11.0/frameworks.nix b/pkgs/os-specific/darwin/apple-sdk-11.0/frameworks.nix index fbfc673a1a9ec..dc4ab1955b506 100644 --- a/pkgs/os-specific/darwin/apple-sdk-11.0/frameworks.nix +++ b/pkgs/os-specific/darwin/apple-sdk-11.0/frameworks.nix @@ -1,4 +1,4 @@ -{ frameworks, libs, libobjc, Libsystem, libnetwork }: with frameworks; with libs; +{ frameworks, libs, libobjc, libnetwork }: with frameworks; with libs; { AGL = { inherit Carbon OpenGL; }; AVFoundation = { inherit ApplicationServices AVFCapture AVFCore CoreGraphics simd UniformTypeIdentifiers; }; From 584d4b96bf71a5074f9486e78e677e97a8558272 Mon Sep 17 00:00:00 2001 From: Theodore Ni <3806110+tjni@users.noreply.github.com> Date: Mon, 19 Sep 2022 11:08:15 -0700 Subject: [PATCH 4/4] cc-wrapper: comment explaining C++ stdlib order There is context here that I needed when resolving an issue in which libc was added to NIX_CFLAGS_COMPILE before the C++ stdlib that took me awhile to understand. It was suggested to me that this context be included as a comment, since it is not obvious and could help others in the future. --- pkgs/build-support/cc-wrapper/cc-wrapper.sh | 25 +++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pkgs/build-support/cc-wrapper/cc-wrapper.sh b/pkgs/build-support/cc-wrapper/cc-wrapper.sh index 83b6817798f26..78759f2cfbbc4 100644 --- a/pkgs/build-support/cc-wrapper/cc-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/cc-wrapper.sh @@ -122,6 +122,31 @@ fi if [[ "$isCxx" = 1 ]]; then if [[ "$cxxInclude" = 1 ]]; then + # + # The motivation for this comment is to explain the reason for appending + # the C++ stdlib to NIX_CFLAGS_COMPILE, which I initially thought should + # change and later realized it shouldn't in: + # + # https://github.com/NixOS/nixpkgs/pull/185569#issuecomment-1234959249 + # + # NIX_CFLAGS_COMPILE contains dependencies added using "-isystem", and + # NIX_CXXSTDLIB_COMPILE adds the C++ stdlib using "-isystem". Appending + # NIX_CXXSTDLIB_COMPILE to NIX_CLAGS_COMPILE emulates this part of the + # include lookup order from GCC/Clang: + # + # > 4. Directories specified with -isystem options are scanned in + # > left-to-right order. + # > 5. Standard system directories are scanned. + # > 6. Directories specified with -idirafter options are scanned + # > in left-to-right order. + # + # NIX_CXX_STDLIB_COMPILE acts as the "standard system directories" that + # are otherwise missing from CC in nixpkgs, so should be added last. + # + # This means that the C standard library should never be present inside + # NIX_CFLAGS_COMPILE, because it MUST come after the C++ stdlib. It is + # added automatically by cc-wrapper later using "-idirafter". + # NIX_CFLAGS_COMPILE_@suffixSalt@+=" $NIX_CXXSTDLIB_COMPILE_@suffixSalt@" fi if [[ "$cxxLibrary" = 1 ]]; then