build: track support/static-main.c (was caught by *-main.c ignore)
ober
a305203bf457d6fc1352e4b2a25fd87fdca810a7
--- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ *.wpo *.o target/ -*-main.c +/*-main.c keys/ secmon-agent secmon-agent.sha256 new file mode 100644 --- /dev/null +++ b/support/static-main.c @@ -0,0 +1,55 @@ +/* Custom main.c for a standalone static jerbuild binary (referenced by + * .jerbuild as main-c). Identical to jerbuild's stock template with ONE + * addition: it sets JERBOA_STATIC=1 before building the heap. + * + * The bundled std modules — (std db sqlite-native), (std crypto native-rust), + * etc. — read JERBOA_STATIC at library-load time and, when set, trust the + * jerboa-native symbols that are linked into this binary (and registered via + * register_ffi_symbols() below from the .jerbuild ffi-symbols list) instead of + * trying to dlopen a libjerboa_native.{so,dylib} that does not exist in a + * static build. + */ +#include "scheme.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <fcntl.h> +#include <sys/types.h> + +#include "petite_boot.h" +#include "scheme_boot.h" +#include "program_boot.h" +#include "ffi_symbols.h" + +static const char *write_program_tmpfile(void) { + static char path[] = "/tmp/jerboa-prog-XXXXXX"; + int fd = mkstemp(path); + if (fd < 0) { perror("mkstemp"); exit(1); } + ssize_t n = write(fd, program_boot_data, program_boot_size); + if (n != (ssize_t)program_boot_size) { + perror("write"); close(fd); unlink(path); exit(1); + } + close(fd); + return path; +} + +int main(int argc, const char *argv[]) { + /* Trust the linked-in jerboa-native symbols (see file header). */ + setenv("JERBOA_STATIC", "1", 1); + + Sscheme_init(NULL); + Sregister_boot_file_bytes("petite", + (void *)petite_boot_data, petite_boot_size); + Sregister_boot_file_bytes("scheme", + (void *)scheme_boot_data, scheme_boot_size); + Sbuild_heap(NULL, NULL); + register_ffi_symbols(); + + const char *prog_path = write_program_tmpfile(); + int status = Sscheme_program(prog_path, argc, argv); + unlink(prog_path); + + Sscheme_deinit(); + return status; +}