www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.ldc - Proposal: configuration for cross compilation

reply "Kai Nacke" <kai redstar.de> writes:
Hi all!

More and more people use LDC to cross-compile for other 
architectures. But end-to-end support is still missing. At least 
some basic tools and libraries differ: C compiler/assembler, 
linker, default druntime and phobos libraries.

Thinking about a solution, I came up with the following proposal. 
Currently, the config file is only used to define some command 
line switches. This can be extended to do a multi-level lookup 
for:

- definitions for tools (compiler, linker) and libraries 
(druntime, phobos)
- additional definitions for each target (command line switched, 
...)

The lookup would sue the triple. The lookup order would be triple 
including environment, triple without environment, os only and 
default. The first entry matched is used. The config file would 
look like:


default:
{
     cc = gcc
     cctype = gnu
     ld = gcc
     ldtype = gnu
     switches = [ ... ]
     defaultlib = ...
     debuglib = ...
     linklibs = rt dl pthread m
}

*-*-freebsd:
{
     cc = clang
     linklibs = pthread m
}

*-*-win32:
{
     cc = cl
     cctype = ms
     ld = link
     ldtype = ms
     linkswitches = /NXCOMPAT /DYNAMICBASE
     linklibs = kernel32.lib user32.lib gdi32.lib
}

arm-*-linux-gnuehabi:
{
     cc = arm-unknown-linux-gnu-gcc
     ld = arm-unknown-linux-gnu-gcc
}

mips64-*-linux:
{
     cc = mips64-unknown-linux-gnu-gcc
     ld = mips64-unknown-linux-gnu-gcc
}


E.g. compiling for Linux/MIPS64 (-mtriple=mips64-linux) would 
result in use of mips64-unknown-linux-gnu-gcc. Compiling for 
FreeBSD would use clang (because this is the default compiler in 
release 10). Default configuration is to use gcc for 
compiling/linking.

What do you think? Does this scheme cover the common cases 
encountered with cross compilation?

Regards,
Kai
May 05 2014
parent reply David Nadlinger via digitalmars-d-ldc <digitalmars-d-ldc puremagic.com> writes:
Hi Kai,

On 5 May 2014, at 12:37, Kai Nacke via digitalmars-d-ldc wrote:
 More and more people use LDC to cross-compile for other architectures. 
 But end-to-end support is still missing.
We are in desperate need of improvements on this front, I agree. I have been using various kludges to switch between environments and ldc2.conf files when cross-compiling myself too. And this in fact should be an area where LDC can really shine compared to e.g. GCC-based compilers, which basically require a whole separate install per target.
 The lookup would sue the triple. The lookup order would be triple 
 including environment, triple without environment, os only and 
 default. The first entry matched is used. The config file would look 
 like:
 […]
This looks like a good start. Two ideas: - What format do you want to use for the config file? libconfig, like we are doing right now? (I didn't know what to make of the missing quotes in your example.) - Do more specific keys always completely override what a more general configuration group might contain? If yes, might there be situations where this gets cumbersome? The example I'm thinking about here is a possible future druntime version with different "ports" directories for the platform specific files, as has been discussed in the past. In this case, there might be an additional import path per platform, which should just be added to the other list of locations. (The question would be whether a facility to address this would be worth the added complexity, though…) Another topic we need to address after this has been finalized is how to best integrate cross-compilation into the build process (this mainly concerns building druntime/Phobos). Glad to see progress on this front! Best, David
May 06 2014
parent reply "Kai Nacke" <kai redstar.de> writes:
Hi David!

On Tuesday, 6 May 2014 at 12:01:32 UTC, David Nadlinger via
digitalmars-d-ldc wrote:
 This looks like a good start. Two ideas:
  - What format do you want to use for the config file? 
 libconfig, like we are doing right now? (I didn't know what to 
 make of the missing quotes in your example.)
I want to use libconfig as it provides the base features. However I did not validate the syntax of my example file.
  - Do more specific keys always completely override what a more 
 general configuration group might contain? If yes, might there 
 be situations where this gets cumbersome? The example I'm 
 thinking about here is a possible future druntime version with 
 different "ports" directories for the platform specific files, 
 as has been discussed in the past. In this case, there might be 
 an additional import path per platform, which should just be 
 added to the other list of locations. (The question would be 
 whether a facility to address this would be worth the added 
 complexity, though…)
I thought about this, too. Some keys tend to be additive. The switches key is a good example: if I want to add a switch to the mips64 section (e.g. -mcpu=octeon) then it would be boring to specify the path to the import modules again. But I dislike the idea that not all keys work in the same way. I solution would be specify to the behaviour in the config file with = (final assigment) and += (add to less specific definition): default: { switches = [ "...", "..."] } mips64-*-linux: { switches += [ "-mcpu=octeon" ] } As I don't know if this is possible with libconfig I would postpone this to the D version of ldc.
 Another topic we need to address after this has been finalized 
 is how to best integrate cross-compilation into the build 
 process (this mainly concerns building druntime/Phobos).
Yes, that is a different topic which needs a solution....
 Glad to see progress on this front!
:-) I currently have too much targets to always fiddle around with the config file. Regards, Kai
May 06 2014
parent "Daniel Murphy" <yebbliesnospam gmail.com> writes:
"Kai Nacke"  wrote in message news:qnuyfewnutwzozxlbxwk forum.dlang.org... 

 [snip] the D version of ldc.
I like the sound of that!
May 12 2014