diff --git a/pkgs/development/compilers/gcc/common/configure-flags.nix b/pkgs/development/compilers/gcc/common/configure-flags.nix index 104851930213e9b..25d4f1f53bae9c4 100644 --- a/pkgs/development/compilers/gcc/common/configure-flags.nix +++ b/pkgs/development/compilers/gcc/common/configure-flags.nix @@ -5,7 +5,7 @@ , threadsCross , version -, binutils, gmp, mpfr, libmpc, isl +, apple-sdk, binutils, gmp, mpfr, libmpc, isl , enableLTO , enableMultilib @@ -112,7 +112,11 @@ let ] ++ lib.optionals (!withoutTargetLibc) [ (if libcCross == null - then "--with-native-system-header-dir=${lib.getDev stdenv.cc.libc}/include" + then ( + # GCC will search for the headers relative to SDKROOT on Darwin, so it will find them in the store. + if targetPlatform.isDarwin then "--with-native-system-header-dir=/usr/include" + else "--with-native-system-header-dir=${lib.getDev stdenv.cc.libc}/include" + ) else "--with-native-system-header-dir=${lib.getDev libcCross}${libcCross.incdir or "/include"}") # gcc builds for cross-compilers (build != host) or cross-built # gcc (host != target) always apply the offset prefix to disentangle @@ -132,7 +136,8 @@ let # # We pick "/" path to effectively avoid sysroot offset and make it work # as a native case. - "--with-build-sysroot=/" + # Darwin requires using the SDK as the sysroot for `SDKROOT` to work correctly. + "--with-build-sysroot=${if targetPlatform.isDarwin then apple-sdk.sdkroot else "/"}" # Same with the stdlibc++ headers embedded in the gcc output "--with-gxx-include-dir=${placeholder "out"}/include/c++/${version}/" ] diff --git a/pkgs/development/compilers/gcc/default.nix b/pkgs/development/compilers/gcc/default.nix index f7e2e06bb79a320..d5d59adabb74cb8 100644 --- a/pkgs/development/compilers/gcc/default.nix +++ b/pkgs/development/compilers/gcc/default.nix @@ -34,6 +34,7 @@ , nukeReferences , callPackage , majorMinorVersion +, apple-sdk , cctools , darwin }: @@ -105,6 +106,7 @@ let ; # inherit generated with 'nix eval --json --impure --expr "with import ./. {}; lib.attrNames (lib.functionArgs gcc${majorVersion}.cc.override)" | jq '.[]' --raw-output' inherit + apple-sdk binutils buildPackages cargo