3.4 KiB
Slint development guide
The build instructions are in the building.md file. The testing instructions are in the testing.md file.
Repository structures
helper_crates
A set of crates that are somehow not strictly related to Slint, and that could be moved to their own repository and have their own version release at some point.
internal
internal contains code that isn't meant to be used directly by a user of Slint.
compiler
The main library for the compiler for .slint.
Nothing in there should depend on the runtime crates.
There is a test subdirectory that contains the syntax tests.
These tests allow you to test the proper error conditions.
Runtime libraries
The library crates that are used at runtime.
coreis the main library. It's meant to be used for all front-ends. Ideally it should be kept as small as possible.corelib-macroscontains some procedural macro used by core library.backendscontains the different backend for the different platform, separated from core library. Currently there is just the gl backendinterpreteris the library used by the more dynamic languages backend to compile and interpret .slint files. It links both against core library and the compiler lib
tools
compileris the tool to generate the target language (e.g. c++) from the .slint files for frontend that have a compilation step and generated code.vieweris a tool that allow to open and view a .slint file.
api
Here one can find the frontends for different languages.
tests
The integration test that are testing a bunch of .slint with different front-ends
See testing.md
examples
Some manual tests
Documentation
There are some documentations comments in the code. HTML documentation can be generated with something like
cargo doc --document-private-items --no-deps --open
Rust to C++ bindings
We use a rather complex mechanism to expose internal data structures implemented in Rust to C++, in a way that allows us to provide a nice C++ API.
As a starting point, we recommend reading the blog entry we published about this:
https://slint.dev/blog/expose-rust-library-to-other-languages.html
What this article omits are how we invoke cbindgen and what kind of tweaks we apply on various levels:
The C++ library consists of four components:
- The
slint-cppcdylib created bycargo/rustcfromapi/cpp. - The public header files in
api/cpp/include. - Internal header files generated by
cbindgen, viacargo xtask cbindgen. - The CMake project to tie it all together by invoking
corrosionto callcargoand invokingcbindgen.
cbindgen
The cbindgen xtask generates multiple header files for four different modules:
- The types in the core library. This is the bulk of the generated code.
- The entry points into the C++ library for creating backends, invoking the event loop, etc. - from
api/cpp/lib.rs. - The types specific to the Qt backend used by the Qt style, such as
NativeButton, etc. - The types used by the C++ interpreter API, written to
slint_interpreter_internal.h.
Typically the input to cbindgen is within ffi sub-modules in the corresponding input crates to cbindgen. These ffi modules are gated with #[cfg(feature = "ffi")].