Reordering FFI libs

This commit is contained in:
2026-02-23 08:20:04 +01:00
parent 4afca18124
commit 4920457282
10 changed files with 62 additions and 73 deletions

View File

@@ -1,8 +1,15 @@
(module utils racket/base
(require racket/path
racket/runtime-path
ffi/unsafe
setup/dirs
)
(provide while
until
get-lib-path
build-lib-path
get-lib
do-for
)
@@ -47,23 +54,27 @@
(do-for-f))))))
(do-for-f))))))
(define (get-lib-path lib)
(let ((platform (system-type)))
(cond
[(eq? platform 'windows)
(let ((try1 (build-path (current-directory) ".." "lib" "dll" lib))
(try2 (build-path (current-directory) "lib" "dll" lib)))
(if (file-exists? try1)
try1
try2)
)]
[(eq? platform 'unix)
(let ((try1 (build-path (current-directory) "lib" lib)))
(when (file-exists? try1)
try1))]
[else
(error (format "Install the shared library: ~a" lib))]
)))
(define-runtime-path lib-path "..")
(define (build-lib-path)
(let ((os-type (system-type 'os*)))
(if (eq? os-type 'windows)
(build-path lib-path "lib" "dll")
(let* ((arch (symbol->string (system-type 'arch)))
(subdir (string-append (symbol->string os-type) "-" arch)))
(let ((path (build-path lib-path "lib" subdir)))
path)))))
(define (get-lib* libs-to-try orig-libs versions)
(if (null? libs-to-try)
(error (format "Cannot find library, tried ~a" orig-libs))
(ffi-lib (car libs-to-try) versions
#:get-lib-dirs (λ () (cons (build-lib-path) (get-lib-search-dirs)))
#:fail (λ () (get-lib* (cdr libs-to-try) orig-libs versions))
)))
(define (get-lib libs-to-try versions)
(get-lib* libs-to-try libs-to-try versions))
) ; end of module