Add config option for CargoArgs

This commit is contained in:
fgh1999
2024-04-19 16:49:47 +00:00
committed by Tate, Hongliang Tian
parent 0c60a2a667
commit 94550dd5c6
3 changed files with 18 additions and 9 deletions

View File

@ -190,6 +190,12 @@ pub struct CargoArgs {
pub release: bool, pub release: bool,
#[arg(long, value_name = "FEATURES", help = "List of features to activate")] #[arg(long, value_name = "FEATURES", help = "List of features to activate")]
pub features: Vec<String>, pub features: Vec<String>,
#[arg(
long = "config",
help = "Override a configuration value",
value_name = "KEY=VALUE"
)]
pub override_configs: Vec<String>,
} }
#[derive(Debug, Args)] #[derive(Debug, Args)]

View File

@ -148,6 +148,10 @@ fn build_kernel_elf(
.arg(cargo_target_directory.as_ref()); .arg(cargo_target_directory.as_ref());
command.args(COMMON_CARGO_ARGS); command.args(COMMON_CARGO_ARGS);
command.arg("--profile=".to_string() + &args.profile); command.arg("--profile=".to_string() + &args.profile);
for override_config in &args.override_configs {
command.arg("--config").arg(override_config);
}
let status = command.status().unwrap(); let status = command.status().unwrap();
if !status.success() { if !status.success() {
error_msg!("Cargo build failed"); error_msg!("Cargo build failed");

View File

@ -147,15 +147,13 @@ fn load_osdk_manifest<S: AsRef<str>>(cargo_args: &CargoArgs, selection: Option<S
/// 1. Split `features` in `cargo_args` to ensure each string contains exactly one feature. /// 1. Split `features` in `cargo_args` to ensure each string contains exactly one feature.
/// 2. Change `profile` to `release` if `--release` is set. /// 2. Change `profile` to `release` if `--release` is set.
fn parse_cargo_args(cargo_args: &CargoArgs) -> CargoArgs { fn parse_cargo_args(cargo_args: &CargoArgs) -> CargoArgs {
let mut features = Vec::new(); let features = cargo_args
.features
for feature in cargo_args.features.iter() { .iter()
for feature in feature.split(',') { .flat_map(|feature| feature.split(','))
if !feature.is_empty() { .filter(|feature| !feature.is_empty())
features.push(feature.to_string()); .map(|feature| feature.to_string())
} .collect();
}
}
let profile = if cargo_args.release { let profile = if cargo_args.release {
"release".to_string() "release".to_string()
@ -167,6 +165,7 @@ fn parse_cargo_args(cargo_args: &CargoArgs) -> CargoArgs {
profile, profile,
release: cargo_args.release, release: cargo_args.release,
features, features,
override_configs: cargo_args.override_configs.clone(),
} }
} }