Compiling Boot With Library

231 views
Skip to first unread message

Mark Damon Hughes

unread,
Jan 6, 2018, 1:46:19 PM1/6/18
to chez-scheme
Supposing that I have two source files:

stdlib.ss:
---
(library (stdlib)
(export foo)
(import (chezscheme))
(define (foo) (format #t "foo~%"))
)
---

foo.ss:
---
#!/usr/bin/env scheme-script
(import (chezscheme))
(load "stdlib.ss")
(import (stdlib))
(foo)
---

% ./foo.ss

Works fine.

I want binaries, or as close as I can get, so I write the following build script:

build.zsh:
---
#!/bin/zsh
rm -f *.so *.wpo
cat <<ENDTEXT |scheme -q --optimize-level 3
;;(generate-wpo-files #t)
(compile-file "stdlib.ss")
(compile-file "$1.ss")
(make-boot-file "$1.boot" '("scheme" "petite") "$1.so" "stdlib.so")
ENDTEXT
---

If I `./build.zsh foo`, I get .so files for stdlib and foo, and foo.boot, but running fails:

% scheme foo.boot
Chez Scheme Version 9.5
Copyright 1984-2017 Cisco Systems, Inc.
Exception: compiled program requires different compilation instance of (stdlib) from one already loaded

What's going on? What's the distinction between .so, .wpo (currently turned off in build.zsh, as they didn't help), and .boot? When and how would compile-whole-program be different or useful?

There's no clear example of a multi-file application program in the manual or examples.

Graham Watt

unread,
Jan 6, 2018, 4:32:26 PM1/6/18
to chez-scheme
I played around with your code and it looks like the problem is the line
(load "stdlib.ss")
in foo.ss
Since stdlib.so is included in the boot file, loading it later results in two different instances of the library being loaded, which is not allowed by Chez.

In Chez parlance so is "scheme object", wpo is "whole program optimization" file, and boot files contain the core parts of Chez. The wpo files allow for cross-library optimizations, similar to link time optimizations that some linkers perform. https://en.wikipedia.org/wiki/Interprocedural_optimization compile-whole-program is nice because you can generate a single file that contains all files needed to run your program.
(compile-imported-libraries #t)
(generate-wpo-files #t)
(compile-program "foo.ss")
(compile-whole-program "foo.wpo" "foo")
Now you can move foo wherever you want and run the following:
scheme --program foo
That's all you need! (If you use "load" to access code, that file will NOT be included in the result of compile-whole-program)

You mentioned wanting to build a binary. I have project that will take a r6rs scheme program and turn it into a redistributable executable: https://github.com/gwatt/chez-exe/ It's currently only tested on linux and mac osx.

Mark Damon Hughes

unread,
Jan 7, 2018, 6:39:12 AM1/7/18
to chez-scheme
OK, that makes sense, though it's surprising that I can just import and have it look up the library!

I'll be checking out your project; it'd be nice to get a Windows binary, too, but that's hard for me to test anyway.

Reply all
Reply to author
Forward
0 new messages