Skip to content

Commit 6cab860

Browse files
author
Harlan Haskins
authored
Merge pull request swiftlang#27736 from harlanhaskins/installwizard
[TBDGen] Use TAPI's defaults for compatibility_version and current_version
2 parents da0099e + 4389c5a commit 6cab860

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

include/swift/TBDGen/TBDGen.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@ struct TBDGenOptions {
4040
std::string ModuleLinkName;
4141

4242
/// The current project version to use in the generated TBD file. Defaults
43-
/// to 1, which matches the default if the DYLIB_CURRENT_VERSION build setting
44-
/// is not set.
45-
version::Version CurrentVersion = {1, 0, 0};
43+
/// to None.
44+
llvm::Optional<version::Version> CurrentVersion = None;
4645

4746
/// The dylib compatibility-version to use in the generated TBD file. Defaults
48-
/// to 1, which matches the default if the DYLIB_COMPATIBILITY_VERSION build
49-
/// setting is not set.
50-
version::Version CompatibilityVersion = {1, 0, 0};
47+
/// to None.
48+
llvm::Optional<version::Version> CompatibilityVersion = None;
5149
};
5250

5351
void enumeratePublicSymbols(FileUnit *module, llvm::StringSet<> &symbols,

lib/TBDGen/TBDGen.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "swift/SIL/TypeLowering.h"
3535
#include "llvm/ADT/StringSet.h"
3636
#include "llvm/Support/Error.h"
37+
#include "llvm/Support/Process.h"
3738
#include "llvm/Support/YAMLTraits.h"
3839
#include "llvm/TextAPI/MachO/InterfaceFile.h"
3940
#include "llvm/TextAPI/MachO/TextAPIReader.h"
@@ -597,7 +598,10 @@ convertToPacked(const version::Version &version) {
597598
}
598599

599600
static bool isApplicationExtensionSafe(const LangOptions &LangOpts) {
600-
return LangOpts.EnableAppExtensionRestrictions;
601+
// Existing linkers respect these flags to determine app extension safety.
602+
return LangOpts.EnableAppExtensionRestrictions ||
603+
llvm::sys::Process::GetEnv("LD_NO_ENCRYPT") ||
604+
llvm::sys::Process::GetEnv("LD_APPLICATION_EXTENSION_SAFE");
601605
}
602606

603607
static void enumeratePublicSymbolsAndWrite(ModuleDecl *M, FileUnit *singleFile,
@@ -615,8 +619,12 @@ static void enumeratePublicSymbolsAndWrite(ModuleDecl *M, FileUnit *singleFile,
615619
file.setApplicationExtensionSafe(
616620
isApplicationExtensionSafe(M->getASTContext().LangOpts));
617621
file.setInstallName(opts.InstallName);
618-
file.setCurrentVersion(convertToPacked(opts.CurrentVersion));
619-
file.setCompatibilityVersion(convertToPacked(opts.CompatibilityVersion));
622+
if (auto currentVersion = opts.CurrentVersion) {
623+
file.setCurrentVersion(convertToPacked(*currentVersion));
624+
}
625+
if (auto compatibilityVersion = opts.CompatibilityVersion) {
626+
file.setCompatibilityVersion(convertToPacked(*compatibilityVersion));
627+
}
620628
file.setTwoLevelNamespace();
621629
file.setSwiftABIVersion(irgen::getSwiftABIVersion());
622630
file.setInstallAPI(opts.IsInstallAPI);

test/TBD/dylib-version.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@
1212
// BOTH: current-version: 2.0.3
1313
// BOTH: compatibility-version: 1.7
1414
// CURRENT: current-version: 2
15-
16-
// Compatibility version defaults to 1 if not present in TBD file, and
17-
// tapi does not write field if compatibility version is 1
18-
19-
// CURRENT-NOT: compatibility-version: 1
20-
2115
// COMPAT: compatibility-version: 2
2216

23-
// Same as above -- current version defaults to 1 and is not present in
24-
// emitted TBD file if it's 1.
25-
// COMPAT-NOT: current-version: 1
26-
2717
// BOGUS: version component contains non-numeric characters

0 commit comments

Comments
 (0)