Cross compilation idea.

IGotD- nise at nise.com
Sun Aug 2 10:00:51 UTC 2020


On Saturday, 1 August 2020 at 10:26:12 UTC, Rel wrote:
>
> As far as I understand there are few things that forbids LDC 
> from cross compiling as easy as Zig:
> 1) Cross linker. Zig uses LLVM's linker which is called LLD. 
> Can LDC use LLD to target all suppored operating systems?

Potentially yes. You can use GNU linker as well.

> 2) Cross libc. Zig bundles minified version of musl, glibc and 
> mingw (I didn't quite understood if it can cross compile to 
> macosx). Do you think LDC could do the same or reuse the work 
> done by the Zig team?

druntime already supports musl and probably glibc as it is 
usually default for Linux. I don't think we should bundle various 
C-libs in the D distribution as it would just baggage the D 
distribution and far from all would use it. Also I don't see the 
benefit of a "minimized" version. The C-library should be 
installed as part of the system with the full version. For 
embedded targets things starts to become more complicated as it's 
full of special cases.

> 3) Cross druntime and phobos. I guess LDC could distribute 
> prebuilt versions of druntime and phobos for most used 
> operating system. Or just build and cache it the first time the 
> user tries to cross compile to new target the first time. What 
> do you think?

LDC has made a compile druntime/phobos tool and this works quite 
well for the supported targets.


I regulary cross compile using LDC but using the GNU linker 
because LLD is a bit immature and this worked well for me without 
much hazzle. The big problem is the structure of the 
druntime/phobos so that it can be adapted to new systems more 
easily. This has been discussed in this forum previously. I see 
no problems supporting more types of C-libraries but 
unfortunately all of them have their own quirks so it is not just 
a plug and play operation. Before that I think we must get rid of

version(this) { } else version(that) {}

in druntime because as we support more targets it is going to 
become a merge hell.



More information about the digitalmars-d-ldc mailing list