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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --bin-skip flag to build command #212

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
32 changes: 17 additions & 15 deletions src/command/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use crate::{
},
};

pub async fn build_all(conf: &Config) -> Result<()> {
pub async fn build_all(conf: &Config, bin_skip: bool) -> Result<()> {
let mut first_failed_project = None;

for proj in &conf.projects {
if !build_proj(proj).await? && first_failed_project.is_none() {
if !build_proj(proj, bin_skip).await? && first_failed_project.is_none() {
first_failed_project = Some(proj);
}
}
Expand All @@ -28,7 +28,7 @@ pub async fn build_all(conf: &Config) -> Result<()> {
}

/// Build the project. Returns true if the build was successful
pub async fn build_proj(proj: &Arc<Project>) -> Result<bool> {
pub async fn build_proj(proj: &Arc<Project>, bin_skip: bool) -> Result<bool> {
if proj.site.root_dir.exists() {
fs::rm_dir_content(&proj.site.root_dir).await.dot()?;
}
Expand All @@ -48,19 +48,21 @@ pub async fn build_proj(proj: &Arc<Project>) -> Result<bool> {
return Ok(false);
}

// it is important to do the precompression of the static files before building the
// server to make it possible to include them as assets into the binary itself
if proj.release
&& proj.precompress
&& compress::compress_static_files(proj.site.root_dir.clone().into())
.await
.is_err()
{
return Ok(false);
}
if !bin_skip {
// it is important to do the precompression of the static files before building the
// server to make it possible to include them as assets into the binary itself
if proj.release
&& proj.precompress
&& compress::compress_static_files(proj.site.root_dir.clone().into())
.await
.is_err()
{
return Ok(false);
}

if !compile::server(proj, &changes).await.await??.is_success() {
return Ok(false);
if !compile::server(proj, &changes).await.await??.is_success() {
return Ok(false);
}
}
Ok(true)
}
2 changes: 1 addition & 1 deletion src/command/end2end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub async fn end2end_all(conf: &Config) -> Result<()> {

pub async fn end2end_proj(proj: &Arc<Project>) -> Result<()> {
if let Some(e2e) = &proj.end2end {
if !super::build::build_proj(proj).await.dot()? {
if !super::build::build_proj(proj, false).await.dot()? {
return Ok(());
}

Expand Down
2 changes: 1 addition & 1 deletion src/command/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::ext::anyhow::{Context, Result};
use crate::service::serve;

pub async fn serve(proj: &Arc<Project>) -> Result<()> {
if !super::build::build_proj(proj).await.dot()? {
if !super::build::build_proj(proj, false).await.dot()? {
return Ok(());
}
let server = serve::spawn_oneshot(proj).await;
Expand Down
2 changes: 1 addition & 1 deletion src/command/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use super::build::build_proj;

pub async fn watch(proj: &Arc<Project>) -> Result<()> {
// even if the build fails, we continue
build_proj(proj).await?;
build_proj(proj, false).await?;

// but if ctrl-c is pressed, we stop
if Interrupt::is_shutdown_requested().await {
Expand Down
85 changes: 81 additions & 4 deletions src/config/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,84 @@ pub struct Opts {
pub verbose: u8,
}

#[derive(Debug, Clone, Parser, PartialEq, Default)]
pub struct BuildOpts {
/// Build artifacts in release mode, with optimizations.
#[arg(short, long)]
pub release: bool,

/// Precompress static assets with gzip and brotli. Applies to release builds only.
#[arg(short = 'P', long)]
pub precompress: bool,

/// Turn on partial hot-reloading. Requires rust nightly [beta]
#[arg(long)]
pub hot_reload: bool,

/// Which project to use, from a list of projects defined in a workspace
#[arg(short, long)]
pub project: Option<String>,

/// The features to use when compiling all targets
#[arg(long)]
pub features: Vec<String>,

/// The features to use when compiling the lib target
#[arg(long)]
pub lib_features: Vec<String>,

/// The cargo flags to pass to cargo when compiling the lib target
#[arg(long)]
pub lib_cargo_args: Option<Vec<String>>,

/// The features to use when compiling the bin target
#[arg(long)]
pub bin_features: Vec<String>,

/// The cargo flags to pass to cargo when compiling the bin target
#[arg(long)]
pub bin_cargo_args: Option<Vec<String>>,

/// Skip building the bin target
#[arg(long)]
pub bin_skip: bool,

/// Verbosity (none: info, errors & warnings, -v: verbose, --vv: very verbose).
#[arg(short, action = clap::ArgAction::Count)]
pub verbose: u8,
}

impl From<BuildOpts> for Opts {
fn from(value: BuildOpts) -> Self {
let BuildOpts {
release,
precompress,
hot_reload,
project,
features,
lib_features,
lib_cargo_args,
bin_features,
bin_cargo_args,
verbose,
..
} = value;

Self {
release,
precompress,
hot_reload,
project,
features,
lib_features,
lib_cargo_args,
bin_features,
bin_cargo_args,
verbose,
}
}
}

#[derive(Debug, Parser)]
#[clap(version)]
pub struct Cli {
Expand All @@ -73,17 +151,16 @@ impl Cli {
use Commands::{Build, EndToEnd, New, Serve, Test, Watch};
match &self.command {
New(_) => None,
Build(opts) | Serve(opts) | Test(opts) | EndToEnd(opts) | Watch(opts) => {
Some(opts.clone())
}
Build(build_opts) => Some(build_opts.clone().into()),
Serve(opts) | Test(opts) | EndToEnd(opts) | Watch(opts) => Some(opts.clone()),
}
}
}

#[derive(Debug, Subcommand, PartialEq)]
pub enum Commands {
/// Build the server (feature ssr) and the client (wasm with feature hydrate).
Build(Opts),
Build(BuildOpts),
/// Run the cargo tests for app, client and server.
Test(Opts),
/// Start the server and end-2-end tests.
Expand Down
2 changes: 1 addition & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod tailwind;

use std::{fmt::Debug, sync::Arc};

pub use self::cli::{Cli, Commands, Log, Opts};
pub use self::cli::{BuildOpts, Cli, Commands, Log, Opts};
use crate::ext::{
anyhow::{Context, Result},
MetadataExt,
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod logger;
pub mod service;
pub mod signal;

use crate::config::Commands;
use crate::config::{BuildOpts, Commands};
use crate::ext::anyhow::{Context, Result};
use crate::ext::PathBufExt;
use crate::logger::GRAY;
Expand Down Expand Up @@ -72,7 +72,7 @@ pub async fn run(args: Cli) -> Result<()> {
use Commands::{Build, EndToEnd, New, Serve, Test, Watch};
match args.command {
New(_) => panic!(),
Build(_) => command::build_all(&config).await,
Build(BuildOpts { bin_skip, .. }) => command::build_all(&config, bin_skip).await,
Serve(_) => command::serve(&config.current_project()?).await,
Test(_) => command::test_all(&config).await,
EndToEnd(_) => command::end2end_all(&config).await,
Expand Down
4 changes: 2 additions & 2 deletions src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use camino::Utf8PathBuf;

use crate::{
config::{Cli, Commands, Opts},
config::{BuildOpts, Cli, Commands},
ext::PathBufExt,
run,
};

#[tokio::test]
async fn workspace_build() {
let command = Commands::Build(Opts::default());
let command = Commands::Build(BuildOpts::default());

let cli = Cli {
manifest_path: Some(Utf8PathBuf::from("examples/workspace/Cargo.toml")),
Expand Down
Loading