Adam does iOS "goodbye world"
Posted 2019-10-07
Blog
Articles- terminal.d gets clipboard functions, ldc 1.20 out.
- DConf keynote speaker announced: Lua architect Roberto Ierusalimschy, Named args DIP discussed
- February 3, 2020
- Adam's terminal suite explained
- Understanding mixin templates, terminal.d improvements
- My attribute-by-default proposal. Also dmd 2.090 came out.
- DConf 2020 announced: June 17-20 in London. @safe by default debated. Adam did: Android, JNI, WebSocket in arsd libs
- tar.xz, --DRT tip, dom bug fixes, more Android and JNI, link to old phobos docs
- LDC 1.19 - Android, AVR. My rant on tests, update on JNI and COM.
- Walter's string interpolation proposal is OK but not great. My Android thing nearing beta release. dub downtime explained.
- Android project update, introduction to arsd.jni
- New pattern about interface contracts
- Adam shares Windows console secrets - DO NOT USE chcp!!
- Adam's rant on benchmarks
- Socket tutorial
- November 4, 2019
- October 28, 2019
- arsd package updates, forum nonsense
- Update on Android
- Adam does iOS "goodbye world"
- September 30, 2019
- D turns 20, Adam rants on software freedom
- Named arg DIPs and my thoughts on code organization
- September 9, 2019
- I wrote about mixin templates vs string mixins on Stack Overflow
- August 26, 2019
- Bug bounty in D again - my hot take, on reusing code, a fun picture, my tentative plan for the next month
- Time invested is worth a lot
- cgi.d's new scheduler, static this tricks
- July 29, 2019
- July 22, 2019
- Solving vs managing problems
- A big week in the arsd repo
- July 1, 2019
- June 24, 2019
- June 17, 2019
- CRTP thoughts, named arguments DIP review, DConf videos now on youtube
- musings on hybrid CT/RT tests, some more progress on new web framework
- a little more webassembly
- May 20, 2019
- Adam's string interpolation proposal
- DMD 2.086 live, GCC 9 with D support formally released, DConf coming soon, links to posts on builder pattern and disallowing implicit conversions with templates, and 2d array op overloads
- template constraint error improvements coming?
- dmd 2.086 beta, dstep 1.0 released, Adam works on memory usage
- obj-c and webassembly report, tips on is expressions linked.
- new ldc, new dmd, dpp on the blog
- D's future discussed in forums
- LDC beta, DConf blog link, Adam introduces gamehelpers.d
- March 18, 2019
- LDC 1.15.0-beta1, responsive design rant
- dmd 2.085.0 released
- Obj-C interop and D without druntime code to copy/paste
- dmd beta, more info coming next time, demo of new web framework initial prototype
- automatic web interface discussion, reflection tips and tricks
- Adam busy with weather and a move, lots of community announcements
- January 28, 2019
- Working on official blog 2018 retro, C++ new wrapped, dmd reading zips?
- dmd obj-c growing, Adam static foreaches an interface to RPC
- dmd 2.084, hope for future, but busy non-D week for me
- IDE tools released, my cgi.d gets new features
- DConf announced, tip, Adam rants: mouse trap
- This Week in D is back!
Core D Development Statistics
In the community
Community announcements
See more at the announce forum.
What Adam is working on
So much stuff these last few days.
cgi.d has compatibility with Musl libc Linux builds now, both plain cgi mode and embedded_httpd_threads tested successfully. Had to fight druntime's overly-conservative Posix headers, and Phobos' LockingTextWriter not working. But was able to work around them thanks to the help of bug2000 on irc.
dom.d, simpledisplay.d, and a few others tested in gdc. They work. Alas cgi.d does not... static foreach was too alluring. I might come back to it.
I also played with ldc for android. I'll write about that next week.
But the big thing is mere minutes ago, I got D working on iOS! Well, sort of. Let's get into the details.
D on iOS
The D Foundation is looking for someone to do this, and I said no because I didn't think I could do it. But I had to set up some osx vm stuff for simpledisplay development anyway... and since it was sitting there, the allure made me spend today on messing with xcode anyway.
Step 1: build a hello world with objective C. Took forever to download all the spam, but it worked!
Step 2: add a button to it. Again, took WAY longer than it probably should have since I know literally nothing about this (I couldn't even find the menu bar for a while LOL), but got it in. Had it call a ViewController method. Since I don't know anything about iOS, I just had it write to a null pointer. When it crashed successfully, I rejoiced.
Step 3: make the controller call a C function that crashed. Easy enough, though adding the .o file was kinda a pain. Had to add it to the xcode project... then add it again, since apparently the first time only added it to the file list, not the build. Oh well.
Step 4: move that from a C file to a D file, with extern(C). Trivial. Actually, even dmd was able to do it! (The iPhone simulator in Xcode actually runs x86_64 code. And there was much rejoicing.)
Step 5: move that ViewController's implementation over to D, using extern(Objective-C). Failed. Failed. Failed. I almost gave up, then I started to xxd test.o.
This is where things got interesting: the storyboard thing complained it couldn't find the ViewController class. Yet I'd get linker errors on duplicate definition if I did it in D and ObjC. Why oh why could it not find what was obviously there?
Turns out D's objective C glue wasn't outputting one specific detail needed. Time to hack dmd's source and add it in... compile... and OMG THE D CLASS GOT CALLED.
This is huge. Now, knowing this works, I can take further steps - defining that view class means I can define *any* class in D and have it work. It means we can use xcode for the interface designer and final linking but not the main code (you just bring in the object file from the outside, and I believe we can have Intel and ARM builds in the same file). Can probably even copy the commands out of xcode and cut it off entirely if we want.
I'll see about putting my dmd change upstream later, then see if we can use ldc to actually generate the arm code too. Probably compile the D runtime on it too... hopefully it is similar enough to osx that a cross compile is reasonable.
Took a LOT longer than I thought but this success is very encouraging.