This repository was archived by the owner on Aug 25, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 7 files changed +65
-10
lines changed Expand file tree Collapse file tree 7 files changed +65
-10
lines changed Original file line number Diff line number Diff line change 11** /target /
22** /* .rs.bk
33Cargo.lock
4+ .idea
Original file line number Diff line number Diff line change @@ -110,10 +110,13 @@ static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
110110 runtime overhead. It is useful when debugging a use-after-free or ` wee_alloc `
111111 itself.
112112
113- - ** static_array_backend** : Force the use of an OS-independent fixed-size (16 MB)
114- backing implementation. Suitable for deploying to non-WASM/Unix/Windows
115- ` #![no_std] ` environments, such as on embedded devices with esoteric or effectively
116- absent operating systems.
113+ - ** static_array_backend** : Force the use of an OS-independent backing
114+ implementation with a global maximum size fixed at compile time.
115+ Suitable for deploying to non-WASM/Unix/Windows ` #![no_std] ` environments,
116+ such as on embedded devices with esoteric or effectively absent operating
117+ systems. The size defaults to 32 MiB (33554432 bytes), and may be controlled
118+ at build-time by supplying an optional environment variable to cargo,
119+ ` WEE_ALLOC_STATIC_ARRAY_BACKEND_BYTES `
117120
118121### Implementation Notes and Constraints
119122
Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ cargo check --target i686-pc-windows-gnu
1111cargo check --features size_classes
1212cargo check --features size_classes --target wasm32-unknown-unknown
1313cargo check --features size_classes --target i686-pc-windows-gnu
14+ cargo check --no-default-features --features " static_array_backend"
15+ cargo check --no-default-features --features " static_array_backend size_classes"
1416cd -
1517
1618cd ./test
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ extra_assertions = []
2626size_classes = []
2727
2828# Enable fixed-sized, OS-independent backing memory implementation
29- static_array_backend = []
29+ static_array_backend = [" spin " ]
3030
3131# This is for internal use only.
3232use_std_for_test_debugging = []
@@ -38,6 +38,7 @@ unreachable = "1.0.0"
3838
3939[dependencies .spin ]
4040version = " 0.4"
41+ optional = true
4142default-features = false
4243features = [" const_fn" ]
4344
Original file line number Diff line number Diff line change 1+ use std:: env:: { self , VarError } ;
2+ use std:: fs:: File ;
3+ use std:: io:: Write ;
4+ use std:: path:: Path ;
5+
6+ const DEFAULT_STATIC_ARRAY_BACKEND_SIZE_BYTES : u32 = 1024 * 1024 * 32 ;
7+ const WEE_ALLOC_STATIC_ARRAY_BACKEND_BYTES : & ' static str = "WEE_ALLOC_STATIC_ARRAY_BACKEND_BYTES" ;
8+
9+ fn main ( ) {
10+ create_static_array_backend_size_bytes_file ( ) ;
11+ export_rerun_rules ( ) ;
12+ }
13+
14+ fn create_static_array_backend_size_bytes_file ( ) {
15+ let out_dir = env:: var ( "OUT_DIR" ) . expect ( "OUT_DIR environment variable not provided" ) ;
16+ let dest_path = Path :: new ( & out_dir) . join ( "wee_alloc_static_array_backend_size_bytes.txt" ) ;
17+ let size: u32 = match env:: var ( WEE_ALLOC_STATIC_ARRAY_BACKEND_BYTES ) {
18+ Ok ( s) => s. parse ( ) . expect ( "Could not interpret WEE_ALLOC_STATIC_ARRAY_BACKEND_BYTES as a 32 bit unsigned integer" ) ,
19+ Err ( ve) => match ve {
20+ VarError :: NotPresent => { DEFAULT_STATIC_ARRAY_BACKEND_SIZE_BYTES } ,
21+ VarError :: NotUnicode ( _) => { panic ! ( "Could not interpret WEE_ALLOC_STATIC_ARRAY_BACKEND_BYTES as a string representing a 32 bit unsigned integer" ) } ,
22+ } ,
23+ } ;
24+ let mut f = File :: create ( & dest_path)
25+ . expect ( "Could not create file to store wee_alloc static_array_backend size metadata." ) ;
26+ write ! ( f, "{}" , size)
27+ . expect ( "Could not write to wee_alloc static_array_backend size metadata file" ) ;
28+ f. flush ( )
29+ . expect ( "Could not flush write to wee_alloc static_array_backend size metadata file" ) ;
30+ }
31+ fn export_rerun_rules ( ) {
32+ println ! (
33+ "cargo:rerun-if-env-changed={}" ,
34+ WEE_ALLOC_STATIC_ARRAY_BACKEND_BYTES
35+ ) ;
36+ for path in [
37+ "./Cargo.toml" ,
38+ "./build.rs" ,
39+ "./src/lib.rs" ,
40+ "./src/imp_static_array.rs" ,
41+ ] . iter ( )
42+ {
43+ println ! ( "cargo:rerun-if-changed={}" , path) ;
44+ }
45+ }
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ use core::ptr::NonNull;
66use memory_units:: { Bytes , Pages } ;
77use spin:: Mutex ;
88
9- const SCRATCH_LEN_BYTES : usize = 1024 * 1024 * 32 ;
9+ const SCRATCH_LEN_BYTES : usize = include ! ( concat! ( env! ( "OUT_DIR" ) , "/wee_alloc_static_array_backend_size_bytes.txt" ) ) ;
1010static mut SCRATCH_HEAP : [ u8 ; SCRATCH_LEN_BYTES ] = [ 0 ; SCRATCH_LEN_BYTES ] ;
1111static mut OFFSET : Mutex < usize > = Mutex :: new ( 0 ) ;
1212
Original file line number Diff line number Diff line change @@ -110,10 +110,13 @@ static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
110110 runtime overhead. It is useful when debugging a use-after-free or `wee_alloc`
111111 itself.
112112
113- - **static_array_backend**: Force the use of an OS-independent fixed-size (16 MB)
114- backing implementation. Suitable for deploying to non-WASM/Unix/Windows
115- `#![no_std]` environments, such as on embedded devices with esoteric or effectively
116- absent operating systems.
113+ - **static_array_backend**: Force the use of an OS-independent backing
114+ implementation with a global maximum size fixed at compile time.
115+ Suitable for deploying to non-WASM/Unix/Windows `#![no_std]` environments,
116+ such as on embedded devices with esoteric or effectively absent operating
117+ systems. The size defaults to 32 MiB (33554432 bytes), and may be controlled
118+ at build-time by supplying an optional environment variable to cargo,
119+ `WEE_ALLOC_STATIC_ARRAY_BACKEND_BYTES`
117120
118121## Implementation Notes and Constraints
119122
You can’t perform that action at this time.
0 commit comments