cosmicnim
libcosmic behind a small C ABI, driven from Nim.
libcosmic's API is generics, traits and closures, so it has no C ABI of its own —
building libcosmic itself as a cdylib exports nothing. The cosmic_ffi crate
therefore defines the C surface: it depends on libcosmic as a normal Rust
crate and exports one function.
cosmic_ffi/ Rust cdylib -> libcosmic_ffi.so + cosmic_ffi.h
nim/ Nim bindings (cosmic.nim) and the demo app (app.nim)
The contract
Rust owns the widget tree; the host owns the application state. Each button
press is handed back through on_press, which writes the next label into the
buffer it is given.
typedef void (*cosmic_on_press)(void *ctx, int32_t button_id,
char *out, size_t out_len);
int32_t cosmic_run(const CosmicConfig *config); /* blocks until closed */
cosmic_run must be called from the main thread, and ctx is only ever
touched from that thread.
Using a prebuilt release
tar xzf cosmic_ffi-<version>-x86_64-unknown-linux-gnu.tar.gz
cp cosmic_ffi-*/libcosmic_ffi.so nim/
cd nim && nim c -r app.nim
Building from source
cd cosmic_ffi && cargo build --release
cp target/release/libcosmic_ffi.so ../nim/
cd ../nim && nim c -r app.nim
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|