From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Taylan Kammer Newsgroups: gmane.lisp.guile.user Subject: Re: Difficulty integrating with Swift/Objective-C Date: Mon, 6 Sep 2021 15:11:23 +0200 Message-ID: <05d9347b-d424-046c-ecc4-bf9f79c469ff@gmail.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18256"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 To: paul , guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Mon Sep 06 15:17:25 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 1mNEV3-0004dv-Kv for guile-user@m.gmane-mx.org; Mon, 06 Sep 2021 15:17:25 +0200 Original-Received: from localhost ([::1]:59018 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNEV2-00042b-4k for guile-user@m.gmane-mx.org; Mon, 06 Sep 2021 09:17:24 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57398) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNEPP-0000mi-B8 for guile-user@gnu.org; Mon, 06 Sep 2021 09:11:37 -0400 Original-Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]:55016) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNEPN-0007ZA-M0 for guile-user@gnu.org; Mon, 06 Sep 2021 09:11:35 -0400 Original-Received: by mail-wm1-x332.google.com with SMTP id g138so4567169wmg.4 for ; Mon, 06 Sep 2021 06:11:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=bXHLBPPxxYewLeu/jQQWKd40O6qysg118M5E3a+mB0w=; b=pO3pa9EYVM4DSbZJp48l1FepudEYy8KXDcnnzGBpBgEu+ZjLw4KajfSwtdertrQGnC bMSW5bj/6dvDNhhtNG7pwK4Byp3VFqV1erZ7Rz46dr6UXDzYCBjvGTnzOGft8Nyg+t/5 1hAVAeHPdXYEmMwlhjd18ZlHZaUz29Lzjic7UCQSmkzy71tCcmxc0gbgY4l68a71xusg 3zyBxTT/8JpDnQjTALRvAZXAyReHYeH1n+NeVe7635u/MIK8Oek8QHZpSuQ3QcJJS42c MQKK+NGUfgoXD+KjO51FKD2YfYx5rGysLqZIKlMS09/YTlYw6kTJSNo+22uH93mHRYJW McEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=bXHLBPPxxYewLeu/jQQWKd40O6qysg118M5E3a+mB0w=; b=cZpyS8A9CXm4mfngGwSNUu0ih7LELGZPioaGGfZPj+Qf/vWoEKIP01GlFJtBiB1+qL ywO0ExrP1EZaLIwyAoCGCqnpgxkxOINgZn6awCaOJjEByk/g4XLDzgewLwsDd3cgJtZw vTJzvi0gHii7PmCLx8dZN8BNiP4cV3Ss1LzibmmluHMzTXDy5WF8Zh4TsVK0QtK+QP+I tq1KTasq30TlPhiy9JR8pz0IFX4luIRAAbTCi4490io0wpAVUZWiWH5cf+c08nTtowNb r4B0KiPjkXKvJkrzetVYVAQYoaLWD1bRK4ZxmxUFGGQHMgdQLlYbjYyPXEQbgo7KuCDe Ly/Q== X-Gm-Message-State: AOAM532ExxhcJzg0RFav8kA6yq/IgyNh1Z2fpKAmS6YwFrDgJJZx3tXn CK3Gd6kMR5Q5BTMiONepzOxx6QI0+CE= X-Google-Smtp-Source: ABdhPJzG+O4qqA/L/dZ58iKFuSPhbvhdp/bkF3SwtAMifw5xDh09ubtdqK+jLeS5MRM0HHBOFyUH7w== X-Received: by 2002:a1c:3b05:: with SMTP id i5mr11731837wma.136.1630933887381; Mon, 06 Sep 2021 06:11:27 -0700 (PDT) Original-Received: from [192.168.178.20] (b2b-109-90-125-150.unitymedia.biz. [109.90.125.150]) by smtp.gmail.com with ESMTPSA id 129sm7248304wmz.26.2021.09.06.06.11.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 Sep 2021 06:11:26 -0700 (PDT) In-Reply-To: Content-Language: en-US Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=taylan.kammer@gmail.com; helo=mail-wm1-x332.google.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, FREEMAIL_FROM=0.001, NICE_REPLY_A=-2.332, RCVD_IN_DNSWL_NONE=-0.0001, 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:17719 Archived-At: On 06.09.2021 12:21, paul wrote: > 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, bu t 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