diff --git a/src/config/models/build.rs b/src/config/models/build.rs index 723d792a..7a439b29 100644 --- a/src/config/models/build.rs +++ b/src/config/models/build.rs @@ -60,6 +60,10 @@ pub struct ConfigOptsBuild { #[arg(long)] pub features: Option, + /// Whether to build an example. + #[arg(long)] + pub example: Option, + /// Whether to include hash values in the output file names [default: true] #[arg(long)] pub filehash: Option, diff --git a/src/config/rt/build.rs b/src/config/rt/build.rs index 10f24e09..d53d9363 100644 --- a/src/config/rt/build.rs +++ b/src/config/rt/build.rs @@ -48,6 +48,8 @@ pub struct RtcBuild { pub staging_dist: PathBuf, /// The configuration of the features passed to cargo. pub cargo_features: Features, + /// Optional example to be passed to cargo. + pub cargo_example: Option, /// Configuration for automatic application download. pub tools: ConfigOptsTools, /// Build process hooks. @@ -160,6 +162,7 @@ impl RtcBuild { staging_dist, final_dist, cargo_features, + cargo_example: opts.example, tools, hooks, inject_autoloader, @@ -197,6 +200,7 @@ impl RtcBuild { final_dist, staging_dist, cargo_features: Features::All, + cargo_example: None, tools: ConfigOptsTools { sass: None, wasm_bindgen: None, diff --git a/src/pipelines/rust/mod.rs b/src/pipelines/rust/mod.rs index ca110f50..1895dcd9 100644 --- a/src/pipelines/rust/mod.rs +++ b/src/pipelines/rust/mod.rs @@ -374,6 +374,10 @@ impl RustApp { args.push("--bin"); args.push(bin); } + if let Some(example) = &self.cfg.cargo_example { + args.push("--example"); + args.push(example); + } match &self.cargo_features { Features::All => args.push("--all-features"), @@ -767,13 +771,22 @@ impl RustApp { return false; } - // must be cdylib or bin + // must be cdylib, bin, or example if !(art.target.kind.contains(&"bin".to_string()) - || art.target.kind.contains(&"cdylib".to_string())) + || art.target.kind.contains(&"cdylib".to_string()) + || art.target.kind.contains(&"example".to_string())) { return false; } + // Are we building an example? + if let Some(example) = &self.cfg.cargo_example { + // it must match + if example != &art.target.name { + return false; + } + } + // if we have the --bin argument if let Some(bin) = &self.bin { // it must match