Skip to content

Commit a803464

Browse files
committed
Support building and serving examples
1 parent a107369 commit a803464

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/config/models/build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ pub struct ConfigOptsBuild {
6060
#[arg(long)]
6161
pub features: Option<String>,
6262

63+
/// Whether to build an example.
64+
#[arg(long)]
65+
pub example: Option<String>,
66+
6367
/// Whether to include hash values in the output file names [default: true]
6468
#[arg(long)]
6569
pub filehash: Option<bool>,

src/config/rt/build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ pub struct RtcBuild {
4848
pub staging_dist: PathBuf,
4949
/// The configuration of the features passed to cargo.
5050
pub cargo_features: Features,
51+
/// Optional example to be passed to cargo.
52+
pub cargo_example: Option<String>,
5153
/// Configuration for automatic application download.
5254
pub tools: ConfigOptsTools,
5355
/// Build process hooks.
@@ -160,6 +162,7 @@ impl RtcBuild {
160162
staging_dist,
161163
final_dist,
162164
cargo_features,
165+
cargo_example: opts.example,
163166
tools,
164167
hooks,
165168
inject_autoloader,
@@ -197,6 +200,7 @@ impl RtcBuild {
197200
final_dist,
198201
staging_dist,
199202
cargo_features: Features::All,
203+
cargo_example: None,
200204
tools: ConfigOptsTools {
201205
sass: None,
202206
wasm_bindgen: None,

src/pipelines/rust/mod.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,10 @@ impl RustApp {
374374
args.push("--bin");
375375
args.push(bin);
376376
}
377+
if let Some(example) = &self.cfg.cargo_example {
378+
args.push("--example");
379+
args.push(example);
380+
}
377381

378382
match &self.cargo_features {
379383
Features::All => args.push("--all-features"),
@@ -767,13 +771,22 @@ impl RustApp {
767771
return false;
768772
}
769773

770-
// must be cdylib or bin
774+
// must be cdylib, bin, or example
771775
if !(art.target.kind.contains(&"bin".to_string())
772-
|| art.target.kind.contains(&"cdylib".to_string()))
776+
|| art.target.kind.contains(&"cdylib".to_string())
777+
|| art.target.kind.contains(&"example".to_string()))
773778
{
774779
return false;
775780
}
776781

782+
// Are we building an example?
783+
if let Some(example) = &self.cfg.cargo_example {
784+
// it must match
785+
if example != &art.target.name {
786+
return false;
787+
}
788+
}
789+
777790
// if we have the --bin argument
778791
if let Some(bin) = &self.bin {
779792
// it must match

0 commit comments

Comments
 (0)