mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
IRGen: Honor -target-variant flag for zippered macCatalyst binaries.
This commit is contained in:
@@ -869,6 +869,22 @@ importer::addCommonInvocationArguments(
|
||||
invocationArgStrs.push_back("-mcx16");
|
||||
}
|
||||
|
||||
if (triple.isOSDarwin()) {
|
||||
if (auto variantTriple = ctx.LangOpts.TargetVariant) {
|
||||
// Passing the -target-variant along to clang causes clang's
|
||||
// CodeGenerator to emit zippered .o files.
|
||||
invocationArgStrs.push_back("-darwin-target-variant");
|
||||
invocationArgStrs.push_back(variantTriple->str());
|
||||
}
|
||||
|
||||
if (ctx.LangOpts.VariantSDKVersion) {
|
||||
invocationArgStrs.push_back("-Xclang");
|
||||
invocationArgStrs.push_back(
|
||||
("-darwin-target-variant-sdk-version=" +
|
||||
ctx.LangOpts.VariantSDKVersion->getAsString()));
|
||||
}
|
||||
}
|
||||
|
||||
if (std::optional<StringRef> R = ctx.SearchPathOpts.getWinSDKRoot()) {
|
||||
invocationArgStrs.emplace_back("-Xmicrosoft-windows-sdk-root");
|
||||
invocationArgStrs.emplace_back(*R);
|
||||
|
||||
@@ -1030,6 +1030,22 @@ static void initLLVMModule(const IRGenModule &IGM, SILModule &SIL) {
|
||||
assert(Module->getSDKVersion() == *IGM.Context.LangOpts.SDKVersion);
|
||||
}
|
||||
|
||||
if (!IGM.VariantTriple.str().empty()) {
|
||||
if (Module->getDarwinTargetVariantTriple().empty()) {
|
||||
Module->setDarwinTargetVariantTriple(IGM.VariantTriple.str());
|
||||
} else {
|
||||
assert(Module->getDarwinTargetVariantTriple() == IGM.VariantTriple.str());
|
||||
}
|
||||
}
|
||||
|
||||
if (IGM.Context.LangOpts.VariantSDKVersion) {
|
||||
if (Module->getDarwinTargetVariantSDKVersion().empty())
|
||||
Module->setDarwinTargetVariantSDKVersion(*IGM.Context.LangOpts.VariantSDKVersion);
|
||||
else
|
||||
assert(Module->getDarwinTargetVariantSDKVersion() ==
|
||||
*IGM.Context.LangOpts.VariantSDKVersion);
|
||||
}
|
||||
|
||||
// Set the module's string representation.
|
||||
Module->setDataLayout(IGM.DataLayout.getStringRepresentation());
|
||||
|
||||
|
||||
@@ -220,7 +220,9 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
|
||||
ModuleName, PrivateDiscriminator)),
|
||||
Module(*ClangCodeGen->GetModule()),
|
||||
DataLayout(irgen.getClangDataLayoutString()),
|
||||
Triple(irgen.getEffectiveClangTriple()), TargetMachine(std::move(target)),
|
||||
Triple(irgen.getEffectiveClangTriple()),
|
||||
VariantTriple(irgen.getEffectiveClangVariantTriple()),
|
||||
TargetMachine(std::move(target)),
|
||||
silConv(irgen.SIL), OutputFilename(OutputFilename),
|
||||
MainInputFilenameForDebugInfo(MainInputFilenameForDebugInfo),
|
||||
TargetInfo(SwiftTargetInfo::get(*this)), DebugInfo(nullptr),
|
||||
@@ -2229,6 +2231,13 @@ llvm::Triple IRGenerator::getEffectiveClangTriple() {
|
||||
return llvm::Triple(CI->getTargetInfo().getTargetOpts().Triple);
|
||||
}
|
||||
|
||||
llvm::Triple IRGenerator::getEffectiveClangVariantTriple() {
|
||||
auto CI = static_cast<ClangImporter *>(
|
||||
&*SIL.getASTContext().getClangModuleLoader());
|
||||
assert(CI && "no clang module loader");
|
||||
return llvm::Triple(CI->getTargetInfo().getTargetOpts().DarwinTargetVariantTriple);
|
||||
}
|
||||
|
||||
const llvm::StringRef IRGenerator::getClangDataLayoutString() {
|
||||
return static_cast<ClangImporter *>(
|
||||
SIL.getASTContext().getClangModuleLoader())
|
||||
|
||||
@@ -554,6 +554,9 @@ public:
|
||||
/// Return the effective triple used by clang.
|
||||
llvm::Triple getEffectiveClangTriple();
|
||||
|
||||
/// Return the effective variant triple used by clang.
|
||||
llvm::Triple getEffectiveClangVariantTriple();
|
||||
|
||||
const llvm::StringRef getClangDataLayoutString();
|
||||
};
|
||||
|
||||
@@ -658,6 +661,7 @@ public:
|
||||
llvm::Module &Module;
|
||||
const llvm::DataLayout DataLayout;
|
||||
const llvm::Triple Triple;
|
||||
const llvm::Triple VariantTriple;
|
||||
std::unique_ptr<llvm::TargetMachine> TargetMachine;
|
||||
ModuleDecl *getSwiftModule() const;
|
||||
AvailabilityContext getAvailabilityContext() const;
|
||||
|
||||
@@ -5,3 +5,5 @@
|
||||
public func test() { }
|
||||
|
||||
// CHECK: "SDK Version", [3 x i32] [i32 10, i32 15, i32 4]
|
||||
// CHECK: "darwin.target_variant.triple", !"{{.*}}-apple-ios13.1-macabi"
|
||||
// CHECK: "darwin.target_variant.SDK Version", [2 x i32] [i32 13, i32 4]
|
||||
|
||||
Reference in New Issue
Block a user