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
6 changes: 2 additions & 4 deletions Sources/SwiftBuildSupport/PackagePIFBuilder+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1000,18 +1000,16 @@ extension ProjectModel.BuildSettings {
mutating func configureDynamicSettings(
productName: String,
targetName: String,
executableName: String,
packageIdentity: PackageIdentity,
packageName: String?,
createDylibForDynamicProducts: Bool,
installPath: String,
delegate: PackagePIFBuilder.BuildDelegate
delegate: PackagePIFBuilder.BuildDelegate,
) {
self[.TARGET_NAME] = targetName
self[.PRODUCT_NAME] = createDylibForDynamicProducts ? productName : executableName
Copy link
Contributor

Choose a reason for hiding this comment

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

Will removing createDylibForDynamicProducts break the use case of xcodebuild building dylibs? We might be missing some tests there...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ya, I think @owenv was saying offline that there is some history here we just don't know about as to why this was like this. I think we should try and move forward with this as it cleans things up and I imagine we should be able to address any fallout quickly if need be...

self[.PRODUCT_NAME] = productName
self[.PRODUCT_MODULE_NAME] = productName
self[.PRODUCT_BUNDLE_IDENTIFIER] = "\(packageIdentity).\(productName)".spm_mangledToBundleIdentifier()
self[.EXECUTABLE_NAME] = executableName
self[.CLANG_ENABLE_MODULES] = "YES"
self[.SWIFT_PACKAGE_NAME] = packageName ?? nil

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,31 +237,25 @@ extension PackagePIFProjectBuilder {
) throws -> (PackagePIFBuilder.ModuleOrProduct, resourceBundleName: String?) {
precondition(sourceModule.isSourceModule)

let pifProductName: String
let executableName: String
let productType: ProjectModel.Target.ProductType

switch desiredModuleType {
case .dynamicLibrary:
// We are re-using this default for dynamic targets as well.
if pifBuilder.createDylibForDynamicProducts {
pifProductName = "lib\(sourceModule.name).dylib"
executableName = pifProductName
productType = .dynamicLibrary
} else {
pifProductName = sourceModule.name + ".framework"
executableName = sourceModule.name
productType = .framework
}

case .staticLibrary, .executable:
pifProductName = "\(sourceModule.name).o"
executableName = pifProductName
#if os(Windows) // Temporary until we get a new productType in swift-build
productType = .staticArchive
#else
productType = .objectFile
#endif

case .macro:
pifProductName = sourceModule.name
executableName = pifProductName
productType = .hostBuildTool
}

Expand All @@ -280,8 +274,8 @@ extension PackagePIFProjectBuilder {
ProjectModel.Target(
id: sourceModule.pifTargetGUID(suffix: targetSuffix),
productType: productType,
name: "\(sourceModule.name)",
productName: pifProductName,
name: sourceModule.name,
productName: "$(EXECUTABLE_NAME)",
approvedByUser: approvedByUser
)
}
Expand Down Expand Up @@ -407,35 +401,22 @@ extension PackagePIFProjectBuilder {
settings.configureDynamicSettings(
productName: sourceModule.name,
targetName: sourceModule.name,
executableName: executableName,
packageIdentity: package.identity,
packageName: sourceModule.packageName,
createDylibForDynamicProducts: pifBuilder.createDylibForDynamicProducts,
installPath: "/usr/local/lib",
delegate: pifBuilder.delegate
delegate: pifBuilder.delegate,
)
} else {
settings[.TARGET_NAME] = sourceModule.name
settings[.PRODUCT_NAME] = "$(TARGET_NAME)"
settings[.PRODUCT_MODULE_NAME] = sourceModule.c99name
settings[.PRODUCT_BUNDLE_IDENTIFIER] = "\(self.package.identity).\(sourceModule.name)"
.spm_mangledToBundleIdentifier()
settings[.EXECUTABLE_NAME] = executableName
settings[.CLANG_ENABLE_MODULES] = "YES"
settings[.GENERATE_PRELINK_OBJECT_FILE] = "NO"
settings[.STRIP_INSTALLED_PRODUCT] = "NO"

// Macros build as executables, so they need slightly different
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did this block need to be dropped?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so correct me if I'm wrong but setting the MACH_O_TYPE should not be required to be set in the PIF as the product type definition in swift-build sets it for us, and with that said i feel CLANG_COVERAGE_MAPPING_LINKER_ARGS should be handled that same way

Copy link
Contributor

Choose a reason for hiding this comment

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

that's a good point, I wonder why this was put here originally...

and yeah, lets sink the CLANG_COVERAGE_MAPPING_LINKER_ARGS change into Swift Build

// build settings from other module types which build a "*.o".
if desiredModuleType == .macro {
settings[.MACH_O_TYPE] = "mh_execute"
} else {
settings[.MACH_O_TYPE] = "mh_object"
// Disable code coverage linker flags since we're producing .o files.
// Otherwise, we will run into duplicated symbols when there are more than one targets that produce .o
// as their product.
settings[.CLANG_COVERAGE_MAPPING_LINKER_ARGS] = "NO"
}
settings[.SWIFT_PACKAGE_NAME] = sourceModule.packageName

if desiredModuleType == .executable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ extension PackagePIFProjectBuilder {
id: product.pifTargetGUID,
productType: pifProductType,
name: product.targetName(),
productName: product.name
productName: "$(EXECUTABLE_NAME)"
)
}
do {
Expand Down Expand Up @@ -115,7 +115,6 @@ extension PackagePIFProjectBuilder {
settings[.PRODUCT_MODULE_NAME] = product.c99name
settings[.PRODUCT_BUNDLE_IDENTIFIER] = "\(self.package.identity).\(product.name)"
.spm_mangledToBundleIdentifier()
settings[.EXECUTABLE_NAME] = product.name
settings[.CLANG_ENABLE_MODULES] = "YES"
settings[.SWIFT_PACKAGE_NAME] = mainModule.packageName

Expand Down Expand Up @@ -596,35 +595,15 @@ extension PackagePIFProjectBuilder {

// FIXME: Cleanup this mess with <rdar://56889224>

let pifProductName: String
let executableName: String
let productType: ProjectModel.Target.ProductType

if desiredProductType == .dynamic {
if pifBuilder.createDylibForDynamicProducts {
pifProductName = "lib\(product.name).dylib"
executableName = pifProductName
productType = .dynamicLibrary
} else {
// If a product is explicitly declared dynamic, we preserve its name,
// otherwise we will compute an automatic one.
if product.libraryType == .dynamic {
if let customExecutableName = pifBuilder.delegate
.customExecutableName(product: product.underlying)
{
executableName = customExecutableName
} else {
executableName = product.name
}
} else {
executableName = PackagePIFBuilder.computePackageProductFrameworkName(productName: product.name)
}
pifProductName = "\(executableName).framework"
productType = .framework
}
} else {
pifProductName = "lib\(product.name).a"
executableName = pifProductName
productType = .packageProduct
}

Expand All @@ -637,7 +616,7 @@ extension PackagePIFProjectBuilder {
id: product.pifTargetGUID(suffix: targetSuffix),
productType: productType,
name: product.targetName(suffix: targetSuffix),
productName: pifProductName
productName: product.name
)
}
do {
Expand Down Expand Up @@ -706,7 +685,6 @@ extension PackagePIFProjectBuilder {
settings.configureDynamicSettings(
productName: product.name,
targetName: product.targetName(),
executableName: executableName,
packageIdentity: package.identity,
packageName: package.identity.c99name,
createDylibForDynamicProducts: pifBuilder.createDylibForDynamicProducts,
Expand Down Expand Up @@ -1037,7 +1015,6 @@ extension PackagePIFProjectBuilder {
settings[.PRODUCT_MODULE_NAME] = moduleName
settings[.PRODUCT_BUNDLE_IDENTIFIER] = "\(self.package.identity).\(name)"
.spm_mangledToBundleIdentifier()
settings[.EXECUTABLE_NAME] = name
settings[.SKIP_INSTALL] = "NO"
settings[.SWIFT_VERSION] = "5.0"
// This should eventually be set universally for all package targets/products.
Expand Down
1 change: 0 additions & 1 deletion Sources/SwiftBuildSupport/PackagePIFProjectBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ struct PackagePIFProjectBuilder {
settings[.PRODUCT_MODULE_NAME] = bundleName
settings[.PRODUCT_BUNDLE_IDENTIFIER] = "\(self.package.identity).\(module.name).resources"
.spm_mangledToBundleIdentifier()
settings[.EXECUTABLE_NAME] = ""
settings[.GENERATE_INFOPLIST_FILE] = "YES"
settings[.PACKAGE_RESOURCE_TARGET_KIND] = "resource"

Expand Down
3 changes: 3 additions & 0 deletions Sources/SwiftBuildSupport/SwiftBuildSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -727,16 +727,19 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {

settings["LIBRARY_SEARCH_PATHS"] = try "$(inherited) \(buildParameters.toolchain.toolchainLibDir.pathString)"
settings["OTHER_CFLAGS"] = (
verboseFlag +
["$(inherited)"]
+ buildParameters.toolchain.extraFlags.cCompilerFlags.map { $0.shellEscaped() }
+ buildParameters.flags.cCompilerFlags.map { $0.shellEscaped() }
).joined(separator: " ")
settings["OTHER_CPLUSPLUSFLAGS"] = (
verboseFlag +
["$(inherited)"]
+ buildParameters.toolchain.extraFlags.cxxCompilerFlags.map { $0.shellEscaped() }
+ buildParameters.flags.cxxCompilerFlags.map { $0.shellEscaped() }
).joined(separator: " ")
settings["OTHER_SWIFT_FLAGS"] = (
verboseFlag +
["$(inherited)"]
+ buildParameters.toolchain.extraFlags.swiftCompilerFlags.map { $0.shellEscaped() }
+ buildParameters.flags.swiftCompilerFlags.map { $0.shellEscaped() }
Expand Down
21 changes: 8 additions & 13 deletions Tests/CommandsTests/BuildCommandTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -554,19 +554,14 @@ struct BuildCommandTestCases {
func nonReachableProductsAndTargetsFunctional(
buildSystem: BuildSystemProvider.Kind,
) async throws {
// skipped on Xcode
try await withKnownIssue {
try await fixture(name: "Miscellaneous/UnreachableTargets") { fixturePath in
let aPath = fixturePath.appending("A")

let result = try await build([], packagePath: aPath, buildSystem: buildSystem)
#expect(!result.binContents.contains("bexec"))
#expect(!result.binContents.contains("BTarget2.build"))
#expect(!result.binContents.contains("cexec"))
#expect(!result.binContents.contains("CTarget.build"))
}
} when: {
buildSystem == .swiftbuild && ProcessInfo.hostOperatingSystem == .windows
try await fixture(name: "Miscellaneous/UnreachableTargets") { fixturePath in
let aPath = fixturePath.appending("A")

let result = try await build([], packagePath: aPath, buildSystem: buildSystem)
#expect(!result.binContents.contains("bexec"))
#expect(!result.binContents.contains("BTarget2.build"))
#expect(!result.binContents.contains("cexec"))
#expect(!result.binContents.contains("CTarget.build"))
}
}

Expand Down
Loading