Skip to content

Commit fd61ed0

Browse files
committed
feat: configure DEFAULT_BUF_SIZE from env variable
1 parent b5803a8 commit fd61ed0

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

build.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::{env, fs, path::PathBuf};
2+
13
fn main() {
24
autocfg::emit_possibility("borrowedbuf_init");
35
autocfg::rerun_path("build.rs");
@@ -13,4 +15,16 @@ fn main() {
1315
if ac.probe_raw(code).is_ok() {
1416
autocfg::emit("borrowedbuf_init");
1517
}
18+
19+
let buf_size = env::var("AXIO_DEFAULT_BUF_SIZE")
20+
.map(|v| v.parse::<usize>().expect("Invalid AXIO_DEFAULT_BUF_SIZE"))
21+
.unwrap_or(1024 * 2);
22+
fs::write(
23+
PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("config.rs"),
24+
format!(
25+
"/// Default buffer size for I/O operations.\npub const DEFAULT_BUF_SIZE: usize = {};",
26+
buf_size
27+
),
28+
)
29+
.expect("Failed to write config file");
1630
}

src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ extern crate alloc;
1111
#[doc(no_inline)]
1212
pub use axerrno::{AxError as Error, AxErrorKind as ErrorKind, AxResult as Result};
1313

14-
/// Default buffer size for I/O operations.
15-
pub const DEFAULT_BUF_SIZE: usize = 1024 * 2;
14+
include!(concat!(env!("OUT_DIR"), "/config.rs"));
1615

1716
mod buffered;
1817
pub mod prelude;

0 commit comments

Comments
 (0)