Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Sources/SWBCore/Settings/BuiltinMacros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,8 @@ public final class BuiltinMacros {
public static let _WRAPPER_RESOURCES_DIR = BuiltinMacros.declareStringMacro("_WRAPPER_RESOURCES_DIR")
public static let __INPUT_FILE_LIST_PATH__ = BuiltinMacros.declarePathMacro("__INPUT_FILE_LIST_PATH__")
public static let LINKER_FILE_LIST_FORMAT = BuiltinMacros.declareEnumMacro("LINKER_FILE_LIST_FORMAT") as EnumMacroDeclaration<ResponseFileFormat>
public static let LIBTOOL_FILE_LIST_FORMAT = BuiltinMacros.declareEnumMacro("LIBTOOL_FILE_LIST_FORMAT") as EnumMacroDeclaration<ResponseFileFormat>

public static let LINKER_RESPONSE_FILE_FORMAT = BuiltinMacros.declareEnumMacro("LINKER_RESPONSE_FILE_FORMAT") as EnumMacroDeclaration<ResponseFileFormat>
public static let SWIFT_RESPONSE_FILE_PATH = BuiltinMacros.declarePathMacro("SWIFT_RESPONSE_FILE_PATH")
public static let __ARCHS__ = BuiltinMacros.declareStringListMacro("__ARCHS__")
Expand Down Expand Up @@ -2459,6 +2461,7 @@ public final class BuiltinMacros {
_WRAPPER_RESOURCES_DIR,
__INPUT_FILE_LIST_PATH__,
LINKER_FILE_LIST_FORMAT,
LIBTOOL_FILE_LIST_FORMAT,
LINKER_RESPONSE_FILE_FORMAT,
__ARCHS__,
__SWIFT_MODULE_ONLY_ARCHS__,
Expand Down
5 changes: 3 additions & 2 deletions Sources/SWBCore/SpecImplementations/LinkerSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ open class LinkerSpec : CommandLineToolSpec, @unchecked Sendable {
return ruleInfo
}

public func inputFileListContents(_ cbc: CommandBuildContext) -> ByteString {
return ByteString(encodingAsUTF8: ResponseFiles.responseFileContents(args: cbc.inputs.map { $0.absolutePath.strWithPosixSlashes }, format: cbc.scope.evaluate(BuiltinMacros.LINKER_FILE_LIST_FORMAT)))
public func inputFileListContents(_ cbc: CommandBuildContext, lookup: ((MacroDeclaration) -> MacroExpression?)? = nil) -> ByteString {
let format = cbc.scope.evaluate(BuiltinMacros.LINKER_FILE_LIST_FORMAT, lookup: lookup)
return ByteString(encodingAsUTF8: ResponseFiles.responseFileContents(args: cbc.inputs.map { $0.absolutePath.strWithPosixSlashes }, format: format))
}

open override func constructTasks(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ private final class EnumBuildOptionType : BuildOptionType {
return try namespace.declareEnumMacro(name) as EnumMacroDeclaration<SwiftAPIDigesterMode>
case "LINKER_FILE_LIST_FORMAT":
return try namespace.declareEnumMacro(name) as EnumMacroDeclaration<ResponseFileFormat>
case "LIBTOOL_FILE_LIST_FORMAT":
return try namespace.declareEnumMacro(name) as EnumMacroDeclaration<ResponseFileFormat>
case "LINKER_RESPONSE_FILE_FORMAT":
return try namespace.declareEnumMacro(name) as EnumMacroDeclaration<ResponseFileFormat>
case "DOCC_MINIMUM_ACCESS_LEVEL":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ public final class LdLinkerSpec : GenericLinkerSpec, SpecIdentifierType, @unchec
let fileListPath = cbc.scope.evaluate(BuiltinMacros.__INPUT_FILE_LIST_PATH__, lookup: linkerDriverLookup)
if !fileListPath.isEmpty {
let fileListPath = fileListPath
cbc.producer.writeFileSpec.constructFileTasks(CommandBuildContext(producer: cbc.producer, scope: cbc.scope, inputs: [], output: fileListPath), delegate, contents: inputFileListContents(cbc), permissions: nil, preparesForIndexing: false, additionalTaskOrderingOptions: [.immediate, .ignorePhaseOrdering])
cbc.producer.writeFileSpec.constructFileTasks(CommandBuildContext(producer: cbc.producer, scope: cbc.scope, inputs: [], output: fileListPath), delegate, contents: inputFileListContents(cbc, lookup: linkerDriverLookup), permissions: nil, preparesForIndexing: false, additionalTaskOrderingOptions: [.immediate, .ignorePhaseOrdering])
inputPaths.append(fileListPath)
}

Expand Down Expand Up @@ -1655,6 +1655,11 @@ public final class LibtoolLinkerSpec : GenericLinkerSpec, SpecIdentifierType, @u
return resolveExecutablePath(producer, lookupPath)
}

public override func inputFileListContents(_ cbc: CommandBuildContext, lookup: ((MacroDeclaration) -> MacroExpression?)? = nil) -> ByteString {
let format = cbc.scope.evaluate(BuiltinMacros.LIBTOOL_FILE_LIST_FORMAT, lookup: lookup)
return ByteString(encodingAsUTF8: ResponseFiles.responseFileContents(args: cbc.inputs.map { $0.absolutePath.strWithPosixSlashes }, format: format))
}

static func discoveredCommandLineToolSpecInfo(_ producer: any CommandProducer, _ delegate: any CoreClientTargetDiagnosticProducingDelegate, toolPath: Path) async throws -> DiscoveredLibtoolLinkerToolSpecInfo {
if toolPath.basenameWithoutSuffix == "llvm-lib" || toolPath.basenameWithoutSuffix == "ar" || toolPath.basenameWithoutSuffix.hasSuffix("-ar") {
return DiscoveredLibtoolLinkerToolSpecInfo(toolPath: toolPath, toolVersion: nil)
Expand Down
3 changes: 2 additions & 1 deletion Sources/SWBGenericUnixPlatform/Specs/UnixLibtool.xcspec
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@
DefaultValue = YES;
},
{
Name = "LINKER_FILE_LIST_FORMAT";
Name = "LIBTOOL_FILE_LIST_FORMAT";
Type = Enumeration;
Values = (
unescapedNewlineSeparated,
unixShellQuotedSpaceSeparated,
unixShellQuotedNewlineSeparated,
windowsShellQuotedNewlineSeparated,
);
Expand Down
24 changes: 23 additions & 1 deletion Sources/SWBUniversalPlatform/Specs/Ld.xcspec
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,30 @@
unixShellQuotedNewlineSeparated,
windowsShellQuotedNewlineSeparated,
);
DefaultValue = "$(LINKER_FILE_LIST_FORMAT_$(LINKER_DRIVER))";
},
{
Name = "LINKER_FILE_LIST_FORMAT_clang";
Type = Enumeration;
Values = (
unescapedNewlineSeparated,
unixShellQuotedSpaceSeparated,
unixShellQuotedNewlineSeparated,
windowsShellQuotedNewlineSeparated,
);
DefaultValue = unescapedNewlineSeparated;
},
{
Name = "LINKER_FILE_LIST_FORMAT_swiftc";
Type = Enumeration;
Values = (
unescapedNewlineSeparated,
unixShellQuotedSpaceSeparated,
unixShellQuotedNewlineSeparated,
windowsShellQuotedNewlineSeparated,
);
DefaultValue = unixShellQuotedSpaceSeparated;
},
{
Name = "LINKER_RESPONSE_FILE_FORMAT";
Type = Enumeration;
Expand All @@ -843,7 +865,7 @@
windowsShellQuotedNewlineSeparated,
);
DefaultValue = unixShellQuotedSpaceSeparated;
}
},
);
}
)
11 changes: 11 additions & 0 deletions Sources/SWBUniversalPlatform/Specs/Libtool.xcspec
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@
Type = Boolean;
DefaultValue = YES;
},
{
Name = "LIBTOOL_FILE_LIST_FORMAT";
Type = Enumeration;
Values = (
unescapedNewlineSeparated,
unixShellQuotedSpaceSeparated,
unixShellQuotedNewlineSeparated,
windowsShellQuotedNewlineSeparated,
);
DefaultValue = unescapedNewlineSeparated;
},
);
}
)
2 changes: 1 addition & 1 deletion Sources/SWBWindowsPlatform/Specs/WindowsLibtool.xcspec
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
IsInputDependency = Yes;
},
{
Name = "LINKER_FILE_LIST_FORMAT";
Name = "LIBTOOL_FILE_LIST_FORMAT";
Type = Enumeration;
Values = (
unescapedNewlineSeparated,
Expand Down
12 changes: 6 additions & 6 deletions Tests/SWBBuildSystemTests/BuildOperationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ fileprivate struct BuildOperationTests: CoreBasedTests {
"SomeFiles",
children: [
TestFile("main.swift"),
TestFile("dynamic.swift"),
TestFile("static.swift"),
TestFile("dynamic library.swift"),
TestFile("static library.swift"),
]),
buildConfigurations: [
TestBuildConfiguration("Debug", buildSettings: [
Expand Down Expand Up @@ -93,7 +93,7 @@ fileprivate struct BuildOperationTests: CoreBasedTests {
])
],
buildPhases: [
TestSourcesBuildPhase(["dynamic.swift"]),
TestSourcesBuildPhase(["dynamic library.swift"]),
]
),
TestStandardTarget(
Expand All @@ -107,7 +107,7 @@ fileprivate struct BuildOperationTests: CoreBasedTests {
])
],
buildPhases: [
TestSourcesBuildPhase(["static.swift"]),
TestSourcesBuildPhase(["static library.swift"]),
]
),
])
Expand All @@ -125,11 +125,11 @@ fileprivate struct BuildOperationTests: CoreBasedTests {
stream <<< "print(\"Hello world\")\n"
}

try await tester.fs.writeFileContents(projectDir.join("dynamic.swift")) { stream in
try await tester.fs.writeFileContents(projectDir.join("dynamic library.swift")) { stream in
stream <<< "public func dynamicLib() { }"
}

try await tester.fs.writeFileContents(projectDir.join("static.swift")) { stream in
try await tester.fs.writeFileContents(projectDir.join("static library.swift")) { stream in
stream <<< "public func staticLib() { }"
}

Expand Down