Skip to content

Commit 7837519

Browse files
authored
Merge pull request #39388 from nkcsgexi/emit-module-emit-abi-5.5
[5.5] Frontend: teach -emit-module and -merge-modules to emit ABI descriptor files
2 parents ee0402d + 0d7548f commit 7837519

File tree

8 files changed

+40
-10
lines changed

8 files changed

+40
-10
lines changed

include/swift/Serialization/SerializationOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace swift {
3131
const char *DocOutputPath = nullptr;
3232
const char *SourceInfoOutputPath = nullptr;
3333
std::string SymbolGraphOutputDir;
34+
std::string ABIDescriptorPath;
3435
bool SkipSymbolGraphInheritedDocs = true;
3536
bool IncludeSPISymbolsInSymbolGraph = false;
3637

lib/Frontend/Frontend.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(
155155
serializationOpts.ImportedHeader = opts.ImplicitObjCHeaderPath;
156156
serializationOpts.ModuleLinkName = opts.ModuleLinkName;
157157
serializationOpts.ExtraClangOptions = getClangImporterOptions().ExtraArgs;
158-
158+
serializationOpts.ABIDescriptorPath = outs.ABIDescriptorOutputPath.c_str();
159+
159160
if (opts.EmitSymbolGraph) {
160161
if (!opts.SymbolGraphOutputDir.empty()) {
161162
serializationOpts.SymbolGraphOutputDir = opts.SymbolGraphOutputDir;

lib/Frontend/FrontendOptions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,8 @@ bool FrontendOptions::canActionEmitLoadedModuleTrace(ActionType action) {
526526
}
527527
bool FrontendOptions::canActionEmitABIDescriptor(ActionType action) {
528528
switch (action) {
529+
case ActionType::MergeModules:
530+
case ActionType::EmitModuleOnly:
529531
case ActionType::CompileModuleFromInterface:
530532
return true;
531533
case ActionType::NoneAction:
@@ -550,8 +552,6 @@ bool FrontendOptions::canActionEmitABIDescriptor(ActionType action) {
550552
case ActionType::ScanDependencies:
551553
case ActionType::PrintVersion:
552554
case ActionType::PrintFeature:
553-
case ActionType::MergeModules:
554-
case ActionType::EmitModuleOnly:
555555
case ActionType::EmitSIL:
556556
case ActionType::EmitSIBGen:
557557
case ActionType::EmitSIB:

lib/Frontend/ModuleInterfaceBuilder.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "swift/Frontend/ModuleInterfaceSupport.h"
2525
#include "swift/SILOptimizer/PassManager/Passes.h"
2626
#include "swift/Serialization/SerializationOptions.h"
27-
#include "swift/APIDigester/ModuleAnalyzerNodes.h"
2827
#include "clang/Frontend/CompilerInstance.h"
2928
#include "clang/Lex/PreprocessorOptions.h"
3029
#include "llvm/ADT/Hashing.h"
@@ -252,6 +251,7 @@ bool ModuleInterfaceBuilder::buildSwiftModuleInternal(
252251
if (!getRelativeDepPath(InPath, SDKPath))
253252
SerializationOpts.ModuleInterface = InPath;
254253

254+
SerializationOpts.ABIDescriptorPath = ABIDescriptorPath.str();
255255
SmallVector<FileDependency, 16> Deps;
256256
bool serializeHashes = FEOpts.SerializeModuleInterfaceDependencyHashes;
257257
if (collectDepsForSerialization(SubInstance, Deps, serializeHashes)) {
@@ -279,9 +279,6 @@ bool ModuleInterfaceBuilder::buildSwiftModuleInternal(
279279
if (SubInstance.getDiags().hadAnyError()) {
280280
return std::make_error_code(std::errc::not_supported);
281281
}
282-
if (!ABIDescriptorPath.empty()) {
283-
swift::ide::api::dumpModuleContent(Mod, ABIDescriptorPath, true);
284-
}
285282
return std::error_code();
286283
});
287284
}, ThreadStackSize);

lib/Option/features.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
},
99
{
1010
"name": "index-unit-output-path"
11+
},
12+
{
13+
"name": "emit-abi-descriptor"
1114
}
1215
]
1316
}

lib/Serialization/Serialization.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "swift/AST/SynthesizedFileUnit.h"
3737
#include "swift/AST/TypeCheckRequests.h"
3838
#include "swift/AST/TypeVisitor.h"
39+
#include "swift/APIDigester/ModuleAnalyzerNodes.h"
3940
#include "swift/Basic/Defer.h"
4041
#include "swift/Basic/Dwarf.h"
4142
#include "swift/Basic/FileSystem.h"
@@ -5547,6 +5548,17 @@ bool Serializer::allowCompilerErrors() const {
55475548
return getASTContext().LangOpts.AllowModuleWithCompilerErrors;
55485549
}
55495550

5551+
5552+
static void emitABIDescriptor(ModuleOrSourceFile DC,
5553+
const SerializationOptions &options) {
5554+
if (!options.ABIDescriptorPath.empty()) {
5555+
if (DC.is<ModuleDecl*>()) {
5556+
swift::ide::api::dumpModuleContent(DC.get<ModuleDecl*>(),
5557+
options.ABIDescriptorPath, true);
5558+
}
5559+
}
5560+
}
5561+
55505562
void swift::serializeToBuffers(
55515563
ModuleOrSourceFile DC, const SerializationOptions &options,
55525564
std::unique_ptr<llvm::MemoryBuffer> *moduleBuffer,
@@ -5570,6 +5582,7 @@ void swift::serializeToBuffers(
55705582
});
55715583
if (hadError)
55725584
return;
5585+
emitABIDescriptor(DC, options);
55735586
if (moduleBuffer)
55745587
*moduleBuffer = std::make_unique<llvm::SmallVectorMemoryBuffer>(
55755588
std::move(buf), options.OutputPath);
@@ -5674,4 +5687,5 @@ void swift::serialize(ModuleOrSourceFile DC,
56745687
symbolgraphgen::emitSymbolGraphForModule(M, SGOpts);
56755688
}
56765689
}
5690+
emitABIDescriptor(DC, options);
56775691
}

test/ModuleInterface/emit-abi-descriptor.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,25 @@
22
// RUN: %empty-directory(%t/Foo.swiftmodule)
33
// RUN: %empty-directory(%t/ResourceDir/%target-sdk-name/prebuilt-modules/Foo.swiftmodule)
44
// RUN: echo "public func foo() {}" > %t/Foo.swift
5-
// RUN: echo "public enum DisplayStyle { case tuple, optional, collection }" > %t/Foo.swift
5+
// RUN: echo "public enum DisplayStyle { case tuple, optional, collection }" >> %t/Foo.swift
6+
7+
// RUN: echo "public func bar() {}" > %t/Bar.swift
68

79
// RUN: %target-swift-frontend -emit-module %t/Foo.swift -module-name Foo -emit-module-interface-path %t/Foo.swiftinterface
810
// RUN: %target-swift-frontend -compile-module-from-interface %t/Foo.swiftinterface -o %t/Foo.swiftmodule -module-name Foo -emit-abi-descriptor-path %t/Foo.json
911

1012
// RUN: %FileCheck %s < %t/Foo.json
1113

14+
// RUN: %target-swift-frontend -emit-module -module-name Bar -emit-module-path %t/Bar.swiftmodule -emit-abi-descriptor-path %t/Bar.json %t/Bar.swift
15+
16+
// RUN: %FileCheck %s < %t/Bar.json
17+
18+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/Foo~partial1.swiftmodule %t/Foo.swift -module-name FooBar
19+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/Foo~partial2.swiftmodule %t/Bar.swift -module-name FooBar
20+
// RUN: %target-swift-frontend -merge-modules -emit-module -emit-module-path %t/FooBar.swiftmodule %t/Foo~partial1.swiftmodule %t/Foo~partial2.swiftmodule -module-name FooBar -emit-abi-descriptor-path %t/FooBar.json
21+
22+
// RUN: %FileCheck %s < %t/FooBar.json
23+
1224
// CHECK: "kind": "Root"
1325
// CHECK-NEXT: "name": "TopLevel"
1426
// CHECK-NEXT: "printedName": "TopLevel"

tools/libSwiftScan/libSwiftScan.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@ swiftscan_compiler_supported_arguments_query() {
508508

509509
swiftscan_string_set_t *
510510
swiftscan_compiler_supported_features_query() {
511-
// TODO: We are yet to figure out how "Features" will be organized.
512-
return nullptr;
511+
std::vector<std::string> allFeatures;
512+
allFeatures.emplace_back("library-level");
513+
allFeatures.emplace_back("emit-abi-descriptor");
514+
return create_set(allFeatures);
513515
}

0 commit comments

Comments
 (0)