mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-28 12:27:16 +03:00
added cargo features to tauri config (#1824)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
parent
9a662d2601
commit
2b814e9c93
5
.changes/features-support.md
Normal file
5
.changes/features-support.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"cli.rs": patch
|
||||
---
|
||||
|
||||
Read cargo features from `tauri.conf.json > build > features` and propagate them on `dev` and `build`.
|
@ -607,6 +607,8 @@ pub struct BuildConfig {
|
||||
pub before_dev_command: Option<String>,
|
||||
/// a shell command to run before `tauri build` kicks in
|
||||
pub before_build_command: Option<String>,
|
||||
/// features passed to `cargo` commands
|
||||
pub features: Option<Vec<String>>,
|
||||
/// Whether we should inject the Tauri API on `window.__TAURI__` or not.
|
||||
#[serde(default)]
|
||||
pub with_global_tauri: bool,
|
||||
@ -648,6 +650,7 @@ fn default_build() -> BuildConfig {
|
||||
dist_dir: default_dist_dir(),
|
||||
before_dev_command: None,
|
||||
before_build_command: None,
|
||||
features: None,
|
||||
with_global_tauri: false,
|
||||
}
|
||||
}
|
||||
|
@ -234,6 +234,16 @@
|
||||
"default": "../dist",
|
||||
"type": "string"
|
||||
},
|
||||
"features": {
|
||||
"description": "features passed to `cargo` commands",
|
||||
"type": [
|
||||
"array",
|
||||
"null"
|
||||
],
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"runner": {
|
||||
"description": "The binary used to build and run the application.",
|
||||
"type": [
|
||||
|
@ -111,7 +111,10 @@ impl Build {
|
||||
.or(runner_from_config)
|
||||
.unwrap_or_else(|| "cargo".to_string());
|
||||
|
||||
rust::build_project(runner, &self.target, self.debug).with_context(|| "failed to build app")?;
|
||||
let cargo_features = &config_.build.features;
|
||||
|
||||
rust::build_project(runner, &self.target, cargo_features, self.debug)
|
||||
.with_context(|| "failed to build app")?;
|
||||
|
||||
let app_settings = rust::AppSettings::new(&config_)?;
|
||||
|
||||
|
@ -90,20 +90,30 @@ struct CargoConfig {
|
||||
build: Option<CargoBuildConfig>,
|
||||
}
|
||||
|
||||
pub fn build_project(runner: String, target: &Option<String>, debug: bool) -> crate::Result<()> {
|
||||
let mut args = vec!["build", "--features=custom-protocol"];
|
||||
pub fn build_project(
|
||||
runner: String,
|
||||
target: &Option<String>,
|
||||
features: &Option<Vec<String>>,
|
||||
debug: bool,
|
||||
) -> crate::Result<()> {
|
||||
let mut command = Command::new(&runner);
|
||||
command.args(["build", "--features=custom-protocol"]);
|
||||
|
||||
if let Some(target) = target {
|
||||
args.push("--target");
|
||||
args.push(target);
|
||||
command.arg("--target");
|
||||
command.arg(target);
|
||||
}
|
||||
|
||||
if let Some(features) = features {
|
||||
command.arg("--features");
|
||||
command.arg(features.join(","));
|
||||
}
|
||||
|
||||
if !debug {
|
||||
args.push("--release");
|
||||
command.arg("--release");
|
||||
}
|
||||
|
||||
let status = Command::new(&runner)
|
||||
.args(args)
|
||||
let status = command
|
||||
.status()
|
||||
.with_context(|| format!("failed to run {}", runner))?;
|
||||
if !status.success() {
|
||||
|
@ -145,10 +145,19 @@ impl Dev {
|
||||
}
|
||||
}
|
||||
|
||||
let cargo_features = config
|
||||
.lock()
|
||||
.unwrap()
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.build
|
||||
.features
|
||||
.clone();
|
||||
|
||||
let (child_wait_tx, child_wait_rx) = channel();
|
||||
let child_wait_rx = Arc::new(Mutex::new(child_wait_rx));
|
||||
|
||||
process = self.start_app(&runner, child_wait_rx.clone());
|
||||
process = self.start_app(&runner, &cargo_features, child_wait_rx.clone());
|
||||
|
||||
let (tx, rx) = channel();
|
||||
|
||||
@ -191,22 +200,34 @@ impl Dev {
|
||||
break;
|
||||
}
|
||||
}
|
||||
process = self.start_app(&runner, child_wait_rx.clone());
|
||||
process = self.start_app(&runner, &cargo_features, child_wait_rx.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn start_app(&self, runner: &str, child_wait_rx: Arc<Mutex<Receiver<()>>>) -> Arc<SharedChild> {
|
||||
fn start_app(
|
||||
&self,
|
||||
runner: &str,
|
||||
features: &Option<Vec<String>>,
|
||||
child_wait_rx: Arc<Mutex<Receiver<()>>>,
|
||||
) -> Arc<SharedChild> {
|
||||
let mut command = Command::new(runner);
|
||||
command.args(&["run", "--no-default-features"]);
|
||||
|
||||
if let Some(target) = &self.target {
|
||||
command.args(&["--target", target]);
|
||||
}
|
||||
|
||||
if let Some(features) = features {
|
||||
command.args(&["--features", &features.join(",")]);
|
||||
}
|
||||
|
||||
if !self.args.is_empty() {
|
||||
command.arg("--").args(&self.args);
|
||||
}
|
||||
|
||||
let child =
|
||||
SharedChild::spawn(&mut command).unwrap_or_else(|_| panic!("failed to run {}", runner));
|
||||
let child_arc = Arc::new(child);
|
||||
|
Loading…
Reference in New Issue
Block a user