Skip to content

This is a minimal example project for the Oculus Quest, written completely in Rust.

Notifications You must be signed in to change notification settings

makepad/rustquest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rustquest

This is a minimal example project for the Oculus Quest, written completely in Rust. It renders a simple colored cube to the screen that moves around when your head pose changes.

Note that this project use neither Android Studio nor Gradle. Instead, the projects contains a build script that uses the platform and build tools in the Android SDK directly.

The project itself is organised into two parts. The android directory contains all the Java code, and is little more than a thin wrapper that forwards callbacks from the operating system to the native layer. The native directory contains all the native code, and is organised as a Cargo crate.

The Cargo crate contains several subcrates named *-sys. These contain all the Rust bindings for the relevant C libraries. Almost all these bindings were autogenerated using the Rust bindgen tool. The only exception are the utility functions in the VR API. These are static inline functions, preventing bindgen from generating bindings for them. As a workaround, I've ported these functions to Rust by hand.

The code itself contains a lot of boilerplate, but is not terribly complicated. The main source of complexity is the fact that the application runs in a separate dedicated thread: all the callbacks from the Java code need to be somehow forwarded to that thread. Luckily, Rust has some very nice primitives for multithreading, so the resulting code shouldn't be that hard to read.

Prerequisites

The following prerequisites are required in order to build the project:

  • Install OpenJDK 8

    • On Ubuntu, you can use the following command: sudo apt install openjdk-8-jdk-headless
    • NOTE: Make sure you install version 8 of the JDK, and not just the latest version. When I tried it, the SDK manager in the Android SDK tools did not work with any version of the JDK other than 8.
    • NOTE: Make sure you install the JDK, and not just the JRE, or you'll end up missing several tools that you'll need in the following steps.
  • Download and extract the Android SDK tools

    • You can download the Android SDK tools here: https://developer.android.com/studio
    • Extract the SDK tools somewhere. You can extract them anywhere you want, but the directory that seems to be the most often used, and the one I ended up using, is ~/Android/SDK/
  • Use the SDK manager to install:

    • Android platform 26
    • Build tools 28.0.3
    • NDK bundle
    • NOTE: Assuming you installed the SDK tools in ~/Android/SDK/, you can find the SDK manager in ~/Android/SDK/tools/bin/.
    • NOTE: These version numbers are based on what the samples in the Oculus Mobile SDK seem to be using.
  • Download and extract the Oculus Mobile SDK

  • Make sure the following environment variables are set:

    • export ANDROID_HOME=$HOME/Android/Sdk
    • export ANDROID_NDK_HOME=$HOME/Android/Sdk/ndk-bundle
    • export OVR_HOME=$HOME/ovr_sdk_mobile
    • export PATH=$ANDROID_HOME/platform-tools:$PATH
    • NOTE: If you installed either the Android SDK tools or the Oculus Mobile SDK in a different location than the one I suggested, you need to change the paths here accordingly.

Usage

I've created several shell scripts that allow you to build, install, start, and stop the application on the Quest. All of these scripts assume that the platform tools are in your $PATH, so before you start, doubly make sure that you've set your environment variables correctly.

IMPORTANT NOTE: Before we can build the application, we need to update the file native/.cargo/config. This is a configuration file that tells Cargo where it can find the compiler toolchain for cross-compiling to Android. Unfortunately, Cargo does not allow you to use either relative paths or environment variables here, so I've had to hardcode these paths. I would like to come up with a more elegant solution here eventually, but for now this the way things are.

  • To build the application, run: ./build.sh

NOTE: The subsequent steps require that the Quest is set in developer mode, and connected to your machine over USB.

  • To install the application, run: ./install.sh

  • To start the application, run: ./start.sh

  • To stop the application, run: ./stop.sh

About

This is a minimal example project for the Oculus Quest, written completely in Rust.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published