From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Olivier Dion via "Bug reports for GUILE, GNU's Ubiquitous Extension Language" Newsgroups: gmane.lisp.guile.bugs Subject: bug#52230: 'guild compile' and C(++) extensions (in the context of LilyPond) Date: Sat, 19 Feb 2022 16:25:41 -0500 Message-ID: <875ypa7dm2.fsf__13567.332345859$1645306008$gmane$org@laura> References: <1fbaea64-8a8f-ea4b-714c-68ced7e1eab8@abou-samra.fr> Reply-To: Olivier Dion Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9355"; mail-complaints-to="usenet@ciao.gmane.io" To: Jean Abou Samra , guile-user@gnu.org, guile-devel@gnu.org, 52230@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Sat Feb 19 22:26:40 2022 Return-path: Envelope-to: guile-bugs@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 1nLXFX-00029b-JZ for guile-bugs@m.gmane-mx.org; Sat, 19 Feb 2022 22:26:39 +0100 Original-Received: from localhost ([::1]:37602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nLXFW-0003Kd-IJ for guile-bugs@m.gmane-mx.org; Sat, 19 Feb 2022 16:26:38 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:56150) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nLXEy-0002Sz-10 for bug-guile@gnu.org; Sat, 19 Feb 2022 16:26:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36704) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nLXEw-0003uZ-SV for bug-guile@gnu.org; Sat, 19 Feb 2022 16:26:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nLXEw-0000qk-4y for bug-guile@gnu.org; Sat, 19 Feb 2022 16:26:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Olivier Dion Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Sat, 19 Feb 2022 21:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 52230 X-GNU-PR-Package: guile Original-Received: via spool by 52230-submit@debbugs.gnu.org id=B52230.16453059563252 (code B ref 52230); Sat, 19 Feb 2022 21:26:02 +0000 Original-Received: (at 52230) by debbugs.gnu.org; 19 Feb 2022 21:25:56 +0000 Original-Received: from localhost ([127.0.0.1]:58834 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nLXEq-0000qO-0h for submit@debbugs.gnu.org; Sat, 19 Feb 2022 16:25:56 -0500 Original-Received: from smtp.polymtl.ca ([132.207.4.11]:45639) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nLXEo-0000qB-By for 52230@debbugs.gnu.org; Sat, 19 Feb 2022 16:25:54 -0500 Original-Received: from localhost (modemcable094.169-200-24.mc.videotron.ca [24.200.169.94]) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 21JLPfFH005985 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 19 Feb 2022 16:25:45 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 21JLPfFH005985 In-Reply-To: <1fbaea64-8a8f-ea4b-714c-68ced7e1eab8@abou-samra.fr> X-Poly-FromMTA: (modemcable094.169-200-24.mc.videotron.ca [24.200.169.94]) at Sat, 19 Feb 2022 21:25:41 +0000 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.io gmane.lisp.guile.bugs:10247 Archived-At: On Sat, 19 Feb 2022, Jean Abou Samra wrote: I had similar problem with Jami. I added C++ primitives to Guile, but these were not load using the foreign function interface. Note, I'm using Guile 3.0.8, but I think the same could be done for Guile 2.0. Basically what I do is to add a `compile` command to my program so to speak. So usually the program does this: main -> install_scheme_primitives() -> Run the program And for compilation main -> compile_in_guile() -> install_scheme_primitives() -> compile-file To be clear here's what install_scheme_primitives() does: -------------------------------------------------------------------------------- void install_scheme_primitives() { /* Define modules here */ auto load_module = [](auto name, auto init){ scm_c_define_module(name, init, NULL); }; load_module("jami account", install_account_primitives); load_module("jami call", install_call_primitives); load_module("jami conversation", install_conversation_primitives); load_module("jami logger bindings", install_logger_primitives); load_module("jami signal bindings", install_signal_primitives); } -------------------------------------------------------------------------------- and here's what compile_in_guile() does: -------------------------------------------------------------------------------- void* compile_in_guile(void* args_raw) { // ... install_scheme_primitives(); // This string is usually formatted scm_c_eval_string("(use-modules (system base compile))" "(compile-file \"foo.scm\" #:output-file \"foo.go\")") // .. } -------------------------------------------------------------------------------- so now I can correctly compile any file in the project. I just add this to Makefile.am: -------------------------------------------------------------------------------- MODULES = foo.scm GOBJECTS = $(MODULES:%=%.go) %.go: %.scm | program @echo GUILD; ./program compile $< $@ -------------------------------------------------------------------------------- Hope that can help. -- Olivier Dion Polymtl