Skip to content

Commit 2e58a0c

Browse files
committed
Rename exporting to dynamic. Start in tests.
1 parent 6322d4b commit 2e58a0c

File tree

5 files changed

+118
-26
lines changed

5 files changed

+118
-26
lines changed

Sources/Build/BuildDescription/SwiftModuleBuildDescription.swift

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ public final class SwiftModuleBuildDescription {
128128
var modulesPath: AbsolutePath {
129129
let suffix = self.buildParameters.suffix
130130
var path = self.buildParameters.buildPath.appending(component: "Modules\(suffix)")
131-
if self.windowsTargetType == .exporting {
132-
path = path.appending("exporting")
131+
if self.windowsTargetType == .dynamic {
132+
path = path.appending("dynamic")
133133
}
134134
return path
135135
}
@@ -268,17 +268,18 @@ public final class SwiftModuleBuildDescription {
268268
/// Whether to disable sandboxing (e.g. for macros).
269269
private let shouldDisableSandbox: Bool
270270

271-
/// For Windows we default to static objects and create copies for objects
272-
/// That export symbols. This will allow consumers to select which one they want.
271+
/// For Windows, we default to static objects and but also create objects
272+
/// that export symbols for DLLs. This allows library targets to be used
273+
/// in both contexts
273274
public enum WindowsTargetType {
274275
case `static`
275-
case exporting
276+
case dynamic
276277
}
277278
/// The target type. Leave nil for non-Windows behavior.
278279
public let windowsTargetType: WindowsTargetType?
279280

280-
/// The corresponding target symbols exporting (not -static)
281-
public private(set) var windowsExportTarget: SwiftModuleBuildDescription? = nil
281+
/// The corresponding target for dynamic library export (i.e., not -static)
282+
public private(set) var windowsDynamicTarget: SwiftModuleBuildDescription? = nil
282283

283284
/// Create a new target description with target and build parameters.
284285
init(
@@ -338,7 +339,7 @@ public final class SwiftModuleBuildDescription {
338339
if buildParameters.triple.isWindows() {
339340
// Default to static and add another target for DLLs
340341
self.windowsTargetType = .static
341-
self.windowsExportTarget = .init(windowsExportFor: self)
342+
self.windowsDynamicTarget = .init(windowsExportFor: self)
342343
} else {
343344
self.windowsTargetType = nil
344345
}
@@ -366,9 +367,9 @@ public final class SwiftModuleBuildDescription {
366367

367368
/// Private init to set up exporting version of this module
368369
private init(windowsExportFor parent: SwiftModuleBuildDescription) {
369-
self.windowsTargetType = .exporting
370-
self.windowsExportTarget = nil
371-
self.tempsPath = parent.tempsPath.appending("exporting")
370+
self.windowsTargetType = .dynamic
371+
self.windowsDynamicTarget = nil
372+
self.tempsPath = parent.tempsPath.appending("dynamic")
372373

373374
// The rest of these are just copied from the parent
374375
self.package = parent.package
@@ -572,7 +573,7 @@ public final class SwiftModuleBuildDescription {
572573
case .static:
573574
// Static on Windows
574575
args += ["-static"]
575-
case .exporting:
576+
case .dynamic:
576577
// Add the static versions to the include path
577578
// FIXME: need to be much more deliberate about what we're including
578579
args += ["-I", self.modulesPath.parentDirectory.pathString]

Sources/Build/BuildManifest/LLBuildManifestBuilder+Swift.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ extension LLBuildManifestBuilder {
5353
)
5454
} else {
5555
try self.addCmdWithBuiltinSwiftTool(target, inputs: inputs, cmdOutputs: cmdOutputs)
56-
if let exportTarget = target.windowsExportTarget {
56+
if let dynamicTarget = target.windowsDynamicTarget {
5757
// Generate dynamic module for Windows
58-
let inputs = try self.computeSwiftCompileCmdInputs(exportTarget)
59-
let objectNodes = exportTarget.buildParameters.prepareForIndexing == .off ? try exportTarget.objects.map(Node.file) : []
60-
let moduleNode = Node.file(exportTarget.moduleOutputPath)
58+
let inputs = try self.computeSwiftCompileCmdInputs(dynamicTarget)
59+
let objectNodes = dynamicTarget.buildParameters.prepareForIndexing == .off ? try dynamicTarget.objects.map(Node.file) : []
60+
let moduleNode = Node.file(dynamicTarget.moduleOutputPath)
6161
let cmdOutputs = objectNodes + [moduleNode]
62-
try self.addCmdWithBuiltinSwiftTool(exportTarget, inputs: inputs, cmdOutputs: cmdOutputs)
63-
self.addTargetCmd(exportTarget, cmdOutputs: cmdOutputs)
64-
try self.addModuleWrapCmd(exportTarget)
62+
try self.addCmdWithBuiltinSwiftTool(dynamicTarget, inputs: inputs, cmdOutputs: cmdOutputs)
63+
self.addTargetCmd(dynamicTarget, cmdOutputs: cmdOutputs)
64+
try self.addModuleWrapCmd(dynamicTarget)
6565
}
6666
}
6767

@@ -542,7 +542,7 @@ extension LLBuildManifestBuilder {
542542
inputs: cmdOutputs,
543543
outputs: [targetOutput]
544544
)
545-
if self.plan.graph.isInRootPackages(target.target, satisfying: target.buildParameters.buildEnvironment), target.windowsTargetType != .exporting {
545+
if self.plan.graph.isInRootPackages(target.target, satisfying: target.buildParameters.buildEnvironment), target.windowsTargetType != .dynamic {
546546
if !target.isTestTarget {
547547
self.addNode(targetOutput, toTarget: .main)
548548
}
@@ -647,8 +647,8 @@ extension SwiftModuleBuildDescription {
647647

648648
public func getLLBuildTargetName() -> String {
649649
let name = self.target.getLLBuildTargetName(buildParameters: self.buildParameters)
650-
if self.windowsTargetType == .exporting {
651-
return "export." + name
650+
if self.windowsTargetType == .dynamic {
651+
return "dynamic." + name
652652
} else {
653653
return name
654654
}

Sources/Build/BuildPlan/BuildPlan+Product.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ extension BuildPlan {
104104
buildProduct.objects += try dependencies.staticTargets.flatMap {
105105
if buildProduct.product.type == .library(.dynamic),
106106
case let .swift(swiftModule) = $0,
107-
let exporting = swiftModule.windowsExportTarget,
107+
let dynamic = swiftModule.windowsDynamicTarget,
108108
buildProduct.product.modules.contains(id: swiftModule.target.id)
109109
{
110110
// On Windows, export symbols from the direct swift targets of the DLL product
111-
return try exporting.objects
111+
return try dynamic.objects
112112
} else {
113113
return try $0.objects
114114
}

Sources/Build/BuildPlan/BuildPlan.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,8 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
537537
switch buildTarget {
538538
case .swift(let target):
539539
try self.plan(swiftTarget: target)
540-
if let exportTarget = target.windowsExportTarget {
541-
try self.plan(swiftTarget: exportTarget)
540+
if let dynamicTarget = target.windowsDynamicTarget {
541+
try self.plan(swiftTarget: dynamicTarget)
542542
}
543543
case .clang(let target):
544544
try self.plan(clangTarget: target)
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2014-2024 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import XCTest
14+
15+
import Basics
16+
@testable import Build
17+
import _InternalTestSupport
18+
19+
@_spi(DontAdoptOutsideOfSwiftPMExposedForBenchmarksAndTestsOnly)
20+
import PackageGraph
21+
22+
final class WindowsBuildPlanTests: XCTestCase {
23+
// Tests that our build plan is build correctly to handle separation
24+
// of object files that export symbols and ones that don't and to ensure
25+
// DLL products pick up the right ones.
26+
func testDynamicSymbolHandling() async throws {
27+
let fs = InMemoryFileSystem(emptyFiles: [
28+
"/libPkg/Sources/coreLib/coreLib.swift",
29+
"/libPkg/Sources/dllLib/dllLib.swift",
30+
"/libPkg/Sources/staticLib/staticLib.swift",
31+
"/libPkg/Sources/objectLib/objectLib.swift",
32+
"/exePkg/Sources/exe/main.swift",
33+
])
34+
35+
let observability = ObservabilitySystem.makeForTesting()
36+
37+
let graph = try loadModulesGraph(
38+
fileSystem: fs,
39+
manifests: [
40+
.createFileSystemManifest(
41+
displayName: "libPkg",
42+
path: "/libPkg",
43+
products: [
44+
.init(name: "DLLProduct", type: .library(.dynamic), targets: ["dllLib"]),
45+
.init(name: "StaticProduct", type: .library(.static), targets: ["staticLib"]),
46+
.init(name: "ObjectProduct", type: .library(.automatic), targets: ["objectLib"]),
47+
],
48+
targets: [
49+
.init(name: "coreLib", dependencies: []),
50+
.init(name: "dllLib", dependencies: ["coreLib"]),
51+
.init(name: "staticLib", dependencies: ["coreLib"]),
52+
.init(name: "objectLib", dependencies: ["coreLib"]),
53+
]
54+
),
55+
.createRootManifest(
56+
displayName: "exePkg",
57+
path: "/exePkg",
58+
dependencies: [.fileSystem(path: "/libPkg")],
59+
targets: [
60+
.init(name: "exe", dependencies: [
61+
.product(name: "DLLProduct", package: "libPkg"),
62+
.product(name: "StaticProduct", package: "libPkg"),
63+
.product(name: "ObjectProduct", package: "libPkg"),
64+
]),
65+
]
66+
)
67+
],
68+
observabilityScope: observability.topScope
69+
)
70+
71+
let plan = try await mockBuildPlan(
72+
graph: graph,
73+
fileSystem: fs,
74+
observabilityScope: observability.topScope
75+
)
76+
77+
let result = try BuildPlanResult(plan: plan)
78+
let exe = try result.buildProduct(for: "exe")
79+
80+
let llbuild = LLBuildManifestBuilder(
81+
plan,
82+
fileSystem: fs,
83+
observabilityScope: observability.topScope
84+
)
85+
try llbuild.generateManifest(at: "/manifest")
86+
87+
for command in llbuild.manifest.commands {
88+
print(command.key)
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)