Skip to content

Commit

Permalink
fix bundling (macos) and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jkelleyrtp committed Nov 8, 2024
1 parent 562eef4 commit 2b1adac
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 42 deletions.
4 changes: 1 addition & 3 deletions examples/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use async_std::task::sleep;
use dioxus::prelude::*;
use web_time::Instant;

const STYLE: Asset = asset!("/examples/assets/clock.css");

fn main() {
dioxus::launch(app);
}
Expand Down Expand Up @@ -36,7 +34,7 @@ fn app() -> Element {
);

rsx! {
document::Link { rel: "stylesheet", href: STYLE }
document::Stylesheet { href: asset!("/examples/assets/clock.css") }
div { id: "app",
div { id: "title", "Carpe diem 🎉" }
div { id: "clock-display", "{time}" }
Expand Down
73 changes: 36 additions & 37 deletions packages/cli/src/cli/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use crate::DioxusCrate;
use crate::{build::BuildArgs, PackageType};
use anyhow::Context;
use itertools::Itertools;
use std::env::current_dir;
use std::str::FromStr;
use tauri_bundler::{PackageSettings, SettingsBuilder};
use std::{collections::HashMap, str::FromStr};
use tauri_bundler::{BundleBinary, BundleSettings, PackageSettings, SettingsBuilder};

use super::*;

Expand Down Expand Up @@ -37,22 +36,32 @@ impl Bundle {
.finish()
.await?;

tracing::debug!("Copying app to output directory...");
tracing::info!("Copying app to output directory...");

_ = std::fs::remove_dir_all(krate.bundle_dir(self.build_arguments.platform()));

let package = krate.package();
let mut name: PathBuf = krate.executable_name().into();
if cfg!(windows) {
name.set_extension("exe");
}

// bundle the app
// Make sure we copy the exe to the bundle dir so the bundler can find it
std::fs::create_dir_all(krate.bundle_dir(self.build_arguments.platform()))?;
std::fs::copy(
&bundle.app.exe,
krate
.bundle_dir(self.build_arguments.platform())
.join(krate.executable_name()),
)?;

let binaries = vec![
tauri_bundler::BundleBinary::new(name.display().to_string(), true)
.set_src_path(Some(krate.workspace_dir().display().to_string())),
// We use the name of the exe but it has to be in the same directory
BundleBinary::new(name.display().to_string(), true)
.set_src_path(Some(bundle.app.exe.display().to_string())),
];

let bundle_config = krate.config.bundle.clone();
let mut bundle_settings: tauri_bundler::BundleSettings = bundle_config.into();
let mut bundle_settings: BundleSettings = krate.config.bundle.clone().into();

if cfg!(windows) {
let windows_icon_override = krate.config.bundle.windows.as_ref().map(|w| &w.icon_path);
Expand All @@ -68,40 +77,29 @@ impl Bundle {
}
}

// Don't copy the executable or the old bundle directory
let ignored_files = [krate
.bundle_dir(self.build_arguments.platform())
.join("bundle")];
if bundle_settings.resources_map.is_none() {
bundle_settings.resources_map = Some(HashMap::new());
}

for entry in std::fs::read_dir(bundle.asset_dir())?.flatten() {
let path = entry.path().canonicalize()?;
if ignored_files.iter().any(|f| path.starts_with(f)) {
continue;
}

// Tauri bundle will add a __root__ prefix if the input path is absolute even though the output path is relative?
// We strip the prefix here to make sure the input path is relative so that the bundler puts the output path in the right place
let path = path
.strip_prefix(&current_dir()?)
.unwrap()
.display()
.to_string();

if let Some(resources) = &mut bundle_settings.resources_map {
resources.insert(path, "".to_string());
} else {
bundle_settings.resources_map = Some([(path, "".to_string())].into());
}
let old = entry.path().canonicalize()?;
let new = PathBuf::from("assets").join(old.file_name().unwrap());

bundle_settings
.resources_map
.as_mut()
.expect("to be set")
.insert(old.display().to_string(), new.display().to_string());
}

// Drain any resources set in the config into the resources map. Tauri bundle doesn't let
// you set both resources and resources_map https://github.com/DioxusLabs/dioxus/issues/2941
for resource_path in bundle_settings.resources.take().into_iter().flatten() {
if let Some(resources) = &mut bundle_settings.resources_map {
resources.insert(resource_path, "".to_string());
} else {
bundle_settings.resources_map = Some([(resource_path, "".to_string())].into());
}
bundle_settings
.resources_map
.as_mut()
.expect("to be set")
.insert(resource_path, "".to_string());
}

let mut settings = SettingsBuilder::new()
Expand All @@ -114,6 +112,7 @@ impl Bundle {
authors: Some(package.authors.clone()),
default_run: Some(krate.executable_name().to_string()),
})
.log_level(log::Level::Debug)
.binaries(binaries)
.bundle_settings(bundle_settings);

Expand All @@ -127,7 +126,7 @@ impl Bundle {

let settings = settings.build()?;

tracing::info!("Bundling project with settings: {:#?}", settings);
tracing::debug!("Bundling project with settings: {:#?}", settings);

// on macos we need to set CI=true (https://github.com/tauri-apps/tauri/issues/2567)
if cfg!(target_os = "macos") {
Expand Down
10 changes: 8 additions & 2 deletions packages/cli/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,17 @@ impl TraceController {

/// Build tracing infrastructure.
pub fn initialize(args: &crate::Cli) {
let our_level = if args.verbose { "debug" } else { "info" };

// By default we capture ourselves at a higher tracing level when serving
// This ensures we're tracing ourselves even if we end up tossing the logs
let mut filter = EnvFilter::new(match args.action {
Commands::Serve(_) => "error,dx=trace,dioxus-cli=trace,manganis-cli-support=debug",
_ => "error,dx=info,dioxus-cli=info,manganis-cli-support=info",
Commands::Serve(_) => {
"error,dx=trace,dioxus-cli=trace,manganis-cli-support=debug".to_string()
}
_ => format!(
"error,dx={our_level},dioxus-cli={our_level},manganis-cli-support={our_level}"
),
});

if env::var(LOG_ENV).is_ok() {
Expand Down

0 comments on commit 2b1adac

Please sign in to comment.