Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support building and serving examples #457

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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