Skip to content

Commit b7e68af

Browse files
committed
docs: describe runtime-agnostic FFI usage
1 parent cdf2d1f commit b7e68af

4 files changed

Lines changed: 46 additions & 26 deletions

File tree

‎README.md‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@
33
[![Build](https://github.com/Serial-IO/cpp-bindings-linux/actions/workflows/build_binary.yml/badge.svg)](https://github.com/Serial-IO/cpp-bindings-linux/actions/workflows/build_binary.yml)
44
[![JSR](https://jsr.io/badges/@serial/cpp-bindings-linux)](https://jsr.io/@serial/cpp-bindings-linux)
55

6-
Linux shared library for serial communication. It implements the
7-
[`cpp-core`](https://github.com/Serial-IO/cpp-core) interface and provides functions for discovering, opening,
8-
configuring, reading from, and writing to serial ports.
6+
Runtime-agnostic Linux shared library for serial communication. It implements
7+
the [`cpp-core`](https://github.com/Serial-IO/cpp-core) interface and provides
8+
functions for discovering, opening, configuring, reading from, and writing to
9+
serial ports.
10+
11+
The library exposes a C-compatible ABI and can be used from any language or
12+
runtime that can load a GNU/Linux shared library and call C functions. Release
13+
artifacts include machine-readable FFI metadata for generating runtime-specific
14+
adapters, including exported symbols, types, callbacks, structs, defaults, and
15+
API documentation.
916

1017
## Requirements
1118

@@ -69,7 +76,9 @@ ctest --test-dir build --output-on-failure
6976

7077
Tests that require a serial device use `SERIAL_TEST_PORT`. They are skipped when no suitable device is available.
7178

72-
The optional Deno FFI smoke tests require Deno 2 and a built library:
79+
The optional runtime integration smoke tests currently use Deno 2 as their FFI
80+
test harness and require a built library. Deno is not required to consume the
81+
library from another compatible runtime:
7382

7483
```sh
7584
cd integration_tests

‎jsr/README.md‎

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,45 @@ Binaries are provided as a
77
[package on JSR](https://jsr.io/@serial/cpp-bindings-linux). They are serialized
88
as a base64 string inside the JSON file.
99

10+
The contained shared libraries and FFI metadata are runtime-agnostic. They can
11+
be used by any language or runtime that can decode base64, write a file, load a
12+
GNU/Linux shared library, and call its C ABI. The TypeScript exports are a
13+
convenient distribution format, not a dependency on a particular runtime.
14+
1015
The package contains portable binaries for `x86_64-linux-gnu` and
1116
`aarch64-linux-gnu`, both requiring glibc 2.28 or newer. The x86-64 artifact
1217
uses the generic x86-64 baseline.
1318

1419
It also includes cpp-core FFI API metadata generated with
1520
[ASTrein](https://github.com/Katze719/ASTrein) at `bin/x86_64/ffi.json` and
1621
`bin/aarch64/ffi.json`. It describes the exported C symbols, parameter and
17-
return types, callbacks, default values, and API documentation used by
18-
downstream FFI adapter generators.
22+
return types, callbacks, structs, default values, and API documentation used by
23+
runtime-specific FFI adapter generators.
1924

2025
This package is primarily intended as a dependency for
2126
[`@serial/serial`](https://jsr.io/@serial/serial). However, it can also be used
2227
independently.
2328

2429
## Usage
2530

26-
Import the JSON and write the binary data to disk. Each architecture export also
27-
contains its matching FFI metadata:
31+
Select the export matching the host architecture. Each export contains the
32+
base64-encoded shared library and its matching FFI metadata:
2833

2934
```ts
3035
import { aarch64, x86_64 } from "@serial/cpp-bindings-linux/bin";
3136

32-
const binary = Deno.build.arch === "aarch64" ? aarch64 : x86_64;
33-
Deno.writeFileSync(`./${binary.filename}`, Uint8Array.fromBase64(binary.data));
37+
// Select this with the architecture API provided by your runtime.
38+
const binary = x86_64;
3439

35-
// The matching FFI metadata is available as `binary.ffi`.
36-
// Now you can open the binary using for example `Deno.dlopen`...
40+
// Decode `binary.data`, write it to `binary.filename`, and load it using your
41+
// runtime's filesystem and native FFI APIs. `binary.ffi` describes the C API
42+
// and its structs for generating or configuring a runtime-specific adapter.
3743
```
3844

45+
Non-JavaScript consumers can download the same architecture-specific `.so` and
46+
`.ffi.json` files directly from the
47+
[GitHub releases](https://github.com/Serial-IO/cpp-bindings-linux/releases).
48+
3949
> [!NOTE]
4050
> For a more in depth guide, check out the
4151
> [Wiki](https://github.com/Serial-IO/cpp-bindings-linux/wiki) section on how to

‎jsr/jsr.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@serial/cpp-bindings-linux",
33
"version": "",
4-
"description": "C++ Linux Bindings for the serial library",
4+
"description": "Runtime-agnostic GNU/Linux serial FFI binaries and API metadata",
55
"license": "LGPL-3.0-only",
66
"exports": {
77
"./bin": "./src/bin/index.ts"

‎jsr/src/bin/index.ts‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77
* ```ts
88
* import { aarch64, x86_64 } from "@serial/cpp-bindings-linux/bin";
99
*
10-
* const binary = Deno.build.arch === "aarch64" ? aarch64 : x86_64;
10+
* // Select this with the architecture API provided by your runtime.
11+
* const binary = x86_64;
1112
*
12-
* Deno.writeFileSync(
13-
* `./${binary.filename}`,
14-
* Uint8Array.fromBase64(binary.data),
15-
* );
16-
*
17-
* // The matching FFI metadata is available as `binary.ffi`.
13+
* // Decode `binary.data`, write it to `binary.filename`, and load it using
14+
* // your runtime's filesystem and native FFI APIs. The matching C API
15+
* // metadata, including struct definitions, is available as `binary.ffi`.
1816
* ```
1917
* @module
2018
*/
@@ -28,15 +26,17 @@ import x86_64ffi from "../../bin/x86_64/ffi.json" with { type: "json" };
2826
* The serialized `aarch64-linux-gnu` shared library and its FFI metadata.
2927
*
3028
* The library targets ARMv8-A and requires glibc 2.28 or newer. Decode `data`
31-
* from base64 and write it to `filename` before loading it with `Deno.dlopen`.
29+
* from base64, write it to `filename`, and load it using the filesystem and
30+
* native FFI APIs provided by your runtime.
3231
*/
3332
const aarch64 = {
3433
...aarch64Library,
3534
/**
3635
* ASTrein-generated metadata describing the library's exported C API.
3736
*
38-
* It contains symbols, parameter and return types, callbacks, default
39-
* values, and API documentation for generating FFI adapters.
37+
* It contains symbols, parameter and return types, callbacks, struct
38+
* definitions, default values, and API documentation for generating
39+
* runtime-specific FFI adapters.
4040
*/
4141
ffi: aarch64ffi,
4242
};
@@ -46,15 +46,16 @@ const aarch64 = {
4646
*
4747
* The library targets the generic x86-64 baseline and requires glibc 2.28 or
4848
* newer. Decode `data` from base64 and write it to `filename` before loading
49-
* it with `Deno.dlopen`.
49+
* it using the filesystem and native FFI APIs provided by your runtime.
5050
*/
5151
const x86_64 = {
5252
...x86_64Library,
5353
/**
5454
* ASTrein-generated metadata describing the library's exported C API.
5555
*
56-
* It contains symbols, parameter and return types, callbacks, default
57-
* values, and API documentation for generating FFI adapters.
56+
* It contains symbols, parameter and return types, callbacks, struct
57+
* definitions, default values, and API documentation for generating
58+
* runtime-specific FFI adapters.
5859
*/
5960
ffi: x86_64ffi,
6061
};

0 commit comments

Comments
 (0)