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

Binary file not shown.

Binary file not shown.

View File

@@ -3,9 +3,7 @@
(require ffi/unsafe
ffi/unsafe/define
setup/dirs
"../utils/utils.rkt"
racket/runtime-path
"libao-ffi.rkt"
)
@@ -17,20 +15,8 @@
ao_clear_async
)
(define-runtime-path libao-async-lib-path "./lib")
(define lib (if (eq? (system-type 'os) 'windows)
(build-path libao-async-lib-path "ao-play-async")
(build-path libao-async-lib-path "libao-play-async")))
(define-ffi-definer define-libao-async
(ffi-lib lib '("0" #f)
#:get-lib-dirs (λ ()
(let ((sp (cons (build-path ".") (get-lib-search-dirs))))
;(displayln sp)
sp))
#:fail (λ () (error "Cannot load libao-play-async"))
))
(define lib (get-lib '("ao-play-async" "libao-play-async") '(#f)))
(define-ffi-definer define-libao-async lib)
(define _libao-async-handle-pointer (_cpointer 'ao-async-handle))

View File

@@ -2,7 +2,6 @@
(require ffi/unsafe
ffi/unsafe/define
setup/dirs
"../utils/utils.rkt"
)
@@ -27,16 +26,7 @@
)
(define ao_lib (ffi-lib "libao" '("3" "4" "5" #f)
#:get-lib-dirs (λ ()
(let ((sp (cons (build-path ".") (get-lib-search-dirs))))
(displayln sp)
sp))
#:fail (λ ()
(ffi-lib (get-lib-path "libao-4.dll")))
))
(define ao_lib (get-lib '("libao") '("5" "4" "3" #f)))
(define-ffi-definer define-libao ao_lib)
(define _libao-pointer (_cpointer 'ao_device))

View File

@@ -2,7 +2,6 @@
(require ffi/unsafe
ffi/unsafe/define
setup/dirs
"../utils/utils.rkt"
)
@@ -15,14 +14,9 @@
FLAC__int32**
)
(define-ffi-definer define-libflac
(ffi-lib "libFLAC" '(#f)
#:get-lib-dirs (lambda ()
(cons (build-path ".") (get-lib-search-dirs)))
#:fail (lambda ()
(ffi-lib (get-lib-path "libFLAC.dll")))
))
(define lib (get-lib '("libFLAC") '(#f)))
(define-ffi-definer define-libflac lib)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Some FLAC Constants

View File

@@ -2,7 +2,6 @@
(require ffi/unsafe
ffi/unsafe/define
setup/dirs
"../utils/utils.rkt"
)
@@ -45,22 +44,30 @@
)
;(define-ffi-definer define-tag-lib
; (ffi-lib "tag" '("0" #f)
; #:get-lib-dirs (lambda ()
; (cons (build-path ".") (get-lib-search-dirs)))
; #:fail (lambda ()
; (ffi-lib (get-lib-path "tag.dll")))
; ))d
;(define-runtime-path lib-path "..");
;
;(define libs (let ((os-type (system-type 'os*)))
; (if (eq? os-type 'windows)
; (list
; (build-path lib-path "lib" "dll" "tag")
; (build-path lib-path "lib" "dll" "tag_c"))
; (let* ((arch (symbol->string (system-type 'arch)))
; (subdir (string-append (symbol->string os-type) "-" arch)))
; (list
; (build-path lib-path "lib" subdir "libtag")
; (build-path lib-path "lib" subdir "libtag_c"))))))
(define-ffi-definer define-tag-c-lib
(ffi-lib "libtag_c" '("2" #f)
#:get-lib-dirs (lambda ()
(cons (build-path ".") (get-lib-search-dirs)))
#:fail (lambda ()
(let ((path (get-lib-path "tag_c.dll")))
(ffi-lib path)))
))
;(define (get-lib l)
; (ffi-lib l '("2" #f)
; #:get-lib-dirs (λ ()
; (cons (build-path ".") (get-lib-search-dirs)))
; #:fail (λ ()
; (error (format "Cannot find library ~a" l)))
; ))
(define libtag (get-lib '("tag" "libtag") '("2" #f)))
(define libtag_c (get-lib '("tag_c" "libtag_c") '("#2" #f)))
(define-ffi-definer define-tag-c-lib libtag_c)
(define TagLib_File_Type
(_enum '(

View File

@@ -1,7 +1,8 @@
#lang racket/base
(require "libao/libao.rkt"
"libflac/flac-decoder.rkt"
data/queue
(require ;"libao/libao.rkt"
;"libflac/flac-decoder.rkt"
;data/queue
racket-sound
)
(define test-file3 #f)

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