July 24, 2014
On Thursday, 8 May 2014 at 16:16:22 UTC, Joakim wrote:
> Well, Android/x86 for now.  I've been plugging away at getting D running on Android/x86 and got all of the druntime modules' unit tests and 37 of 50 phobos modules' unit tests to pass. I had to hack dmd into producing something like packed TLS for ELF, my patch is online here:
>
> http://164.138.25.188/dmd/packed_tls_for_elf.patch
>
> I simply turned off all TLS flags for ELF and spliced in the el_picvar patch from OS X to call ___tls_get_addr.  Somebody who knows dmd better than me should verify to make sure this is right.
>
> I've also put online preliminary pulls for druntime and phobos:
>
> https://github.com/D-Programming-Language/druntime/pull/784
> https://github.com/D-Programming-Language/phobos/pull/2150
>
> Now that a significant chunk of D is working on Android/x86, I'm looking for others to pitch in.  We really need to get D on mobile, and Android/x86 is an ideal place to start.  Dan Olson has done some nice work getting D on iOS using ldc, I'm sure he could use help too:
>
> http://forum.dlang.org/thread/m2txc2kqxv.fsf@comcast.net
> http://forum.dlang.org/thread/m2d2h15ao3.fsf@comcast.net
>
> Stuff remaining to be done:
>
> 1. Fix all phobos unit tests.  Those who know the failing modules better would be best equipped to get them to work.
>
> 2. I tried creating an Android app, ie an apk, which is really just a shared library called from the Dalvik JVM, as opposed to the standalone executables I've been running from the Android command line so far.  The apk enters the D code and then segfaults in the new TLS support, I'll debug that next.
>
> 3. Use ldc/gdc to build for Android/ARM.
>
> 4. Start translating various headers on Android so they can be called from D, ie EGL, OpenGL ES, sensors, etc.
>
> 5. Integrate the D compilers into the existing Makefile-based build system of the Android NDK.  Right now, I extract the necessary compiler and linker commands and run them by hand when necessary.
>
> All you need to get going is to download the latest Android NDK (http://developer.android.com/tools/sdk/ndk/index.html) and run Android/x86 (http://www.android-x86.org/, I recommend the 4.3 build) in a VM.  I'll put up some basic setup and build instructions if someone is interested.

An update on the porting effort: I just got most modules' unit tests to pass as part of an Android/x86 app, a native "apk," ie a D shared library called from a small C wrapper, no Java required. :)

All druntime/phobos modules but one, std.datetime, passed their tests on the Android/x86 command-line a couple months ago.  Three of those modules segfault when run as part of the tests in an apk- core.thread, std.parallelism, and std.socket- going to look at those next.  I'm guessing the first two might be related to the C wrapper also calling pthreads, as they passed on the command-line.

This means most of 1. and 2. above can be crossed off the list.  I'll start cleaning up my fairly simple build process and document it on the wiki, so that others can easily play with D on Android/x86.  Most of the patches so far have been merged into git master, with the dmd patch above now a PR:

https://github.com/D-Programming-Language/dmd/pull/3643

Only small tweaks were needed beyond that, which I'll submit as PRs in the coming days.  Looking forward to help on 3., 4., and 5. above, and to seeing what others do with this new platform.
July 24, 2014
On Thursday, 24 July 2014 at 01:17:44 UTC, Joakim wrote:
> On Thursday, 8 May 2014 at 16:16:22 UTC, Joakim wrote:
>> Well, Android/x86 for now.  I've been plugging away at getting D running on Android/x86 and got all of the druntime modules' unit tests and 37 of 50 phobos modules' unit tests to pass. I had to hack dmd into producing something like packed TLS for ELF, my patch is online here:
>>
>> http://164.138.25.188/dmd/packed_tls_for_elf.patch
>>
>> I simply turned off all TLS flags for ELF and spliced in the el_picvar patch from OS X to call ___tls_get_addr.  Somebody who knows dmd better than me should verify to make sure this is right.
>>
>> I've also put online preliminary pulls for druntime and phobos:
>>
>> https://github.com/D-Programming-Language/druntime/pull/784
>> https://github.com/D-Programming-Language/phobos/pull/2150
>>
>> Now that a significant chunk of D is working on Android/x86, I'm looking for others to pitch in.  We really need to get D on mobile, and Android/x86 is an ideal place to start.  Dan Olson has done some nice work getting D on iOS using ldc, I'm sure he could use help too:
>>
>> http://forum.dlang.org/thread/m2txc2kqxv.fsf@comcast.net
>> http://forum.dlang.org/thread/m2d2h15ao3.fsf@comcast.net
>>
>> Stuff remaining to be done:
>>
>> 1. Fix all phobos unit tests.  Those who know the failing modules better would be best equipped to get them to work.
>>
>> 2. I tried creating an Android app, ie an apk, which is really just a shared library called from the Dalvik JVM, as opposed to the standalone executables I've been running from the Android command line so far.  The apk enters the D code and then segfaults in the new TLS support, I'll debug that next.
>>
>> 3. Use ldc/gdc to build for Android/ARM.
>>
>> 4. Start translating various headers on Android so they can be called from D, ie EGL, OpenGL ES, sensors, etc.
>>
>> 5. Integrate the D compilers into the existing Makefile-based build system of the Android NDK.  Right now, I extract the necessary compiler and linker commands and run them by hand when necessary.
>>
>> All you need to get going is to download the latest Android NDK (http://developer.android.com/tools/sdk/ndk/index.html) and run Android/x86 (http://www.android-x86.org/, I recommend the 4.3 build) in a VM.  I'll put up some basic setup and build instructions if someone is interested.
>
> An update on the porting effort: I just got most modules' unit tests to pass as part of an Android/x86 app, a native "apk," ie a D shared library called from a small C wrapper, no Java required. :)
>
> All druntime/phobos modules but one, std.datetime, passed their tests on the Android/x86 command-line a couple months ago.  Three of those modules segfault when run as part of the tests in an apk- core.thread, std.parallelism, and std.socket- going to look at those next.  I'm guessing the first two might be related to the C wrapper also calling pthreads, as they passed on the command-line.
>
> This means most of 1. and 2. above can be crossed off the list.
>  I'll start cleaning up my fairly simple build process and document it on the wiki, so that others can easily play with D on Android/x86.  Most of the patches so far have been merged into git master, with the dmd patch above now a PR:
>
> https://github.com/D-Programming-Language/dmd/pull/3643
>
> Only small tweaks were needed beyond that, which I'll submit as PRs in the coming days.  Looking forward to help on 3., 4., and 5. above, and to seeing what others do with this new platform.

Congratulations! I'll definitely give it a try when Android/Arm get ready and I think your great efforts will give D a new life as the best programming language for mobile platform.D may be another ObjC once it runs on Android/iOS stably.
July 24, 2014
On Thursday, 24 July 2014 at 01:17:44 UTC, Joakim wrote:
> This means most of 1. and 2. above can be crossed off the list.
>  I'll start cleaning up my fairly simple build process and document it on the wiki, so that others can easily play with D on Android/x86.  Most of the patches so far have been merged into git master, with the dmd patch above now a PR:
>
> https://github.com/D-Programming-Language/dmd/pull/3643
>
> Only small tweaks were needed beyond that, which I'll submit as PRs in the coming days.  Looking forward to help on 3., 4., and 5. above, and to seeing what others do with this new platform.

Very awesome news. Great work!
August 17, 2014
On Thursday, 24 July 2014 at 01:17:44 UTC, Joakim wrote:
>  I'll start cleaning up my fairly simple build process and document it on the wiki, so that others can easily play with D on Android/x86.
Finally cleaned up my build process a bit and wrote it up on the wiki:

http://wiki.dlang.org/Build_DMD_for_Android

It got a little long, as I don't have everything scripted yet, tried to explain all my steps, and attempted to put everything in one place, including listing the necessary android adb commands.  Hopefully, some of you can help script more of it and eventually integrate D into the Android build scripts.  Let me know if you have any problems with the process.

> Looking forward to help on 3., 4., and 5. above, and to seeing what others do with this new platform.

I finally built a native Android/x86 GUI app in D, translated from a sample C app in the Android NDK, after translating a bunch of android headers and putting them up on github:

https://github.com/joakim-noah/android

Thanks to Jacob Carlborg and the excellent work he's done on dstep, for allowing me to automate translation of most of those headers and save a bunch of time. :) I'll submit the repo to deimos or dub, whichever is the better place to put it.

I'll keep updating the wiki with more info, how to build for the command-line and run the druntime/phobos unit tests, along with directions for future work.
August 18, 2014
On 17/08/14 20:19, Joakim wrote:

> Thanks to Jacob Carlborg and the excellent work he's done on dstep, for
> allowing me to automate translation of most of those headers and save a
> bunch of time. :) I'll submit the repo to deimos or dub, whichever is
> the better place to put it.

Cool :) I recommend dub.

-- 
/Jacob Carlborg
September 03, 2014
Le 17/08/2014 20:19, Joakim a écrit :
> On Thursday, 24 July 2014 at 01:17:44 UTC, Joakim wrote:
>>  I'll start cleaning up my fairly simple build process and document it
>> on the wiki, so that others can easily play with D on Android/x86.
> Finally cleaned up my build process a bit and wrote it up on the wiki:
>
> http://wiki.dlang.org/Build_DMD_for_Android
>
> It got a little long, as I don't have everything scripted yet, tried to
> explain all my steps, and attempted to put everything in one place,
> including listing the necessary android adb commands. Hopefully, some of
> you can help script more of it and eventually integrate D into the
> Android build scripts.  Let me know if you have any problems with the
> process.
>
>> Looking forward to help on 3., 4., and 5. above, and to seeing what
>> others do with this new platform.
>
> I finally built a native Android/x86 GUI app in D, translated from a
> sample C app in the Android NDK, after translating a bunch of android
> headers and putting them up on github:
>
> https://github.com/joakim-noah/android
>
> Thanks to Jacob Carlborg and the excellent work he's done on dstep, for
> allowing me to automate translation of most of those headers and save a
> bunch of time. :) I'll submit the repo to deimos or dub, whichever is
> the better place to put it.
>
> I'll keep updating the wiki with more info, how to build for the
> command-line and run the druntime/phobos unit tests, along with
> directions for future work.

It's maybe more than we need to port DQuick to Android.

Really nice.
May 07, 2015
On Sunday, 17 August 2014 at 18:19:29 UTC, Joakim wrote:
> I'll keep updating the wiki with more info, how to build for the command-line and run the druntime/phobos unit tests, along with directions for future work.

An update: I tinkered with ldc and Android/ARM for the hackathon.  Didn't get that working yet, but I took Dan Olson's advice to reuse the existing llvm TLS function calls and got ldc to work with Android/x86 a couple days ago.

41 of 42 druntime modules' tests pass: only core.internal convert doesn't, but that module's tests aren't normally run by ldc anyway.  Around 15 of 71 phobos modules' tests fail somewhere, most likely related to "long double" issues that either need to be backported, as git master for ldc is still using a year-old druntime/phobos that doesn't have some subsequent Android PRs, or fixed, but I haven't looked into those much yet.  Obviously, I can reuse some of this work for Android/ARM, so it should help.

I'm putting these in-progress patches online, in case my ultrabook gets run over by a bus or someone else would like to tinker with them.  All it required was a small patch to llvm:

https://gist.github.com/joakim-noah/1fb23fba1ba5b7e87e1a

and these patches for ldc, druntime, and phobos:

https://gist.github.com/joakim-noah/bb0b04965470332d10e4
https://gist.github.com/joakim-noah/c27a0c7f2b5b65cdc268
https://gist.github.com/joakim-noah/07ed7ab1e5732ab91126

Most of the druntime and phobos patches were backported from PRs already committed in their respective master branches.  The only real new work is in druntime's rt.sections_ldc.  It's all a bit hacky right now, but I'll clean it up and submit PRs eventually.

I tried the same approach that worked on x86 on ARM, with the similar ARM GOT relocation as can be seen in the llvm patch above, but it didn't work.  I'm reading up on the relevant ELF relocation info and looking at the ARM assembly.  If anybody better versed with those low-level linker details would like to chip in, that should be the last remaining piece to get much of Android/ARM working.
May 08, 2015
On Thursday, 7 May 2015 at 15:58:01 UTC, Joakim wrote:
> On Sunday, 17 August 2014 at 18:19:29 UTC, Joakim wrote:
>> I'll keep updating the wiki with more info, how to build for the command-line and run the druntime/phobos unit tests, along with directions for future work.
>
> An update: I tinkered with ldc and Android/ARM for the hackathon.
>  Didn't get that working yet, but I took Dan Olson's advice to reuse the existing llvm TLS function calls and got ldc to work with Android/x86 a couple days ago.
>
> 41 of 42 druntime modules' tests pass: only core.internal convert doesn't, but that module's tests aren't normally run by ldc anyway.  Around 15 of 71 phobos modules' tests fail somewhere, most likely related to "long double" issues that either need to be backported, as git master for ldc is still using a year-old druntime/phobos that doesn't have some subsequent Android PRs, or fixed, but I haven't looked into those much yet.  Obviously, I can reuse some of this work for Android/ARM, so it should help.
>
> I'm putting these in-progress patches online, in case my ultrabook gets run over by a bus or someone else would like to tinker with them.  All it required was a small patch to llvm:
>
> https://gist.github.com/joakim-noah/1fb23fba1ba5b7e87e1a
>
> and these patches for ldc, druntime, and phobos:
>
> https://gist.github.com/joakim-noah/bb0b04965470332d10e4
> https://gist.github.com/joakim-noah/c27a0c7f2b5b65cdc268
> https://gist.github.com/joakim-noah/07ed7ab1e5732ab91126
>
> Most of the druntime and phobos patches were backported from PRs already committed in their respective master branches.  The only real new work is in druntime's rt.sections_ldc.  It's all a bit hacky right now, but I'll clean it up and submit PRs eventually.
>
> I tried the same approach that worked on x86 on ARM, with the similar ARM GOT relocation as can be seen in the llvm patch above, but it didn't work.  I'm reading up on the relevant ELF relocation info and looking at the ARM assembly.  If anybody better versed with those low-level linker details would like to chip in, that should be the last remaining piece to get much of Android/ARM working.

Good news! Thank you for your work!

Once Android support become working, I'm planning to add Android support to DlangUI library. It's actually a port of C++ UI library I'm using on Android for Cool Reader GL app. So it should not be hard to port it back to Android.

Best regards,
     Vadim
May 08, 2015
On 8/05/2015 6:33 p.m., Vadim Lopatin wrote:
> On Thursday, 7 May 2015 at 15:58:01 UTC, Joakim wrote:
>> On Sunday, 17 August 2014 at 18:19:29 UTC, Joakim wrote:
>>> I'll keep updating the wiki with more info, how to build for the
>>> command-line and run the druntime/phobos unit tests, along with
>>> directions for future work.
>>
>> An update: I tinkered with ldc and Android/ARM for the hackathon.
>>  Didn't get that working yet, but I took Dan Olson's advice to reuse
>> the existing llvm TLS function calls and got ldc to work with
>> Android/x86 a couple days ago.
>>
>> 41 of 42 druntime modules' tests pass: only core.internal convert
>> doesn't, but that module's tests aren't normally run by ldc anyway.
>> Around 15 of 71 phobos modules' tests fail somewhere, most likely
>> related to "long double" issues that either need to be backported, as
>> git master for ldc is still using a year-old druntime/phobos that
>> doesn't have some subsequent Android PRs, or fixed, but I haven't
>> looked into those much yet.  Obviously, I can reuse some of this work
>> for Android/ARM, so it should help.
>>
>> I'm putting these in-progress patches online, in case my ultrabook
>> gets run over by a bus or someone else would like to tinker with
>> them.  All it required was a small patch to llvm:
>>
>> https://gist.github.com/joakim-noah/1fb23fba1ba5b7e87e1a
>>
>> and these patches for ldc, druntime, and phobos:
>>
>> https://gist.github.com/joakim-noah/bb0b04965470332d10e4
>> https://gist.github.com/joakim-noah/c27a0c7f2b5b65cdc268
>> https://gist.github.com/joakim-noah/07ed7ab1e5732ab91126
>>
>> Most of the druntime and phobos patches were backported from PRs
>> already committed in their respective master branches.  The only real
>> new work is in druntime's rt.sections_ldc.  It's all a bit hacky right
>> now, but I'll clean it up and submit PRs eventually.
>>
>> I tried the same approach that worked on x86 on ARM, with the similar
>> ARM GOT relocation as can be seen in the llvm patch above, but it
>> didn't work.  I'm reading up on the relevant ELF relocation info and
>> looking at the ARM assembly.  If anybody better versed with those
>> low-level linker details would like to chip in, that should be the
>> last remaining piece to get much of Android/ARM working.
>
> Good news! Thank you for your work!
>
> Once Android support become working, I'm planning to add Android support
> to DlangUI library. It's actually a port of C++ UI library I'm using on
> Android for Cool Reader GL app. So it should not be hard to port it back
> to Android.
>
> Best regards,
>       Vadim

I'm also looking forward to it. Assuming a getting started tutorial is made, I'll probably get Devisualization.Window support for it as well within a month.
May 08, 2015
"Joakim" <dlang@joakim.fea.st> writes:

> Around 15 of 71 phobos modules' tests fail somewhere, most likely related to "long double" issues that either need to be backported, as git master for ldc is still using a year-old druntime/phobos that doesn't have some subsequent Android PRs, or fixed, but I haven't looked into those much yet.  Obviously, I can reuse some of this work for Android/ARM, so it should help.

Joakim, the ldc merge-2.067 branch works well and has updated druntime/phobos.  I know it has some of your Android updates.  You may have more fun working with it.

> I tried the same approach that worked on x86 on ARM, with the similar ARM GOT relocation as can be seen in the llvm patch above, but it didn't work.  I'm reading up on the relevant ELF relocation info and looking at the ARM assembly.  If anybody better versed with those low-level linker details would like to chip in, that should be the last remaining piece to get much of Android/ARM working.

I am not better versed, but I do like to tinker, so maybe I'll see something this weekend.

I wonder if we should keep a common LLVM fork with changes to support D on targets without builtin TLS?  I did another LLVM hack in x86 backend to support TLS on iPhone sim, and have been thinking about adding a fallback TLS, like emulated tls that gcc and gdc has, to support TLS using a target plugin to get lookup address.  That way it could be wired into any old embedded multi thread RTOS with some sort of thread-local support.

Maybe someday could even get LLVM to accept some patches.