Skip to content

Commit

Permalink
Support building and serving examples
Browse files Browse the repository at this point in the history
  • Loading branch information
pragmatrix committed Mar 27, 2024
1 parent a107369 commit a803464
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/config/models/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ pub struct ConfigOptsBuild {
#[arg(long)]
pub features: Option<String>,

/// Whether to build an example.
#[arg(long)]
pub example: Option<String>,

/// Whether to include hash values in the output file names [default: true]
#[arg(long)]
pub filehash: Option<bool>,
Expand Down
4 changes: 4 additions & 0 deletions src/config/rt/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// Configuration for automatic application download.
pub tools: ConfigOptsTools,
/// Build process hooks.
Expand Down Expand Up @@ -160,6 +162,7 @@ impl RtcBuild {
staging_dist,
final_dist,
cargo_features,
cargo_example: opts.example,
tools,
hooks,
inject_autoloader,
Expand Down Expand Up @@ -197,6 +200,7 @@ impl RtcBuild {
final_dist,
staging_dist,
cargo_features: Features::All,
cargo_example: None,
tools: ConfigOptsTools {
sass: None,
wasm_bindgen: None,
Expand Down
17 changes: 15 additions & 2 deletions src/pipelines/rust/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a803464

Please sign in to comment.