diff --git a/Makefile b/Makefile index 6c0aad1..7973c4e 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/ensure_no_std/src/main.rs b/ensure_no_std/src/main.rs index 157c5dc..518f18a 100644 --- a/ensure_no_std/src/main.rs +++ b/ensure_no_std/src/main.rs @@ -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) -> ! { diff --git a/musicxml/src/parser/zip_parser.rs b/musicxml/src/parser/zip_parser.rs index 63221d5..6ae0ed3 100644 --- a/musicxml/src/parser/zip_parser.rs +++ b/musicxml/src/parser/zip_parser.rs @@ -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::(); const CENTRAL_FILE_HEADER_LEN: usize = core::mem::size_of::();