From 6a11171755c917532fd3ff2b4b38cf2057beaca9 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Tue, 11 Jun 2024 00:52:28 +0000 Subject: [PATCH] [ModuleInterface] Save `-public-autolink-library` module option Serialize the `-public-autolink-library ` option to the moduleinterface file because it can affect the LINK_LIBRARY entries in a swiftmodule file. Without saving the option, the library won't be linked when a module compiled from the moduleinterface is used. This change marks the `-public-autolink-library` option as a module interface option and reads it when building a swiftmodule by module loader. --- include/swift/Option/FrontendOptions.td | 7 ++++--- lib/Frontend/ModuleInterfaceBuilder.cpp | 2 ++ test/ModuleInterface/public-autolink-library.swift | 6 ++++++ 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 test/ModuleInterface/public-autolink-library.swift diff --git a/include/swift/Option/FrontendOptions.td b/include/swift/Option/FrontendOptions.td index 1cbcc3e8a4341..2dc7e18b04240 100644 --- a/include/swift/Option/FrontendOptions.td +++ b/include/swift/Option/FrontendOptions.td @@ -207,9 +207,6 @@ def no_serialize_debugging_options : def autolink_library : Separate<["-"], "autolink-library">, HelpText<"Add dependent library">, Flags<[FrontendOption]>; -def public_autolink_library : Separate<["-"], "public-autolink-library">, - HelpText<"Add public dependent library">, Flags<[FrontendOption]>; - def disable_typo_correction : Flag<["-"], "disable-typo-correction">, HelpText<"Disable typo correction">; @@ -369,6 +366,10 @@ def enable_resilience : Flag<["-"], "enable-resilience">, def enable_experimental_async_top_level : Flag<["-"], "enable-experimental-async-top-level">, HelpText<"Enable experimental concurrency in top-level code">; + +def public_autolink_library : + Separate<["-"], "public-autolink-library">, + HelpText<"Add public dependent library">; } // HIDDEN FLAGS diff --git a/lib/Frontend/ModuleInterfaceBuilder.cpp b/lib/Frontend/ModuleInterfaceBuilder.cpp index 23b7a496d1853..632b04008826f 100644 --- a/lib/Frontend/ModuleInterfaceBuilder.cpp +++ b/lib/Frontend/ModuleInterfaceBuilder.cpp @@ -276,6 +276,8 @@ std::error_code ExplicitModuleInterfaceBuilder::buildSwiftModuleFromInterface( SerializationOpts.ModuleLinkName = FEOpts.ModuleLinkName; SerializationOpts.AutolinkForceLoad = !Invocation.getIRGenOptions().ForceLoadSymbolName.empty(); + SerializationOpts.PublicDependentLibraries = + Invocation.getIRGenOptions().PublicLinkLibraries; SerializationOpts.UserModuleVersion = FEOpts.UserModuleVersion; SerializationOpts.AllowableClients = FEOpts.AllowableClients; StringRef SDKPath = Instance.getASTContext().SearchPathOpts.getSDKPath(); diff --git a/test/ModuleInterface/public-autolink-library.swift b/test/ModuleInterface/public-autolink-library.swift new file mode 100644 index 0000000000000..e19e02256a617 --- /dev/null +++ b/test/ModuleInterface/public-autolink-library.swift @@ -0,0 +1,6 @@ +// RUN: %empty-directory(%t) +// RUN: %target-swift-frontend -typecheck -module-name Foo -emit-module-interface-path %t/Foo.swiftinterface %s -module-link-name Foo -enable-library-evolution -public-autolink-library Bar +// RUN: %target-swift-frontend -compile-module-from-interface -o %t/Foo.swiftmodule %t/Foo.swiftinterface +// RUN: %target-swift-ide-test -print-module-metadata -module-to-print Foo -I %t -source-filename %s | %FileCheck %s + +// CHECK: link library: Bar