www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Having trouble cross compiling with LDC

reply o <o o.o> writes:
I have heard that LDC has great support for cross compilation, 
but I can't figure out how to use it.

I have a linux x64 host, and I am looking for a definitive step 
by step guide to setting up LDC to cross compile targeting 
windows x64, macosx, and linux arm64(raspberry pi).

 From what I understand, the basic steps are as follows (but I 
don't know how to actually go about doing them):

1. Use ldc-build-runtime to compile phobos library binaries for 
the target OS/Arch.

2. Run LDC, and tell it where to find the phobos binaries from 
step 1, and tell it to use lld as a linker.

3. LDC outputs an executable that can run on the target platform.

But, how do I actually go about doing these steps? How do I use 
ldc-build-runtime? How do I tell LDC to use the cross-compiled 
phobos/runtime instead of the default one?

Thanks!
Dec 08 2018
next sibling parent Jacob Carlborg <doob me.com> writes:
On Saturday, 8 December 2018 at 22:16:32 UTC, o wrote:
 I have heard that LDC has great support for cross compilation, 
 but I can't figure out how to use it.

 I have a linux x64 host, and I am looking for a definitive step 
 by step guide to setting up LDC to cross compile targeting 
 windows x64, macosx, and linux arm64(raspberry pi).

 From what I understand, the basic steps are as follows (but I 
 don't know how to actually go about doing them):

 1. Use ldc-build-runtime to compile phobos library binaries for 
 the target OS/Arch.
If LDC already provides a release for this target, as it does with macOS and Windows, you can just download that and extract druntime and Phobos.
 2. Run LDC, and tell it where to find the phobos binaries from 
 step 1, and tell it to use lld as a linker.
LLD will not work for targeting macOS, you need the LD64 linker, built for Linux. Not sure if it will work for Linux Arm64.
 3. LDC outputs an executable that can run on the target 
 platform.

 But, how do I actually go about doing these steps? How do I use 
 ldc-build-runtime? How do I tell LDC to use the cross-compiled 
 phobos/runtime instead of the default one?
I've created a Docker image (or rather a Dockerfile) for cross-compiling to macOS [1] and one for cross-compiling to Windows [2]. These Docker images are configured to output binaries for the target by default. Note that the SDKs/libraries are downloaded from someone's Dropbox account. [1] https://github.com/jacob-carlborg/docker-ldc-darwin/blob/master/Dockerfile [2] https://github.com/jacob-carlborg/docker-ldc-windows/blob/master/Dockerfile -- /Jacob Carlborg
Dec 09 2018
prev sibling next sibling parent Joakim <dlang joakim.fea.st> writes:
On Saturday, 8 December 2018 at 22:16:32 UTC, o wrote:
 I have heard that LDC has great support for cross compilation, 
 but I can't figure out how to use it.

 I have a linux x64 host, and I am looking for a definitive step 
 by step guide to setting up LDC to cross compile targeting 
 windows x64, macosx, and linux arm64(raspberry pi).
They can be a bit hard to find, but they're out there. Windows - https://github.com/ldc-developers/ldc/pull/2142#issuecomment-304472412 Mac is tougher because it requires their proprietary SDK, but Jacob has put up a docker with it - https://forum.dlang.org/post/qdcqofzdaaunwaowrzlg forum.dlang.org Raspberry Pi - https://github.com/pander86/raspberry_vibed/blob/master/README.md
 From what I understand, the basic steps are as follows (but I 
 don't know how to actually go about doing them):

 1. Use ldc-build-runtime to compile phobos library binaries for 
 the target OS/Arch.
There's a wiki page on this: https://wiki.dlang.org/Building_LDC_runtime_libraries We should link it from the help text for ldc-build-runtime.
 2. Run LDC, and tell it where to find the phobos binaries from 
 step 1, and tell it to use lld as a linker.

 3. LDC outputs an executable that can run on the target 
 platform.
Yes, see the Android examples on its wiki page: https://wiki.dlang.org/Build_D_for_Android You don't have to use lld, we support other common linkers. Of course, you'll need those linkers built to cross-link for your target, but if you're using an existing C/C++ cross-compilation toolkit and integrating it with ldc as shown on the wiki, there should be a cross-linker available. The advantage of lld is that it has good support for many platforms built in, the disadvantage is that it is still being developed and may producing crashing binaries on occasion.
 But, how do I actually go about doing these steps? How do I use 
 ldc-build-runtime? How do I tell LDC to use the cross-compiled 
 phobos/runtime instead of the default one?
See the instructions and examples above and ask questions if you can't figure out how to extend them for your situation. We can and do plan to streamline the cross-compilation process for common targets, but we cannot make available copyrighted C runtimes or anticipate every niche target out there.
Dec 09 2018
prev sibling parent reply kinke <noone nowhere.com> writes:
On Saturday, 8 December 2018 at 22:16:32 UTC, o wrote:
 I have heard that LDC has great support for cross compilation, 
 but I can't figure out how to use it.

 I have a linux x64 host, and I am looking for a definitive step 
 by step guide to setting up LDC to cross compile targeting 
 windows x64, macosx, and linux arm64(raspberry pi).
This was long overdue, so I added a Wiki page with a step-by-step guide (still WIP): https://wiki.dlang.org/Cross-compiling_with_LDC
Dec 09 2018
parent o <o o.o> writes:
On Sunday, 9 December 2018 at 16:00:12 UTC, kinke wrote:
 On Saturday, 8 December 2018 at 22:16:32 UTC, o wrote:
 I have heard that LDC has great support for cross compilation, 
 but I can't figure out how to use it.

 I have a linux x64 host, and I am looking for a definitive 
 step by step guide to setting up LDC to cross compile 
 targeting windows x64, macosx, and linux arm64(raspberry pi).
This was long overdue, so I added a Wiki page with a step-by-step guide (still WIP): https://wiki.dlang.org/Cross-compiling_with_LDC
Thanks so much! This is extremely helpful, and just what I was looking for!!
Dec 09 2018