Skip to content

Commit

Permalink
[Dependency Scanning] Do now write out bridging header dependencies o…
Browse files Browse the repository at this point in the history
…f binary modules unless in CAS mode

We only record these dependencies in CAS mode, because we require explicit PCH tasks to be produced for imported header of binary module dependencies. In the meantime, in non-CAS mode loading clients will consume the `.h` files encoded in the `.swiftmodules` directly.

Followup changes to SwiftDriver will enable explicit PCH compilation of such dependenceis, but for the time being restore prior behavior for non-CAS explicit module builds.

Resolves rdar://116006619
  • Loading branch information
artemcm committed Oct 10, 2023
1 parent a66f28e commit 19d3090
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
19 changes: 13 additions & 6 deletions lib/Serialization/SerializedModuleLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,12 +477,19 @@ SerializedModuleLoaderBase::scanModuleFile(Twine modulePath, bool isFramework) {

auto importedHeaderSet = binaryModuleImports.get().headerImports;
std::vector<std::string> importedHeaders;
importedHeaders.reserve(importedHeaderSet.size());
llvm::transform(importedHeaderSet.keys(),
std::back_inserter(importedHeaders),
[](llvm::StringRef N) {
return N.str();
});
// FIXME: We only record these dependencies in CAS mode, because
// we require explicit PCH tasks to be produced for imported header
// of binary module dependencies. In the meantime, in non-CAS mode
// loading clients will consume the `.h` files encoded in the `.swiftmodules`
// directly.
if (Ctx.ClangImporterOpts.CASOpts.has_value()) {
importedHeaders.reserve(importedHeaderSet.size());
llvm::transform(importedHeaderSet.keys(),
std::back_inserter(importedHeaders),
[](llvm::StringRef N) {
return N.str();
});
}

auto &importedOptionalModuleSet = binaryModuleOptionalImports.get().moduleImports;
std::vector<std::string> importedOptionalModuleNames;
Expand Down
12 changes: 7 additions & 5 deletions test/ScanDependencies/header_deps_of_binary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t/clang-module-cache)
// RUN: %empty-directory(%t/PCH)
// RUN: %empty-directory(%t/HEADER)
// RUN: %empty-directory(%t/SwiftModules)
// RUN: %empty-directory(%t/CAS)

// - Set up Foo Swift dependency
// RUN: echo "extension Profiler {" >> %t/foo.swift
// RUN: echo " public static let count: Int = 42" >> %t/foo.swift
// RUN: echo "}" >> %t/foo.swift

// - Set up Foo bridging header
// RUN: echo "struct Profiler { void* ptr; };" >> %t/foo.h
// RUN: echo "struct Profiler { void* ptr; };" >> %t/HEADER/foo.h

// - Compile bridging header
// RUN: %target-swift-frontend -enable-objc-interop -emit-pch %t/foo.h -o %t/PCH/foo.pch -disable-implicit-swift-modules
// RUN: %target-swift-frontend -enable-objc-interop -emit-pch %t/HEADER/foo.h -o %t/PCH/foo.pch -disable-implicit-swift-modules

// - Set up explicit dependencies for Foo
// RUN: %target-swift-emit-pcm -module-name SwiftShims %swift-lib-dir/swift/shims/module.modulemap -o %t/inputs/SwiftShims.pcm
Expand Down Expand Up @@ -50,7 +52,7 @@
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/SwiftModules/Foo.swiftmodule %t/foo.swift -module-name Foo -import-objc-header %t/PCH/foo.pch -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -disable-implicit-swift-modules -explicit-swift-module-map-file %t/foo_inputs_map.json

// - Scan main module
// RUN: %target-swift-frontend -scan-dependencies %s -I %t/SwiftModules -I %S/Inputs/Swift -o %t/deps.json
// RUN: %target-swift-frontend -scan-dependencies %s -I %t/SwiftModules -I %S/Inputs/Swift -o %t/deps.json -cache-compile-job -cas-path %t/cas
// RUN: %validate-json %t/deps.json | %FileCheck %s

// CHECK: "swift": "FooClient"
Expand All @@ -59,12 +61,12 @@
// CHECK: "commandLine": [
// CHECK: "-include-pch",
// CHECK-NEXT: "-Xcc",
// CHECK-NEXT: "{{.*}}{{/|\\}}PCH{{/|\\}}foo.pch"
// CHECK-NEXT: "{{.*}}{{/|\\}}HEADER{{/|\\}}foo.h"


// CHECK: "swiftPrebuiltExternal": "Foo"
// CHECK: "headerDependencies": [
// CHECK: "{{.*}}{{/|\\}}PCH{{/|\\}}foo.pch"
// CHECK: "{{.*}}{{/|\\}}HEADER{{/|\\}}foo.h"
// CHECK: ],

import FooClient

0 comments on commit 19d3090

Please sign in to comment.