tui-ffi: skip dlopen chain under JERBOA_STATIC
ober
fbf218a84db76034eed3cbfe184b2842e2d98141
--- a/src/jcode/ui/tui-ffi.ss +++ b/src/jcode/ui/tui-ffi.ss @@ -61,21 +61,29 @@ ;; ---- Load shared library ---- (def _shim-loaded - (let ((try-load (lambda (p) - (guard (e [#t #f]) - (and (file-exists? p) - (load-shared-object p)))))) - (or (try-load "jcode_tui_shim.dylib") - (try-load "jcode_tui_shim.so") - ;; Next to the binary - (try-load (path-join (path-directory (car (command-line))) "jcode_tui_shim.dylib")) - (try-load (path-join (path-directory (car (command-line))) "jcode_tui_shim.so")) - ;; ~/.local/bin (common install location) - (try-load (path-join (getenv "HOME") ".local" "bin" "jcode_tui_shim.dylib")) - ;; vendor dir (development) - (try-load "vendor/termbox2/jcode_tui_shim.dylib") - (try-load "vendor/termbox2/jcode_tui_shim.so") - #f))) + ;; In static builds (JERBOA_STATIC=1) the termbox shim is linked into + ;; the binary and its symbols are pre-registered via Sforeign_symbol — + ;; load-shared-object of a named file always fails (dlopen is stubbed), + ;; so skip the chain entirely and trust foreign-entry?. + (let ((static? (let ((v (getenv "JERBOA_STATIC"))) + (and v (not (string=? v "")) (not (string=? v "0")))))) + (if static? + #t + (let ((try-load (lambda (p) + (guard (e [#t #f]) + (and (file-exists? p) + (load-shared-object p)))))) + (or (try-load "jcode_tui_shim.dylib") + (try-load "jcode_tui_shim.so") + ;; Next to the binary + (try-load (path-join (path-directory (car (command-line))) "jcode_tui_shim.dylib")) + (try-load (path-join (path-directory (car (command-line))) "jcode_tui_shim.so")) + ;; ~/.local/bin (common install location) + (try-load (path-join (getenv "HOME") ".local" "bin" "jcode_tui_shim.dylib")) + ;; vendor dir (development) + (try-load "vendor/termbox2/jcode_tui_shim.dylib") + (try-load "vendor/termbox2/jcode_tui_shim.so") + #f))))) ;; Safe FFI binding — returns error-raising lambda if symbol not found (defrule (define-tb name c-name arg-types ret-type)