From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: paul Newsgroups: gmane.lisp.guile.user Subject: Re: Difficulty integrating with Swift/Objective-C Date: Mon, 06 Sep 2021 20:21:56 +1000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; format=flowed Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1023"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.4.15; emacs 27.2 To: Taylan Kammer , guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Mon Sep 06 12:22:54 2021 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mNBm9-000AYA-Fl for guile-user@m.gmane-mx.org; Mon, 06 Sep 2021 12:22:54 +0200 Original-Received: from localhost ([::1]:55570 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNBm8-00020Q-Is for guile-user@m.gmane-mx.org; Mon, 06 Sep 2021 06:22:52 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48592) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNBlk-000203-CS for guile-user@gnu.org; Mon, 06 Sep 2021 06:22:30 -0400 Original-Received: from aibo.runbox.com ([91.220.196.211]:50958) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNBlh-0004S3-6c for guile-user@gnu.org; Mon, 06 Sep 2021 06:22:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=inktvis.org ; s=selector1; h=Content-Type:MIME-Version:Message-ID:Date:In-reply-to: Subject:To:From:References; bh=BhzBlBpw7EPvOP9jbfEbfK6R+kLXUL36h7pMr8wZ/z0=; b=GftpsPd2agY34T5WV4T/gfmm12u0/S14F5EAZw2tM/P3Gjjl/zh7TjMebBEEEdV2ZMy7aejB3K 1d5QlAAUZaM53LEgOKk6uKdieQNNpGNsakv8v71WI+hNga1u1UjQG7i/WQIzaE4UeZcq4xCx6JjpZ fZ5JrhqChwe2znmi61QWEjcLsjwJ6sSrqQ6uxF4XX/2Qt1vwvCO6ng9O/EfXTeHEbRl5TquxjSlPV mn2wIVl8/85cApbNy7Y7IRHSmBer8YzGyhx1CSETIwsnPOBW1mr9+KK9qvrwM2Xo/1ks2oisMhboH h4SmejsH2A+sjtBZSnH+J2tXuOmSC4ZjlgWEg==; Original-Received: from [10.9.9.72] (helo=submission01.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1mNBlc-0000vg-Ik; Mon, 06 Sep 2021 12:22:20 +0200 Original-Received: by submission01.runbox with esmtpsa [Authenticated ID (826552)] (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) id 1mNBlM-0002Gc-89; Mon, 06 Sep 2021 12:22:05 +0200 In-reply-to: Received-SPF: pass client-ip=91.220.196.211; envelope-from=paul@inktvis.org; helo=aibo.runbox.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:17717 Archived-At: Hello again list, Taylan, On 2021-09-05 at 18:26 AEST, quoth Taylan Kammer : > 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.