rive-runtime

repository·main·Indexed 22 days ago

https://github.com/rive-app/rive-runtime

The core C++ engine for Rive, providing low-level capabilities for loading .riv files, managing state machines, and rendering vector graphics. It features a high-performance vector renderer with RenderContextImpl backends for Metal, Vulkan, D3D11, D3D12, and OpenGL/WebGL, as well as an abstract Renderer interface for custom external renderers.

Tokens
3.8K
Snippets
15
Records
21
Agent score
78%

What's inside rive-runtime

  1. What is rive-runtime

    main

    rive-runtime is the lowest-level C++ runtime for Rive. It is responsible for loading .riv files, advancing state machines and animations, and handling drawing via an abstract Renderer interface.

    Key capabilities include:

    • Loading artboards and contents from .riv files.
    • Querying state machines from artboards.
    • Mutating the artboard hierarchy and solving changes via Artboard::advance.
    • A high-performance vector renderer with RenderContextImpl backends for Metal, Vulkan, D3D11, D3D12, and OpenGL/WebGL.
    • An abstract Renderer interface that allows developers to hook up their own external vector renderer.
  2. Use the WebGPU port for Emscripten

    main

    The WebGPU port provides WebGPU bindings for Emscripten, including the webgpu.h header provided by emdawnwgpu. You can integrate this into your Emscripten build process using either a local port file or a remote port file via the --use-port flag.

    # Using a remote port
    --use-port=[your_path]/webgpu-remoteport.py
    
    # Using a local port
    --use-port=[your_path]/webgpu-port.py
  3. Run memory checks (macOS only)

    main

    On macOS, you can run tests under the built-in leaks tool to check for memory leaks. This wraps the test binary with leaks --atExit.

    cd tests/unit_tests
    ./test.sh memory

    Note: The memory flag is ignored on Linux and Windows.

  4. Prerequisites for building rive-runtime

    main

    Before building, ensure you have the following installed based on your platform:

    C++17 Toolchain

    • macOS: clang from Xcode Command Line Tools (xcode-select --install).
    • Linux: clang from your distribution (e.g., apt install clang).
    • Windows: Visual Studio 2022 with the C++ Clang Compiler for Windows and MSBuild support for LLVM (clang-cl) toolset individual components.

    Git

    • git is required. The build script clones a pinned premake5 on the first run.
    • Windows Users: Install Git for Windows and select "Use Git and optional Unix tools from the Command Prompt" during setup to ensure sh.exe is on your PATH.

    Platform SDKs

    • macOS / iOS: Xcode.
    • Windows: Windows SDK (for D3D).
    • Linux: A Vulkan or OpenGL development environment.
    • Vulkan: The Vulkan SDK.
  5. Run tests in rive-runtime

    main

    Golden Testing

    Primary testing is done via golden testing, which renders known scenes and compares them against reference images. Use the goldens and gms binaries found in out/<config>/ to run these tests.

    Unit Testing

    Unit tests use the Catch2 framework. To run them, navigate to the tests/unit_tests directory and execute the test script:

    cd tests/unit_tests
    ./test.sh

    Unit tests are located in:

    • tests/unit_tests/runtime/ (core runtime)
    • tests/unit_tests/renderer/ (renderer)

    To add a new test, create an xxx_test.cpp file in the appropriate directory; the harness will detect it automatically.

  6. Build and serve for WebGL2 (WASM)

    main

    To build the renderer for WebGL2 using WebAssembly (WASM), use the ninja wasm release flags. Once built, navigate to the output directory and start a local Python HTTP server to view the results.

    build_rive.sh ninja wasm release
    cd out/wasm_release
    python3 -m http.server 5555
  7. Build rive-runtime

    main

    The build process is driven by premake5 using helper scripts. You should run these scripts from a directory containing premake5.lua (typically the tests/ directory) to build the core library, the GPU renderer, and the player sample app.

    macOS / Linux

    git clone https://github.com/rive-app/rive-runtime.git
    cd rive-runtime/tests
    ../build/build_rive.sh release

    Windows

    git clone https://github.com/rive-app/rive-runtime.git
    cd rive-runtime\tests
    ..\build\build_rive.ps1 release
  8. Configure Wagyu extensions in the WebGPU port

    main

    The WebGPU port optionally provides Wagyu extensions via the webgpu_wagyu.h header. These extensions are specific to Wagyu use cases and are not part of the WebGPU standard. To enable them, pass the wagyu=true option to the --use-port flag using colon-delimited key=value pairs.

    --use-port=webgpu-remoteport.py:wagyu=true
  9. Build variants and flags for build_rive

    main

    The build_rive.sh (macOS/Linux/MinGW) and build_rive.ps1 (Windows) scripts support various build configurations.

    Note for Windows: Substitute build_rive.ps1 for build_rive.sh in the commands below.

    CommandDescription
    build_rive.shDebug build for the host
    build_rive.sh release cleanClean then build release
    build_rive.sh ninja releaseUse Ninja instead of make/MSBuild
    build_rive.sh ios releaseCross-compile for iOS
    build_rive.sh android releaseCross-compile for Android (defaults to arm64)
    build_rive.sh ninja release wasmCross-compile for WebAssembly
    build_rive.sh --toolset=msc release(Windows only) Build with MSVC's cl.exe instead of clang-cl