Skip to content

Commit 9c85fbc

Browse files
authored
AST,DependencyScan,IRGen,Serialization,Tooling: track library style (#78777)
Track if the dependency is static or dynamic. This is in preparation for helping rename the static library to differentiate it from import libraries.
1 parent 8d69807 commit 9c85fbc

26 files changed

+158
-96
lines changed

include/swift-c/DependencyScan/DependencyScan.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ swiftscan_module_info_get_details(swiftscan_dependency_info_t info);
155155
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
156156
swiftscan_link_library_info_get_link_name(
157157
swiftscan_link_library_info_t info);
158+
SWIFTSCAN_PUBLIC bool
159+
swiftscan_link_library_info_get_is_static(swiftscan_link_library_info_t info);
158160
SWIFTSCAN_PUBLIC bool swiftscan_link_library_info_get_is_framework(
159161
swiftscan_link_library_info_t info);
160162
SWIFTSCAN_PUBLIC bool swiftscan_link_library_info_get_should_force_load(

include/swift/AST/IRGenOptions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "llvm/Support/VersionTuple.h"
3434
#include <optional>
3535
#include <string>
36+
#include <tuple>
3637
#include <vector>
3738

3839
namespace swift {
@@ -258,7 +259,7 @@ class IRGenOptions {
258259
SmallVector<LinkLibrary, 4> LinkLibraries;
259260

260261
/// The public dependent libraries specified on the command line.
261-
std::vector<std::string> PublicLinkLibraries;
262+
std::vector<std::tuple<std::string, bool>> PublicLinkLibraries;
262263

263264
/// If non-empty, the (unmangled) name of a dummy symbol to emit that can be
264265
/// used to force-load this module.

include/swift/AST/LinkLibrary.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,19 @@ class LinkLibrary {
3232
private:
3333
std::string Name;
3434
unsigned Kind : 1;
35+
unsigned Static : 1;
3536
unsigned ForceLoad : 1;
3637

3738
public:
38-
LinkLibrary(StringRef N, LibraryKind K, bool forceLoad = false)
39-
: Name(N), Kind(static_cast<unsigned>(K)), ForceLoad(forceLoad) {
39+
LinkLibrary(StringRef N, LibraryKind K, bool Static, bool forceLoad = false)
40+
: Name(N), Kind(static_cast<unsigned>(K)), Static(Static),
41+
ForceLoad(forceLoad) {
4042
assert(getKind() == K && "not enough bits for the kind");
4143
}
4244

4345
LibraryKind getKind() const { return static_cast<LibraryKind>(Kind); }
4446
StringRef getName() const { return Name; }
47+
bool isStaticLibrary() const { return Static; }
4548
bool shouldForceLoad() const { return ForceLoad; }
4649
};
4750

include/swift/DependencyScan/DependencyScanImpl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ struct swiftscan_dependency_info_s {
6969

7070
struct swiftscan_link_library_info_s {
7171
swiftscan_string_ref_t name;
72+
bool isStatic;
7273
bool isFramework;
7374
bool forceLoad;
7475
};

include/swift/DependencyScan/SerializedModuleDependencyCacheFormat.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ using llvm::BCVBR;
4141
const unsigned char MODULE_DEPENDENCY_CACHE_FORMAT_SIGNATURE[] = {'I', 'M', 'D','C'};
4242
const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MAJOR = 9;
4343
/// Increment this on every change.
44-
const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MINOR = 0;
44+
const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MINOR = 1;
4545

4646
/// Various identifiers in this format will rely on having their strings mapped
4747
/// using this ID.
@@ -148,12 +148,12 @@ using IdentifierArrayLayout =
148148
// A record for a given link library node containing information
149149
// required for the build system client to capture a requirement
150150
// to link a given dependency library.
151-
using LinkLibraryLayout =
152-
BCRecordLayout<LINK_LIBRARY_NODE, // ID
153-
IdentifierIDField, // libraryName
154-
IsFrameworkField, // isFramework
155-
IsForceLoadField // forceLoad
156-
>;
151+
using LinkLibraryLayout = BCRecordLayout<LINK_LIBRARY_NODE, // ID
152+
IdentifierIDField, // libraryName
153+
IsFrameworkField, // isFramework
154+
IsStaticField, // isStatic
155+
IsForceLoadField // forceLoad
156+
>;
157157
using LinkLibraryArrayLayout =
158158
BCRecordLayout<LINK_LIBRARY_ARRAY_NODE, IdentifierIDArryField>;
159159

include/swift/Frontend/Frontend.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ class CompilerInvocation {
230230
return ClangImporterOpts.ExtraArgs;
231231
}
232232

233-
void addLinkLibrary(StringRef name, LibraryKind kind) {
234-
IRGenOpts.LinkLibraries.push_back({name, kind});
233+
void addLinkLibrary(StringRef name, LibraryKind kind, bool isStaticLibrary) {
234+
IRGenOpts.LinkLibraries.emplace_back(name, kind, isStaticLibrary);
235235
}
236236

237237
ArrayRef<LinkLibrary> getLinkLibraries() const {

include/swift/Serialization/SerializationOptions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <set>
2222
#include <string>
23+
#include <tuple>
2324
#include <vector>
2425

2526
namespace swift {
@@ -150,7 +151,7 @@ class SerializationOptions {
150151
uint64_t getSize() const { return Size; }
151152
};
152153
ArrayRef<FileDependency> Dependencies;
153-
ArrayRef<std::string> PublicDependentLibraries;
154+
ArrayRef<std::tuple<std::string, bool>> PublicDependentLibraries;
154155

155156
bool AutolinkForceLoad = false;
156157
bool SerializeAllSIL = false;

lib/AST/ModuleDependencies.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -503,24 +503,33 @@ swift::dependencies::checkImportNotTautological(const ImportPath::Module moduleP
503503
return false;
504504
}
505505

506-
void
507-
swift::dependencies::registerCxxInteropLibraries(
508-
const llvm::Triple &Target,
509-
StringRef mainModuleName,
510-
bool hasStaticCxx, bool hasStaticCxxStdlib, CXXStdlibKind cxxStdlibKind,
511-
std::function<void(const LinkLibrary&)> RegistrationCallback) {
512-
if (cxxStdlibKind == CXXStdlibKind::Libcxx)
513-
RegistrationCallback(LinkLibrary("c++", LibraryKind::Library));
514-
else if (cxxStdlibKind == CXXStdlibKind::Libstdcxx)
515-
RegistrationCallback(LinkLibrary("stdc++", LibraryKind::Library));
506+
void swift::dependencies::registerCxxInteropLibraries(
507+
const llvm::Triple &Target, StringRef mainModuleName, bool hasStaticCxx,
508+
bool hasStaticCxxStdlib, CXXStdlibKind cxxStdlibKind,
509+
std::function<void(const LinkLibrary &)> RegistrationCallback) {
510+
511+
switch (cxxStdlibKind) {
512+
case CXXStdlibKind::Libcxx:
513+
RegistrationCallback(
514+
LinkLibrary{"c++", LibraryKind::Library, /*static=*/false});
515+
break;
516+
case CXXStdlibKind::Libstdcxx:
517+
RegistrationCallback(
518+
LinkLibrary{"stdc++", LibraryKind::Library, /*static=*/false});
519+
break;
520+
case CXXStdlibKind::Msvcprt:
521+
// FIXME: should we be explicitly linking in msvcprt or will the module do
522+
// so?
523+
break;
524+
case CXXStdlibKind::Unknown:
525+
// FIXME: we should probably emit a warning or a note here.
526+
break;
527+
}
516528

517529
// Do not try to link Cxx with itself.
518-
if (mainModuleName != CXX_MODULE_NAME) {
519-
RegistrationCallback(LinkLibrary(Target.isOSWindows() && hasStaticCxx
520-
? "libswiftCxx"
521-
: "swiftCxx",
522-
LibraryKind::Library));
523-
}
530+
if (mainModuleName != CXX_MODULE_NAME)
531+
RegistrationCallback(
532+
LinkLibrary{"swiftCxx", LibraryKind::Library, hasStaticCxx});
524533

525534
// Do not try to link CxxStdlib with the C++ standard library, Cxx or
526535
// itself.
@@ -529,19 +538,9 @@ swift::dependencies::registerCxxInteropLibraries(
529538
return mainModuleName == Name;
530539
})) {
531540
// Only link with CxxStdlib on platforms where the overlay is available.
532-
switch (Target.getOS()) {
533-
case llvm::Triple::Win32: {
534-
RegistrationCallback(
535-
LinkLibrary(hasStaticCxxStdlib ? "libswiftCxxStdlib" : "swiftCxxStdlib",
536-
LibraryKind::Library));
537-
break;
538-
}
539-
default:
540-
if (Target.isOSDarwin() || Target.isOSLinux())
541-
RegistrationCallback(LinkLibrary("swiftCxxStdlib",
542-
LibraryKind::Library));
543-
break;
544-
}
541+
if (Target.isOSDarwin() || Target.isOSLinux() || Target.isOSWindows())
542+
RegistrationCallback(LinkLibrary{"swiftCxxStdlib", LibraryKind::Library,
543+
hasStaticCxxStdlib});
545544
}
546545
}
547546

@@ -569,7 +568,8 @@ swift::dependencies::registerBackDeployLibraries(
569568
if (*compatibilityVersion > version)
570569
return;
571570

572-
RegistrationCallback({libraryName, LibraryKind::Library, forceLoad});
571+
RegistrationCallback(
572+
{libraryName, LibraryKind::Library, /*static=*/true, forceLoad});
573573
};
574574

575575
#define BACK_DEPLOYMENT_LIB(Version, Filter, LibraryName, ForceLoad) \

lib/ClangImporter/ClangImporter.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4105,15 +4105,11 @@ void ClangModuleUnit::collectLinkLibraries(
41054105
if (clangModule->UseExportAsModuleLinkName)
41064106
return;
41074107

4108-
for (auto clangLinkLib : clangModule->LinkLibraries) {
4109-
LibraryKind kind;
4110-
if (clangLinkLib.IsFramework)
4111-
kind = LibraryKind::Framework;
4112-
else
4113-
kind = LibraryKind::Library;
4114-
4115-
callback(LinkLibrary(clangLinkLib.Library, kind));
4116-
}
4108+
for (auto clangLinkLib : clangModule->LinkLibraries)
4109+
callback(LinkLibrary{clangLinkLib.Library,
4110+
clangLinkLib.IsFramework ? LibraryKind::Framework
4111+
: LibraryKind::Library,
4112+
/*static=*/false});
41174113
}
41184114

41194115
StringRef ClangModuleUnit::getFilename() const {

lib/ClangImporter/ClangModuleDependencyScanner.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,10 @@ ModuleDependencyVector ClangImporter::bridgeClangModuleDependencies(
266266

267267
std::vector<LinkLibrary> LinkLibraries;
268268
for (const auto &ll : clangModuleDep.LinkLibraries)
269-
LinkLibraries.push_back(
270-
{ll.Library,
271-
ll.IsFramework ? LibraryKind::Framework : LibraryKind::Library});
269+
LinkLibraries.emplace_back(
270+
ll.Library,
271+
ll.IsFramework ? LibraryKind::Framework : LibraryKind::Library,
272+
/*static=*/false);
272273

273274
// Module-level dependencies.
274275
llvm::StringSet<> alreadyAddedModules;

0 commit comments

Comments
 (0)