dlang / visuald

Visual D - Visual Studio extension for the D programming language
http://rainers.github.io/visuald/visuald/StartPage.html
Boost Software License 1.0
288 stars 69 forks source link

Cross-compiling in LDC? #283

Open TurkeyMan opened 2 days ago

TurkeyMan commented 2 days ago

I need to start doing ARM/RISC-V/XTENSA builds... LDC can target these platforms with compiler flags, but I'm not sure how to support this in the VS configuration matrix. The wizard creates configurations that target Windows x86/x64, and it builds MS-COFF and uses the MS linker. I need to add a new item to the 'platform' column in the matrix, where such configurations cause LDC to emit ELF (just needs to give -mtriple=riscv32-unknown-elf to the compiler), but also swap the MS linker for the LLVM linker... which seems more complicated.

I tried to hack this by cloning the x64 config and use a post-build step to link instead of the linker, but when I add a platform to the matrix, configurations for that new platform seem to have the LDC compiler disappear from the configuration completely...

What's the process to do this nicely?

rainers commented 2 days ago

For platforms that VS supports already (e.g. ARM), you can copy the D releated files from "c:\Program Files\Microsoft Visual Studio\2022\Preview\Msbuild\Microsoft\VC\v170\Platforms\x64\ImportBefore" and ImportAfter to the respective platform folder. This adds the compiler options to the setup pages. Adding a new platform seems to work by copying the full platform folder and editing Platform.Default.props replacing the platform name.

I guess you can also do this in a user/solution directory, but I have not tried this yet.

Regarding the linker, Visual D also replaces the linker if you enable demangling of the linker output, so you might have to adapt that. See LinkToolPath/LinkToolExe in "c:\Program Files (x86)\VisualD\msbuild\dcompile.targets" . This assumes compatible linker options, though.

TurkeyMan commented 1 day ago

Ah yes, I was looking through the targets and project files for direct references to code that handled the D compiler; but I missed the ImportBefore and ImportAfter implicit inclusion mechanic. I got some stuff working. VS is really pretty bad at extension of this nature. MSBuild just feels like a really bad design overall! I wonder why they commit to such a stupid architecture?