Automated porting of druntime to new platforms using libclang

Jacob Carlborg doob at
Mon Jan 6 23:36:35 PST 2014

On 2014-01-07 07:02, Joakim wrote:
> I've been porting dmd to Android/x86 recently and I've been thinking
> about whether there's an easier way to handle such porting in the
> future.  The vast majority of my druntime patches simply find the
> equivalent function or macro in the Android C library, bionic.  This is
> just a lot of name and parameter type checking most of the time:
> couldn't this be automated for new platforms with libclang?
> Write a D utility that finds all the platform blocks in druntime and
> calls libclang to parse the headers and translate the results into D,
> like htod does, then inserts the new version blocks into druntime, which
> you can then quickly manually check.  Perhaps this can be built on top
> of dstep, which I just found while googling about htod for this post: :)

That could probably be built on top of DStep or a modified version of DStep.

> Obviously no utility will catch everything, for example, it's not going
> to know how to replace missing functions.

For what case one could add a static assert.

> I'm not sure if libclang
> provides for a way to handle architecture-specific declarations either.

Unfortunately it doesn't. I need some way to deal with the preprocessor 
in DStep as well, also the Clang developers have showed interested in be 
able to deal with the preprocesssor from libclang.

Clang can of course deal with this. We probably need to expose an 
libclang API for PPCallbacks:

> I don't have any experience with libclang, so I thought I'd run the idea
> by you all first.  Let me know if you see any problems with this idea.

Any help on improving DStep is much appreciated. I can help you out if 
you have an questions about DStep and probably on libclang as well.

/Jacob Carlborg

More information about the digitalmars-d-ldc mailing list