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 9, 2023
1 parent b41a957 commit ba5250b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Subheadings to categorize changes are `added, changed, deprecated, removed, fixe
- Added `data-target-path` to `copy-dir`.
- Allow processing `<script>` tags with the asset pipeline.
- Added `data-loader-shim` to workers to create shim script.
- Added `--example` command line option to `trunk build`, `serve` and `watch`.
### changed
- Updated gloo-worker example to use gloo-worker crate v2.1.
- Our website (trunkrs.dev) now only updates on new releases.
Expand Down
18 changes: 4 additions & 14 deletions src/config/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ pub struct ConfigOptsBuild {
/// [default: ""]
#[arg(long)]
pub features: Option<String>,
/// Whether to build an example.
#[clap(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 Expand Up @@ -283,21 +286,8 @@ impl ConfigOpts {
}

fn cli_opts_layer_build(cli: ConfigOptsBuild, cfg_base: Self) -> Self {
let opts = ConfigOptsBuild {
target: cli.target,
release: cli.release,
dist: cli.dist,
public_url: cli.public_url,
no_default_features: cli.no_default_features,
all_features: cli.all_features,
features: cli.features,
filehash: cli.filehash,
pattern_script: cli.pattern_script,
pattern_preload: cli.pattern_preload,
pattern_params: cli.pattern_params,
};
let cfg_build = ConfigOpts {
build: Some(opts),
build: Some(cli),
watch: None,
serve: None,
clean: None,
Expand Down
3 changes: 3 additions & 0 deletions src/config/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ pub struct RtcBuild {
pub staging_dist: PathBuf,
/// The configuration of the features passed to cargo.
pub cargo_features: Features,
/// If set, the example passed to cargo.
pub cargo_example: Option<String>,
/// Configuration for automatic application download.
pub tools: ConfigOptsTools,
/// Build process hooks.
Expand Down Expand Up @@ -125,6 +127,7 @@ impl RtcBuild {
staging_dist,
final_dist,
cargo_features,
cargo_example: opts.example,
tools,
hooks,
inject_autoloader,
Expand Down
10 changes: 10 additions & 0 deletions src/pipelines/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub struct RustApp {
/// An optional binary name which will cause cargo & wasm-bindgen to process only the target
/// binary.
bin: Option<String>,
/// An optional example to build.
example: Option<String>,
/// An option to instruct wasm-bindgen to preserve debug info in the final WASM output, even
/// for `--release` mode.
keep_debug: bool,
Expand Down Expand Up @@ -161,13 +163,16 @@ impl RustApp {
}
};

let example = cfg.cargo_example.clone();

Ok(Self {
id,
cfg,
cargo_features,
manifest,
ignore_chan,
bin,
example,
keep_debug,
typescript,
no_demangle,
Expand Down Expand Up @@ -196,6 +201,7 @@ impl RustApp {
manifest,
ignore_chan,
bin: None,
example: None,
keep_debug: false,
typescript: false,
no_demangle: false,
Expand Down Expand Up @@ -240,6 +246,10 @@ impl RustApp {
args.push("--bin");
args.push(bin);
}
if let Some(example) = &self.example {
args.push("--example");
args.push(example);
}

match &self.cargo_features {
Features::All => args.push("--all-features"),
Expand Down

0 comments on commit ba5250b

Please sign in to comment.