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 "Developers list for Guile, the GNU extensibility library" Newsgroups: gmane.lisp.guile.devel,gmane.lisp.guile.user Subject: Re: 'guild compile' and C(++) extensions (in the context of LilyPond) Date: Sat, 19 Feb 2022 16:25:41 -0500 Message-ID: <875ypa7dm2.fsf@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="7663"; 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: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Sat Feb 19 22:26:22 2022 Return-path: Envelope-to: guile-devel@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 1nLXFG-0001n0-8g for guile-devel@m.gmane-mx.org; Sat, 19 Feb 2022 22:26:22 +0100 Original-Received: from localhost ([::1]:36320 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nLXFF-0002Sx-4O for guile-devel@m.gmane-mx.org; Sat, 19 Feb 2022 16:26:21 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:56148) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nLXEv-0002Sk-L7; Sat, 19 Feb 2022 16:26:01 -0500 Original-Received: from smtp.polymtl.ca ([132.207.4.11]:60683) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nLXEq-0003uF-Ka; Sat, 19 Feb 2022 16:25:59 -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 Received-SPF: pass client-ip=132.207.4.11; envelope-from=olivier.dion@polymtl.ca; helo=smtp.polymtl.ca X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.io gmane.lisp.guile.devel:21133 gmane.lisp.guile.user:18110 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