Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
- Add an opt-in Linux `InstallShutdownHook` for SIGTERM/SIGINT. Its
async-signal-safe self-pipe hands graceful state flushing to a normal watcher
thread, while a repeated signal still terminates a stuck shutdown.
- Compile the Racket backend dependency graph with `raco make` before creating
`core.zo`, so a same-length edit to a transitive source module cannot leave
stale bytecode in a successful native build.
- Add the Linux tray contract: `rivet::system::TrayIcon` hosts an
org.kde.StatusNotifierItem with a com.canonical.dbusmenu menu over the
session bus (GDBus), the pairing every desktop watcher serves (GNOME via
Expand Down
30 changes: 21 additions & 9 deletions rivet-cli/build.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,7 @@
(make-directory* runtime-dir)

(define core (build-path res-dir "core.zo"))
(define raco (find-executable-path "raco"))
(run! 'build-project!
raco
"ctool"
"--runtime" (path->string runtime-dir)
"--runtime-access" "runtime"
"--mods" (path->string core)
(path->string backend))
(compile-backend-module-bundle! backend core runtime-dir)

(for ([source (in-list
(list (racket-runtime-petite-boot runtime)
Expand All @@ -172,6 +165,24 @@
(build-path runtime-dir (file-name-from-path source))))
core)

(define (compile-backend-module-bundle! backend core [runtime-dir #f])
(define raco (find-executable-path "raco"))
;; `raco ctool --mods` can consume an existing compiled entry module without
;; refreshing its transitive dependencies. Compile the dependency graph first
;; so same-length source edits cannot leave stale bytecode in the bundle.
(run! 'build-project! raco "make" (path->string backend))
(apply run!
'build-project!
raco
"ctool"
(append
(if runtime-dir
(list "--runtime" (path->string runtime-dir)
"--runtime-access" "runtime")
'())
(list "--mods" (path->string core)
(path->string backend)))))

(define (prepare-windows-import-library! project runtime lib-exe)
(unless lib-exe
(error 'build-project!
Expand Down Expand Up @@ -484,4 +495,5 @@
(provide copy-project-resources!
write-app-info!
required-project-icon
prepare-windows-icon-resource!))
prepare-windows-icon-resource!
compile-backend-module-bundle!))
48 changes: 48 additions & 0 deletions tests/backend-build.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#lang racket/base

(require rackunit
racket/file
(submod "../rivet-cli/build.rkt" test-support))

(define temp-root (make-temporary-file "rivet-backend-build-~a" 'directory))
(define dependency-before
"#lang racket/base\n(provide value)\n(define value 'before)\n")
(define dependency-after
"#lang racket/base\n(provide value)\n(define value 'after!)\n")

(define (write-module path text)
(call-with-output-file path
#:exists 'truncate/replace
(lambda (out) (display text out))))

(dynamic-wind
void
(lambda ()
(define backend (build-path temp-root "backend.rkt"))
(define dependency (build-path temp-root "dependency.rkt"))
(define bundle (build-path temp-root "core.zo"))
(define compiled-dependency
(build-path temp-root "compiled" "dependency_rkt.zo"))

(write-module backend
"#lang racket/base\n(require \"dependency.rkt\")\n(provide result)\n(define result value)\n")
(check-equal? (string-length dependency-before)
(string-length dependency-after))
(write-module dependency dependency-before)
(compile-backend-module-bundle! backend bundle)
(define before (file->bytes compiled-dependency))

;; Keep the source length unchanged while making it newer than the cached
;; bytecode, matching the regression reported by a real Rivet application.
(write-module dependency dependency-after)
(define source-time (file-or-directory-modify-seconds dependency))
(for ([compiled (in-list
(list compiled-dependency
(build-path temp-root "compiled" "dependency_rkt.dep")))])
(file-or-directory-modify-seconds compiled (sub1 source-time)))
(compile-backend-module-bundle! backend bundle)

(check-not-equal? (file->bytes compiled-dependency) before)
(check-true (file-exists? bundle)))
(lambda ()
(delete-directory/files temp-root)))
Loading