Skip to content
Draft
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
36 changes: 31 additions & 5 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,47 @@ concurrency:
cancel-in-progress: true

jobs:
tests:
name: Test
tests-using-native:
strategy:
fail-fast: false
matrix:
buildSystem: ["native", "swiftbuild"]
linuxSwiftVersion: ['["nightly-main", "nightly-6.2"]', '["nightly-main"]']
exclude:
- buildSystem: "swiftbuild"
linuxSwiftVersion: '["nightly-main", "nightly-6.2"]'
- buildSystem: "native"
linuxSwiftVersion: '["nightly-main"]'
name: Test (${{ matrix.buildSystem }})
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
with:
linux_os_versions: '["amazonlinux2", "bookworm", "noble", "jammy", "rhel-ubi9"]'
linux_swift_versions: ${{ matrix.linuxSwiftVersion }}
linux_pre_build_command: ./.github/scripts/prebuild.sh
linux_build_command: 'swift build --build-tests --build-system ${{ matrix.buildSystem}}'
windows_swift_versions: '["nightly-main"]'
windows_pre_build_command: 'Invoke-Program .\.github\scripts\prebuild.ps1'
windows_build_command: 'Invoke-Program swift build --build-tests --build-system ${{ matrix.buildSystem}}'
enable_ios_checks: true
enable_macos_checks: true
macos_exclude_xcode_versions: "[{\"xcode_version\": \"16.3\"}, {\"xcode_version\": \"16.4\"}]"
macos_build_command: 'swift build --build-tests --build-system ${{ matrix.buildSystem}}'

tests-using-swiftbuild:
name: Test (all SwiftBuild)
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
with:
linux_os_versions: '["amazonlinux2", "bookworm", "noble", "jammy", "rhel-ubi9"]'
linux_swift_versions: '["nightly-main"]'
linux_pre_build_command: ./.github/scripts/prebuild.sh
linux_build_command: 'swift build'
linux_build_command: 'swift run --build-system swiftbuild swift-build --build-tests --build-system swiftbuild'
windows_swift_versions: '["nightly-main"]'
windows_pre_build_command: 'Invoke-Program .\.github\scripts\prebuild.ps1'
windows_build_command: 'Invoke-Program swift build'
windows_build_command: 'Invoke-Program swift run --build-system swiftbuild swift-build --build-tests --build-system swiftbuild'
enable_ios_checks: true
enable_macos_checks: true
macos_exclude_xcode_versions: "[{\"xcode_version\": \"16.3\"}, {\"xcode_version\": \"16.4\"}]"
macos_build_command: 'swift build'
macos_build_command: 'swift run --build-system swiftbuild swift-build --build-tests --build-system swiftbuild'

soundness:
name: Soundness
Expand Down
29 changes: 17 additions & 12 deletions Sources/SwiftBuildSupport/PackagePIFBuilder+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import enum SwiftBuild.ProjectModel

enum TargetSuffix: String {
case testable, dynamic

func hasSuffix(id: GUID) -> Bool {
id.value.hasSuffix("-\(self.rawValue)")
}
Expand Down Expand Up @@ -524,18 +524,18 @@ extension PackageGraph.ResolvedModule {

/// Target-specific single-value build settings declared in the manifest and that apply to the target itself.
var targetSingleValueSettings: [BuildConfiguration: SingleValueSettingsByPlatform] = [:]

/// Target-specific multiple-value build settings declared in the manifest and that apply to the target itself.
var targetMultipleValueSettings: [BuildConfiguration: MultipleValueSettingsByPlatform] = [:]

/// Target-specific single-value build settings that should be imparted to client targets (packages and projects).
var impartedSingleValueSettings: SingleValueSettingsByPlatform = [:]

/// Target-specific multiple-value build settings that should be imparted to client targets (packages and projects).
var impartedMultipleValueSettings: MultipleValueSettingsByPlatform = [:]

// MARK: - Convenience Methods

/// Apply all settings to a ProjectModel.BuildSettings instance
func apply(to buildSettings: inout ProjectModel.BuildSettings, for configuration: BuildConfiguration) {
// Apply single value settings for all platforms
Expand All @@ -550,7 +550,7 @@ extension PackageGraph.ResolvedModule {
}
}
}

// Apply multiple value settings for all platforms
if let multipleValuesByPlatform = targetMultipleValueSettings[configuration] {
// First, collect all multiple-value settings that are being used
Expand All @@ -560,7 +560,7 @@ extension PackageGraph.ResolvedModule {
usedMultipleValueSettings.insert(setting)
}
}

// Now apply the platform-specific values
for (platform, multipleValues) in multipleValuesByPlatform {
for (setting, values) in multipleValues {
Expand All @@ -577,7 +577,7 @@ extension PackageGraph.ResolvedModule {
}
}
}

/// Apply imparted settings to a ProjectModel.BuildSettings instance
func applyImparted(to buildSettings: inout ProjectModel.BuildSettings) {
// Apply imparted single value settings for all platforms
Expand All @@ -590,7 +590,7 @@ extension PackageGraph.ResolvedModule {
}
}
}

// Apply imparted multiple value settings for all platforms
for (platform, multipleValues) in impartedMultipleValueSettings {
for (setting, values) in multipleValues {
Expand Down Expand Up @@ -621,7 +621,7 @@ extension PackageGraph.ResolvedModule {
let values: [String]
let singleValueSetting: ProjectModel.BuildSettings.SingleValueSetting?
let multipleValueSetting: ProjectModel.BuildSettings.MultipleValueSetting?

switch declaration {
case .LINK_FRAMEWORKS:
singleValueSetting = nil
Expand Down Expand Up @@ -1032,6 +1032,11 @@ extension ProjectModel.BuildSettings {
self[.PRODUCT_BUNDLE_IDENTIFIER] = "\(packageIdentity).\(productName)".spm_mangledToBundleIdentifier()
self[.SWIFT_PACKAGE_NAME] = packageName ?? nil

//This should really be swift-build defaults set in the .xcspec files, but changing that requires some extensive testing to ensure xcode projects are not effected.
// So for now lets just force it here.
self[.EXECUTABLE_PREFIX] = "lib"
self[.EXECUTABLE_PREFIX, Platform.windows] = ""

if !createDylibForDynamicProducts {
self[.GENERATE_INFOPLIST_FILE] = "YES"
// If the built framework is named same as one of the target in the package,
Expand Down Expand Up @@ -1106,7 +1111,7 @@ extension ObservabilityScope {

let indentation = String(repeating: " ", count: Int(indent))
let message = "PIF: \(indentation)\(message)"

let diagnostic = Diagnostic(severity: severity, message: message, metadata: metadata)
self.emit(diagnostic)
}
Expand All @@ -1133,7 +1138,7 @@ public struct SourceLocation: Sendable {

public init(_ file: StaticString, _ line: UInt) {
precondition(file.description.hasContent)

self.file = file
self.line = line
}
Expand Down
26 changes: 13 additions & 13 deletions Tests/PackageLoadingTests/PackageBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ struct PackageBuilderTests {
try TargetDescription(name: "Random"),
]
)

try PackageBuilderTester(manifest, in: fs) { package, diagnostics in
try package.checkModule("Random") { result in
#expect("/\(predefinedSourceDir)" == result.target.path)
Expand Down Expand Up @@ -1177,7 +1177,7 @@ struct PackageBuilderTests {
try TargetDescription(name: "MyTests", type: .test),
]
)

try PackageBuilderTester(manifest, in: fs) { package, diagnostics in
try package.checkModule("MyTests") { result in
#expect("/\(predefinedSourceDir)" == result.target.path)
Expand Down Expand Up @@ -1280,7 +1280,7 @@ struct PackageBuilderTests {
try TargetDescription(name: "MyPlugin", type: .plugin, pluginCapability: .buildTool),
]
)

try PackageBuilderTester(manifest, in: fs) { package, diagnostics in
try package.checkModule("MyPlugin") { result in
result.checkSources(root: result.target.path.appending(component: predefinedSourceDir).pathString, paths: "Foo.swift")
Expand Down Expand Up @@ -2838,19 +2838,19 @@ struct PackageBuilderTests {
// invalid - same target in package "Bar"
"Bar",
"Bar",

// invalid - same target in package "Bar"
"Bar2",
.product(name: "Bar2", package: "Bar"),

// invalid - same target in this package
"Foo2",
"Foo2",

// invalid - same target in this package
"Foo3",
.target(name: "Foo3"),

// valid - different packages
"Qux",
.product(name: "Qux", package: "Bar")
Expand Down Expand Up @@ -2979,7 +2979,7 @@ struct PackageBuilderTests {
func testXcodeResources5_4AndEarlier() throws {
// In SwiftTools 5.4 and earlier, supported xcbuild file types are supported by default.
// Of course, modern file types such as xcstrings won't be supported here because those require a newer Swift tools version in general.

let root: AbsolutePath = "/Foo"
let foo = root.appending(components: "Sources", "Foo")

Expand Down Expand Up @@ -3011,11 +3011,11 @@ struct PackageBuilderTests {
}
}
}

@Test
func testXcodeResources5_5AndLater() throws {
// In SwiftTools 5.5 and later, xcbuild file types are only supported when explicitly passed via additionalFileRules.

let root: AbsolutePath = "/Foo"
let foo = root.appending(components: "Sources", "Foo")

Expand Down Expand Up @@ -3140,7 +3140,7 @@ struct PackageBuilderTests {
internalSourcesDir.appending("Internal.swift").pathString,
productSourcesDir.appending("Product.swift").pathString,
snippetsDir.appending("ASnippet.swift").pathString)

let manifest = Manifest.createRootManifest(
displayName: "Foo", toolsVersion: .v5_7,
products: [
Expand All @@ -3150,7 +3150,7 @@ struct PackageBuilderTests {
try TargetDescription(name: "Internal"),
try TargetDescription(name: "Product"),
])

try PackageBuilderTester(manifest, path: root, in: fs) { result, diagnostics in
result.checkProduct("Product") { product in
product.check(type: .library(.automatic), targets: ["Product"])
Expand Down Expand Up @@ -3315,7 +3315,7 @@ struct PackageBuilderTests {
}
}
}

@Test
func testCWarningControlFlags() throws {
let fs = InMemoryFileSystem(emptyFiles:
Expand Down
Loading
Loading