Using Rust With VxWorks 7

Dec 3, 2020 | Rust, VxWorks

1 Introduction

VxWorks is a Real Time Operating System built by Wind River, and Rust is a programming language designed
for performance and safety-critical type applications.

Rust :

Wind River supports Rust 1.39 in user space on 32/64-bit ARM and Intel architecture devices. Rust is automatically included
into the VxWorks source build (VSB) projects on those CPU architectures.

This blog describes how to build and deploy a multi-threaded Dining Philosophers Rust application on VxWorks 7 from a Windows
workstation. Rust applications run on VxWorks as real-time processes (RTPs).

2 Prerequisites

These instructions assume that you are using:

Wind River VxWorks 7, SR0650

3 Related Documentation

For more information on these topics, refer to:

Wind River documentation:
VxWorks Support for Third Party Software

Non-Wind River Documentation:
The Rust Programming Language,

4 Create and Build the VxWorks Source Build (VSB) Project

Open a DOS shell, configure the build environment and then build the project.

cd <WIND_HOME>              // your installation directory
wrenv -p vxworks-7
cd <YOUR_WORKSPACE>         // your workspace
vxprj vsb create rust_vsb -bsp vxsim_windows -smp -force -S
cd rust_vsb                 // your workspace
make -j 32                  // build the VSB

Once your VxWorks source build (VSB) has built, check that it contains the Rust layer. Verify that the following directory exists:


5 Create and Build the Basic VxWorks Image Project (VIP)

Create the basic VxWorks image project (VIP) as follows.

cd ..
vxprj create -smp vxsim_windows rust_vip -profile PROFILE_DEVELOPMENT -vsb rust_vsb
cd rust_vip
vxprj vip bundle add BUNDLE_RUST
                            // set VxWorks process pthread scheduling to the POSIX 1003.1 standard
vxprj build

6 Create a Dining Philosophers Example Rust Application

Rust applications are managed and built from the Cargo utility.

cd ..
cd rust_vsb\usr\rust
cargo new dining_phil
cd dining_phil\src

Edit the dining_phil project source file Replace the contents with the following Rust source code:

use std::sync::{Arc, Mutex};
use std::thread;
struct Philosopher {
    name: String,
    left: usize,
    right: usize,
impl Philosopher {
    fn new(name: &str, left: usize, right: usize) -> Philosopher {
        Philosopher {
            name: name.to_string(),
            left: left,
            right: right,
    fn eat(&self, table: &Table) {
        let _left = table.forks[self.left].lock().unwrap();
        let _right = table.forks[self.right].lock().unwrap();
        println!("{} is eating.",;
        println!("{} is done eating.",;
struct Table {
    forks: Vec<Mutex<()>>,
fn main() {
    let table = Arc::new(Table {
        forks: vec![
    let philosophers = vec![
        Philosopher::new("Donald", 0, 1),
        Philosopher::new("Larry", 1, 2),
        Philosopher::new("Mark", 2, 3),
        Philosopher::new("John", 3, 4),
        Philosopher::new("Bruce", 0, 4),
    let handles: Vec<_> = philosophers
        .map(|p| {
            let table = table.clone();
            thread::spawn(move || {
    for h in handles {

7 Build Dining Philosophers Example Rust Application

cd ..
cargo build
Compiling dining_phil v0.1.0 (C:\NoScan\WindRiverPRT\workspace\rust_vsb\usr\rust\dining_phil)
warning: use of deprecated item 'std::thread::sleep_ms': replaced by `std::thread::sleep`
  --> src\
25 |         thread::sleep_ms(1000);
   |         ^^^^^^^^^^^^^^^^
   = note: `#[warn(deprecated)]` on by default
    Finished dev [unoptimized + debuginfo] target(s) in 2.45s

8 Boot VxWorks and Run the Rust Application

8.1 Boot the VxWorks Simulator Target

cd rust_vip\default

8.2 Locate the Dining Philosophers Application on the VxWorks Simulator

From the VxWorks Simulator kernel shell:

-> cmd
[vxWorks *]# cd ../../rust_vsb/usr/rust/dining_phil/target/x86_64-wrs-vxworks/debug

8.3 Run the Dining Philosophers Application

[vxWorks *]# ./dining_phil.vxe
Launching process './dining_phil.vxe' ...
Process './dining_phil.vxe' (process Id = 0x4001d6c30) launched.
Donald is eating.
Mark is eating.
Donald is done eating.
Mark is done eating.
Larry is eating.
Bruce is eating.
Larry is done eating.
Bruce is done eating.
John is eating.
John is done eating.
[vxWorks *]#

Browse Category

Join our DO-178C group on LinkedIn

Got A Project In Mind?

We fix, develop and test embedded software for the aerospace & defence industry specialising in DO-178C safety-critical testing. Speak to us. We have laser focus, unprecedented attention-to-detail and provide phenomenal value.