From a8e4d3a32ee6797f82e0afda1b4fc2343e5df6bc Mon Sep 17 00:00:00 2001 From: midchildan Date: Tue, 19 Nov 2024 10:50:00 +0900 Subject: [PATCH] xcbuild: find system toolchain on macOS Sonoma and earlier (cherry picked from commit 82a00b78e4e5b17f163cb9d4587ddd0b12504820) (cherry picked from commit b3122a125ef56e5501955ce399c379c625f70201) --- .../Use-system-toolchain-for-usr-bin.patch | 52 +++++++++++-------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/pkgs/by-name/xc/xcbuild/patches/Use-system-toolchain-for-usr-bin.patch b/pkgs/by-name/xc/xcbuild/patches/Use-system-toolchain-for-usr-bin.patch index 9e8314235709..f1b5a38fbcf0 100644 --- a/pkgs/by-name/xc/xcbuild/patches/Use-system-toolchain-for-usr-bin.patch +++ b/pkgs/by-name/xc/xcbuild/patches/Use-system-toolchain-for-usr-bin.patch @@ -1,8 +1,7 @@ -diff --git a/Libraries/xcsdk/Tools/xcrun.cpp b/Libraries/xcsdk/Tools/xcrun.cpp -index 9d6d4576d7..73aabc3d42 100644 ---- a/Libraries/xcsdk/Tools/xcrun.cpp -+++ b/Libraries/xcsdk/Tools/xcrun.cpp -@@ -23,10 +23,14 @@ +diff -Naur a/Libraries/xcsdk/Tools/xcrun.cpp b/Libraries/xcsdk/Tools/xcrun.cpp +--- a/Libraries/xcsdk/Tools/xcrun.cpp 1970-01-01 09:00:01 ++++ b/Libraries/xcsdk/Tools/xcrun.cpp 2024-11-19 01:44:38 +@@ -23,10 +23,19 @@ #include #include @@ -12,12 +11,17 @@ index 9d6d4576d7..73aabc3d42 100644 using libutil::Filesystem; using libutil::FSUtil; -+#define SYSTEM_DEVELOPER_DIR "/private/var/select/developer_dir" ++namespace { ++ const std::vector kSystemDeveloperDirs = { ++ "/private/var/select/developer_dir", ++ "/private/var/db/xcode_select_link" ++ }; ++} + class Options { private: ext::optional _help; -@@ -398,6 +402,8 @@ +@@ -398,6 +407,8 @@ fprintf(stderr, "\n"); } @@ -26,7 +30,7 @@ index 9d6d4576d7..73aabc3d42 100644 /* * Collect search paths for the tool. * Can be in toolchains, target (if one is provided), developer root, -@@ -408,10 +414,42 @@ +@@ -408,10 +419,46 @@ executablePaths.insert(executablePaths.end(), defaultExecutablePaths.begin(), defaultExecutablePaths.end()); /* @@ -49,16 +53,20 @@ index 9d6d4576d7..73aabc3d42 100644 + * Fixes https://github.com/NixOS/nixpkgs/issues/353875. + */ + std::vector toolchainPaths = { }; -+ if (executablePaths.size() < originalSize && filesystem->exists(SYSTEM_DEVELOPER_DIR)) { -+ auto linkTarget = filesystem->readSymbolicLinkCanonical(SYSTEM_DEVELOPER_DIR); -+ if (linkTarget) { -+ auto usrBinPath = FSUtil::NormalizePath(*linkTarget + "/usr/bin"); -+ if (filesystem->exists(usrBinPath)) { -+ toolchainPaths.push_back(usrBinPath); -+ } -+ auto toolchainUsrBinPath = FSUtil::NormalizePath(*linkTarget + "/Toolchains/XcodeDefault.xctoolchain/usr/bin"); -+ if (filesystem->exists(toolchainUsrBinPath)) { -+ toolchainPaths.push_back(toolchainUsrBinPath); ++ if (executablePaths.size() < originalSize) { ++ for (const auto& dir : kSystemDeveloperDirs) { ++ if (filesystem->exists(dir)) { ++ auto linkTarget = filesystem->readSymbolicLinkCanonical(dir); ++ if (linkTarget) { ++ auto usrBinPath = FSUtil::NormalizePath(*linkTarget + "/usr/bin"); ++ if (filesystem->exists(usrBinPath)) { ++ toolchainPaths.push_back(usrBinPath); ++ } ++ auto toolchainUsrBinPath = FSUtil::NormalizePath(*linkTarget + "/Toolchains/XcodeDefault.xctoolchain/usr/bin"); ++ if (filesystem->exists(toolchainUsrBinPath)) { ++ toolchainPaths.push_back(toolchainUsrBinPath); ++ } ++ } + } + } + } @@ -69,12 +77,12 @@ index 9d6d4576d7..73aabc3d42 100644 fprintf(stderr, "error: tool '%s' not found\n", options.tool()->c_str()); return 1; } -@@ -428,8 +466,6 @@ +@@ -427,8 +474,6 @@ + return 0; } else { /* Run is the default. */ - -- std::unordered_map environment = processContext->environmentVariables(); - +- std::unordered_map environment = processContext->environmentVariables(); + if (target != nullptr) { /* - * Update effective environment to include the target path.