-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add a project example from @willemolding's
Cannon-rs
project
- Loading branch information
Showing
10 changed files
with
401 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Rust target dir | ||
target |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "hello-rs-willem" | ||
edition = "2021" | ||
version = "0.0.1" | ||
authors = ["Willem Olding"] | ||
|
||
[dependencies] | ||
linked_list_allocator = "0.10.5" | ||
|
||
[profile.release] | ||
panic = "abort" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# [`Cannon-rs`][cannon-rs-willem] example program | ||
|
||
This is an example Rust program for Cannon that uses Willem Olding's [program template][program-template-willem]. | ||
|
||
## Building | ||
|
||
The program can be built using Badboilabs' provided container: | ||
|
||
```sh | ||
docker run --rm --platform linux/amd64 -v `pwd`/:/code -w="/code" ghcr.io/badboilabs/cannon-rs/builder:main cargo build --release -Zbuild-std | ||
``` | ||
|
||
[cannon-rs-willem]: https://github.com/BadBoiLabs/Cannon-rs | ||
[program-template-willem]: https://github.com/BadBoiLabs/Cannon-rs/tree/main/project-template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"arch": "mips", | ||
"cpu": "mips32", | ||
"crt-objects-fallback": "false", | ||
"crt-static-respected": true, | ||
"data-layout": "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64", | ||
"dynamic-linking": true, | ||
"env": "gnu", | ||
"features": "-mips32r2,-fpxx,-nooddspreg,+mips32,+crt-static,+soft-float", | ||
"has-rpath": true, | ||
"has-thread-local": true, | ||
"linker-flavor": "gnu-cc", | ||
"llvm-target": "mips-unknown-linux-gnu", | ||
"max-atomic-width": 32, | ||
"os": "linux", | ||
"position-independent-executables": true, | ||
"relro-level": "full", | ||
"supported-split-debuginfo": [ | ||
"packed", | ||
"unpacked", | ||
"off" | ||
], | ||
"target-endian": "big", | ||
"target-family": [ | ||
"unix" | ||
], | ||
"target-mcount": "_mcount", | ||
"target-pointer-width": "32" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
///! This is actually just a wrapper around linked_list_allocator that allows it to work in our environment | ||
///! Different allocator can be used if desired | ||
use core::alloc::{GlobalAlloc, Layout}; | ||
use core::cell::RefCell; | ||
use core::mem::MaybeUninit; | ||
use core::ptr::{self, NonNull}; | ||
struct Alloc { | ||
heap: RefCell<linked_list_allocator::Heap>, | ||
} | ||
|
||
impl Alloc { | ||
const fn new() -> Self { | ||
Self { | ||
heap: RefCell::new(linked_list_allocator::Heap::empty()), | ||
} | ||
} | ||
} | ||
|
||
unsafe impl GlobalAlloc for Alloc { | ||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 { | ||
self.heap | ||
.borrow_mut() | ||
.allocate_first_fit(layout) | ||
.ok() | ||
.map_or(ptr::null_mut(), |allocation| allocation.as_ptr()) | ||
} | ||
|
||
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { | ||
self.heap | ||
.borrow_mut() | ||
.deallocate(NonNull::new_unchecked(ptr), layout) | ||
} | ||
} | ||
|
||
#[global_allocator] | ||
static mut ALLOCATOR: Alloc = Alloc::new(); | ||
|
||
pub unsafe fn init(heap: &mut [MaybeUninit<u8>]) { | ||
ALLOCATOR | ||
.heap | ||
.borrow_mut() | ||
.init(heap.as_mut_ptr() as *mut u8, heap.len()) | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! init_heap { | ||
( $x:expr ) => {{ | ||
use core::mem::MaybeUninit; | ||
static mut HEAP: [MaybeUninit<u8>; $x] = [MaybeUninit::uninit(); $x]; | ||
unsafe { crate::heap::init(&mut HEAP) } | ||
}}; | ||
} |
Oops, something went wrong.