So what is the state of cross-compilation in D?

Joakim dlang at joakim.fea.st
Fri Jan 19 15:34:40 UTC 2018


On Friday, 19 January 2018 at 08:08:42 UTC, Jonathan M Davis 
wrote:
> On Friday, January 19, 2018 06:53:16 Rel via Digitalmars-d 
> wrote:
>> On Wednesday, 17 January 2018 at 12:31:35 UTC, Kagamin wrote:
>> > https://wiki.dlang.org/Build_D_for_Android 
>> > https://wiki.dlang.org/Building_LDC_runtime_libraries 
>> > https://github.com/ldc-developers/ldc/pull/2142#issuecomment-304472412
>>
>> As far as I understand I will need a C toolchain that allows 
>> cross-compilation to target OS in order to build runtime 
>> libraries, is it correct? Why is D's runtime library is 
>> written in C? I thought that D is pretty much capable to have 
>> runtime libraries written in D, especially after the 
>> introduction of -betterC flag.
>
> D's runtime is not written in C. It's written in D. However, 
> the C linker is used to link, and by default, it's used by 
> calling the C/C++ compiler (at least, that's what dmd does). 
> ldc would be using LLVM's linker and possibly using it through 
> clang.
>
> However, D's runtime does _call_ into various C functions, 
> because they're part of the OS' API, and that means that D is 
> ultimately using the C runtime in addition to its own. So, C is 
> also used in that way even though none of D's runtime is 
> written in C.

Mostly right, but there are a few C and assembly files in 
druntime and phobos, such as the zlib files here:

https://github.com/dlang/phobos/tree/master/etc/c/zlib

Those require a C compiler for all targets, including 
cross-compilation, if you want to build the stdlib, hence the 
requirement he noted.



More information about the Digitalmars-d mailing list