ldc-developers / ldc

The LLVM-based D Compiler.
http://wiki.dlang.org/LDC
Other
1.22k stars 264 forks source link

ARM/AArch64 cross-compilation targets aren't respected in an MSVC environment on Windows. #4624

Open just-harry opened 7 months ago

just-harry commented 7 months ago

In a fully set-up MSVC environment (e.g. an environment set-up by Visual Studio's vcvarsall.bat) with a target of AArch64 ($Env:VSCMD_ARG_TGT_ARCH == arm64) or ARM ($Env:VSCMD_ARG_TGT_ARCH == arm), LDC will set-up an MSVC environment for x86-64 or x86, even if the -mtriple supplied to LDC is aarch64-windows or arm-windows (for example).

This results in the wrong libraries being supplied to the linker, and C files being preprocessed for the wrong target when cl is used for preprocessing.

This seems to be because setupMsvcEnvironmentImpl expects only x64 or x86 for the VSCMD_ARG_TGT_ARCH environment variable: https://github.com/ldc-developers/ldc/blob/b75fc4cd0dcdb55ef3be1904e2ddce9355a10a95/driver/tool.cpp#L295-L300

just-harry commented 7 months ago

A proposed fix: https://github.com/ldc-developers/ldc/pull/4625

kinke commented 7 months ago

4625 fixed this partially - an already set-up MSVC environment for ARM targets should work now, but setting it up manually would require more work, e.g., in function https://github.com/dlang/dmd/blob/748fab1e02b9f9e8980833b79e9448937bfecfab/compiler/src/dmd/vsoptions.d#L380.