Library to use and publish shared libraries for bun:ffi
.
- Add bun-ffi-z dependency
bun install @chainsafe/bun-ffi-z
- Add bun-ffi-z section to package.json
"bun-ffi-z": {
"name": "example",
"targets": [
"linux-x64-gnu",
"linux-arm64-gnu",
"linux-x64-musl",
"linux-arm64-musl",
"darwin-x64",
"darwin-arm64",
"win32-x64"
],
"zigCwd": "zig"
}
- Use bun-ffi-z to select the proper library
import {openLibrary} from "@chainsafe/bun-ffi-z";
const lib = await openLibrary(
import.meta.dirname,
{
add: {
args: ["u32", "u32"],
returns: "u32"
}
}
)
export const symbols = lib.symbols;
export const close = lib.close;
- Build shared library for native host
bun-ffi-z build
- On publish CI, prepare an "artifacts" subdirectory which contains all prebuilt binaries
- name: Download all artifacts
if: ${{ steps.release.outputs.release_created }}
uses: actions/download-artifact@v4
with:
path: artifacts
- Prepare
targetPackages
subdirectory by copying prebuilt binaries inside "artifacts" folder prepared above
bun-ffi-z prepublish --artifacts artifacts
Note that both targetPackages
and artifacts
are relative to bun folder.
- Publish the root package and all target packages prepared above in
targetPackages
subdirectory
bun-ffi-z publish
MIT