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

feat: some simple UI tweaks to CLI #3301

Merged
merged 1 commit into from
Dec 6, 2024
Merged
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
2 changes: 2 additions & 0 deletions packages/cli/src/build/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,8 @@ impl AppBundle {
/// Run any final tools to produce apks or other artifacts we might need.
async fn assemble(&self) -> Result<()> {
if let Platform::Android = self.build.build.platform() {
self.build.status_running_gradle();

// make sure we can execute the gradlew script
#[cfg(unix)]
{
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/build/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ impl BuildRequest {
});
}

pub(crate) fn status_running_gradle(&self) {
_ = self.progress.unbounded_send(BuildUpdate::Progress {
stage: BuildStage::RunningGradle,
})
}

pub(crate) fn status_build_diagnostic(&self, message: CompilerMessage) {
_ = self
.progress
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/cli/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ pub(crate) fn post_create(path: &Path) -> Result<()> {
file.write_all(new_readme.as_bytes())?;

tracing::info!(dx_src = ?TraceSrc::Dev, "Generated project at {}", path.display());
tracing::info!(dx_src = ?TraceSrc::Dev, "`cd` to your project and run `dx serve` to start developing. Build cool things! ✌️");

Ok(())
}
Expand Down
27 changes: 11 additions & 16 deletions packages/cli/src/dioxus_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use anyhow::Context;
use itertools::Itertools;
use krates::{cm::Target, KrateDetails};
use krates::{cm::TargetKind, Cmd, Krates, NodeId};
use std::path::Path;
use std::path::PathBuf;
use std::sync::Arc;
use std::{io::Write, path::Path};
use toml_edit::Item;

// Contains information about the crate we are currently in and the dioxus config for that crate
Expand All @@ -20,9 +20,9 @@ pub(crate) struct DioxusCrate {
pub(crate) settings: CliSettings,
}

pub(crate) static PROFILE_WASM: &str = "dioxus-wasm";
pub(crate) static PROFILE_ANDROID: &str = "dioxus-android";
pub(crate) static PROFILE_SERVER: &str = "dioxus-server";
pub(crate) static PROFILE_WASM: &str = "wasm-dev";
pub(crate) static PROFILE_ANDROID: &str = "android-dev";
pub(crate) static PROFILE_SERVER: &str = "server-dev";

impl DioxusCrate {
pub(crate) fn new(target: &TargetArgs) -> Result<Self> {
Expand Down Expand Up @@ -291,18 +291,19 @@ impl DioxusCrate {
self.config.web.pre_compress && release
}

// The `opt-level=2` increases build times, but can noticeably decrease time
// The `opt-level=1` increases build times, but can noticeably decrease time
// between saving changes and being able to interact with an app (for wasm/web). The "overall"
// time difference (between having and not having the optimization) can be
// almost imperceptible (~1 s) but also can be very noticeable (~6 s) — depends
// on setup (hardware, OS, browser, idle load).
//
// Find or create the client and server profiles in the .cargo/config.toml file
// Find or create the client and server profiles in the top-level Cargo.toml file
// todo(jon): we should/could make these optional by placing some defaults somewhere
pub(crate) fn initialize_profiles(&self) -> crate::Result<()> {
let config_path = self.workspace_dir().join(".cargo/config.toml");
let config_path = self.workspace_dir().join("Cargo.toml");
let mut config = match std::fs::read_to_string(&config_path) {
Ok(config) => config.parse::<toml_edit::DocumentMut>().map_err(|e| {
crate::Error::Other(anyhow::anyhow!("Failed to parse .cargo/config.toml: {}", e))
crate::Error::Other(anyhow::anyhow!("Failed to parse Cargo.toml: {}", e))
})?,
Err(_) => Default::default(),
};
Expand All @@ -322,7 +323,6 @@ impl DioxusCrate {
if let toml_edit::Entry::Vacant(entry) = table.entry(PROFILE_SERVER) {
let mut server = toml_edit::Table::new();
server.insert("inherits", Item::Value("dev".into()));
// server.insert("opt-level", Item::Value(2.into()));
entry.insert(Item::Table(server));
}

Expand All @@ -333,13 +333,8 @@ impl DioxusCrate {
}
}

// Write the config back to the file
if let Some(parent) = config_path.parent() {
std::fs::create_dir_all(parent)?;
}
let file = std::fs::File::create(config_path)?;
let mut buf_writer = std::io::BufWriter::new(file);
write!(buf_writer, "{}", config)?;
std::fs::write(config_path, config.to_string())
.context("Failed to write profiles to Cargo.toml")?;

Ok(())
}
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ impl TraceController {
return Ok(());
}

if field.name() == "dx_src" && !args.verbosity.verbose {
return Ok(());
}

write!(writer, "{}", format_field(field.name(), value))
})
.delimited(" "),
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/serve/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ impl Output {
}
BuildStage::OptimizingWasm {} => lines.push("Optimizing wasm".yellow()),
BuildStage::RunningBindgen {} => lines.push("Running wasm-bindgen".yellow()),
BuildStage::RunningGradle {} => lines.push("Running gradle assemble".yellow()),
BuildStage::Bundling {} => lines.push("Bundling app".yellow()),
BuildStage::CopyingAssets {
current,
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl App {
webviews: HashMap::new(),
control_flow: ControlFlow::Wait,
unmounted_dom: Cell::new(Some(virtual_dom)),
float_all: !cfg!(debug_assertions),
float_all: false,
show_devtools: false,
cfg: Cell::new(Some(cfg)),
shared: Rc::new(SharedContext {
Expand Down
1 change: 1 addition & 0 deletions packages/dx-wire-format/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub enum BuildStage {
path: PathBuf,
},
Bundling,
RunningGradle,
Success,
Failed,
Aborted,
Expand Down
Loading