What stops DMD from cross-compiling?
Jacob Carlborg
doob at me.com
Fri Apr 27 15:31:37 UTC 2018
On 2018-04-27 12:56, Rel wrote:
> So, okey, bare with me here. As I once told here before the only one
> thing I love about Golang is the ability to easily cross-compile code
> from any supported OS targeting any supported OS. So I was thinking what
> actually stops DMD from doing the same thing? DMD has own backends
> targeting X86 and x64 already, it seems to work well with LLD (at least
> for me) that was integrated not so long ago, and LLD has the ability to
> cross-link.
>
> So I'm not a compiler expert here, and I'm not familiar with the DMD
> code base, but from a user perspective the one huge showstopper for
> bringing the same level of cross-compilation to DMD like Golang has
> seems to be the dependency on C-library.
DMD can cross-compile between 32-bit and 64-bit on the same platform. To
targeting a different platform than the host the code in DMD needs to be
reorganized a bit. When compiling the compiler it will only include
support for targeting the same platform as you're compiling on.
Currently it's using #ifdefs to decide which target should be supported.
This occurs the compile time of the compiler. This needs to occur at
runtime instead. It doesn't depend on anything expect for the standard C
library so it should be fairly straight forward to fix.
> As of 2.079 we can write code
> that is not dependent on the druntime and libc, so technically we can
> reimplement the needed parts of cruntime in D and make it the part of
> druntime itself. What do you think about it?
That would work, but it requires a lot of effort. It's not only
depending on the C standard library, it also depends on other system
functionality that are not part of the kernel. For example, the thread
local storage implementation depends on the platform. If we're only
using the kernel that would be needed to be implemented as well.
It's possible to use the libraries provided by the target platform when
cross-compiling. I've done that with LDC and created two Dockerfiles,
one targeting Windows [1] and one targeting macOS [2]. Note, the SDKs
for macOS and Windows are downloaded from Dropbox accounts.
[1]
https://github.com/jacob-carlborg/docker-ldc-windows/blob/master/Dockerfile
[2]
https://github.com/jacob-carlborg/docker-ldc-darwin/blob/master/Dockerfile
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list