mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Frontend: allow specifying a different target triple for internal clang instance to use
Before this change, we always use the Swift target triple to instantiate the internal Clang instance. When loading a Swift module from the textual interface, we may pick up a lower target triple to use to build the Swift module because the target is hard-coded in the textual interface file. This implies we may end up building multiple versions of the same Clang module, one for each target triple of the loading Swift module. This change adds a new frontend flag -clang-target to allow clients to specify a consistent clang target to use across the Swift module boundaries. This value won't change because it's not part of .swiftinterface files. swift-driver should pass down -clang-target for each frontend invocation, and its value should be identical to -target. Related to: rdar://72480261
This commit is contained in:
@@ -686,6 +686,20 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
||||
Opts.TargetVariant = llvm::Triple(A->getValue());
|
||||
}
|
||||
|
||||
// Collect -clang-target value if specified in the front-end invocation.
|
||||
// Usually, the driver will pass down a clang target with the
|
||||
// exactly same value as the main target, so we could dignose the usage of
|
||||
// unavailable APIs.
|
||||
// The reason we cannot infer clang target from -target is that not all
|
||||
// front-end invocation will include a -target to start with. For instance,
|
||||
// when compiling a Swift module from a textual interface, -target isn't
|
||||
// necessary because the textual interface hardcoded the proper target triple
|
||||
// to use. Inferring -clang-target there will always give us the default
|
||||
// target triple.
|
||||
if (const Arg *A = Args.getLastArg(OPT_clang_target)) {
|
||||
Opts.ClangTarget = llvm::Triple(A->getValue());
|
||||
}
|
||||
|
||||
Opts.EnableCXXInterop |= Args.hasArg(OPT_enable_cxx_interop);
|
||||
Opts.EnableObjCInterop =
|
||||
Args.hasFlag(OPT_enable_objc_interop, OPT_disable_objc_interop,
|
||||
|
||||
Reference in New Issue
Block a user