Skip to content

Commit 3bd4853

Browse files
committed
[Frontend] Add -swift-compiler-version option to frontend, module interfaces
This option is going to be used to indicate what compiler was used to build swift interface/module which is required for SE-0438.
1 parent 7dfdfe0 commit 3bd4853

File tree

5 files changed

+35
-0
lines changed

5 files changed

+35
-0
lines changed

include/swift/Basic/Version.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ StringRef getCurrentCompilerChannel();
187187
/// users.
188188
unsigned getUpcomingCxxInteropCompatVersion();
189189

190+
/// Retrieves the version of the running compiler. It could be a tag or
191+
/// a "development" version that only has major/minor.
192+
std::string getCompilerVersion();
193+
190194
} // end namespace version
191195
} // end namespace swift
192196

include/swift/Frontend/FrontendOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ class FrontendOptions {
110110
/// User-defined module version number.
111111
llvm::VersionTuple UserModuleVersion;
112112

113+
/// The Swift compiler version number that would be used to synthesize
114+
/// swiftinterface files and subsequently swiftmodules.
115+
llvm::VersionTuple SwiftCompilerVersion;
116+
113117
/// A set of modules allowed to import this module.
114118
std::set<std::string> AllowableClients;
115119

include/swift/Option/Options.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ def package_description_version: Separate<["-"], "package-description-version">,
303303
HelpText<"The version number to be applied on the input for the PackageDescription availability kind">,
304304
MetaVarName<"<vers>">;
305305

306+
def swift_compiler_version : Separate<["-"], "swift-compiler-version">,
307+
Flags<[FrontendOption, HelpHidden, ModuleInterfaceOptionIgnorable]>,
308+
HelpText<"The version of the Swift compiler used to emit swift interface and module">,
309+
MetaVarName<"<compvers>">;
310+
306311
def tools_directory : Separate<["-"], "tools-directory">,
307312
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild,
308313
ArgumentIsPath]>,

lib/Basic/Version.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,5 +339,18 @@ unsigned getUpcomingCxxInteropCompatVersion() {
339339
return SWIFT_VERSION_MAJOR + 1;
340340
}
341341

342+
std::string getCompilerVersion() {
343+
std::string buf;
344+
llvm::raw_string_ostream OS(buf);
345+
346+
#if defined(SWIFT_COMPILER_VERSION)
347+
OS << SWIFT_COMPILER_VERSION;
348+
#else
349+
OS << SWIFT_VERSION_STRING;
350+
#endif
351+
352+
return OS.str();
353+
}
354+
342355
} // end namespace version
343356
} // end namespace swift

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,15 @@ bool ArgsToFrontendOptionsConverter::convert(
299299
if (const Arg *A = Args.getLastArg(OPT_public_module_name))
300300
Opts.PublicModuleName = A->getValue();
301301

302+
if (auto A = Args.getLastArg(OPT_swift_compiler_version)) {
303+
if (Opts.SwiftCompilerVersion.tryParse(A->getValue())) {
304+
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
305+
A->getAsString(Args), A->getValue());
306+
}
307+
} else {
308+
Opts.SwiftCompilerVersion.tryParse(version::getCompilerVersion());
309+
}
310+
302311
// This must be called after computing module name, module abi name,
303312
// and module link name. If computing module aliases is unsuccessful,
304313
// return early.

0 commit comments

Comments
 (0)