From 643b2684c885289ff6f7f6441b1b39cd619c1523 Mon Sep 17 00:00:00 2001 From: Dave Inglis Date: Wed, 8 Oct 2025 10:23:23 -0400 Subject: [PATCH] Fix building .S files on windows & resource bundles - building .S files on windows requires clang to have TMP/TEMP env passed (also move the linker change that added TMPDIR to the tool env to the spec file for consistency). - fix the resource bundle error that when touching a file was passing a badly quoted path. --- Sources/SWBCore/SpecImplementations/Tools/LinkerTools.swift | 6 +----- Sources/SWBCore/SpecImplementations/Tools/TouchTool.swift | 3 +-- Sources/SWBWindowsPlatform/Specs/WindowsCompile.xcspec | 2 ++ Sources/SWBWindowsPlatform/Specs/WindowsLd.xcspec | 4 +++- Tests/SWBCoreTests/CommandLineSpecTests.swift | 2 +- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Sources/SWBCore/SpecImplementations/Tools/LinkerTools.swift b/Sources/SWBCore/SpecImplementations/Tools/LinkerTools.swift index 53861da9..c87c79f6 100644 --- a/Sources/SWBCore/SpecImplementations/Tools/LinkerTools.swift +++ b/Sources/SWBCore/SpecImplementations/Tools/LinkerTools.swift @@ -740,16 +740,12 @@ public final class LdLinkerSpec : GenericLinkerSpec, SpecIdentifierType, @unchec } } - var environment: [(String, String)] = self.environmentFromSpec(cbc, delegate) - // On Windows, some linker drivers require TMPDIR to be set. - if cbc.producer.hostOperatingSystem == .windows { - environment.append(("TMPDIR", cbc.scope.evaluate(BuiltinMacros.OBJROOT).str)) - } // Compute the inputs and outputs. var inputs: [any PlannedNode] = inputPaths.map{ delegate.createNode($0) } await inputs.append(contentsOf: additionalInputDependencies(cbc, delegate, optionContext: discoveredCommandLineToolSpecInfo(cbc.producer, cbc.scope, delegate), lookup: lookup).map(delegate.createNode)) + let environment: [(String, String)] = self.environmentFromSpec(cbc, delegate) // Add dependencies for any arguments indicating a file path. Self.addAdditionalDependenciesFromCommandLine(cbc, commandLine, EnvironmentBindings(environment), &inputs, &outputs, delegate) diff --git a/Sources/SWBCore/SpecImplementations/Tools/TouchTool.swift b/Sources/SWBCore/SpecImplementations/Tools/TouchTool.swift index e6997b72..57ab5f1a 100644 --- a/Sources/SWBCore/SpecImplementations/Tools/TouchTool.swift +++ b/Sources/SWBCore/SpecImplementations/Tools/TouchTool.swift @@ -42,8 +42,7 @@ final class TouchToolSpec : CommandLineToolSpec, SpecIdentifierType, @unchecked delegate.error("Can't determine path to cmd.exe because the ComSpec environment variable is not set") return } - // FIXME: Need to properly quote the path here, or generally handle this better - commandLine = [commandShellPath, "/c", "copy /b \"\(input.absolutePath.str)\" +,,"] + commandLine = [commandShellPath, "/c", "copy", "/b", input.absolutePath.str, "+,,"] } else { commandLine = ["/usr/bin/touch", "-c", input.absolutePath.str] } diff --git a/Sources/SWBWindowsPlatform/Specs/WindowsCompile.xcspec b/Sources/SWBWindowsPlatform/Specs/WindowsCompile.xcspec index 159969be..2945e91a 100644 --- a/Sources/SWBWindowsPlatform/Specs/WindowsCompile.xcspec +++ b/Sources/SWBWindowsPlatform/Specs/WindowsCompile.xcspec @@ -17,6 +17,8 @@ Type = Compiler; BasedOn = "default:com.apple.compilers.llvm.clang.1_0"; EnvironmentVariables = { + "TEMP" = "$(OBJROOT)"; + "TMP" = "$(OBJROOT)"; }; Name = "Apple LLVM Windows"; Description = "Apple LLVM Windows compiler"; diff --git a/Sources/SWBWindowsPlatform/Specs/WindowsLd.xcspec b/Sources/SWBWindowsPlatform/Specs/WindowsLd.xcspec index b4ef6fbc..9b6cd229 100644 --- a/Sources/SWBWindowsPlatform/Specs/WindowsLd.xcspec +++ b/Sources/SWBWindowsPlatform/Specs/WindowsLd.xcspec @@ -21,7 +21,9 @@ IsAbstract = Yes; SupportsInputFileList = No; EnvironmentVariables = { - "TEMP" = "$(TEMP)"; + "TEMP" = "$(OBJROOT)"; + "TMP" = "$(OBJROOT)"; + "TMPDIR" = "$(OBJROOT)"; "PATH" = "$(TOOLCHAIN_DIR)/usr/bin;$(DEVELOPER_DIR)/Runtimes/$(TOOLCHAIN_VERSION)/usr/bin;$(PATH)"; }; Options = ( diff --git a/Tests/SWBCoreTests/CommandLineSpecTests.swift b/Tests/SWBCoreTests/CommandLineSpecTests.swift index f902a2dc..bc534914 100644 --- a/Tests/SWBCoreTests/CommandLineSpecTests.swift +++ b/Tests/SWBCoreTests/CommandLineSpecTests.swift @@ -1720,7 +1720,7 @@ import SWBMacro #expect(task.execDescription == "Touch input") if core.hostOperatingSystem == .windows { let commandShellPath = try #require(getEnvironmentVariable("ComSpec"), "Can't determine path to cmd.exe because the ComSpec environment variable is not set") - task.checkCommandLine([commandShellPath, "/c", "copy /b \"\(Path.root.join("tmp/input").str)\" +,,"]) + task.checkCommandLine([commandShellPath, "/c", "copy", "/b", Path.root.join("tmp/input").str, "+,,"]) } else { task.checkCommandLine(["/usr/bin/touch", "-c", Path.root.join("tmp/input").str]) }