Consolidates the per-package FFI-lib finders: every package that
owned a C-side helper carried its own _find_flare_*_lib
helper -- 7 callers, 4 lookalike implementations of the same
CONDA_PREFIX / bare-checkout fallback search. Different
return values for
"library not present" ("build/libflare_X.so" vs
"libflare_X.so"); identical search order otherwise.
This module is the single canonical home. Each call site that
opens a flare-bundled shared object goes through
:func:find_flare_lib; the bundled shim's name (the X in
libflare_X.so) is the only argument.
Library naming convention
flare bundles four FFI shims under $CONDA_PREFIX/lib/:
libflare_tls.so -- OpenSSL hooks (TLS handshake, AEAD,
hkdf, hmac, sha1) plus the flare_read / flare_write
thin wrappers used by the io_uring reactor's hot path.
libflare_zlib.so -- zlib + gzip + raw-deflate thin
wrappers consumed by :mod:flare.http.encoding (HTTP
Content-Encoding) and :mod:flare.ws.permessage_deflate
(WebSocket permessage-deflate).
libflare_brotli.so -- libbrotlienc + libbrotlidec
consumed by :mod:flare.http.encoding for Content-Encoding: br.
libflare_fs.so -- access(2) + open(2) +
read(2) + close(2) thin wrappers consumed by
:mod:flare.http.fs (FileServer static-file path).
Search order (used by every call site):
$FLARE_LIB_DIR/libflare_<name>.so -- when FLARE_LIB_DIR is
an absolute path; for running outside pixi.
$CONDA_PREFIX/lib/libflare_<name>.so -- the canonical
install location, populated by flare/<sub>/ffi/build.sh
on pixi activation.
<exe dir>/libflare_<name>.so and <exe dir>/../lib/...,
the running executable's directory (symlinks resolved) -- for a
binary shipped next to its libraries.
- The bare
libflare_<name>.so, which dlopen resolves on the
binary's rpath (mojo build records the lib directory of the
environment it built in) and then the system library path. Never
the working directory.
Steps 2-4 are :func:flare.utils._dlopen.find_library, the search
every magmalake tin that loads a library shares; each of 2 and 3 is
taken only when the file is there.
The path is built via String("") += prefix += literal
rather than the prefix + literal concat operator. See the
:mod:flare.tls.config module docstring for the full rationale
(Mojo's concat can return a String whose buffer aliases another
getenv + literal result, so two sequential
CONDA_PREFIX + ... calls can clobber each other's bytes).
Public API
find_flare_lib(name: String) -> String
Resolves libflare_<name>.so in the order above. name is
the bare suffix ("tls", "zlib", "brotli", "fs").
dl_sym[FT](lib: OwnedDLHandle, name: String) raises -> FT
Resolve a C-ABI function symbol. OwnedDLHandle.get_function
returns an origin-bound _DLCallable that cannot be called
or stored the way plain function pointers used to be;
get_symbol + address reinterpret is the replacement every
FFI call site across :mod:flare now shares.