Skip to content

Commit 6d948c8

Browse files
committed
add support for building examples
1 parent 4c9d85f commit 6d948c8

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

src/cmd/build.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ pub struct Build {
7878
#[arg(default_missing_value="true", num_args=0..=1)]
7979
pub filehash: Option<bool>,
8080

81+
/// Which example to build
82+
#[arg(long, env = "TRUNK_BUILD_EXAMPLE")]
83+
pub example: Option<String>,
84+
8185
/// When desired, set a custom root certificate chain (same format as Cargo's config.toml http.cainfo)
8286
#[arg(long, env = "TRUNK_BUILD_ROOT_CERTIFICATE")]
8387
pub root_certificate: Option<String>,
@@ -135,6 +139,7 @@ impl Build {
135139
all_features,
136140
features,
137141
filehash,
142+
example,
138143
root_certificate,
139144
accept_invalid_certs,
140145
minify,
@@ -160,6 +165,7 @@ impl Build {
160165
config.build.features = features.unwrap_or(config.build.features);
161166

162167
config.build.filehash = filehash.unwrap_or(config.build.filehash);
168+
config.build.example = example.or(config.build.example);
163169

164170
config.build.root_certificate = root_certificate.or(config.build.root_certificate);
165171
config.build.accept_invalid_certs =

src/config/models/build.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ pub struct Build {
7171
#[serde(default = "default::filehash")]
7272
pub filehash: bool,
7373

74+
/// Whether to build an example.
75+
#[serde(default)]
76+
#[serde(skip_serializing_if = "Option::is_none")]
77+
pub example: Option<String>,
78+
7479
/// Optional pattern for the app loader script [default: None]
7580
///
7681
/// Patterns should include the sequences `{base}`, `{wasm}`, and `{js}` in order to
@@ -200,6 +205,7 @@ impl Default for Build {
200205
no_default_features: false,
201206
all_features: false,
202207
features: vec![],
208+
example: None,
203209
filehash: default::filehash(),
204210
pattern_script: None,
205211
inject_scripts: default::inject_scripts(),

src/config/rt/build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ pub struct RtcBuild {
5454
pub staging_dist: PathBuf,
5555
/// The configuration of the features passed to cargo.
5656
pub cargo_features: Features,
57+
/// Optional example to be passed to cargo.
58+
pub cargo_example: Option<String>,
5759
/// Configuration for automatic application download.
5860
pub tools: Tools,
5961
/// Build process hooks.
@@ -186,6 +188,7 @@ impl RtcBuild {
186188
staging_dist,
187189
final_dist,
188190
cargo_features,
191+
cargo_example: build.example,
189192
tools,
190193
hooks,
191194
inject_autoloader,
@@ -227,6 +230,7 @@ impl RtcBuild {
227230
final_dist,
228231
staging_dist,
229232
cargo_features: Features::All,
233+
cargo_example: None,
230234
tools: Default::default(),
231235
hooks: Vec::new(),
232236
inject_autoloader: true,

src/pipelines/rust/mod.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,10 @@ impl RustApp {
420420
args.push("--bin");
421421
args.push(bin);
422422
}
423+
if let Some(example) = &self.cfg.cargo_example {
424+
args.push("--example");
425+
args.push(example);
426+
}
423427

424428
match &self.cargo_features {
425429
Features::All => args.push("--all-features"),
@@ -818,13 +822,22 @@ impl RustApp {
818822
return false;
819823
}
820824

821-
// must be cdylib or bin
825+
// must be cdylib, bin, or example
822826
if !(art.target.kind.contains(&"bin".to_string())
823-
|| art.target.kind.contains(&"cdylib".to_string()))
827+
|| art.target.kind.contains(&"cdylib".to_string())
828+
|| art.target.kind.contains(&"example".to_string()))
824829
{
825830
return false;
826831
}
827832

833+
// Are we building an example?
834+
if let Some(example) = &self.cfg.cargo_example {
835+
// it must match
836+
if example != &art.target.name {
837+
return false;
838+
}
839+
}
840+
828841
// if we have the --bin argument
829842
if let Some(bin) = &self.bin {
830843
// it must match

0 commit comments

Comments
 (0)