www.digitalmars.com         C & C++   DMDScript  

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

reply Rel <relmail rambler.ru> writes:
Well, to be completely honest with you the only one
thing I like about the Go programming language is the
ability to easily cross-compile your Go program from
any supported OS to any supported OS.

So I was wondering what is the story of cross-compilation
for different D language compilers? Is it possible to some
extent now? Do you guys have interest in it?

Basically as far as I understood what makes Go suitable
for cross-compilation is their own linker implementation,
and D compilers use current system linker.
Jan 17 2018
next sibling parent reply Kagamin <spam here.lot> writes:
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
Jan 17 2018
parent reply Rel <relmail rambler.ru> writes:
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. I'd like to cross-compile from Windows machine to Linux and Mac OSX. Where can I get C toolchain that will allow me to cross-compile D's runtime libraries from Windows to Linux and Mac OSX?
Jan 18 2018
next sibling parent reply Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
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. - Jonathan M Davis
Jan 19 2018
next sibling parent rikki cattermole <rikki cattermole.co.nz> writes:
On 19/01/2018 8:08 AM, 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.
It's in built into LLVM. No requirements on having clang (we already have it on offer).
 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.
 
 - Jonathan M Davis
 
Jan 19 2018
prev sibling parent Joakim <dlang joakim.fea.st> writes:
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.
Jan 19 2018
prev sibling next sibling parent Jacob Carlborg <doob me.com> writes:
On 2018-01-19 07:53, Rel wrote:

 I'd like to cross-compile from Windows machine to Linux and
 Mac OSX. Where can I get C toolchain that will allow me to
 cross-compile D's runtime libraries from Windows to Linux
 and Mac OSX?
Here's a Dockerfile that cross-compiles to macOS: https://github.com/jacob-carlborg/docker-ldc-darwin/blob/master/Dockerfile -- /Jacob Carlborg
Jan 19 2018
prev sibling parent Kagamin <spam here.lot> writes:
On Friday, 19 January 2018 at 06:53:16 UTC, Rel wrote:
 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?
If you're going to compile the compiler, LLVM is written in C++, so you would have the C toolchain for that.
Jan 19 2018
prev sibling next sibling parent reply Andre Pany <andre s-e-a-p.de> writes:
On Wednesday, 17 January 2018 at 12:06:23 UTC, Rel wrote:
 Well, to be completely honest with you the only one
 thing I like about the Go programming language is the
 ability to easily cross-compile your Go program from
 any supported OS to any supported OS.

 So I was wondering what is the story of cross-compilation
 for different D language compilers? Is it possible to some
 extent now? Do you guys have interest in it?

 Basically as far as I understood what makes Go suitable
 for cross-compilation is their own linker implementation,
 and D compilers use current system linker.
Cross compiling from Windows to raspberry pi: http://d-land.sepany.de/einstieg-in-die-raspberry-pi-entwicklung-mit-ldc.html Kind regards Andre
Jan 17 2018
parent reply Mike Franklin <slavo5150 yahoo.com> writes:
On Wednesday, 17 January 2018 at 13:24:37 UTC, Andre Pany wrote:
 On Wednesday, 17 January 2018 at 12:06:23 UTC, Rel wrote:
 Well, to be completely honest with you the only one
 thing I like about the Go programming language is the
 ability to easily cross-compile your Go program from
 any supported OS to any supported OS.

 So I was wondering what is the story of cross-compilation
 for different D language compilers? Is it possible to some
 extent now? Do you guys have interest in it?

 Basically as far as I understood what makes Go suitable
 for cross-compilation is their own linker implementation,
 and D compilers use current system linker.
Cross compiling from Windows to raspberry pi: http://d-land.sepany.de/einstieg-in-die-raspberry-pi-entwicklung-mit-ldc.html Kind regards Andre
Andre, That link appears to be dead. It was actually quite a nice resource. Any chance you can republish it or something? Thanks, Mike
Jul 28 2018
parent Andre Pany <andre s-e-a-p.de> writes:
On Saturday, 28 July 2018 at 08:56:30 UTC, Mike Franklin wrote:
 On Wednesday, 17 January 2018 at 13:24:37 UTC, Andre Pany wrote:
 On Wednesday, 17 January 2018 at 12:06:23 UTC, Rel wrote:
 Well, to be completely honest with you the only one
 thing I like about the Go programming language is the
 ability to easily cross-compile your Go program from
 any supported OS to any supported OS.

 So I was wondering what is the story of cross-compilation
 for different D language compilers? Is it possible to some
 extent now? Do you guys have interest in it?

 Basically as far as I understood what makes Go suitable
 for cross-compilation is their own linker implementation,
 and D compilers use current system linker.
Cross compiling from Windows to raspberry pi: http://d-land.sepany.de/einstieg-in-die-raspberry-pi-entwicklung-mit-ldc.html Kind regards Andre
Andre, That link appears to be dead. It was actually quite a nice resource. Any chance you can republish it or something? Thanks, Mike
While changing the tool to generate the site, the urls changed. New link is http://d-land.sepany.de/tutorials/einplatinenrechner/einstieg-in-die-raspberry-pi-entwicklung-mit-ldc/ I need to update the article, I wrote it while LDC 1.5.0 was actual. Kind regards Andre
Jul 28 2018
prev sibling next sibling parent reply Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Wednesday, 17 January 2018 at 12:06:23 UTC, Rel wrote:
 Well, to be completely honest with you the only one
 thing I like about the Go programming language is the
 ability to easily cross-compile your Go program from
 any supported OS to any supported OS.

 So I was wondering what is the story of cross-compilation
 for different D language compilers? Is it possible to some
 extent now? Do you guys have interest in it?

 Basically as far as I understood what makes Go suitable
 for cross-compilation is their own linker implementation,
 and D compilers use current system linker.
LDC is a cross compiler by default. the `-mtriple` flag tells LDC what arch, OS and cpu to target. `-linker=lld-link` or `-linker=lld` (not really sure of the difference) will use LLVM crosslinker, so provided you have the appropriate libraries to link against it should work
Jan 17 2018
parent Jacob Carlborg <doob me.com> writes:
On 2018-01-17 14:28, Nicholas Wilson wrote:

 LDC is a cross compiler by default.
 the `-mtriple` flag tells LDC what arch, OS and cpu to target.
 `-linker=lld-link` or `-linker=lld` (not really sure of the difference) 
 will use LLVM crosslinker, so provided you have the appropriate 
 libraries to link against it should work
Unfortunately LLD is not ready yet for all targets, but for those targets it is ready it should work. -- /Jacob Carlborg
Jan 17 2018
prev sibling parent Jacob Carlborg <doob me.com> writes:
On 2018-01-17 13:06, Rel wrote:
 Well, to be completely honest with you the only one
 thing I like about the Go programming language is the
 ability to easily cross-compile your Go program from
 any supported OS to any supported OS.
 
 So I was wondering what is the story of cross-compilation
 for different D language compilers? Is it possible to some
 extent now? 
Yes, it works with LDC.
 Do you guys have interest in it?
Yes.
 Basically as far as I understood what makes Go suitable
 for cross-compilation is their own linker implementation,
 and D compilers use current system linker.
If the system linker supports cross-compilation it's no problem. Here's a Dockerfile [1] with LDC that cross-compiles to macOS. [1] https://github.com/jacob-carlborg/docker-ldc-darwin/blob/master/Dockerfile -- /Jacob Carlborg
Jan 17 2018