jflib
JFLib is a GUI library and everything it stands on, without the standard library: windows and controls, text, images in many formats, the GPU, files, the network, documents, and a runtime of its own. This one dependency brings all of it; a program links only what it uses. The same app runs on Windows, Linux, macOS, iOS, Android and in the browser.
docs/GUIDE.md in this package explains how an app is written, docs/API.md lists every public
item. Both lie below ~/.cargo/registry/src/ once Cargo has downloaded the crate; the guide is
also on docs.rs as jflib::guide, the
API reference on GitHub.
Quick start
# (--formats all: also MSIX, AppImage, RPM, Flatpak;
# on a Mac --formats dmg)
cargo jflib new writes the template that lies in this package as template/. Without the tool,
copy it (cp -r ~/.cargo/registry/src/*/jflib-0.2.*/template hallo, then rename Cargo.toml.in
to Cargo.toml).
| File | What it is for |
|---|---|
Cargo.toml |
jflib, and jflib-build for the build script; the profiles below |
build.rs |
jflib_build::app(), or jflib_build::console() for a command-line program |
.cargo/config.toml |
the linker (rust-lld, it comes with rustup) and what Linux needs (with std only +crt-static for Windows) |
src/lib.rs |
the app: a ui::App and ui::main! |
src/main.rs |
the program, it only links the app, so the same code builds for the browser |
PERMISSIONS |
what the app may do; without the file everything |
PACKAGE |
its name, id and file types for --register |
assets/ (optional) |
files the app reads as app://NAME |
res/app.ico (optional) |
its icon on Windows |
tests/smoke.uis |
a test script, run with --script |
Names come from the crate in code: use jflib::{style, ui};, then ui::Ui, plat::read_file.
Apps with std
JFLib is no_std and brings everything an app needs from one hand. Write apps no_std as well
where you can, and look in docs/API.md before adding a crate. An app that needs a crate with
std turns on the feature std (cargo jflib new --std writes such an app):
= { = ["std"], = "0.2" }
Then src/lib.rs has no #![no_std], src/main.rs is extern crate hallo; fn main() { jflib::plat::std_start() }, .cargo/config.toml only links the C runtime in on Windows
(+crt-static) and PERMISSIONS covers JFLib's own calls only. Linux programs with std are built
on Linux (cc, glibc), macOS and iOS ones on a Mac; in the browser std has no clock, files or
threads and there is no threads mode; on Android std::fs needs the app's real folder
(docs/GUIDE.md, "An app with std").
Don't add a second window loop or UI crate (winit, eframe, egui, SDL): ui::launch is the whole
stack, not one crate of several as with egui and eframe. Don't run an async runtime (tokio) on the
UI thread: JFLib runs async blocks itself (ui.spawn); a crate that needs tokio gets it on a
thread of its own, with results back through plat::wake().
The profiles
Cargo takes no profile from a dependency, so every project needs these in its Cargo.toml.
Without panic = "abort" the build stops at ui::main! with a message that says so. An app with
std that must survive panics of its own code turns on the feature unwind instead of std and
writes panic = "unwind" in both profiles: a panic it catches with std::panic::catch_unwind
leaves it running, one nobody catches ends it with JFLib's crash report (docs/GUIDE.md, "An app
with std").
[]
= "abort"
= 1
= 0
= false
= false
[]
= "abort"
= 2
= 1
= "fat"
= 0
= "symbols"
Targets
| Target | Build | Notes |
|---|---|---|
| Windows | cargo build; ARM64: --target aarch64-pc-windows-msvc |
rust-lld; the program links without import libraries, the build scripts need what Rust's msvc toolchain always needs (the Visual Studio Build Tools) |
| Linux | cargo build --target x86_64-unknown-linux-gnu; ARM64: --target aarch64-unknown-linux-gnu |
a window links against glibc (the GPU); a command-line program can be one static file (.cargo/config.toml) |
| macOS | cargo build on a Mac; cargo jflib mac makes NAME.app |
Apple silicon; Apple's linker needs nothing in .cargo/config.toml |
| iOS | cargo build --target aarch64-apple-ios (or aarch64-apple-ios-sim) on a Mac |
devices and the simulator; cargo jflib makes no iOS app yet |
| Browser | cargo jflib web |
scalar, SIMD and with threads, the page around them and the licences in target/jflib-web/NAME/; threads need rustup component add rust-src |
| Android | cargo jflib android |
an APK for arm64-v8a (or --abi x86_64 for the emulator) in target/jflib-android/; needs the Android SDK, the NDK, a JDK and rustup target add aarch64-linux-android; the app's code in src/lib.rs as the template has it |
The style: jflib::style is WinUI unless the environment variable JFLIB_STYLE names another
(classic, kde, macos, netlab). All five are always there under their own names for the
switch at run time (jflib::style_kde::STYLE).
Good to know
- A file added later: after adding
PERMISSIONS,PACKAGE,assets/orres/app.icoto a project that had none, runcargo clean -p NAMEonce. The build script watches only what exists; watching a missing file would compile the program again on every build. - Always
--targetfor Linux, on Linux too: without it Cargo hands the target's flags to the build scripts and proc macros as well, and the static relocation model breaks them. With it they are linked by cc as usual and only the program by rust-lld. Without the two linker flags cc links the program too. - Paths in a release program: panic messages name the source files with the build
machine's paths.
RUSTFLAGS="--remap-path-prefix=$HOME=~"removes them. - Versions: the crates below
jflib(jflib-ui,jflib-plat, ...) always come in the same version and change together. Only the way throughjflibis promised, together withjflib-buildandcargo jflib(docs/VERSIONING.md, "The crates on crates.io"). - Your own system calls: JFLib checks a program's file, network and process access against
its
PERMISSIONSin its platform layer. A crate that calls the system itself goes around it; only thesandboxline confines it, as far as the operating system enforces the manifest (docs/PERMISSIONS.md, "OS sandbox").
What's new in 0.2.0
JFLib runs natively on macOS and iOS now, with windows through AppKit and UIKit, VoiceOver, the
app's menus in the Mac's menu bar and a Metal backend for the GPU, and cargo jflib makes a Mac
app and its disk image. Windows and Linux run on ARM64 as well. Three crates join the facade:
jflib::render3d, a 3D engine on the GPU layer, jflib::gltf, which imports glTF 2.0 models,
and jflib::render2d, a 2D renderer for CAD drawings. NetLab is an official style
(jflib::style_netlab, JFLIB_STYLE=netlab), and the feature unwind lets an app with std
survive the panics it catches. The UI learned what phones and tablets and apps that host web
content need, and shows GPU content beside its widgets. Programs link again with Rust 1.99, which
failed on Windows with 0.1.0, and a round of fixes closes holes against hostile documents, images
and packets and removes deadlocks and races. plat::dl_sym and plat::dl_close are unsafe fn
now. Every crate has a README and a changelog of its own; the
library's changelog sums them up and
links to each.
License
MIT or Apache-2.0, at your choice. Parts carry third-party licenses in addition, named in each
crate's manifest and its licenses/ folder.