@@ -289,17 +289,33 @@ namespace {
289
289
bool setupMsvcEnvironmentImpl (
290
290
bool forPreprocessingOnly,
291
291
std::vector<std::pair<std::wstring, wchar_t *>> *rollback) {
292
- const bool x64 = global.params .targetTriple -> isArch64Bit () ;
292
+ const auto &triple = * global.params .targetTriple ;
293
293
294
294
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
+ }
301
316
}
302
317
318
+ const bool x64 = triple.isArch64Bit ();
303
319
const auto begin = std::chrono::steady_clock::now ();
304
320
305
321
static VSOptions vsOptions; // cache, as this can be expensive
0 commit comments