Skip to content

use correct config scope for release and custom cli profiles #404

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion src/build/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub enum BuildSubcommands {
Web(BuildWebArgs),
}

#[derive(Debug, Args)]
#[derive(Debug, Args, Default)]
pub struct BuildWebArgs {
// Bundle all web artifacts into a single folder.
#[arg(short = 'b', long = "bundle", action = ArgAction::SetTrue, default_value_t = false)]
Expand Down
18 changes: 18 additions & 0 deletions src/build/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use args::BuildArgs;

#[cfg(feature = "web")]
use args::{BuildSubcommands, BuildWebArgs};

#[cfg(feature = "web")]
use crate::web::build::build_web;
use crate::{bin_target::select_run_binary, config::CliConfig, external_cli::cargo};
Expand All @@ -9,6 +12,21 @@ pub mod args;
pub fn build(args: &mut BuildArgs) -> anyhow::Result<()> {
let metadata = cargo::metadata::metadata()?;

// Check if the profile, passed as an argument matches a default profile from the CLI.
// if it matches, set the flags accordingly.
if let Some(profile) = &args.cargo_args.compilation_args.profile {
if profile == "release" {
args.cargo_args.compilation_args.is_release = true;
}
#[cfg(feature = "web")]
if profile == "web-release" {
args.cargo_args.compilation_args.is_release = true;
args.subcommand = Some(BuildSubcommands::Web(BuildWebArgs::default()));
} else if profile == "web" {
args.subcommand = Some(BuildSubcommands::Web(BuildWebArgs::default()));
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we integrate this logic directly into the is_release() functions of the args? Then e.g. also the wasm_opt detection works consistently with the config and we don't need to add other feature gated logic here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call! What do you think now?

let bin_target = select_run_binary(
&metadata,
args.cargo_args.package_args.package.as_deref(),
Expand Down
11 changes: 11 additions & 0 deletions src/run/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@ pub struct RunWebArgs {
pub headers: Vec<String>,
}

impl Default for RunWebArgs {
fn default() -> Self {
Self {
port: 4000,
open: false,
create_packed_bundle: false,
headers: Vec::new(),
}
}
}

impl From<RunArgs> for BuildArgs {
fn from(args: RunArgs) -> Self {
BuildArgs {
Expand Down
18 changes: 18 additions & 0 deletions src/run/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(feature = "web")]
use args::RunWebArgs;

#[cfg(feature = "web")]
use crate::web::run::run_web;
use crate::{bin_target::select_run_binary, config::CliConfig, external_cli::cargo};
Expand All @@ -9,6 +12,21 @@ pub mod args;
pub fn run(args: &mut RunArgs) -> anyhow::Result<()> {
let metadata = cargo::metadata::metadata()?;

// Check if the profile, passed as an argument matches a default profile from the CLI.
// if it matches, set the flags accordingly.
if let Some(profile) = &args.cargo_args.compilation_args.profile {
if profile == "release" {
args.cargo_args.compilation_args.is_release = true;
}
#[cfg(feature = "web")]
if profile == "web-release" {
args.cargo_args.compilation_args.is_release = true;
args.subcommand = Some(args::RunSubcommands::Web(RunWebArgs::default()));
} else if profile == "web" {
args.subcommand = Some(args::RunSubcommands::Web(RunWebArgs::default()));
}
}

let bin_target = select_run_binary(
&metadata,
args.cargo_args.package_args.package.as_deref(),
Expand Down
9 changes: 5 additions & 4 deletions src/web/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ pub fn build_web(
metadata: &Metadata,
bin_target: &BinTarget,
) -> anyhow::Result<WebBundle> {
let Some(BuildSubcommands::Web(web_args)) = &args.subcommand else {
anyhow::bail!("tried to build for the web without matching arguments");
};
let web_args = args
.subcommand
.as_ref()
.map(|BuildSubcommands::Web(web_args)| web_args);

let mut profile_args = configure_default_web_profiles(metadata)?;
// `--config` args are resolved from left to right,
Expand Down Expand Up @@ -66,7 +67,7 @@ pub fn build_web(
metadata,
args.profile(),
bin_target,
web_args.create_packed_bundle,
web_args.is_some_and(|web_args| web_args.create_packed_bundle),
)
.context("Failed to create web bundle")?;

Expand Down