GNU bug report logs - #52230
Variable not visible to compiler causes compilation failure when importing module

Previous Next

Package: guile;

Reported by: Jean Abou Samra <jean <at> abou-samra.fr>

Date: Wed, 1 Dec 2021 21:55:02 UTC

Severity: normal

Full log


Message #14 received at 52230 <at> debbugs.gnu.org (full text, mbox):

From: Jean Abou Samra <jean <at> abou-samra.fr>
To: Olivier Dion <olivier.dion <at> polymtl.ca>, guile-user <at> gnu.org,
 guile-devel <at> gnu.org, 52230 <at> debbugs.gnu.org
Subject: Re: 'guild compile' and C(++) extensions (in the context of LilyPond)
Date: Tue, 22 Feb 2022 07:34:10 +0100

Le 19/02/2022 à 22:25, Olivier Dion a écrit :
> On Sat, 19 Feb 2022, Jean Abou Samra <jean <at> abou-samra.fr> 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.



Thank you Olivier, this is hugely helpful. So far we thought
we'd need to restructure our set of Scheme files in proper
modules to make separate byte-compilation happen. This works
in my experiments, and can compile several files that are
part of the same module as well, using the #:env argument
of compile-file. Thanks again, much appreciated.

Best regards,
Jean





This bug report was last modified 3 years and 114 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.