Skip to content

Commit 33d0793

Browse files
authored
feat(cli): allow runner configuration to be an object with cwd and args (#13811)
* Update config.schema.json * Add RunnerConfig for customizable build runner Replaces runner String with RunnerConfig in CLI and config, allowing advanced runner configuration via string or object with cmd, cwd, and args. Updates schema and usage to support new format, and adds tests for serialization, deserialization, and API. Enables more flexible build and run command customization. * Create runner-object-config.md * Remove unused RunnerConfig import in tests Cleaned up the test module in config.rs by removing the unused RunnerConfig import from two test functions. * Fix tests failing Updates related tests in tauri-utils to improve readability and maintain consistency. Minor import reordering in tauri-cli for clarity. * Move RunnerConfig enum and impls above BuildConfig Relocated the RunnerConfig enum and its associated implementations to appear before the BuildConfig definition. This improves code organization and logical grouping of configuration-related types.
1 parent 7bc77a0 commit 33d0793

File tree

8 files changed

+428
-18
lines changed

8 files changed

+428
-18
lines changed

.changes/runner-object-config.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'tauri-cli': 'minor:feat'
3+
'tauri-utils': 'minor:feat'
4+
---
5+
6+
Allow runner configuration to be an object with cmd, cwd, and args properties. The runner can now be configured as `{ "cmd": "my_runner", "cwd": "/path", "args": ["--quiet"] }` while maintaining backwards compatibility with the existing string format.

crates/tauri-cli/config.schema.json

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,9 +1805,13 @@
18051805
"properties": {
18061806
"runner": {
18071807
"description": "The binary used to build and run the application.",
1808-
"type": [
1809-
"string",
1810-
"null"
1808+
"anyOf": [
1809+
{
1810+
"$ref": "#/definitions/RunnerConfig"
1811+
},
1812+
{
1813+
"type": "null"
1814+
}
18111815
]
18121816
},
18131817
"devUrl": {
@@ -1880,6 +1884,45 @@
18801884
},
18811885
"additionalProperties": false
18821886
},
1887+
"RunnerConfig": {
1888+
"description": "The runner configuration.",
1889+
"anyOf": [
1890+
{
1891+
"description": "A string specifying the binary to run.",
1892+
"type": "string"
1893+
},
1894+
{
1895+
"description": "An object with advanced configuration options.",
1896+
"type": "object",
1897+
"required": [
1898+
"cmd"
1899+
],
1900+
"properties": {
1901+
"cmd": {
1902+
"description": "The binary to run.",
1903+
"type": "string"
1904+
},
1905+
"cwd": {
1906+
"description": "The current working directory to run the command from.",
1907+
"type": [
1908+
"string",
1909+
"null"
1910+
]
1911+
},
1912+
"args": {
1913+
"description": "Arguments to pass to the command.",
1914+
"type": [
1915+
"array",
1916+
"null"
1917+
],
1918+
"items": {
1919+
"type": "string"
1920+
}
1921+
}
1922+
}
1923+
}
1924+
]
1925+
},
18831926
"FrontendDist": {
18841927
"description": "Defines the URL or assets to embed in the application.",
18851928
"anyOf": [

crates/tauri-cli/src/build.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::{
1515
use anyhow::Context;
1616
use clap::{ArgAction, Parser};
1717
use std::env::set_current_dir;
18+
use tauri_utils::config::RunnerConfig;
1819
use tauri_utils::platform::Target;
1920

2021
#[derive(Debug, Clone, Parser)]
@@ -25,7 +26,7 @@ use tauri_utils::platform::Target;
2526
pub struct Options {
2627
/// Binary to use to build the application, defaults to `cargo`
2728
#[clap(short, long)]
28-
pub runner: Option<String>,
29+
pub runner: Option<RunnerConfig>,
2930
/// Builds with the debug flag
3031
#[clap(short, long)]
3132
pub debug: bool,
@@ -210,7 +211,7 @@ pub fn setup(
210211
}
211212

212213
if options.runner.is_none() {
213-
options.runner.clone_from(&config_.build.runner);
214+
options.runner = config_.build.runner.clone();
214215
}
215216

216217
options

crates/tauri-cli/src/dev.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::{
1717
use anyhow::{bail, Context};
1818
use clap::{ArgAction, Parser};
1919
use shared_child::SharedChild;
20-
use tauri_utils::platform::Target;
20+
use tauri_utils::{config::RunnerConfig, platform::Target};
2121

2222
use std::{
2323
env::set_current_dir,
@@ -49,7 +49,7 @@ pub const TAURI_CLI_BUILTIN_WATCHER_IGNORE_FILE: &[u8] =
4949
pub struct Options {
5050
/// Binary to use to run the application
5151
#[clap(short, long)]
52-
pub runner: Option<String>,
52+
pub runner: Option<RunnerConfig>,
5353
/// Target triple to build against
5454
#[clap(short, long)]
5555
pub target: Option<String>,
@@ -224,9 +224,14 @@ pub fn setup(interface: &AppInterface, options: &mut Options, config: ConfigHand
224224
}
225225

226226
if options.runner.is_none() {
227-
options
227+
options.runner = config
228+
.lock()
229+
.unwrap()
230+
.as_ref()
231+
.unwrap()
232+
.build
228233
.runner
229-
.clone_from(&config.lock().unwrap().as_ref().unwrap().build.runner);
234+
.clone();
230235
}
231236

232237
let mut cargo_features = config

crates/tauri-cli/src/interface/rust.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use tauri_bundler::{
2525
IosSettings, MacOsSettings, PackageSettings, Position, RpmSettings, Size, UpdaterSettings,
2626
WindowsSettings,
2727
};
28-
use tauri_utils::config::{parse::is_configuration_file, DeepLinkProtocol, Updater};
28+
use tauri_utils::config::{parse::is_configuration_file, DeepLinkProtocol, RunnerConfig, Updater};
2929

3030
use super::{AppSettings, DevProcess, ExitReason, Interface};
3131
use crate::{
@@ -47,7 +47,7 @@ use manifest::{rewrite_manifest, Manifest};
4747

4848
#[derive(Debug, Default, Clone)]
4949
pub struct Options {
50-
pub runner: Option<String>,
50+
pub runner: Option<RunnerConfig>,
5151
pub debug: bool,
5252
pub target: Option<String>,
5353
pub features: Option<Vec<String>>,

crates/tauri-cli/src/interface/rust/desktop.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,21 @@ fn cargo_command(
230230
available_targets: &mut Option<Vec<RustupTarget>>,
231231
config_features: Vec<String>,
232232
) -> crate::Result<Command> {
233-
let runner = options.runner.unwrap_or_else(|| "cargo".into());
233+
let runner_config = options.runner.unwrap_or_else(|| "cargo".into());
234234

235-
let mut build_cmd = Command::new(runner);
235+
let mut build_cmd = Command::new(runner_config.cmd());
236236
build_cmd.arg(if dev { "run" } else { "build" });
237237

238+
// Set working directory if specified
239+
if let Some(cwd) = runner_config.cwd() {
240+
build_cmd.current_dir(cwd);
241+
}
242+
243+
// Add runner-specific arguments first
244+
if let Some(runner_args) = runner_config.args() {
245+
build_cmd.args(runner_args);
246+
}
247+
238248
if let Some(target) = &options.target {
239249
if available_targets.is_none() {
240250
*available_targets = fetch_available_targets();

crates/tauri-schema-generator/schemas/config.schema.json

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,9 +1805,13 @@
18051805
"properties": {
18061806
"runner": {
18071807
"description": "The binary used to build and run the application.",
1808-
"type": [
1809-
"string",
1810-
"null"
1808+
"anyOf": [
1809+
{
1810+
"$ref": "#/definitions/RunnerConfig"
1811+
},
1812+
{
1813+
"type": "null"
1814+
}
18111815
]
18121816
},
18131817
"devUrl": {
@@ -1880,6 +1884,45 @@
18801884
},
18811885
"additionalProperties": false
18821886
},
1887+
"RunnerConfig": {
1888+
"description": "The runner configuration.",
1889+
"anyOf": [
1890+
{
1891+
"description": "A string specifying the binary to run.",
1892+
"type": "string"
1893+
},
1894+
{
1895+
"description": "An object with advanced configuration options.",
1896+
"type": "object",
1897+
"required": [
1898+
"cmd"
1899+
],
1900+
"properties": {
1901+
"cmd": {
1902+
"description": "The binary to run.",
1903+
"type": "string"
1904+
},
1905+
"cwd": {
1906+
"description": "The current working directory to run the command from.",
1907+
"type": [
1908+
"string",
1909+
"null"
1910+
]
1911+
},
1912+
"args": {
1913+
"description": "Arguments to pass to the command.",
1914+
"type": [
1915+
"array",
1916+
"null"
1917+
],
1918+
"items": {
1919+
"type": "string"
1920+
}
1921+
}
1922+
}
1923+
}
1924+
]
1925+
},
18831926
"FrontendDist": {
18841927
"description": "Defines the URL or assets to embed in the application.",
18851928
"anyOf": [

0 commit comments

Comments
 (0)