[Feature Request] Build GNU Guile script as a standalone executable

Srayan Jana <[email protected]> Mon, 11 Aug 2025 07:45:55 +0000
Newsgroups gmane.lisp.guile.devel
Message-ID <CH3PR14MB7560ABD91781EB92FA95ACF2E028A@CH3PR14MB7560.namprd14.prod.outlook.com>
Hi!
Long time listener, first time caller. This is my first time using a mailing list so lets hope this works.

For the past week or so, I've been noodling away at a way to compile GNU Guile + scripts to a standalone binary. This is mostly motivated by the fact that Guile seems to have a lot of interesting stuff happening these days, and it would be fun to be able to make a game in it or something that I could distribute on itch.io (like what the Spritely Institute have been doing lately)

I've been keeping a log of my trials and tribulations here:
https://forum.systemcrafters.net/t/how-to-compile-a-simple-guile-program-into-a-standalone-executable/1751/6

The TL;DR is that I forked a repository someone else made, and got a standalone executable working. Yippie!
https://github.com/ValorZard/guile-embed-example

How it works is that it expects a "main.scm" file to exist in the root to execute, and then the main.scm recursively loads everything in the src/ folder.

However, this only works if someone has already installed Guile on their computer, which kinda defeats the purpose.

I started attempting to build Guile from source by adding it as a CMake ExternalProject.

```
cmake_minimum_required(VERSION 3.16)

project(guile-embed-example VERSION 0.0.1)

include(ExternalProject)
ExternalProject_Add(
  GUILE

  GIT_REPOSITORY "https://codeberg.org/guile/guile.git"
  GIT_TAG "main"
  PREFIX ${CMAKE_BINARY_DIR}/guile
  SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/guile
  CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
  CONFIGURE_COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR}/guile && guix shell --container -f ./guix.scm
  BUILD_COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR}/guile && guix build -f guix.scm
  INSTALL_COMMAND ""
)


find_package(PkgConfig)

pkg_check_modules(GUILE guile-3.0 REQUIRED IMPORTED_TARGET)

add_executable(guile-test guile-test.cc)

target_link_libraries(guile-test PkgConfig::GUILE)

file(COPY main.scm DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
file(COPY src DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")

target_compile_options(guile-test
    PRIVATE
        $<$<CONFIG:Debug>:-Wall -Wextra -pedantic -Wshadow -Wunused -Wconversion>
)

install(TARGETS guile-test DESTINATION "." RUNTIME DESTINATION bin)
```


That didn't turn out well since Guile relies so much on Guix. And Guix dumps the binaries it compiles into /gnu/store and not inside of my CMake project, which is not good.

Besides, I also feel like using CMake is a losing battle anyways, since it would tie it to a C++ build system. Instead, what I'd probably want to do is have a guile script that runs and builds everything together. Fortunately, there is prior art: https://git.dthompson.us/chickadee/tree/chickadee/cli/bundle.scm, which was used for davexunit.itch.io/bonnie-bee<https://davexunit.itch.io/bonnie-bee>
https://davexunit.itch.io/super-bloom

The big problem I can think of when it comes to making a more generalized guile build system is that guile relies heavily on the Guix ecosystem, and everything in Guix is installed globally in /gnu/store. (Unless you do guix pack -RR of course). I don't know Guix SUPER well, but I think you could probably have your guile script inside a guix pack, and then run the script once you unzip it. However, I don't think that would work on windows, and also isn't the one-click executable I want.

So I guess after all of this, I really want to hear your thoughts on this effort. Should I keep trying to make this work? I'd love to submit a Pull Request at some point making this all work, but I want to know where I should put my attention into.


________________________________

Srayan Jana