Add Cargo Arguments and Cross-Architecture Support (#1777)

* Add passthrough to cargo build

* Add platform_triple flag

* Add handling to bundle and serve commands

* Show full stacked error from Tauri in bundling

Previously only the top-level error was shown, giving only vague data
for debugging the build process

* Adjust bundle platform triple when cross compiling

* Rename --platform-triple to --target

* restore some deleted docs on CLI commands

---------

Co-authored-by: Evan Almloff <evanalmloff@gmail.com>
This commit is contained in:
Bennett-PetzoldandEvan Almloff authored and GitHub committed 2024-01-02 15:19:29 -06:00
1 parent fd7c9e0359
commit 80a8e1f512
6 files changed
+81 -11

No files matched your search

+16 -1
View File
@@ -93,6 +93,8 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result<BuildResult> {
cmd cmd
}; };
let cmd = cmd.args(&config.cargo_args);
let cmd = match executable { let cmd = match executable {
ExecutableType::Binary(name) => cmd.arg("--bin").arg(name), ExecutableType::Binary(name) => cmd.arg("--bin").arg(name),
ExecutableType::Lib(name) => cmd.arg("--lib").arg(name), ExecutableType::Lib(name) => cmd.arg("--lib").arg(name),
@@ -286,6 +288,14 @@ pub fn build_desktop(config: &CrateConfig, _is_serve: bool) -> Result<BuildResul
cmd = cmd.arg("--features").arg(features_str); cmd = cmd.arg("--features").arg(features_str);
} }
if let Some(target) = &config.target {
cmd = cmd.arg("--target").arg(target);
}
let target_platform = config.target.as_deref().unwrap_or("");
cmd = cmd.args(&config.cargo_args);
let cmd = match &config.executable { let cmd = match &config.executable {
crate::ExecutableType::Binary(name) => cmd.arg("--bin").arg(name), crate::ExecutableType::Binary(name) => cmd.arg("--bin").arg(name),
crate::ExecutableType::Lib(name) => cmd.arg("--lib").arg(name), crate::ExecutableType::Lib(name) => cmd.arg("--lib").arg(name),
@@ -303,12 +313,17 @@ pub fn build_desktop(config: &CrateConfig, _is_serve: bool) -> Result<BuildResul
let mut res_path = match &config.executable { let mut res_path = match &config.executable {
crate::ExecutableType::Binary(name) | crate::ExecutableType::Lib(name) => { crate::ExecutableType::Binary(name) | crate::ExecutableType::Lib(name) => {
file_name = name.clone(); file_name = name.clone();
config.target_dir.join(release_type).join(name) config
.target_dir
.join(target_platform)
.join(release_type)
.join(name)
} }
crate::ExecutableType::Example(name) => { crate::ExecutableType::Example(name) => {
file_name = name.clone(); file_name = name.clone();
config config
.target_dir .target_dir
.join(target_platform)
.join(release_type) .join(release_type)
.join("examples") .join("examples")
.join(name) .join(name)
+6
View File
@@ -37,6 +37,12 @@ impl Build {
.platform .platform
.unwrap_or(crate_config.dioxus_config.application.default_platform); .unwrap_or(crate_config.dioxus_config.application.default_platform);
if let Some(target) = self.build.target {
crate_config.set_target(target);
}
crate_config.set_cargo_args(self.build.cargo_args);
// #[cfg(feature = "plugin")] // #[cfg(feature = "plugin")]
// let _ = PluginManager::on_build_start(&crate_config, &platform); // let _ = PluginManager::on_build_start(&crate_config, &platform);
+13 -2
View File
@@ -76,6 +76,12 @@ impl Bundle {
crate_config.set_profile(self.build.profile.unwrap()); crate_config.set_profile(self.build.profile.unwrap());
} }
if let Some(target) = &self.build.target {
crate_config.set_target(target.to_string());
}
crate_config.set_cargo_args(self.build.cargo_args);
// build the desktop app // build the desktop app
build_desktop(&crate_config, false)?; build_desktop(&crate_config, false)?;
@@ -148,6 +154,11 @@ impl Bundle {
.collect(), .collect(),
); );
} }
if let Some(target) = &self.build.target {
settings = settings.target(target.to_string());
}
let settings = settings.build(); let settings = settings.build();
// on macos we need to set CI=true (https://github.com/tauri-apps/tauri/issues/2567) // on macos we need to set CI=true (https://github.com/tauri-apps/tauri/issues/2567)
@@ -156,9 +167,9 @@ impl Bundle {
tauri_bundler::bundle::bundle_project(settings.unwrap()).unwrap_or_else(|err|{ tauri_bundler::bundle::bundle_project(settings.unwrap()).unwrap_or_else(|err|{
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
panic!("Failed to bundle project: {}\nMake sure you have automation enabled in your terminal (https://github.com/tauri-apps/tauri/issues/3055#issuecomment-1624389208) and full disk access enabled for your terminal (https://github.com/tauri-apps/tauri/issues/3055#issuecomment-1624389208)", err); panic!("Failed to bundle project: {:#?}\nMake sure you have automation enabled in your terminal (https://github.com/tauri-apps/tauri/issues/3055#issuecomment-1624389208) and full disk access enabled for your terminal (https://github.com/tauri-apps/tauri/issues/3055#issuecomment-1624389208)", err);
#[cfg(not(target_os = "macos"))] #[cfg(not(target_os = "macos"))]
panic!("Failed to bundle project: {}", err); panic!("Failed to bundle project: {:#?}", err);
}); });
Ok(()) Ok(())
+24 -8
View File
@@ -6,10 +6,6 @@ use super::*;
/// Config options for the build system. /// Config options for the build system.
#[derive(Clone, Debug, Default, Deserialize, Parser)] #[derive(Clone, Debug, Default, Deserialize, Parser)]
pub struct ConfigOptsBuild { pub struct ConfigOptsBuild {
/// The index HTML file to drive the bundling process [default: index.html]
#[arg(long)]
pub target: Option<PathBuf>,
/// Build in release mode [default: false] /// Build in release mode [default: false]
#[clap(long)] #[clap(long)]
#[serde(default)] #[serde(default)]
@@ -35,14 +31,18 @@ pub struct ConfigOptsBuild {
/// Space separated list of features to activate /// Space separated list of features to activate
#[clap(long)] #[clap(long)]
pub features: Option<Vec<String>>, pub features: Option<Vec<String>>,
/// Rustc platform triple
#[clap(long)]
pub target: Option<String>,
/// Extra arguments passed to cargo build
#[clap(last = true)]
pub cargo_args: Vec<String>,
} }
#[derive(Clone, Debug, Default, Deserialize, Parser)] #[derive(Clone, Debug, Default, Deserialize, Parser)]
pub struct ConfigOptsServe { pub struct ConfigOptsServe {
/// The index HTML file to drive the bundling process [default: index.html]
#[arg(short, long)]
pub target: Option<PathBuf>,
/// Port of dev server /// Port of dev server
#[clap(long)] #[clap(long)]
#[clap(default_value_t = 8080)] #[clap(default_value_t = 8080)]
@@ -89,6 +89,14 @@ pub struct ConfigOptsServe {
/// Space separated list of features to activate /// Space separated list of features to activate
#[clap(long)] #[clap(long)]
pub features: Option<Vec<String>>, pub features: Option<Vec<String>>,
/// Rustc platform triple
#[clap(long)]
pub target: Option<String>,
/// Extra arguments passed to cargo build
#[clap(last = true)]
pub cargo_args: Vec<String>,
} }
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Serialize, Deserialize, Debug)] #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Serialize, Deserialize, Debug)]
@@ -129,4 +137,12 @@ pub struct ConfigOptsBundle {
/// Space separated list of features to activate /// Space separated list of features to activate
#[clap(long)] #[clap(long)]
pub features: Option<Vec<String>>, pub features: Option<Vec<String>>,
/// Rustc platform triple
#[clap(long)]
pub target: Option<String>,
/// Extra arguments passed to cargo build
#[clap(last = true)]
pub cargo_args: Vec<String>,
} }
+6
View File
@@ -34,6 +34,12 @@ impl Serve {
// Subdirectories don't work with the server // Subdirectories don't work with the server
crate_config.dioxus_config.web.app.base_path = None; crate_config.dioxus_config.web.app.base_path = None;
if let Some(target) = self.serve.target {
crate_config.set_target(target);
}
crate_config.set_cargo_args(self.serve.cargo_args);
let platform = self let platform = self
.serve .serve
.platform .platform
+16
View File
@@ -211,6 +211,8 @@ pub struct CrateConfig {
pub verbose: bool, pub verbose: bool,
pub custom_profile: Option<String>, pub custom_profile: Option<String>,
pub features: Option<Vec<String>>, pub features: Option<Vec<String>>,
pub target: Option<String>,
pub cargo_args: Vec<String>,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@@ -278,6 +280,8 @@ impl CrateConfig {
let verbose = false; let verbose = false;
let custom_profile = None; let custom_profile = None;
let features = None; let features = None;
let target = None;
let cargo_args = vec![];
Ok(Self { Ok(Self {
out_dir, out_dir,
@@ -294,6 +298,8 @@ impl CrateConfig {
custom_profile, custom_profile,
features, features,
verbose, verbose,
target,
cargo_args,
}) })
} }
@@ -331,6 +337,16 @@ impl CrateConfig {
self.features = Some(features); self.features = Some(features);
self self
} }
pub fn set_target(&mut self, target: String) -> &mut Self {
self.target = Some(target);
self
}
pub fn set_cargo_args(&mut self, cargo_args: Vec<String>) -> &mut Self {
self.cargo_args = cargo_args;
self
}
} }
#[derive(Debug, Clone, Serialize, Deserialize, Default)] #[derive(Debug, Clone, Serialize, Deserialize, Default)]