Skip to content

Commit

Permalink
Change ensure_no_std to just build and thumbv7em-none-eabihf
Browse files Browse the repository at this point in the history
  • Loading branch information
wcampbell0x2a committed Aug 9, 2023
1 parent 5d4a8b2 commit 0d80be6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ jobs:
with:
toolchain: nightly
override: true
- run: cd ensure_no_std && cargo run --release
target: thumbv7em-none-eabihf
- run: cd ensure_no_std && cargo build --release --target thumbv7em-none-eabihf

ensure_wasm:
name: Ensure wasm
Expand Down
3 changes: 2 additions & 1 deletion ensure_no_std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ default = ["alloc"]
alloc = []

[dependencies]
wee_alloc = "0.4"
cortex-m-rt = "0.7.3"
deku = { path = "../", default-features = false, features = ["alloc"] }
embedded-alloc = "0.5.0"

40 changes: 24 additions & 16 deletions ensure_no_std/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
//! Based on https://github.com/rustwasm/wee_alloc/tree/master/example
//! Run with `cargo +nightly run --release`
//! cargo build --target thumbv7em-none-eabihf
#![no_std]
#![no_main]
#![feature(core_intrinsics, alloc_error_handler)]

extern crate alloc;
extern crate wee_alloc;

#[no_mangle]
pub extern "C" fn _start() -> ! {
loop {}
}
use core::panic::PanicInfo;

#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
}
use cortex_m_rt::entry;
use embedded_alloc::Heap;

#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
static HEAP: Heap = Heap::empty();

use alloc::{format, vec, vec::Vec};
use deku::prelude::*;
Expand All @@ -35,8 +26,18 @@ struct DekuTest {
data: Vec<u8>,
}

#[no_mangle]
pub extern "C" fn main() -> () {
#[entry]
fn main() -> ! {
// Initialize the allocator BEFORE you use it
{
use core::mem::MaybeUninit;
const HEAP_SIZE: usize = 1024;
static mut HEAP_MEM: [MaybeUninit<u8>; HEAP_SIZE] = [MaybeUninit::uninit(); HEAP_SIZE];
unsafe { HEAP.init(HEAP_MEM.as_ptr() as usize, HEAP_SIZE) }
}

// now the allocator is ready types like Box, Vec can be used.

let test_data: Vec<u8> = vec![0b10101_101, 0x02, 0xBE, 0xEF];

// Test reading
Expand All @@ -54,4 +55,11 @@ pub extern "C" fn main() -> () {
// Test writing
let val = val.to_bytes().unwrap();
assert_eq!(test_data, val);

loop { /* .. */ }
}

#[panic_handler]
fn panic(_: &PanicInfo) -> ! {
loop {}
}
2 changes: 2 additions & 0 deletions src/impls/primitive.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#[cfg(feature = "alloc")]
use alloc::format;
#[cfg(feature = "alloc")]
use alloc::string::ToString;
use core::convert::TryInto;

use acid_io::Read;
Expand Down
4 changes: 2 additions & 2 deletions src/impls/slice.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Implementations of DekuRead and DekuWrite for [T; N] where 0 < N <= 32
use bitvec::prelude::*;
pub use deku_derive::*;

use crate::{DekuError, DekuRead, DekuWrite};

#[cfg(feature = "const_generics")]
mod const_generics_impl {
use bitvec::prelude::*;
use crate::{DekuError, DekuRead, DekuWrite};
use core::mem::MaybeUninit;
use std::io::Read;

Expand Down

0 comments on commit 0d80be6

Please sign in to comment.