unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* bug#52230: 'guild compile' and C(++) extensions (in the context of LilyPond)
       [not found] <24ba24dc-004e-7c00-96eb-ea2412d2e89b@abou-samra.fr>
@ 2022-02-19 21:08 ` Jean Abou Samra
  2022-02-19 21:25   ` Olivier Dion via Developers list for Guile, the GNU extensibility library
  0 siblings, 1 reply; 3+ messages in thread
From: Jean Abou Samra @ 2022-02-19 21:08 UTC (permalink / raw)
  To: guile-user, guile-devel, 52230

Hi,

(Cross-posted to guile-user, guile-devel and the debbugs
issue, I'm unsure where this should go.)

In LilyPond, we have now made a development release with
binaries using Guile 2.2. However, a major problem is that
we don't ship Guile bytecode yet. Notably, one problem
to get the bytecode in a build system is that we are
currently forced to use GUILE_AUTO_COMPILE=1 to generate
it -- which means we need to compile the entire suite of
regression tests in order to exercise all files. This
also means spurious test differences when Guile gets
noisy about byte-compilation 
(https://debbugs.gnu.org/cgi/bugreport.cgi?bug=16364).
In summary: it would mean a lot less headache to be
able to use 'guild compile'. Unfortunately, this does
not work. One issue is that our Scheme files are mostly
not Guile modules, but loaded directly with primitive-load-path.
This will be a lot of work to fix, but it is on our end.
However, I don't understand how to get around another
issue, which is how our Scheme code interfaces with C++.

   https://debbugs.gnu.org/cgi/bugreport.cgi?bug=52230

Basically, if a Scheme file has something like

   (define-public point-stencil (ly:make-stencil "" '(0 . 0) '(0 . 0)))

where ly:make-stencil is a procedure defined in C++,
I can get this file to compile, but I can't get files
using it as a module to compile. Investigation shows
that Guile is apparently trying to load the module
when compiling.

$ cat print.scm
(define-module (print))

(display "Module running!")
$ guild compile print.scm
wrote 
`/home/jean/.cache/guile/ccache/3.0-LE-8-4.4/home/jean/repos/lilypond/print.scm.go' 

$ cat import.scm
(use-modules (print))
$ guild compile -L . print.scm
wrote 
`/home/jean/.cache/guile/ccache/3.0-LE-8-4.4/home/jean/repos/lilypond/print.scm.go' 

$ guild compile -L . import.scm
Module running!wrote 
`/home/jean/.cache/guile/ccache/3.0-LE-8-4.4/home/jean/repos/lilypond/import.scm.go' 



For functions defined in C++, that does not work: they
are added by the entry point in the function that scm_boot_guile
calls, using scm_c_define_gsubr. They aren't defined until
the program is actually run.

So how is 'guild compile' supposed to work with C(++) code?

Thanks in advance,
Jean






^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: 'guild compile' and C(++) extensions (in the context of LilyPond)
  2022-02-19 21:08 ` bug#52230: 'guild compile' and C(++) extensions (in the context of LilyPond) Jean Abou Samra
@ 2022-02-19 21:25   ` Olivier Dion via Developers list for Guile, the GNU extensibility library
  2022-02-22  6:34     ` Jean Abou Samra
  0 siblings, 1 reply; 3+ messages in thread
From: Olivier Dion via Developers list for Guile, the GNU extensibility library @ 2022-02-19 21:25 UTC (permalink / raw)
  To: Jean Abou Samra, guile-user, guile-devel, 52230

On Sat, 19 Feb 2022, Jean Abou Samra <jean@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.

-- 
Olivier Dion
Polymtl



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: 'guild compile' and C(++) extensions (in the context of LilyPond)
  2022-02-19 21:25   ` Olivier Dion via Developers list for Guile, the GNU extensibility library
@ 2022-02-22  6:34     ` Jean Abou Samra
  0 siblings, 0 replies; 3+ messages in thread
From: Jean Abou Samra @ 2022-02-22  6:34 UTC (permalink / raw)
  To: Olivier Dion, guile-user, guile-devel, 52230



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




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-02-22  6:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <24ba24dc-004e-7c00-96eb-ea2412d2e89b@abou-samra.fr>
2022-02-19 21:08 ` bug#52230: 'guild compile' and C(++) extensions (in the context of LilyPond) Jean Abou Samra
2022-02-19 21:25   ` Olivier Dion via Developers list for Guile, the GNU extensibility library
2022-02-22  6:34     ` Jean Abou Samra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).