Skip to content

Commit 5c1fe52

Browse files
authored
feat(cli.rs): allow using cross instead of cargo, add target triple arg (#1664)
1 parent 894643c commit 5c1fe52

14 files changed

Lines changed: 140 additions & 27 deletions

File tree

.changes/cli-runner-arg.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cli.rs": patch
3+
---
4+
5+
Adds `--runner [PROGRAM]` argument on the `dev` and `build` command, allowing using the specified program to run and build the application (example program: `cross`).

.changes/cli-target-triple.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cli.rs": patch
3+
---
4+
5+
Adds `--target [TARGET_TRIPLE]` option to the `build` command (example: `--target arm-unknown-linux-gnueabihf`).

.changes/cli-targets-refactor.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cli.rs": patch
3+
---
4+
5+
Rename `--target` option on the `build` command to `--bundle`.

examples/api/src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ tauri-build = { path = "../../../core/tauri-build" }
1111
[dependencies]
1212
serde_json = "1.0"
1313
serde = { version = "1.0", features = [ "derive" ] }
14-
tauri = { path = "../../../core/tauri", features =["api-all", "cli", "updater"]}
14+
tauri = { path = "../../../core/tauri", features = ["api-all", "cli", "updater"] }
1515

1616
[features]
1717
default = [ "custom-protocol" ]

examples/helloworld/src-tauri/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ description = "A very simple Tauri Appplication"
55
edition = "2018"
66

77
[build-dependencies]
8-
tauri-build = { path = "../../../core/tauri-build", features = [ "codegen" ]}
8+
tauri-build = { path = "../../../core/tauri-build", features = [ "codegen" ] }
99

1010
[dependencies]
1111
serde_json = "1.0"
1212
serde = { version = "1.0", features = [ "derive" ] }
13-
tauri = { path = "../../../core/tauri", features =["api-all"]}
13+
tauri = { path = "../../../core/tauri", features = ["api-all"] }
1414

1515
[features]
1616
default = [ "custom-protocol" ]

examples/multiwindow/src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ license = "Apache-2.0 OR MIT"
99
tauri-build = { path = "../../../core/tauri-build" }
1010

1111
[dependencies]
12-
tauri = { path = "../../../core/tauri", features =["api-all"]}
12+
tauri = { path = "../../../core/tauri", features = ["api-all"] }
1313

1414
[features]
1515
default = [ "custom-protocol" ]

examples/updater/src-tauri/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ edition = "2018"
66
license = "Apache-2.0 OR MIT"
77

88
[build-dependencies]
9-
tauri-build = { path = "../../../core/tauri-build", features = [ "codegen" ]}
9+
tauri-build = { path = "../../../core/tauri-build", features = [ "codegen" ] }
1010

1111
[dependencies]
1212
serde_json = "1.0"
1313
serde = { version = "1.0", features = [ "derive" ] }
14-
tauri = { path = "../../../core/tauri", features =["api-all", "updater"]}
14+
tauri = { path = "../../../core/tauri", features = ["api-all", "updater"] }
1515

1616
[features]
1717
default = [ "custom-protocol" ]

tooling/cli.rs/config_definition.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,8 @@ fn default_dialog() -> Option<bool> {
583583
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
584584
#[serde(rename_all = "camelCase", deny_unknown_fields)]
585585
pub struct BuildConfig {
586+
/// The binary used to build and run the application.
587+
pub runner: Option<String>,
586588
/// the app's dev server URL, or the path to the directory containing an index.html file
587589
#[serde(default = "default_dev_path")]
588590
pub dev_path: String,
@@ -629,6 +631,7 @@ pub struct Config {
629631

630632
fn default_build() -> BuildConfig {
631633
BuildConfig {
634+
runner: None,
632635
dev_path: default_dev_path(),
633636
dist_dir: default_dist_dir(),
634637
before_dev_command: None,

tooling/cli.rs/schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,13 @@
234234
"default": "../dist",
235235
"type": "string"
236236
},
237+
"runner": {
238+
"description": "The binary used to build and run the application.",
239+
"type": [
240+
"string",
241+
"null"
242+
]
243+
},
237244
"withGlobalTauri": {
238245
"description": "Whether we should inject the Tauri API on `window.__TAURI__` or not.",
239246
"default": false,

tooling/cli.rs/src/build.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ mod rust;
1919

2020
#[derive(Default)]
2121
pub struct Build {
22+
runner: Option<String>,
2223
debug: bool,
2324
verbose: bool,
24-
targets: Option<Vec<String>>,
25+
target: Option<String>,
26+
bundles: Option<Vec<String>>,
2527
config: Option<String>,
2628
}
2729

@@ -40,8 +42,18 @@ impl Build {
4042
self
4143
}
4244

43-
pub fn targets(mut self, targets: Vec<String>) -> Self {
44-
self.targets = Some(targets);
45+
pub fn runner(mut self, runner: String) -> Self {
46+
self.runner.replace(runner);
47+
self
48+
}
49+
50+
pub fn target(mut self, target: String) -> Self {
51+
self.target.replace(target);
52+
self
53+
}
54+
55+
pub fn bundles(mut self, bundles: Vec<String>) -> Self {
56+
self.bundles.replace(bundles);
4557
self
4658
}
4759

@@ -90,7 +102,13 @@ impl Build {
90102
));
91103
}
92104

93-
rust::build_project(self.debug)?;
105+
let runner_from_config = config_.build.runner.clone();
106+
let runner = self
107+
.runner
108+
.or(runner_from_config)
109+
.unwrap_or_else(|| "cargo".to_string());
110+
111+
rust::build_project(runner, &self.target, self.debug)?;
94112

95113
let app_settings = rust::AppSettings::new(&config_)?;
96114

@@ -135,7 +153,7 @@ impl Build {
135153
settings_builder = settings_builder.verbose();
136154
}
137155

138-
if let Some(names) = self.targets {
156+
if let Some(names) = self.bundles {
139157
let mut types = vec![];
140158
for name in names {
141159
if name == "none" {

0 commit comments

Comments
 (0)