Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into async_runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin-Niederman authored Oct 21, 2023
2 parents 16c290e + 72f67f7 commit e589833
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@ target = "./armv7a-vexos-eabi.json"
[target.armv7a-vexos]
runner = "python runner.py"

[target.wasm32-unknown-unknown]
rustflags = [
"-Ctarget-feature=+atomics,+bulk-memory,+mutable-globals",
"-Clink-arg=--shared-memory",
]

[unstable]
build-std = ["core", "compiler_builtins", "alloc"]
67 changes: 67 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Rust

on: [push, pull_request]

jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- name: Setup | Checkout
uses: actions/checkout@v2

- name: Setup | Toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true

- name: Check
uses: actions-rs/cargo@v1
with:
command: check

fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- name: Setup | Checkout
uses: actions/checkout@v2

- name: Setup | Toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true

- name: Setup | Install Rustfmt
run: rustup component add rustfmt

- name: Format
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Setup | Checkout
uses: actions/checkout@v2

- name: Setup | Toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: clippy
override: true

- name: Clippy
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features
5 changes: 4 additions & 1 deletion pros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pros"
version = "0.0.10-rc.1"
version = "0.0.10"
edition = "2021"
description = "Rust bindings for PROS"
keywords = ["PROS", "Robotics", "bindings"]
Expand All @@ -27,5 +27,8 @@ cfg-if = "1.0.0"
async-task = { version = "4.5.0", default-features = false }
waker-fn = "1.1.1"

[target.'cfg(target_arch = "wasm32")'.dependencies]
dlmalloc = { version = "0.2.4", features = ["global"] }

[features]
lvgl = ["pros-sys/xapi"]
2 changes: 1 addition & 1 deletion pros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![feature(error_in_core, stdsimd, negative_impls)]
#![cfg_attr(not(target_arch = "wasm32"), no_std)]
#![no_std]

extern crate alloc;

Expand Down
25 changes: 24 additions & 1 deletion pros/src/wasm_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,34 @@

extern crate alloc;

use core::panic::PanicInfo;

use alloc::{
alloc::{alloc, dealloc, handle_alloc_error, Layout},
alloc::{alloc, dealloc, handle_alloc_error, GlobalAlloc, Layout},
collections::BTreeMap,
ffi::CString,
format,
};

use dlmalloc::GlobalDlmalloc;

// no multithreading in wasm
static mut LAYOUTS: BTreeMap<*mut u8, Layout> = BTreeMap::new();

#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
extern "C" {
fn sim_abort(msg: *const core::ffi::c_char) -> !;
}

let msg_str = format!("{info}");
let msg_c_str = CString::new(msg_str).unwrap();

unsafe {
sim_abort(msg_c_str.as_ptr());
}
}

#[no_mangle]
extern "C" fn wasm_memalign(alignment: usize, size: usize) -> *mut u8 {
if size == 0 {
Expand Down Expand Up @@ -38,3 +58,6 @@ extern "C" fn wasm_free(ptr: *mut u8) {
unsafe { dealloc(ptr, layout) };
}
}

#[global_allocator]
static ALLOCATOR: GlobalDlmalloc = GlobalDlmalloc;

0 comments on commit e589833

Please sign in to comment.