Hitchikers Guide to Porting Phobos / D Runtime to other architectures

Dwhatever not at real.com
Mon Jan 6 12:23:22 PST 2014


On Monday, 6 January 2014 at 17:52:44 UTC, Sean Kelly wrote:
> On Monday, 6 January 2014 at 11:47:57 UTC, Dwhatever wrote:
>> I'm trying to do the same, trying to compile OS free code but 
>> I haven't so far been successful because D requires the 
>> runtime and then also Phobos.
>
> D doesn't require Phobos.  The compiler implicitly links against
> libphobos.a, but that isn't the same thing.  All a D app 
> actually
> needs is Druntime.  And you can replace the GC in Druntime with
> gcstub (backed by malloc) and stub out the thread API if these
> aren't appropriate for your target.  This still means using a
> custom Druntime, but making the changes should really be pretty
> straightforward in most cases.  The most complicated aspect of
> porting will be how you handle core.stdc, since Druntime still
> relies on C library calls for various things.

I'm using LDC and unfortunately the -mtriple=arm-eabi isn't 
supported so I have to use -mtriple=arm-linux which automatically 
sets the "Posix" version string. I can always try to stub all the 
Posix calls in the library but what I think would work is that 
you have a stubbed version when there isn't any system name like 
Windows or Posix. For example.

version (Windows)
{
   ...
}
else version (Posix)
{
   ...
}
else
{
   //Stubbed interface
}

However, it isn't really obvious what is missing when stubbing 
all the interfaces. Perhaps some stubbed interfaces should have a 
reference to some function so that the programmer understands 
that this must be implemented. For example malloc and free would 
be obvious.


More information about the Digitalmars-d mailing list