How to compile a simple guile program into a standalone executable?

Hi!

say I have a guile file that just consists of

`(display “Hello, Guile!”)`

How do I compile that into a standalone executable. It SEEMS like I could make a guix shell maybe and then figure out how to compile that into a standalone image or something I can share with people, but I’m not totally sure.

Also, there doesn’t seem to be any documentation on how to create a proper guix.scm file, other than dthompsons example in his article. I guess I just have to copy it and modify it a little?

Here are two of the links I looked into:

2 Likes

So to be clear, what I want is to compile my little guile program into a standalone executable, and then send that to someone else, and that other person can just go

`./my_cool_program` in the terminal

and “Hello, Guile!” will print out

Okay so after taking with David Thompson on Mastodon, seems like this isn’t currently possible

But then, the question arises, is there a way to make a super simple C wrapper that calls Guile and starts up the runtime? That way, all I need is one `bootstrap.c` file that i need to compile and run.

So what I’m thinking in terms of folder structure is something like

my cool project

  • /git-submodule-to-guile

  • bootstrap.c

  • hello_guile.scm

  • Makefile

And then by running `make` you startup your guile program

For posterity: I figured out how to compile a guile file, and then run that guile file.

$ cat hello.scm
(display "hello, world\n")

$ guild compile -o hello.go hello.scm
wrote `hello.go'

$ guile -c '(load-compiled "hello.go")'
hello, world

We still can’t go from this to a standalone exe though.

Okay so I kinda got it working

The idea is that you bundle your guile scheme scripts using CMake, and then load in your “main” script in the c program to start it up.

This works but it uses CMake, and I don’t think I can bundle other guile libraries with it (like guile-websocket or threads). It’s also pretty fragile since I’m just copying the scheme files using CMake, which is NOT recommended.

So the next step would be to somehow switch out CMake for Guix somehow I think so I can bundle everything together nicely

(I really hope its okay if I keep posting updates/discoveries I find. Mods/Admins, feel free to scold me)

dthompson mentioned that they did something sort of like this for their lisp game jams.

So I know that if I keep going down this path, it’s probably doable somehow.

2 Likes

If you want your guile program run in the terminal, you can do script with

#!/usr/local/bin/guile -s
!#
(display "Hello, world!")
(newline)

Please check

https://www.gnu.org/software/guile/manual/html_node/Guile-Scripting.html#:\~:text=A%20Guile%20script%20is%20simply%20a%20file%20of,tells%20Guile%20how%20to%20handle%20the%20Scheme%20code.

Maybe looking at Nuitka, that does compile Python to an executable, can help?

If I remember correctly the project lead is quite approachable.