From 6b1ad8ff01bb537964f5b61424e30d71ac3961f6 Mon Sep 17 00:00:00 2001 From: Mathieu Post Date: Sun, 11 Oct 2026 15:11:51 +0200 Subject: [PATCH] SDKBuilder: allow local toolset and OpenAppleMacrosServer (offline sdk build) xtool sdk build downloads darwin-tools-linux-llvm's toolset and the OpenAppleMacrosServer binary from GitHub releases. Builds without network (Nix and other sandboxed package builds, air-gapped machines) cannot do that. Two optional environment variables point at local copies instead: - XTOOL_TOOLSET_TARBALL: a toolset-.tar.gz, unpacked with tar - XTOOL_OAM_SERVER: an OpenAppleMacrosServer executable, copied (written as a new file, so a read-only source does not make the SDK copy read-only) Without them, nothing changes. --- Sources/XToolSupport/SDKBuilder.swift | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Sources/XToolSupport/SDKBuilder.swift b/Sources/XToolSupport/SDKBuilder.swift index 09af2dd7..fb58c39b 100644 --- a/Sources/XToolSupport/SDKBuilder.swift +++ b/Sources/XToolSupport/SDKBuilder.swift @@ -242,6 +242,15 @@ struct SDKBuilder { withIntermediateDirectories: false ) + if let local = ProcessInfo.processInfo.environment["XTOOL_TOOLSET_TARBALL"] { + let tar = Process() + // /bin/sh finds tar on PATH (the Nix build sandbox has no /usr/bin/env) + tar.executableURL = URL(fileURLWithPath: "/bin/sh") + tar.arguments = ["-c", "exec tar xzf \"$0\" -C \"$1\"", local, toolsetDir.path] + try tar.run() + tar.waitUntilExit() + guard tar.terminationStatus == 0 else { throw Console.Error("Could not unpack toolset \(local)") } + } else { @Dependency(\.httpClient) var httpClient let url = URL(string: """ https://github.com/xtool-org/darwin-tools-linux-llvm/releases/download/\ @@ -280,6 +289,7 @@ struct SDKBuilder { try await execution.standardInputWriter.finish() } .checkSuccess() + } // swift-build assumes we have an Apple-flavored librarian for Apple platforms // (https://github.com/swiftlang/swift-build/blob/b2433e74e/Sources/SWBCore/SpecImplementations/Tools/LinkerTools.swift#L1735) @@ -386,6 +396,13 @@ struct SDKBuilder { } private func installMacros(in output: URL) async throws { + if let local = ProcessInfo.processInfo.environment["XTOOL_OAM_SERVER"] { + let dest = output.appendingPathComponent("OpenAppleMacrosServer") + // write a new file: a copy would keep the read-only mode of the Nix store + try Data(contentsOf: URL(fileURLWithPath: local)).write(to: dest) + try FileManager.default.setAttributes([.posixPermissions: 0o755], ofItemAtPath: dest.path) + return + } @Dependency(\.httpClient) var httpClient let url = URL(string: """ https://github.com/xtool-org/OpenAppleMacros/releases/download/\