#ldc2 and macOS/iOS target

1 messages · Page 1 of 1 (latest)

strange tusk
#

Hello, I haven't been here for a while. I've seen and tested that ⁨⁨⁨⁨extern (Objective-C)⁩⁩⁩⁩ is working now to access macOS/Cocoa API's on Arm64 Macs. Very nice, thanks! 🙏 👍
Any progress/news with a LDC iOS runtime (iPhone/iPad)? Anything useable yet? 50%, 80%, 100% working? Full support for classes, garbage collection? 🤔 ⁨⁨```D
//
// ldc2 -L-framework -LFoundation main.d && ./main
//
module app;

import core.attribute : selector;

extern (Objective-C)
extern class NSString {
static NSString alloc() @selector("alloc");

// mutable
// NSString initWithUTF8String(char* str) @selector("initWithUTF8String:");

// immutable
NSString initWithUTF8String(immutable char* str) @selector("initWithUTF8String:");

void release() @selector("release");

}

extern (C) void NSLog(NSString, ...);

void main() {
// mutable version
//char* text = "Hello World!\0".dup.ptr;
//auto str = NSString.alloc().initWithUTF8String(text);
//auto str = NSString.alloc().initWithUTF8String("Hello World!\0".dup.ptr);

// immutable version
auto str = NSString.alloc().initWithUTF8String("Hello World!\0".ptr);

NSLog(str);
str.release();

}

cerulean mauve
#

the ios druntime has been there for a long time

strange tusk
#

Classes didn't work, only basic BetterC stuff. That was like round about 1 year ago. What is "a long time" for you? 😉

#

So everything working now, we can develop iOS apps out-of-the-box? Neat! 👍

cerulean mauve
#

it was all implemented prior to 2019 when i first did some of the fixes.......

#

extern(Objective-C) full support is new, i shipped that in opend in October 2024 and upstream followed a few months later

but the actual druntime stuff, gc etc, has all worked for ages. ldc has shipped with ios druntime this whole time

strange tusk
#

Do you have a minimalistic example app? Just a simple iOS app that displays a button and a dialog box on iPhone and iPad when pressed? I have not seen anything like this 1 or 2 years ago - i must have missed it.

cerulean mauve
#

but that's different from druntime lol you can download an old ldc and do like string a; a ~= "foo"; and use druntime it just won't display anything without either an extern(C) call into objc runtime or a objc helper file

#

extern(Objective-C) is about making it easy to interface with the operating system

betterC has never been a requirement on ios. maybe you're just mixing it up cuz ⁨extern(Objective-C) class ....⁩ wasn't implemented on ldc ios until opend did it

strange tusk
#

Thanks! I will check it out! 🙏 👍

cerulean mauve
#

thanks to luna here for doing a lot of fixes too for arm mac

strange tusk
cerulean mauve
#

in opend yes, upstream no

strange tusk
#

Ok. 👍

cerulean mauve
#

i actually did them almost back to back lol

strange tusk
#

Thank you! 🙏

fickle pine
#

So to run such code libphobos.dylib should be provided within the application? as static build is not available I suppose

cerulean mauve
#

ummm no?

#

ldc comes with dynamic and static, same as any other target, static is the default choice

fickle pine
#

I thought Apple is forbidding static builds 🙂

strange tusk
#

Now i'm confused, @fickle pine

cerulean mauve
fickle pine
#

druntime should be available I think. Phobos probably not included..

strange tusk
#

So the D system is only half-available on iOS?

fickle pine
cerulean mauve
#

stop spreading bullshit with no evidence

fickle pine
#

if you just build "empty" dynamicLibrary - libadam_is_cool.dylib
and copy it - its not gonna work

strange tusk
#

Thanks to both of you! 🙏 I will try it out, but it sounds like full iOS application development still isn't a thing out-of-the-box. Not supported by default D system. Same for WASM web development. 👍

#

At least macOS Arm64 app development should be possible now.

fickle pine
#

I don't think that full iOS app development is recommended in any case...
What I'm doing and interested in - is to have iOS app (UI) + shared library (D) for performant parts of the app

#

macos arm is supported since M1.. like 3 years at least now - but only LDC

strange tusk
#

Objective-C import didn't work with LDC < 1.40.0

fickle pine
#

oh Obj-C is now fixed yeah

#

and Framework support was improved recently

strange tusk
#

What do you use for iOS GUI when you use D for the performance part?

fickle pine
#

Currently it is Flutter app

strange tusk
#

Do you combine D with Dart?

cerulean mauve
strange tusk
#

Could probably write everything using Flutter/Dart

fickle pine
strange tusk
#

So the reason for the mix is not that D is faster, it's missing knowledge

cerulean mauve
#

could write everythign using D too

fickle pine
#

yes to both of you 🙂

strange tusk
#

👍

#

Thanks, i will try it 👍

swift cairn
#

@lavish wasp

lavish wasp
#

But ⁨extern(Objective-C)⁩ should support everything needed, both in upstream D and in OpenD if @cerulean mauve has merged back my improvements

#

There's also experimental support for Swift Objective-C Stub Classes in LDC

#

(Which is important for some newer APIs)

#

My objective-d dub package provides bindings to Foundation and Core Foundation (still incomplete as of now)

cerulean mauve
lavish wasp
#

But there should overall be enough infrastructure in place to make iOS apps purely in D without ever needing more than the xcode command line tools

cerulean mauve
#

but yeah i didn't ever go far, basically just that hello world button, but it was pure D and worked fine

lavish wasp
#

mmm if I remember correctly you still relied on xcode stuff to host the button, no?

#

No pure D creation of the app delegate?

#

Or do I misremember

cerulean mauve
#

you can do either, i played with both