Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.

Commit 382f4c9

Browse files
rmazfacebook-github-bot
authored andcommitted
always include Foundation with explicit modules
Summary: When compiling explicit modules unconditionally add the Foundation framework. This is required as Swift generated headers will always export Foundation (and Darwin) regardless of Swift contents. Reviewed By: milend fbshipit-source-id: a4d5d74660816637f83b4ccb5493628bed1ca221
1 parent 7b3de33 commit 382f4c9

7 files changed

Lines changed: 20 additions & 2 deletions

File tree

src/com/facebook/buck/swift/SwiftCompileBase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ public ImmutableList<String> constructCompilerArgs(SourcePathResolverAdapter res
336336
// Import the swiftmodule and pcm output of SDK frameworks and Objc dependencies
337337
for (ExplicitModuleOutput module : moduleDeps) {
338338
if (module.getName().equals(moduleName)) {
339+
Preconditions.checkState(!module.getIsSwiftmodule());
339340
// We cannot import the direct path to the underlying module as it will conflict with
340341
// the exported module of the same name when debugging. Instead we need to import the
341342
// exported module path, this will be remapped in the VFS overlay to the underlying one.

src/com/facebook/buck/swift/SwiftLibraryDescription.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,10 @@ private static void collectFrameworkPcmDependencies(
10851085

10861086
// Always import Darwin, this is required for the C stdlib
10871087
builder.addAll(sdkDepsProvider.getSdkClangModuleDependencies("Darwin", targetTriple));
1088+
1089+
// We also need Foundation as this is unconditionally added to exports in Swift generated
1090+
// headers.
1091+
builder.addAll(sdkDepsProvider.getSdkClangModuleDependencies("Foundation", targetTriple));
10881092
}
10891093

10901094
private static ImmutableList<Arg> getModuleCompileSwiftArgs(

test/com/facebook/buck/swift/SwiftLibraryIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ public void testExplicitModules() throws IOException {
457457
Files.createSymbolicLink(
458458
projectRoot.getPath().resolve("xcode"), Paths.get("/var/db/xcode_select_link"));
459459

460-
BuildTarget target = workspace.newBuildTarget("//:a#iphonesimulator-x86_64,swift-compile");
460+
BuildTarget target = workspace.newBuildTarget("//:a#iphonesimulator-x86_64,static");
461461
ProcessResult result = workspace.runBuckCommand("build", target.getFullyQualifiedName());
462462
result.assertSuccess();
463463
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[apple]
22
toolchain_set_target = "//:toolchain"
3+
use_swift_delegate = false
34

45
[project]
56
read_only_paths = xcode

test/com/facebook/buck/swift/testdata/swift_explicit_modules/BUCK.fixture

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apple_library(
22
name = "a",
33
srcs = ["a.swift"],
4-
deps = [":b", ":c"],
4+
deps = [":b", ":c", ":d"],
55
uses_explicit_modules = True,
66
)
77

@@ -19,6 +19,14 @@ apple_library(
1919
libraries = ["$SDKROOT/usr/lib/libz.dylib"],
2020
)
2121

22+
apple_library(
23+
name = "d",
24+
exported_headers = ["d.h"],
25+
srcs = ["d.swift"],
26+
modular = True,
27+
uses_explicit_modules = True,
28+
)
29+
2230
apple_toolchain_set(
2331
name = "toolchain",
2432
apple_toolchains = [

test/com/facebook/buck/swift/testdata/swift_explicit_modules/d.h

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
public func doStdlibStuff() -> Int {
3+
return 123
4+
}

0 commit comments

Comments
 (0)