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
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ extension PackagePIFProjectBuilder {
on: moduleDependencyGUID,
platformFilters: packageConditions
.toPlatformFilter(toolsVersion: package.manifest.toolsVersion),
linkProduct: true
// Only link the testable version of executables which use Swift, as we do not currently support renaming entrypoints written in other languages.
linkProduct: moduleDependency.usesSwift
)
log(.debug, indent: 1, "Added linked dependency on target '\(moduleDependencyGUID)'")
}
Expand Down
34 changes: 24 additions & 10 deletions Sources/SwiftBuildSupport/SwiftBuildSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
throw error
}

let request = try self.makeBuildRequest(configuredTargets: configuredTargets, derivedDataPath: derivedDataPath, genSymbolGraph: genSymbolGraph)
let request = try await self.makeBuildRequest(session: session, configuredTargets: configuredTargets, derivedDataPath: derivedDataPath, genSymbolGraph: genSymbolGraph)

struct BuildState {
private var targetsByID: [Int: SwiftBuild.SwiftBuildMessage.TargetStartedInfo] = [:]
Expand Down Expand Up @@ -521,7 +521,7 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
case .taskComplete(let info):
let startedInfo = try buildState.completed(task: info)
if info.result != .success {
self.observabilityScope.emit(severity: .error, message: "\(startedInfo.ruleInfo) failed with a nonzero exit code")
self.observabilityScope.emit(severity: .error, message: "\(startedInfo.ruleInfo) failed with a nonzero exit code. Command line: \(startedInfo.commandLineDisplayString ?? "<no command line>")")
}
let targetInfo = try buildState.target(for: startedInfo)
self.delegate?.buildSystem(self, didFinishCommand: BuildSystemCommand(startedInfo, targetInfo: targetInfo))
Expand Down Expand Up @@ -631,7 +631,7 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
)
}

private func makeBuildParameters(genSymbolGraph: Bool) throws -> SwiftBuild.SWBBuildParameters {
private func makeBuildParameters(session: SWBBuildServiceSession, genSymbolGraph: Bool) async throws -> SwiftBuild.SWBBuildParameters {
// Generate the run destination parameters.
let runDestination = makeRunDestination()

Expand All @@ -642,11 +642,20 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {

// Generate a table of any overriding build settings.
var settings: [String: String] = [:]
// An error with determining the override should not be fatal here.
settings["CC"] = try? buildParameters.toolchain.getClangCompiler().pathString
// Always specify the path of the effective Swift compiler, which was determined in the same way as for the
// native build system.
settings["SWIFT_EXEC"] = buildParameters.toolchain.swiftCompilerPath.pathString

// If the SwiftPM toolchain corresponds to a toolchain registered with the lower level build system, add it to the toolchain stack.
// Otherwise, apply overrides for each component of the SwiftPM toolchain.
if let toolchainID = try await session.lookupToolchain(at: buildParameters.toolchain.toolchainDir.pathString) {
settings["TOOLCHAINS"] = "\(toolchainID.rawValue) $(inherited)"
} else {
// FIXME: This list of overrides is incomplete.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Do we have a GitHub issue tracking this FIXME? If so, can we add it as a code comment?

// An error with determining the override should not be fatal here.
settings["CC"] = try? buildParameters.toolchain.getClangCompiler().pathString
// Always specify the path of the effective Swift compiler, which was determined in the same way as for the
// native build system.
settings["SWIFT_EXEC"] = buildParameters.toolchain.swiftCompilerPath.pathString
}

// FIXME: workaround for old Xcode installations such as what is in CI
settings["LM_SKIP_METADATA_EXTRACTION"] = "YES"
if genSymbolGraph {
Expand Down Expand Up @@ -705,6 +714,11 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
settings["ARCHS"] = architectures.joined(separator: " ")
}

// When building with the CLI for macOS, test bundles should generate entrypoints for compatibility with swiftpm-testing-helper.
if buildParameters.triple.isMacOSX {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

macOS, or all Darwin?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well we don't support command-line execution of tests on other Apple platforms anyway, so...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Execution doesn't matter, this is about the build. The build system does not assume that the machine/tool building the tests is the one running them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay: we support neither building nor executing tests on iOS using SwiftPM.

settings["GENERATE_TEST_ENTRYPOINTS_FOR_BUNDLES"] = "YES"
}

func reportConflict(_ a: String, _ b: String) throws -> String {
throw StringError("Build parameters constructed conflicting settings overrides '\(a)' and '\(b)'")
}
Expand All @@ -727,9 +741,9 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
return params
}

public func makeBuildRequest(configuredTargets: [SWBTargetGUID], derivedDataPath: Basics.AbsolutePath, genSymbolGraph: Bool) throws -> SWBBuildRequest {
public func makeBuildRequest(session: SWBBuildServiceSession, configuredTargets: [SWBTargetGUID], derivedDataPath: Basics.AbsolutePath, genSymbolGraph: Bool) async throws -> SWBBuildRequest {
var request = SWBBuildRequest()
request.parameters = try makeBuildParameters(genSymbolGraph: genSymbolGraph)
request.parameters = try await makeBuildParameters(session: session, genSymbolGraph: genSymbolGraph)
request.configuredTargets = configuredTargets.map { SWBConfiguredTarget(guid: $0.rawValue, parameters: request.parameters) }
request.useParallelTargets = true
request.useImplicitDependencies = false
Expand Down
8 changes: 2 additions & 6 deletions Tests/CommandsTests/TestCommandTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ struct TestCommandTests {
}

@Test(
.issue("https://github.com/swiftlang/swift-package-manager/issues/8955", relationship: .defect),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: This issue is merged. Can we remove the withKnownIssue block to confirm whether the test now always passes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also hits a different underlying issue now that the first one is fixed which needs further investigation

arguments: SupportedBuildSystemOnAllPlatforms, BuildConfiguration.allCases,
)
func enableDisableTestabilityDefaultShouldRunWithTestability(
Expand Down Expand Up @@ -274,7 +273,7 @@ struct TestCommandTests {
}

#expect(
stderr.contains("was not compiled for testing"),
stderr.contains("was not compiled for testing") || stderr.contains("ignore swiftmodule built without '-enable-testing'"),
"got stdout: \(stdout), stderr: \(stderr)",
)
}
Expand Down Expand Up @@ -668,7 +667,6 @@ struct TestCommandTests {
} when: {
(buildSystem == .swiftbuild && .linux == ProcessInfo.hostOperatingSystem)
|| ProcessInfo.hostOperatingSystem == .windows
|| (buildSystem == .swiftbuild && .macOS == ProcessInfo.hostOperatingSystem && tcdata.testRunner == .SwiftTesting)
}
}

Expand Down Expand Up @@ -995,8 +993,6 @@ struct TestCommandTests {
}

@Test(
.SWBINTTODO("Fails to find test executable"),
.issue("https://github.com/swiftlang/swift-package-manager/pull/8722", relationship: .fixedBy),
arguments: SupportedBuildSystemOnAllPlatforms, BuildConfiguration.allCases,
)
func basicSwiftTestingIntegration(
Expand All @@ -1017,7 +1013,7 @@ struct TestCommandTests {
)
}
} when: {
buildSystem == .swiftbuild
buildSystem == .swiftbuild && ProcessInfo.hostOperatingSystem != .macOS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (possibly blocking): Do we know why this test failed on Linux and Windows? Could we add an issue trait to the test to track it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch fixed it on macOS, linux/windows now hit a different underlying issue which needs further investigation

}
}

Expand Down