Skip to content
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ Package.resolved
/stage/
Utilities/InstalledSwiftPMConfiguration/config.json
Fixtures/BinaryLibraries/Static/Package1/Simple.artifactbundle/build
/Packages/

Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,6 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
flags += frameworks.flatMap { ["-framework", $0] }
}

// Prebuilt libraries.
let prebuiltLibPaths = OrderedSet(self.staticTargets.reduce([]) {
$0 + self.buildParameters.createScope(for: $1).evaluate(.PREBUILT_LIBRARY_PATHS)
})
let prebuiltLibraries = OrderedSet(self.staticTargets.reduce([]) {
$0 + self.buildParameters.createScope(for: $1).evaluate(.PREBUILT_LIBRARIES)
})
flags += prebuiltLibPaths.flatMap({ ["-L", $0] }) + prebuiltLibraries.map({ "-l" + $0 })

// Other linker flags.
for target in self.staticTargets {
let scope = self.buildParameters.createScope(for: target)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1093,9 +1093,6 @@ public final class SwiftModuleBuildDescription {
// Other C flags.
flags += scope.evaluate(.OTHER_CFLAGS).flatMap { ["-Xcc", $0] }

// Prebuilt include paths
flags += scope.evaluate(.PREBUILT_INCLUDE_PATHS).flatMap { ["-I", $0] }

// Include path for the toolchain's copy of SwiftSyntax.
#if BUILD_MACROS_AS_DYLIBS
if module.type == .macro {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,6 @@ extension LLBuildManifestBuilder {
// Ignore Plugin Modules.
if module.underlying is PluginModule { return }

if target.target.platformConstraint == .all && module.platformConstraint == .host {
// Skip module that is host only.
// This only happens when the target isn't actually referenced by the root package.
return
}

guard let description else {
throw InternalError("No build description for module: \(module)")
}
Expand Down
3 changes: 3 additions & 0 deletions Sources/Build/BuildPlan/BuildPlan+Clang.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ extension BuildPlan {
}
clangTarget.libraryBinaryPaths.insert(library.libraryPath)
}
case .prebuilt:
// Skip since prebuilts are for Swift modules only at the moment
break
}

default: continue
Expand Down
12 changes: 10 additions & 2 deletions Sources/Build/BuildPlan/BuildPlan+Product.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ extension BuildPlan {
}
}

// Add prebuilt libraries
for path in dependencies.prebuiltLibraryPaths {
buildProduct.additionalFlags += [path.pathString]
}

// Don't link libc++ or libstd++ when building for Embedded Swift.
// Users can still link it manually for embedded platforms when needed,
// by providing `-Xlinker -lc++` options via CLI or `Package.swift`.
Expand Down Expand Up @@ -125,6 +130,7 @@ extension BuildPlan {
staticTargets: [ModuleBuildDescription],
systemModules: [ResolvedModule],
libraryBinaryPaths: Set<AbsolutePath>,
prebuiltLibraryPaths: Set<AbsolutePath>,
availableTools: [String: AbsolutePath]
) {
let product = productDescription.product
Expand Down Expand Up @@ -242,6 +248,7 @@ extension BuildPlan {
var staticTargets = [ModuleBuildDescription]()
var systemModules = [ResolvedModule]()
var libraryBinaryPaths: Set<AbsolutePath> = []
var prebuiltLibraryPaths: Set<AbsolutePath> = []
var availableTools = [String: AbsolutePath]()

for dependency in allDependencies {
Expand Down Expand Up @@ -323,13 +330,14 @@ extension BuildPlan {
for library in libraries {
libraryBinaryPaths.insert(library.libraryPath)
}
case .prebuilt(let prebuilt):
prebuiltLibraryPaths.insert(prebuilt.libraryPath)
case .unknown:
throw InternalError("unknown binary target '\(module.name)' type")
}
case .plugin:
continue
}

case .product(let product, let description):
// Add the dynamic products to array of libraries to link.
if product.type == .library(.dynamic) {
Expand All @@ -348,7 +356,7 @@ extension BuildPlan {
})
}

return (linkLibraries, staticTargets, systemModules, libraryBinaryPaths, availableTools)
return (linkLibraries, staticTargets, systemModules, libraryBinaryPaths, prebuiltLibraryPaths, availableTools)
}

/// Extracts the artifacts from an artifactsArchive
Expand Down
21 changes: 9 additions & 12 deletions Sources/Build/BuildPlan/BuildPlan+Swift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,6 @@ extension BuildPlan {
swiftTarget.additionalFlags += target.pluginDerivedPublicHeaderPaths.flatMap {
["-Xcc", "-I", "-Xcc", $0.pathString]
}
case let target as SwiftModule:
// Copy include paths over if needed
let targetPaths = Set(swiftTarget.target.underlying.buildSettings.assignments[.PREBUILT_INCLUDE_PATHS]?.flatMap(\.values) ?? [])
if let assignment = target.buildSettings.assignments[.PREBUILT_INCLUDE_PATHS] {
for path in assignment.flatMap(\.values) {
if !prebuiltPaths.contains(path), !targetPaths.contains(path) {
swiftTarget.additionalFlags += ["-I", path]
}
// Dedup the path
prebuiltPaths.insert(path)
}
}
case let target as SystemLibraryModule:
swiftTarget.additionalFlags += ["-Xcc", "-fmodule-map-file=\(target.moduleMapPath.pathString)"]
swiftTarget.additionalFlags += try pkgConfig(for: target).cFlags
Expand Down Expand Up @@ -94,6 +82,15 @@ extension BuildPlan {
}
swiftTarget.libraryBinaryPaths.insert(library.libraryPath)
}
case .prebuilt(let prebuilt):
for path in prebuilt.headerPaths.map(\.pathString) {
if !prebuiltPaths.contains(path) {
swiftTarget.additionalFlags += ["-I", path]
}
// Dedup the path
prebuiltPaths.insert(path)
}
swiftTarget.libraryBinaryPaths.insert(prebuilt.libraryPath)
}
default:
break
Expand Down
3 changes: 0 additions & 3 deletions Sources/Build/BuildPlan/BuildPlan+Test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ extension BuildPlan {
dependencies: testProduct.modules.map { .module($0, conditions: []) },
defaultLocalization: testProduct.defaultLocalization,
supportedPlatforms: testProduct.supportedPlatforms,
platformConstraint: .all,
platformVersionProvider: testProduct.platformVersionProvider
)

Expand Down Expand Up @@ -169,7 +168,6 @@ extension BuildPlan {
dependencies: testProduct.modules.map { .module($0, conditions: []) } + resolvedTargetDependencies,
defaultLocalization: testProduct.defaultLocalization,
supportedPlatforms: testProduct.supportedPlatforms,
platformConstraint: .all,
platformVersionProvider: testProduct.platformVersionProvider
)

Expand Down Expand Up @@ -216,7 +214,6 @@ extension BuildPlan {
dependencies: entryPointResolvedTarget.dependencies + resolvedTargetDependencies,
defaultLocalization: testProduct.defaultLocalization,
supportedPlatforms: testProduct.supportedPlatforms,
platformConstraint: .all,
platformVersionProvider: testProduct.platformVersionProvider
)
let entryPointTargetBuildDescription = try SwiftModuleBuildDescription(
Expand Down
4 changes: 2 additions & 2 deletions Sources/Build/BuildPlan/BuildPlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ extension BuildPlan {
case .test:
self = .product(product, product.hasDirectMacroDependencies ? .host : destination)
default:
self = .product(product, product.platformConstraint == .host ? .host : destination)
self = .product(product, destination)
}
}

Expand All @@ -971,7 +971,7 @@ extension BuildPlan {
// This means that i.e. test products that reference macros
// would force all of their successors to be `host`.
// Also if the module has a platform constraint of `host`, use that.
self = .module(module, module.platformConstraint == .host ? .host : destination)
self = .module(module, destination)
}
}
}
Expand Down
Loading
Loading