[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Difficulty integrating with Swift/Objective-C
From: |
Taylan Kammer |
Subject: |
Re: Difficulty integrating with Swift/Objective-C |
Date: |
Mon, 6 Sep 2021 15:11:23 +0200 |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 |
On 06.09.2021 12:21, paul wrote:
> Hello again list, Taylan,
>
> On 2021-09-05 at 18:26 AEST, quoth Taylan Kammer <taylan.kammer@gmail.com>:
>> To narrow down the issue, I'd attempt a few things, in order:
>>
>> 1. Compile only the C code, adding a main() function, just to make sure the
>> OS
>> and the chosen Guile version and such are working fine with each other.
>>
>> 2. Compile pure Objective-C code, calling that run_guile() function firstly
>> directly from the main() function in main.m of the Objective-C
>> program, and
>> commenting out the NSApplicationMain() call that would initialize
>> Apple's
>> application framework.
>>
>> 3. See if reactivating the NSApplicationMain() call causes problems. (It
>> should
>> be called *after* the Guile initialization.)
>>
>> 4. See if you can use Guile's C functions from
>> -applicationDidFinishLaunching:
>> e.g. by doing: scm_c_eval_string("(begin (display 'HelloWorld)
>> (newline))")
>>
>> If that works, we now have an Objective-C + Guile application, and want to
>> move
>> to using Swift instead. This is where my Apple knowledge hits its limits
>> because
>> I never used Swift. :-)
>>
>> But I guess Swift should have something equivalent to the main() function of
>> C and
>> Objective-C, and calling Guile initialization from there might do the trick.
>
> Thank you very much for your tips. I was actually able to unstick myself
> with your suggestions: first i created a blank Objective-C CLI app and
> integrated Guile, that worked well! Next i created a new, blank, Objective-C
> AppKit GUI app. The same procedure worked well there, too.
>
> The more challenging bit was learning how to take my existing Swift app and
> (re-)introduce a main() in Objective-C. Because it turns out that Swift has
> some conveniences that cause it to autogenerate a _main symbol
> behind-the-scenes. In any case you can turn that off and create an
> Objective-C main function (my project didn't have Objective-C to start with,
> but it was enough to create a new file with a main() copied from my earlier
> from-scratch experiments) which - long story short - i was able to modify and
> get Guile booting correctly! I was even able to complete step 4, to my
> surprise (sort of), and call scm_c_eval_string straight from my Application
> Kit code. This takes a bit of fiddling (Apple's so-called Precompiled
> Bridging Header) to make Swift aware of C-land functions, but my app actually
> already has a Rust-based core which i call out to with this mechanism so here
> i was on firmer ground.
>
> I think there must have been something weird about the state of my project
> last night, because initially i was still having the EXC_BAD_ACCESS issues,
> but making a new branch off my main and doing the above worked well.
>
> It should be said that i still couldn't use the Homebrew-packaged version of
> Guile because of the JIT errors i described elsewhere, but this isn't a
> blocker because i'm able to compile my own libguile with `--enable-jit=no`.
>
> Thanks again, i spent all weekend messing with this and couldn't figure it
> out, your input was super useful.
>
> All the best,
> p.
I'm happy to hear it worked, and thanks for reporting back. :-)
Personally I don't do any Apple-related development these days but it's
good to know what does and doesn't work.
--
Taylan