5.22 Declaring Foreign Libraries Needed at Run Time
| (require ffi/unsafe/runtime-lib) | package: base |
Added in version 9.2.0.6 of package base.
syntax
(define-runtime-lib id maybe-ffi-lib-args [platform-spec lib-spec ...] ... [else else-body ...+])
platform-spec = os-id | os*-id | arch-id | platform-string | 32 | 64 | (or platform-spec ...) | (and platform-spec ...) lib-spec = (so lib-string) | (so lib-string (vers ...)) vers = string | #f maybe-ffi-lib-args =
| #:ffi-lib-args (arg ...)
A platform-spec implies a set of libraries that are loaded in order as enumerated by the accompanying lib-specs, where the lib-string within a lib-spec becomes the first argument to ffi-lib, and the vers sequence (if present) is quoted as the second argument. The defined id is bound to a ffi-lib result for the last lib-spec, or to #f if no lib-specs are present in the matching clause. Besides loading the library for each lib-spec at run time, the libraries are declared at compile time for use by tools such as raco exe and raco dist. Cross compilation is handled automatically, so that the target platforms libraries are listed at compile time, while run time loads libraries suitable to the host platform.
If no platform-spec matches, then id is bound to
the result of the else-body sequence—
Each platform-spec is is compared to the result of (system-type 'os), (system-type 'os*), (system-type 'arch), (system-type 'platform), and/or (system-type 'word). In an and form, all platform-specs much match, while only one matching platform-spec is needed ro an or form.
Extra keyword arguments can be supplied the run-time ffi-lib call for a platform-spec match through an optional #:ffi-lib-args declaration. There’s a single #:ffi-lib-args declaration, because it needs to be independent of the platform-spec that turns out to match. The run-time call receives either an absolute path based on resolved lib-spec, or it receives just the initial lib-string within a lib-spec (due to limitations of define-runtime-path), so #:fail is the most likely useful extra argument to ffi-lib.