Skip to content

Commit a33af66

Browse files
authored
Fix linking against library targets on Mac and Linux (#9158)
1 parent ed504d7 commit a33af66

File tree

2 files changed

+46
-46
lines changed

2 files changed

+46
-46
lines changed

Sources/SwiftBuildSupport/PackagePIFProjectBuilder+Products.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -613,16 +613,16 @@ extension PackagePIFProjectBuilder {
613613
// Swift Build will *not* produce a separate artifact for a package product, but will instead consider any
614614
// dependency on the package product to be a dependency on the whole set of targets
615615
// on which the package product depends.
616-
let librayUmbrellaTargetKeyPath = try self.project.addTarget { _ in
616+
let libraryUmbrellaTargetKeyPath = try self.project.addTarget { _ in
617617
ProjectModel.Target(
618618
id: product.pifTargetGUID(suffix: targetSuffix),
619619
productType: productType,
620620
name: product.targetName(suffix: targetSuffix),
621-
productName: product.name
621+
productName: "$(EXECUTABLE_NAME)"
622622
)
623623
}
624624
do {
625-
let librayTarget = self.project[keyPath: librayUmbrellaTargetKeyPath]
625+
let librayTarget = self.project[keyPath: libraryUmbrellaTargetKeyPath]
626626
log(
627627
.debug,
628628
"Created target '\(librayTarget.id)' of type '\(librayTarget.productType)' with " +
@@ -637,7 +637,7 @@ extension PackagePIFProjectBuilder {
637637
let binaryFileRef = self.binaryGroup.addFileReference { id in
638638
FileReference(id: id, path: binaryTarget.artifactPath.pathString)
639639
}
640-
self.project[keyPath: librayUmbrellaTargetKeyPath].addLibrary { id in
640+
self.project[keyPath: libraryUmbrellaTargetKeyPath].addLibrary { id in
641641
BuildFile(id: id, fileRef: binaryFileRef, codeSignOnCopy: true, removeHeadersOnCopy: true)
642642
}
643643
log(.debug, indent: 1, "Added use of binary library '\(binaryTarget.artifactPath)'")
@@ -646,7 +646,7 @@ extension PackagePIFProjectBuilder {
646646
// We add these as linked dependencies; because the product type is `.packageProduct`,
647647
// SwiftBuild won't actually link them, but will instead impart linkage to any clients that
648648
// link against the package product.
649-
self.project[keyPath: librayUmbrellaTargetKeyPath].common.addDependency(
649+
self.project[keyPath: libraryUmbrellaTargetKeyPath].common.addDependency(
650650
on: module.pifTargetGUID,
651651
platformFilters: [],
652652
linkProduct: true
@@ -657,7 +657,7 @@ extension PackagePIFProjectBuilder {
657657
for module in product.modules where module.underlying.isSourceModule && module.resources.hasContent {
658658
// FIXME: Find a way to determine whether a module has generated resources
659659
// here so that we can embed resources into dynamic targets.
660-
self.project[keyPath: librayUmbrellaTargetKeyPath].common.addDependency(
660+
self.project[keyPath: libraryUmbrellaTargetKeyPath].common.addDependency(
661661
on: pifTargetIdForResourceBundle(module.name),
662662
platformFilters: []
663663
)
@@ -667,7 +667,7 @@ extension PackagePIFProjectBuilder {
667667
FileReference(id: id, path: "$(CONFIGURATION_BUILD_DIR)/\(packageName)_\(module.name).bundle")
668668
}
669669
if embedResources {
670-
self.project[keyPath: librayUmbrellaTargetKeyPath].addResourceFile { id in
670+
self.project[keyPath: libraryUmbrellaTargetKeyPath].addResourceFile { id in
671671
BuildFile(id: id, fileRef: fileRef)
672672
}
673673
log(.debug, indent: 1, "Added use of resource bundle '\(fileRef.path)'")
@@ -693,7 +693,7 @@ extension PackagePIFProjectBuilder {
693693
installPath: installPath(for: product.underlying),
694694
delegate: pifBuilder.delegate
695695
)
696-
self.project[keyPath: librayUmbrellaTargetKeyPath].common.addSourcesBuildPhase { id in
696+
self.project[keyPath: libraryUmbrellaTargetKeyPath].common.addSourcesBuildPhase { id in
697697
ProjectModel.SourcesBuildPhase(id: id)
698698
}
699699
}
@@ -702,7 +702,7 @@ extension PackagePIFProjectBuilder {
702702
pifBuilder.delegate.configureLibraryProduct(
703703
product: product.underlying,
704704
project: &self.project,
705-
target: librayUmbrellaTargetKeyPath,
705+
target: libraryUmbrellaTargetKeyPath,
706706
additionalFiles: additionalFilesGroupKeyPath
707707
)
708708

@@ -732,7 +732,7 @@ extension PackagePIFProjectBuilder {
732732
FileReference(id: id, path: binaryTarget.path.pathString)
733733
}
734734
let toolsVersion = package.manifest.toolsVersion
735-
self.project[keyPath: librayUmbrellaTargetKeyPath].addLibrary { id in
735+
self.project[keyPath: libraryUmbrellaTargetKeyPath].addLibrary { id in
736736
BuildFile(
737737
id: id,
738738
fileRef: binaryFileRef,
@@ -747,7 +747,7 @@ extension PackagePIFProjectBuilder {
747747

748748
if moduleDependency.type == .plugin {
749749
let dependencyId = moduleDependency.pifTargetGUID
750-
self.project[keyPath: librayUmbrellaTargetKeyPath].common.addDependency(
750+
self.project[keyPath: libraryUmbrellaTargetKeyPath].common.addDependency(
751751
on: dependencyId,
752752
platformFilters: packageConditions
753753
.toPlatformFilter(toolsVersion: package.manifest.toolsVersion),
@@ -768,7 +768,7 @@ extension PackagePIFProjectBuilder {
768768
if let product = moduleDependency
769769
.productRepresentingDependencyOfBuildPlugin(in: mainModuleProducts)
770770
{
771-
self.project[keyPath: librayUmbrellaTargetKeyPath].common.addDependency(
771+
self.project[keyPath: libraryUmbrellaTargetKeyPath].common.addDependency(
772772
on: product.pifTargetGUID,
773773
platformFilters: packageConditions
774774
.toPlatformFilter(toolsVersion: package.manifest.toolsVersion),
@@ -785,7 +785,7 @@ extension PackagePIFProjectBuilder {
785785
}
786786
}
787787

788-
self.project[keyPath: librayUmbrellaTargetKeyPath].common.addDependency(
788+
self.project[keyPath: libraryUmbrellaTargetKeyPath].common.addDependency(
789789
on: moduleDependency.pifTargetGUID,
790790
platformFilters: packageConditions.toPlatformFilter(toolsVersion: package.manifest.toolsVersion),
791791
linkProduct: true
@@ -803,7 +803,7 @@ extension PackagePIFProjectBuilder {
803803
buildSettings: &settings
804804
) {
805805
let shouldLinkProduct = productDependency.isLinkable
806-
self.project[keyPath: librayUmbrellaTargetKeyPath].common.addDependency(
806+
self.project[keyPath: libraryUmbrellaTargetKeyPath].common.addDependency(
807807
on: productDependency.pifTargetGUID,
808808
platformFilters: packageConditions
809809
.toPlatformFilter(toolsVersion: package.manifest.toolsVersion),
@@ -838,10 +838,10 @@ extension PackagePIFProjectBuilder {
838838
settings[.PACKAGE_REGISTRY_SIGNATURE] = String(data: data, encoding: .utf8)
839839
}
840840

841-
self.project[keyPath: librayUmbrellaTargetKeyPath].common.addBuildConfig { id in
841+
self.project[keyPath: libraryUmbrellaTargetKeyPath].common.addBuildConfig { id in
842842
BuildConfig(id: id, name: "Debug", settings: settings)
843843
}
844-
self.project[keyPath: librayUmbrellaTargetKeyPath].common.addBuildConfig { id in
844+
self.project[keyPath: libraryUmbrellaTargetKeyPath].common.addBuildConfig { id in
845845
BuildConfig(id: id, name: "Release", settings: settings)
846846
}
847847

@@ -861,7 +861,7 @@ extension PackagePIFProjectBuilder {
861861
type: moduleOrProductType,
862862
name: product.name,
863863
moduleName: product.c99name,
864-
pifTarget: .target(self.project[keyPath: librayUmbrellaTargetKeyPath]),
864+
pifTarget: .target(self.project[keyPath: libraryUmbrellaTargetKeyPath]),
865865
indexableFileURLs: [],
866866
headerFiles: [],
867867
linkedPackageBinaries: linkedPackageBinaries,

Tests/FunctionalTests/ModuleAliasingFixtureTests.swift

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -91,38 +91,38 @@ struct ModuleAliasingFixtureTests {
9191
let buildSystem = data.buildSystem
9292
let configuration = data.config
9393
try await withKnownIssue(isIntermittent: true) {
94-
try await fixture(name: "ModuleAliasing/DirectDeps2") { fixturePath in
95-
let pkgPath = fixturePath.appending(components: "AppPkg")
96-
let buildPath = try pkgPath.appending(components: buildSystem.binPath(for: configuration))
97-
let expectedModules = [
98-
"AUtils.swiftmodule",
99-
"BUtils.swiftmodule",
100-
]
101-
try await executeSwiftBuild(
102-
pkgPath,
103-
configuration: configuration,
104-
extraArgs: ["--vv"],
105-
buildSystem: buildSystem,
106-
)
107-
expectFileExists(at: buildPath.appending(components: executableName("App")))
108-
for file in expectedModules {
109-
switch buildSystem {
110-
case .native:
111-
expectFileExists(at: buildPath.appending(components: "Modules", file))
112-
case .swiftbuild:
113-
expectFileExists(at: buildPath.appending(components: file))
114-
case .xcode:
115-
Issue.record("expectations are not implemented")
94+
try await fixture(name: "ModuleAliasing/DirectDeps2") { fixturePath in
95+
let pkgPath = fixturePath.appending(components: "AppPkg")
96+
let buildPath = try pkgPath.appending(components: buildSystem.binPath(for: configuration))
97+
let expectedModules = [
98+
"AUtils.swiftmodule",
99+
"BUtils.swiftmodule",
100+
]
101+
try await executeSwiftBuild(
102+
pkgPath,
103+
configuration: configuration,
104+
extraArgs: ["--vv"],
105+
buildSystem: buildSystem,
106+
)
107+
expectFileExists(at: buildPath.appending(components: executableName("App")))
108+
for file in expectedModules {
109+
switch buildSystem {
110+
case .native:
111+
expectFileExists(at: buildPath.appending(components: "Modules", file))
112+
case .swiftbuild:
113+
expectFileExists(at: buildPath.appending(components: file))
114+
case .xcode:
115+
Issue.record("expectations are not implemented")
116+
}
116117
}
118+
_ = try await executeSwiftBuild(
119+
pkgPath,
120+
configuration: configuration,
121+
buildSystem: buildSystem,
122+
)
117123
}
118-
_ = try await executeSwiftBuild(
119-
pkgPath,
120-
configuration: configuration,
121-
buildSystem: buildSystem,
122-
)
123-
}
124124
} when: {
125-
buildSystem == .swiftbuild
125+
ProcessInfo.hostOperatingSystem == .windows && buildSystem == .swiftbuild
126126
}
127127
}
128128

0 commit comments

Comments
 (0)