Testing a small http-client on Linux using no_std & embedded reqwless.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add nightly immediate-abort size build command

rektide 8fe60d49 90168248

+90
+19
README.md
··· 75 75 - HTTPS profile (`--no-default-features --features backend-posix-libc,dns-getaddrinfo,https`) 76 76 - Before: `631408` bytes 77 77 - After: `296824` bytes 78 + 79 + ## Nightly aggressive size build 80 + 81 + For nightly-only size optimizations, including location/detail stripping, debug-fmt stripping, 82 + and `panic=immediate-abort`, use: 83 + 84 + ```bash 85 + cargo run -p xtask -- nightly-size -- --no-default-features --features backend-posix-libc,dns-getaddrinfo 86 + ``` 87 + 88 + This command applies: 89 + 90 + - `RUSTFLAGS="-Zlocation-detail=none -Zfmt-debug=none -Zunstable-options -Cpanic=immediate-abort"` 91 + - `-Z build-std=std,panic_abort` 92 + - `-Z build-std-features=` 93 + 94 + Measured with the HTTP profile above on this repository: 95 + 96 + - Nightly aggressive output size: `41288` bytes
+8
xtask/src/main.rs
··· 1 1 // pattern: Imperative Shell 2 2 3 + mod nightly_size; 3 4 mod validate; 4 5 5 6 use clap::{Parser, Subcommand}; 7 + use nightly_size::run_nightly_size_build; 6 8 use validate::{run_validate_tasks, ValidateTask}; 7 9 8 10 #[derive(Parser)] ··· 19 21 #[arg(value_enum)] 20 22 tasks: Vec<ValidateTask>, 21 23 }, 24 + /// Build with nightly-only size flags and panic=immediate-abort. 25 + NightlySize { 26 + #[arg(trailing_var_arg = true, allow_hyphen_values = true)] 27 + args: Vec<String>, 28 + }, 22 29 } 23 30 24 31 fn main() { ··· 32 39 let cli = Cli::parse(); 33 40 match cli.command { 34 41 Task::Validate { tasks } => run_validate_tasks(&tasks), 42 + Task::NightlySize { args } => run_nightly_size_build(&args), 35 43 } 36 44 }
+63
xtask/src/nightly_size.rs
··· 1 + use std::env; 2 + use std::process::Command; 3 + 4 + const NIGHTLY_SIZE_RUSTFLAGS: &str = 5 + "-Zlocation-detail=none -Zfmt-debug=none -Zunstable-options -Cpanic=immediate-abort"; 6 + 7 + pub fn run_nightly_size_build(extra_args: &[String]) -> Result<(), String> { 8 + let host_target = detect_host_target()?; 9 + let rustflags = compose_rustflags(); 10 + 11 + let mut command = Command::new("cargo"); 12 + command 13 + .arg("+nightly") 14 + .arg("build") 15 + .arg("--release") 16 + .arg("-Z") 17 + .arg("build-std=std,panic_abort") 18 + .arg("-Z") 19 + .arg("build-std-features=") 20 + .arg("--target") 21 + .arg(&host_target) 22 + .args(extra_args) 23 + .env("RUSTFLAGS", rustflags); 24 + 25 + let status = command 26 + .status() 27 + .map_err(|error| format!("failed to run cargo +nightly build: {error}"))?; 28 + if status.success() { 29 + Ok(()) 30 + } else { 31 + Err(format!("nightly size build failed with status {status}")) 32 + } 33 + } 34 + 35 + fn compose_rustflags() -> String { 36 + match env::var("RUSTFLAGS") { 37 + Ok(existing_flags) if !existing_flags.trim().is_empty() => { 38 + format!("{existing_flags} {NIGHTLY_SIZE_RUSTFLAGS}") 39 + } 40 + _ => NIGHTLY_SIZE_RUSTFLAGS.to_owned(), 41 + } 42 + } 43 + 44 + fn detect_host_target() -> Result<String, String> { 45 + let output = Command::new("rustc") 46 + .arg("-vV") 47 + .output() 48 + .map_err(|error| format!("failed to run rustc -vV: {error}"))?; 49 + if !output.status.success() { 50 + return Err(format!("rustc -vV failed with status {}", output.status)); 51 + } 52 + 53 + let stdout = String::from_utf8(output.stdout) 54 + .map_err(|error| format!("rustc -vV output is not valid UTF-8: {error}"))?; 55 + 56 + for line in stdout.lines() { 57 + if let Some(host_target) = line.strip_prefix("host: ") { 58 + return Ok(host_target.to_owned()); 59 + } 60 + } 61 + 62 + Err("failed to detect host target triple from rustc -vV".to_owned()) 63 + }