diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-08-15 17:05:45 +0200 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2025-08-25 19:44:50 +0200 |
| commit | a34e0b1ec57350cfa1d61aa6fc2eced077be5623 (patch) | |
| tree | f2272f878eda77d2f148152bfa6b9f4fcbb7d84e /release | |
| parent | 648938b6623954a71ecee2990d57ce9df2e197b7 (diff) | |
Add build command.
Diffstat (limited to 'release')
| -rw-r--r-- | release/src/build.rs | 45 | ||||
| -rw-r--r-- | release/src/cargo.rs | 54 | ||||
| -rw-r--r-- | release/src/main.rs | 6 |
3 files changed, 97 insertions, 8 deletions
diff --git a/release/src/build.rs b/release/src/build.rs index adf251b4d..d1abb2aa1 100644 --- a/release/src/build.rs +++ b/release/src/build.rs | |||
| @@ -1,5 +1,46 @@ | |||
| 1 | use anyhow::Result; | 1 | use anyhow::Result; |
| 2 | 2 | ||
| 3 | pub(crate) fn build(ctx: &crate::Context) -> Result<()> { | 3 | use crate::cargo::{CargoArgsBuilder, CargoBatchBuilder}; |
| 4 | todo!() | 4 | |
| 5 | pub(crate) fn build(ctx: &crate::Context, crate_name: Option<&str>) -> Result<()> { | ||
| 6 | let mut batch_builder = CargoBatchBuilder::new(); | ||
| 7 | |||
| 8 | // Process either specific crate or all crates | ||
| 9 | let crates_to_build: Vec<_> = if let Some(name) = crate_name { | ||
| 10 | // Build only the specified crate | ||
| 11 | if let Some(krate) = ctx.crates.get(name) { | ||
| 12 | vec![krate] | ||
| 13 | } else { | ||
| 14 | return Err(anyhow::anyhow!("Crate '{}' not found", name)); | ||
| 15 | } | ||
| 16 | } else { | ||
| 17 | // Build all crates | ||
| 18 | ctx.crates.values().collect() | ||
| 19 | }; | ||
| 20 | |||
| 21 | // Process selected crates and add their build configurations to the batch | ||
| 22 | for krate in crates_to_build { | ||
| 23 | for config in &krate.configs { | ||
| 24 | let mut args_builder = CargoArgsBuilder::new() | ||
| 25 | .subcommand("build") | ||
| 26 | .arg("--release") | ||
| 27 | .arg(format!("--manifest-path={}/Cargo.toml", krate.path.to_string_lossy())); | ||
| 28 | |||
| 29 | if let Some(ref target) = config.target { | ||
| 30 | args_builder = args_builder.target(target); | ||
| 31 | } | ||
| 32 | |||
| 33 | if !config.features.is_empty() { | ||
| 34 | args_builder = args_builder.features(&config.features); | ||
| 35 | } | ||
| 36 | |||
| 37 | batch_builder.add_command(args_builder.build()); | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | // Execute the cargo batch command | ||
| 42 | let batch_args = batch_builder.build(); | ||
| 43 | crate::cargo::run(&batch_args, &ctx.root)?; | ||
| 44 | |||
| 45 | Ok(()) | ||
| 5 | } | 46 | } |
diff --git a/release/src/cargo.rs b/release/src/cargo.rs index 1a4f79f20..0b28458e9 100644 --- a/release/src/cargo.rs +++ b/release/src/cargo.rs | |||
| @@ -1,10 +1,8 @@ | |||
| 1 | //! Tools for working with Cargo. | 1 | //! Tools for working with Cargo. |
| 2 | 2 | ||
| 3 | use std::{ | 3 | use std::ffi::OsStr; |
| 4 | ffi::OsStr, | 4 | use std::path::{Path, PathBuf}; |
| 5 | path::{Path, PathBuf}, | 5 | use std::process::{Command, Stdio}; |
| 6 | process::{Command, Stdio}, | ||
| 7 | }; | ||
| 8 | 6 | ||
| 9 | use anyhow::{bail, Context as _, Result}; | 7 | use anyhow::{bail, Context as _, Result}; |
| 10 | use clap::ValueEnum as _; | 8 | use clap::ValueEnum as _; |
| @@ -107,6 +105,17 @@ pub struct CargoArgsBuilder { | |||
| 107 | 105 | ||
| 108 | impl CargoArgsBuilder { | 106 | impl CargoArgsBuilder { |
| 109 | #[must_use] | 107 | #[must_use] |
| 108 | pub fn new() -> Self { | ||
| 109 | Self { | ||
| 110 | toolchain: None, | ||
| 111 | subcommand: String::new(), | ||
| 112 | target: None, | ||
| 113 | features: vec![], | ||
| 114 | args: vec![], | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | #[must_use] | ||
| 110 | pub fn toolchain<S>(mut self, toolchain: S) -> Self | 119 | pub fn toolchain<S>(mut self, toolchain: S) -> Self |
| 111 | where | 120 | where |
| 112 | S: Into<String>, | 121 | S: Into<String>, |
| @@ -192,3 +201,38 @@ impl CargoArgsBuilder { | |||
| 192 | args | 201 | args |
| 193 | } | 202 | } |
| 194 | } | 203 | } |
| 204 | |||
| 205 | #[derive(Debug, Default)] | ||
| 206 | pub struct CargoBatchBuilder { | ||
| 207 | commands: Vec<Vec<String>>, | ||
| 208 | } | ||
| 209 | |||
| 210 | impl CargoBatchBuilder { | ||
| 211 | #[must_use] | ||
| 212 | pub fn new() -> Self { | ||
| 213 | Self { commands: vec![] } | ||
| 214 | } | ||
| 215 | |||
| 216 | #[must_use] | ||
| 217 | pub fn command(mut self, args: Vec<String>) -> Self { | ||
| 218 | self.commands.push(args); | ||
| 219 | self | ||
| 220 | } | ||
| 221 | |||
| 222 | pub fn add_command(&mut self, args: Vec<String>) -> &mut Self { | ||
| 223 | self.commands.push(args); | ||
| 224 | self | ||
| 225 | } | ||
| 226 | |||
| 227 | #[must_use] | ||
| 228 | pub fn build(&self) -> Vec<String> { | ||
| 229 | let mut args = vec!["batch".to_string()]; | ||
| 230 | |||
| 231 | for command in &self.commands { | ||
| 232 | args.push("---".to_string()); | ||
| 233 | args.extend(command.clone()); | ||
| 234 | } | ||
| 235 | |||
| 236 | args | ||
| 237 | } | ||
| 238 | } | ||
diff --git a/release/src/main.rs b/release/src/main.rs index 7850bbb8d..b1bc17255 100644 --- a/release/src/main.rs +++ b/release/src/main.rs | |||
| @@ -134,6 +134,10 @@ fn list_crates(root: &PathBuf) -> Result<BTreeMap<CrateId, Crate>> { | |||
| 134 | 134 | ||
| 135 | let metadata = &parsed.package.metadata.embassy; | 135 | let metadata = &parsed.package.metadata.embassy; |
| 136 | 136 | ||
| 137 | if metadata.skip { | ||
| 138 | continue; | ||
| 139 | } | ||
| 140 | |||
| 137 | let mut dependencies = Vec::new(); | 141 | let mut dependencies = Vec::new(); |
| 138 | for (k, _) in parsed.dependencies { | 142 | for (k, _) in parsed.dependencies { |
| 139 | if k.starts_with("embassy-") { | 143 | if k.starts_with("embassy-") { |
| @@ -266,7 +270,7 @@ fn main() -> Result<()> { | |||
| 266 | } | 270 | } |
| 267 | } | 271 | } |
| 268 | Command::Build { crate_name } => { | 272 | Command::Build { crate_name } => { |
| 269 | build::build(&ctx)?; | 273 | build::build(&ctx, crate_name.as_deref())?; |
| 270 | } | 274 | } |
| 271 | Command::SemverCheck { crate_name } => { | 275 | Command::SemverCheck { crate_name } => { |
| 272 | let c = ctx.crates.get(&crate_name).unwrap(); | 276 | let c = ctx.crates.get(&crate_name).unwrap(); |
