slint/docs/building.md
Olivier Goffart 287670c140 CI: Split the C++ test driver in a different run
This allows to paralelize better.
And also to remove the cpp from the default workspace so it is
not build by default and the ffi feature will not be build by default
2021-03-16 16:55:49 +01:00

123 lines
3.6 KiB
Markdown

# SixtyFPS build guide
This page explain how to build and test SixtyFPS.
## Prerequisites
### Installing Rust
Install Rust by following the [Rust Getting Started Guide](https://www.rust-lang.org/learn/get-started).
Once this is done, you should have the ```rustc``` compiler and the ```cargo``` build system installed in your path.
### For the NodeJS backend
For the nodejs backend, the following component are needed:
* **node** (including npm)
* **python**
It would be nice if building the nodejs backend was optional, but right now it is part of the workspace.
You can still not build it by doing `cargo build --workspace --exclude sixtyfps-node`. But cargo test will fail.
### For the C++ dev (optional)
* **cmake** (3.16 or newer)
* A C++ compiler that can do C++17 (e.g., **MSVC 2019** on Windows)
## Testing
Most of the project is written in Rust, and compiling and running the test can
done with cargo.
```sh
cargo build
cargo test
```
**Important:** Note that `cargo test` does not work without first calling `cargo build` because the
C++ tests or the nodejs tests will not find the required dynamic library otherwise
### C++ test
The C++ crate are not included in the workspace's default members, so it need to be build explicitly
```sh
cargo build --lib -p sixtyfps-cpp
cargo test --bin test-driver-cpp
```
## C++ Build
This is just a normal cmake build.
```sh
mkdir cppbuild && cd cppbuild
cmake -GNinja ..
cmake --build .
```
The build will call cargo to build the rust libraries, and build the examples.
In order to install the libraries and everything you need, use:
```sh
cmake --install .
```
You can pass `-DCMAKE_INSTALL_PREFIX` in the first cmake command in order to choose the install location
## Cross-Compiling
SixtyFPS can be cross-compiled to different target architecures and environments. For the Rust build we
have had a good experience using [`cross`](https://github.com/rust-embedded/cross). For convenience we're
including a `Cross.toml` configuration file for `cross` in the source tree along with Docker containers that
allow targeting a Debian ARMv7 and ARMv8 based Distribution with X11 or Wayland, out of the box.
This includes for example the Raspberry Pi OS. Using the following steps you can run the examples on a
pi:
```sh
cross build --target armv7-unknown-linux-gnueabihf --workspace --exclude sixtyfps-node --release
scp target/armv7-unknown-linux-gnueabihf/release/printerdemo pi@raspberrypi.local:.
```
Finally on a shell on the Pi:
```sh
DISPLAY=:0 ./printerdemo
```
## Examples
See the [examples](/examples) folder for examples to build, run and test.
## Running the viewer
SixtyFPS also includes a viewer tool that can load `.60`files dynamically at run-time. It is a
cargo-integrated binary and can be run directly on the `.60`files, for example:
```sh
cargo run --release --bin viewer -- examples/printerdemo/ui/printerdemo.60
```
## Generating the documentation
### rustdoc
With nightly rust, the documentation of the sixtyfps-rs embed the language reference using the
[`external_doc`](https://github.com/rust-lang/rust/issues/44732) feature.
That language reference has snippets in the .60 language which can be previewed by injecting
html to the documentation with the `--html-in-header` rustdoc flag.
Here is how to build the documentation to include preview of the .60 files.
```sh
RUSTDOCFLAGS="--html-in-header=$PWD/api/sixtyfps-rs/sixtyfps-docs-integration.html" cargo +nightly doc --no-deps
```
### C++ doc
To generate the C++ API documentation, one need to have doxygen installed, and run this command
```
cargo xtask cppdocs
```