Skip to content

Commit b29edc8

Browse files
authored
Handle already-set-up MSVC environments targeting AArch64/ARM. (#4625)
1 parent 2e10c20 commit b29edc8

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

driver/tool.cpp

+23-7
Original file line numberDiff line numberDiff line change
@@ -289,17 +289,33 @@ namespace {
289289
bool setupMsvcEnvironmentImpl(
290290
bool forPreprocessingOnly,
291291
std::vector<std::pair<std::wstring, wchar_t *>> *rollback) {
292-
const bool x64 = global.params.targetTriple->isArch64Bit();
292+
const auto &triple = *global.params.targetTriple;
293293

294294
if (env::has(L"VSINSTALLDIR") && !env::has(L"LDC_VSDIR_FORCE")) {
295-
// Assume a fully set up environment (e.g., VS native tools command prompt).
296-
// Skip the MSVC setup unless the environment is set up for a different
297-
// target architecture.
298-
const auto tgtArch = env::get("VSCMD_ARG_TGT_ARCH"); // VS 2017+
299-
if (tgtArch.empty() || tgtArch == (x64 ? "x64" : "x86"))
300-
return true;
295+
const auto tripleArch = triple.getArch();
296+
const char *expectedArch = nullptr;
297+
298+
if (tripleArch == llvm::Triple::ArchType::x86_64)
299+
expectedArch = "x64";
300+
else if (tripleArch == llvm::Triple::ArchType::x86)
301+
expectedArch = "x86";
302+
else if (tripleArch == llvm::Triple::ArchType::aarch64)
303+
expectedArch = "arm64";
304+
else if (tripleArch == llvm::Triple::ArchType::arm ||
305+
tripleArch == llvm::Triple::ArchType::thumb)
306+
expectedArch = "arm";
307+
308+
if (expectedArch) {
309+
// Assume a fully set up environment (e.g., VS native tools command prompt).
310+
// Skip the MSVC setup unless the environment is set up for a different
311+
// target architecture.
312+
const auto tgtArch = env::get("VSCMD_ARG_TGT_ARCH"); // VS 2017+
313+
if (tgtArch.empty() || tgtArch == expectedArch)
314+
return true;
315+
}
301316
}
302317

318+
const bool x64 = triple.isArch64Bit();
303319
const auto begin = std::chrono::steady_clock::now();
304320

305321
static VSOptions vsOptions; // cache, as this can be expensive

0 commit comments

Comments
 (0)