Skip to content

Commit

Permalink
chore: try to make cargo profile messages make more sense
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Sep 16, 2024
1 parent 56cb22c commit 8fa20a8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Trunk.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ trunk-version = "*"
target = "index.html"
# Build in release mode.
release = false
# Use a custom cargo profile
# Use a custom cargo profile. Overrides the default chosen by cargo. Ignored if the 'index.html' has one configured.
# cargo_profile = ""
# The output dir for all final assets.
dist = "dist"
Expand Down
2 changes: 1 addition & 1 deletion schemas/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"type": "boolean"
},
"cargo_profile": {
"description": "Cargo profile to use. Conflicts with `release`.",
"description": "Cargo profile to use.\n\nOverrides the default chosen by cargo. Ignored if the 'index.html' has one configured.",
"default": null,
"type": [
"string",
Expand Down
4 changes: 3 additions & 1 deletion src/config/models/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ pub struct Build {
#[serde(default)]
pub release: bool,

/// Cargo profile to use. Conflicts with `release`.
/// Cargo profile to use.
///
/// Overrides the default chosen by cargo. Ignored if the 'index.html' has one configured.
#[serde(default)]
pub cargo_profile: Option<String>,

Expand Down
16 changes: 12 additions & 4 deletions src/pipelines/rust/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,21 @@ impl RustApp {

// cargo profile

let cargo_profile = match cfg.release {
let data_cargo_profile = match cfg.release {
true => attrs.get("data-cargo-profile-dev"),
false => attrs.get("data-cargo-profile-release"),
}
.or_else(|| attrs.get("data-cargo-profile"))
.or_else(|| cfg.cargo_profile.as_ref())
.cloned();
.or_else(|| attrs.get("data-cargo-profile"));

let cargo_profile = match data_cargo_profile {
Some(cargo_profile) => {
if let Some(config_cargo_profile) = &cfg.cargo_profile {
log::warn!("Cargo profile from configuration ({config_cargo_profile}) will be overridden with HTML file's more specific setting ({cargo_profile})");
}
Some(cargo_profile.clone())
}
None => cfg.cargo_profile.as_ref().cloned(),
};

// cargo features

Expand Down

0 comments on commit 8fa20a8

Please sign in to comment.