-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Support separate modules for static and dynamic exporting symbols for Windows #8049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift open source project | ||
// | ||
// Copyright (c) 2014-2024 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See http://swift.org/LICENSE.txt for license information | ||
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import XCTest | ||
|
||
import Basics | ||
@testable import Build | ||
import LLBuildManifest | ||
import _InternalTestSupport | ||
|
||
@_spi(DontAdoptOutsideOfSwiftPMExposedForBenchmarksAndTestsOnly) | ||
import PackageGraph | ||
|
||
final class WindowsBuildPlanTests: XCTestCase { | ||
// Tests that our build plan is build correctly to handle separation | ||
// of object files that export symbols and ones that don't and to ensure | ||
// DLL products pick up the right ones. | ||
|
||
func doTest(triple: Triple) async throws { | ||
let fs = InMemoryFileSystem(emptyFiles: [ | ||
"/libPkg/Sources/coreLib/coreLib.swift", | ||
"/libPkg/Sources/dllLib/dllLib.swift", | ||
"/libPkg/Sources/staticLib/staticLib.swift", | ||
"/libPkg/Sources/objectLib/objectLib.swift", | ||
"/exePkg/Sources/exe/main.swift", | ||
]) | ||
|
||
let observability = ObservabilitySystem.makeForTesting() | ||
|
||
let graph = try loadModulesGraph( | ||
fileSystem: fs, | ||
manifests: [ | ||
.createFileSystemManifest( | ||
displayName: "libPkg", | ||
path: "/libPkg", | ||
products: [ | ||
.init(name: "DLLProduct", type: .library(.dynamic), targets: ["dllLib"]), | ||
.init(name: "StaticProduct", type: .library(.static), targets: ["staticLib"]), | ||
.init(name: "ObjectProduct", type: .library(.automatic), targets: ["objectLib"]), | ||
], | ||
targets: [ | ||
.init(name: "coreLib", dependencies: []), | ||
.init(name: "dllLib", dependencies: ["coreLib"]), | ||
.init(name: "staticLib", dependencies: ["coreLib"]), | ||
.init(name: "objectLib", dependencies: ["coreLib"]), | ||
] | ||
), | ||
.createRootManifest( | ||
displayName: "exePkg", | ||
path: "/exePkg", | ||
dependencies: [.fileSystem(path: "/libPkg")], | ||
targets: [ | ||
.init(name: "exe", dependencies: [ | ||
.product(name: "DLLProduct", package: "libPkg"), | ||
.product(name: "StaticProduct", package: "libPkg"), | ||
.product(name: "ObjectProduct", package: "libPkg"), | ||
]), | ||
] | ||
) | ||
], | ||
observabilityScope: observability.topScope | ||
) | ||
|
||
let label: String | ||
let dylibPrefix: String | ||
let dylibExtension: String | ||
let dynamic: String | ||
switch triple { | ||
case Triple.x86_64Windows: | ||
label = "x86_64-unknown-windows-msvc" | ||
dylibPrefix = "" | ||
dylibExtension = "dll" | ||
dynamic = "/dynamic" | ||
case Triple.x86_64MacOS: | ||
label = "x86_64-apple-macosx" | ||
dylibPrefix = "lib" | ||
dylibExtension = "dylib" | ||
dynamic = "" | ||
case Triple.x86_64Linux: | ||
label = "x86_64-unknown-linux-gnu" | ||
dylibPrefix = "lib" | ||
dylibExtension = "so" | ||
dynamic = "" | ||
default: | ||
label = "fixme" | ||
dylibPrefix = "" | ||
dylibExtension = "" | ||
dynamic = "" | ||
} | ||
|
||
let tools: [String: [String]] = [ | ||
"C.exe-\(label)-debug.exe": [ | ||
"/path/to/build/\(label)/debug/coreLib.build/coreLib.swift.o", | ||
"/path/to/build/\(label)/debug/exe.build/main.swift.o", | ||
"/path/to/build/\(label)/debug/objectLib.build/objectLib.swift.o", | ||
"/path/to/build/\(label)/debug/staticLib.build/staticLib.swift.o", | ||
"/path/to/build/\(label)/debug/\(dylibPrefix)DLLProduct.\(dylibExtension)", | ||
"/path/to/build/\(label)/debug/exe.product/Objects.LinkFileList", | ||
] + (triple.isMacOSX ? [] : [ | ||
// modulewrap | ||
"/path/to/build/\(label)/debug/coreLib.build/coreLib.swiftmodule.o", | ||
"/path/to/build/\(label)/debug/exe.build/exe.swiftmodule.o", | ||
"/path/to/build/\(label)/debug/objectLib.build/objectLib.swiftmodule.o", | ||
"/path/to/build/\(label)/debug/staticLib.build/staticLib.swiftmodule.o", | ||
]), | ||
"C.DLLProduct-\(label)-debug.dylib": [ | ||
"/path/to/build/\(label)/debug/coreLib.build/coreLib.swift.o", | ||
"/path/to/build/\(label)/debug/dllLib.build\(dynamic)/dllLib.swift.o", | ||
"/path/to/build/\(label)/debug/DLLProduct.product/Objects.LinkFileList", | ||
] + (triple.isMacOSX ? [] : [ | ||
"/path/to/build/\(label)/debug/coreLib.build/coreLib.swiftmodule.o", | ||
"/path/to/build/\(label)/debug/dllLib.build/dllLib.swiftmodule.o", | ||
]) | ||
] | ||
|
||
let plan = try await BuildPlan( | ||
destinationBuildParameters: mockBuildParameters( | ||
destination: .target, | ||
triple: triple | ||
), | ||
toolsBuildParameters: mockBuildParameters( | ||
destination: .host, | ||
triple: triple | ||
), | ||
graph: graph, | ||
fileSystem: fs, | ||
observabilityScope: observability.topScope | ||
) | ||
|
||
let llbuild = LLBuildManifestBuilder( | ||
plan, | ||
fileSystem: fs, | ||
observabilityScope: observability.topScope | ||
) | ||
try llbuild.generateManifest(at: "/manifest") | ||
|
||
for (name, inputNames) in tools { | ||
let command = try XCTUnwrap(llbuild.manifest.commands[name]) | ||
XCTAssertEqual(Set(command.tool.inputs), Set(inputNames.map({ Node.file(.init($0)) }))) | ||
} | ||
} | ||
|
||
func testWindows() async throws { | ||
try await doTest(triple: .x86_64Windows) | ||
} | ||
|
||
// Make sure we didn't mess up macOS | ||
func testMacOS() async throws { | ||
try await doTest(triple: .x86_64MacOS) | ||
} | ||
|
||
// Make sure we didn't mess up linux | ||
func testLinux() async throws { | ||
try await doTest(triple: .x86_64Linux) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't like how we're putting all the modules in a single directory and adding it to the include path. Since the exporting modules have the same name, I had to create another directory to put them in and add that include path for the products that consume them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah putting all the modules in the same directory is extra annoying because you can end up
import
ing things you haven't declared a dependency on.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question is, who do I break if I change this?