Skip to content

Commit

Permalink
Ensure that library is no_std
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgecrw committed Oct 2, 2024
1 parent 60083b0 commit 4be637b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ publish:
cargo publish -p musicxml

checknostd:
cd ensure_no_std && cargo rustc -- -C link-arg=-nostartfiles
cd ensure_no_std && cargo build --release --target x86_64-unknown-none

check:
cargo clippy -- -W clippy::all -W clippy::correctness -W clippy::suspicious -W clippy::complexity -W clippy::perf -W clippy::style -W clippy::pedantic -W clippy::panic -A clippy::doc_markdown -A clippy::wildcard_imports -A clippy::module_name_repetitions -D warnings
Expand Down
18 changes: 17 additions & 1 deletion ensure_no_std/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
#![no_std]
#![no_main]
#[allow(unused_imports)]

extern crate alloc;

#[allow(unused_imports)]
use musicxml;
use core::panic::PanicInfo;
use alloc::alloc::{GlobalAlloc, Layout};

#[derive(Default)]
pub struct Allocator;
unsafe impl GlobalAlloc for Allocator {
unsafe fn alloc(&self, _layout: Layout) -> *mut u8 {
core::ptr::null_mut()
}
unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {
}
}

#[global_allocator]
static GLOBAL_ALLOCATOR: Allocator = Allocator;

#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
Expand Down
3 changes: 3 additions & 0 deletions musicxml/src/parser/zip_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
use alloc::{collections::BTreeMap, vec::Vec};
use miniz_oxide::inflate::decompress_to_vec;

#[cfg(not(feature = "std"))]
use alloc::string::{String, ToString};

const DEFLATE_METHOD_CODE: u16 = 8;
const LOCAL_FILE_HEADER_LEN: usize = core::mem::size_of::<LocalFileHeader>();
const CENTRAL_FILE_HEADER_LEN: usize = core::mem::size_of::<CentralFileHeader>();
Expand Down

0 comments on commit 4be637b

Please sign in to comment.