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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support passing custom profiles to cargo #295

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Trunk.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
target = "index.html"
# Build in release mode.
release = false
# Build with a custom profile, defined in the Cargo.toml.
profile = "minified"
# The output dir for all final assets.
dist = "dist"
# The public URL from which assets are to be served.
Expand Down
5 changes: 5 additions & 0 deletions src/config/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pub struct ConfigOptsBuild {
#[structopt(long)]
#[serde(default)]
pub release: bool,
/// Build artifacts with the specified profile
#[structopt(long)]
pub profile: Option<String>,
/// The output dir for all final assets [default: dist]
#[structopt(short, long, parse(from_os_str))]
pub dist: Option<PathBuf>,
Expand Down Expand Up @@ -253,6 +256,7 @@ impl ConfigOpts {
let opts = ConfigOptsBuild {
target: cli.target,
release: cli.release,
profile: cli.profile,
dist: cli.dist,
public_url: cli.public_url,
pattern_script: cli.pattern_script,
Expand Down Expand Up @@ -416,6 +420,7 @@ impl ConfigOpts {
if l.release {
g.release = true;
}
g.profile = g.profile.or(l.profile);
g.pattern_preload = g.pattern_preload.or(l.pattern_preload);
g.pattern_script = g.pattern_script.or(l.pattern_script);
g.pattern_params = g.pattern_params.or(l.pattern_params);
Expand Down
3 changes: 3 additions & 0 deletions src/config/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub struct RtcBuild {
pub target_parent: PathBuf,
/// Build in release mode.
pub release: bool,
/// Build artifacts with the specified profile.
pub profile: Option<String>,
/// The public URL from which assets are to be served.
pub public_url: String,
/// The directory where final build artifacts are placed after a successful build.
Expand Down Expand Up @@ -72,6 +74,7 @@ impl RtcBuild {
target,
target_parent,
release: opts.release,
profile: opts.profile,
staging_dist,
final_dist,
public_url: opts.public_url.unwrap_or_else(|| "/".into()),
Expand Down
7 changes: 6 additions & 1 deletion src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ pub fn spawn_hooks(cfg: Arc<RtcBuild>, stage: PipelineStage) -> HookHandles {
.args(&hook_cfg.command_arguments)
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.env("TRUNK_PROFILE", if cfg.release { "release" } else { "debug" })
.env(
"TRUNK_PROFILE",
cfg.profile
.as_deref()
.unwrap_or_else(|| if cfg.release { "release" } else { "debug" }),
)
.env("TRUNK_HTML_FILE", &cfg.target)
.env("TRUNK_SOURCE_DIR", &cfg.target_parent)
.env("TRUNK_STAGING_DIR", &cfg.staging_dist)
Expand Down
18 changes: 15 additions & 3 deletions src/pipelines/rust_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ impl RustApp {
if self.cfg.release {
args.push("--release");
}
if let Some(profile) = &self.cfg.profile {
args.push("--profile");
args.push(profile);
}
if let Some(bin) = &self.bin {
args.push("--bin");
args.push(bin);
Expand Down Expand Up @@ -210,7 +214,11 @@ impl RustApp {

// Ensure our output dir is in place.
let wasm_bindgen_name = Application::WasmBindgen.name();
let mode_segment = if self.cfg.release { "release" } else { "debug" };
let mode_segment = self
.cfg
.profile
.as_deref()
.unwrap_or_else(|| if self.cfg.release { "release" } else { "debug" });
let bindgen_out = self
.manifest
.metadata
Expand Down Expand Up @@ -273,7 +281,7 @@ impl RustApp {
#[tracing::instrument(level = "trace", skip(self, hashed_name))]
async fn wasm_opt_build(&self, hashed_name: &str) -> Result<()> {
// If not in release mode, we skip calling wasm-opt.
if !self.cfg.release {
if !self.cfg.release && self.cfg.profile.is_none() {
return Ok(());
}

Expand All @@ -287,7 +295,11 @@ impl RustApp {

// Ensure our output dir is in place.
let wasm_opt_name = Application::WasmOpt.name();
let mode_segment = if self.cfg.release { "release" } else { "debug" };
let mode_segment = self
.cfg
.profile
.as_deref()
.unwrap_or_else(|| if self.cfg.release { "release" } else { "debug" });
let output = self
.manifest
.metadata
Expand Down
6 changes: 5 additions & 1 deletion src/pipelines/sass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ impl Sass {
let sass = tools::get(Application::Sass, version).await?;

// Compile the target SASS/SCSS file.
let style = if self.cfg.release { "compressed" } else { "expanded" };
let style = if self.cfg.profile.is_some() || self.cfg.release {
"compressed"
} else {
"expanded"
};
let path_str = dunce::simplified(&self.asset.path).display().to_string();
let file_name = format!("{}.css", &self.asset.file_stem.to_string_lossy());
let file_path = dunce::simplified(&self.cfg.staging_dist.join(&file_name))
Expand Down