Skip to content

victorporof/rsx-demo

Repository files navigation

Under heavy research and development, please don't use this yet!

rsx-demo

License: MPL 2.0

Several demos for embedding RSX and rendering display lists generated by the RSX Primitives library.

Purpose

Quick and easy example code. For much more in-depth walkthroughs and documentation on how to build your own projects from scratch, see this.

How to build

First, clone this repository recursively:

git clone git@github.com:victorporof/rsx-demo.git --recursive

Finally, edit the Cargo.toml file to specify which target you want to build for. The default target is WebRender, so you don't need to edit the file for that target.

Building for native targets with WebRender

Edit the Cargo.toml file to specify a native target and make sure the project isn't set up to compile as a library.

Cargo.toml

[features]
default = ["target-native"]

Then, simply

cargo run

Building for web targets

Edit the Cargo.toml file to specify a web target and make sure the project isn't set up to compile as a library.

Cargo.toml

[features]
default = ["target-web"]

As prerequisites, you need to install Emscripten, a couple of Rust targets, as well as some npm development dependencies.

Installing Rust targets

rustup target add asmjs-unknown-emscripten
rustup target add wasm32-unknown-emscripten

Installing Emscripten

Follow the steps outlined in the official docs, or build from source from the Github repo. If you're using fish as your shell, the emsdk_env.sh script won't add the necessary entries to your $PATH, so either run it under sh or add the paths yourself.

./emsdk update
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh

Installing NPM dependencies

npm install

Building and running

cargo build --target=asmjs-unknown-emscripten
npm start

First time builds can take a very long time! Be patient.

Building for iOS targets

Edit the Cargo.toml file to specify an iOS target and make this crate a library. As prerequisites, you need to install the appropriate architectures, as well as cargo-lipo and build jemalloc.

Cargo.toml

[lib]
name = "rsx_demo"
path = "src/main.rs"
crate-type = ["staticlib", "cdylib"]

[features]
default = ["target-ios"]

Then, install the appropriate architectures, as well as cargo-lipo:

rustup target add aarch64-apple-ios armv7-apple-ios armv7s-apple-ios x86_64-apple-ios i386-apple-ios
cargo install cargo-lipo

Then simply:

cargo lipo --release

Then open XCode project, first installing the CocoaPods dependencies:

cd fixtures/ios/Example/
pod install
open Example.xcworkspace

Write your own frontend

To make changes to the underlying Rust code, simply edit main.rs and example.css files inside the src directory. For more examples and syntax, see the RSX compiler plugin crate.

Caveats

  1. Editing CSS files require Rust files to be re-saved before building. This is because cargo build tries really hard not to rebuild if not necessary, and CSS files aren't on its radar.
  2. Mutation and user input isn't fully supported yet. Although support is trivial to add, there's no implementation or example code yet. Stay tuned.

About

Several demos for embedding RSX code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published