Skip to content

Commit fd68b7f

Browse files
authored
fix(cli): do not generate .cargo/config file (#10785)
1 parent dc0612b commit fd68b7f

File tree

9 files changed

+44
-73
lines changed

9 files changed

+44
-73
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-cli": patch:enhance
3+
"@tauri-apps/cli": patch:enhance
4+
---
5+
6+
Remove the `.cargo/config` file creation that used to fix mobile build caches.

examples/api/src-tauri/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
/target/
44

55
# cargo-mobile
6-
.cargo/
76
/gen

tooling/cli/src/mobile/android/build.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub fn command(options: Options, noise_level: NoiseLevel) -> Result<()> {
107107
tauri_utils::platform::Target::Android,
108108
options.config.as_ref().map(|c| &c.0),
109109
)?;
110-
let (interface, app, config, metadata) = {
110+
let (interface, config, metadata) = {
111111
let tauri_config_guard = tauri_config.lock().unwrap();
112112
let tauri_config_ = tauri_config_guard.as_ref().unwrap();
113113

@@ -121,7 +121,7 @@ pub fn command(options: Options, noise_level: NoiseLevel) -> Result<()> {
121121
build_options.features.as_ref(),
122122
&Default::default(),
123123
);
124-
(interface, app, config, metadata)
124+
(interface, config, metadata)
125125
};
126126

127127
let profile = if options.debug {
@@ -141,7 +141,7 @@ pub fn command(options: Options, noise_level: NoiseLevel) -> Result<()> {
141141
)?;
142142

143143
let mut env = env()?;
144-
configure_cargo(&app, Some((&mut env, &config)))?;
144+
configure_cargo(&mut env, &config)?;
145145

146146
crate::build::setup(&interface, &mut build_options, tauri_config.clone(), true)?;
147147

tooling/cli/src/mobile/android/dev.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use cargo_mobile2::{
2727
env::Env,
2828
target::Target,
2929
},
30-
config::app::App,
3130
opts::{FilterLevel, NoiseLevel, Profile},
3231
target::TargetTrait,
3332
};
@@ -128,7 +127,7 @@ fn run_command(options: Options, noise_level: NoiseLevel) -> Result<()> {
128127
.unwrap_or_else(|| Target::all().values().next().unwrap().triple.into());
129128
dev_options.target = Some(target_triple.clone());
130129

131-
let (interface, app, config, metadata) = {
130+
let (interface, config, metadata) = {
132131
let tauri_config_guard = tauri_config.lock().unwrap();
133132
let tauri_config_ = tauri_config_guard.as_ref().unwrap();
134133

@@ -141,7 +140,7 @@ fn run_command(options: Options, noise_level: NoiseLevel) -> Result<()> {
141140
dev_options.features.as_ref(),
142141
&Default::default(),
143142
);
144-
(interface, app, config, metadata)
143+
(interface, config, metadata)
145144
};
146145

147146
let tauri_path = tauri_dir();
@@ -160,7 +159,6 @@ fn run_command(options: Options, noise_level: NoiseLevel) -> Result<()> {
160159
tauri_config,
161160
device,
162161
env,
163-
&app,
164162
&config,
165163
&metadata,
166164
noise_level,
@@ -175,7 +173,6 @@ fn run_dev(
175173
tauri_config: ConfigHandle,
176174
device: Option<Device>,
177175
mut env: Env,
178-
app: &App,
179176
config: &AndroidConfig,
180177
metadata: &AndroidMetadata,
181178
noise_level: NoiseLevel,
@@ -193,7 +190,7 @@ fn run_dev(
193190
let out_dir = bin_path.parent().unwrap();
194191
let _lock = flock::open_rw(out_dir.join("lock").with_extension("android"), "Android")?;
195192

196-
configure_cargo(app, Some((&mut env, config)))?;
193+
configure_cargo(&mut env, config)?;
197194

198195
// run an initial build to initialize plugins
199196
let target_triple = dev_options.target.as_ref().unwrap();

tooling/cli/src/mobile/android/mod.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use cargo_mobile2::{
1414
config::app::{App, DEFAULT_ASSET_DIR},
1515
opts::{FilterLevel, NoiseLevel},
1616
os,
17+
target::TargetTrait,
1718
util::prompt,
1819
};
1920
use clap::{Parser, Subcommand};
@@ -28,10 +29,8 @@ use sublime_fuzzy::best_match;
2829
use tauri_utils::resources::ResourcePaths;
2930

3031
use super::{
31-
ensure_init, get_app,
32-
init::{command as init_command, configure_cargo},
33-
log_finished, read_options, CliOptions, OptionsHandle, Target as MobileTarget,
34-
MIN_DEVICE_MATCH_SCORE,
32+
ensure_init, get_app, init::command as init_command, log_finished, read_options, CliOptions,
33+
OptionsHandle, Target as MobileTarget, MIN_DEVICE_MATCH_SCORE,
3534
};
3635
use crate::{
3736
helpers::config::{BundleResources, Config as TauriConfig},
@@ -327,3 +326,22 @@ fn inject_resources(config: &AndroidConfig, tauri_config: &TauriConfig) -> Resul
327326

328327
Ok(())
329328
}
329+
330+
fn configure_cargo(env: &mut Env, config: &AndroidConfig) -> Result<()> {
331+
for target in Target::all().values() {
332+
let config = target.generate_cargo_config(config, env)?;
333+
let target_var_name = target.triple.replace('-', "_").to_uppercase();
334+
if let Some(linker) = config.linker {
335+
env.base.insert_env_var(
336+
format!("CARGO_TARGET_{target_var_name}_LINKER"),
337+
linker.into(),
338+
);
339+
}
340+
env.base.insert_env_var(
341+
format!("CARGO_TARGET_{target_var_name}_RUSTFLAGS"),
342+
config.rustflags.join(" ").into(),
343+
);
344+
}
345+
346+
Ok(())
347+
}

tooling/cli/src/mobile/init.rs

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@ use crate::{
99
Result,
1010
};
1111
use cargo_mobile2::{
12-
android::{
13-
config::Config as AndroidConfig, env::Env as AndroidEnv, target::Target as AndroidTarget,
14-
},
12+
android::env::Env as AndroidEnv,
1513
config::app::App,
16-
dot_cargo,
1714
reserved_names::KOTLIN_ONLY_KEYWORDS,
18-
target::TargetTrait as _,
1915
util::{
2016
self,
2117
cli::{Report, TextWrapper},
@@ -40,43 +36,6 @@ pub fn command(
4036
Ok(())
4137
}
4238

43-
pub fn configure_cargo(
44-
app: &App,
45-
android: Option<(&mut AndroidEnv, &AndroidConfig)>,
46-
) -> Result<()> {
47-
if let Some((env, config)) = android {
48-
for target in AndroidTarget::all().values() {
49-
let config = target.generate_cargo_config(config, env)?;
50-
let target_var_name = target.triple.replace('-', "_").to_uppercase();
51-
if let Some(linker) = config.linker {
52-
env.base.insert_env_var(
53-
format!("CARGO_TARGET_{target_var_name}_LINKER"),
54-
linker.into(),
55-
);
56-
}
57-
env.base.insert_env_var(
58-
format!("CARGO_TARGET_{target_var_name}_RUSTFLAGS"),
59-
config.rustflags.join(" ").into(),
60-
);
61-
}
62-
}
63-
64-
let mut dot_cargo = dot_cargo::DotCargo::load(app)?;
65-
// Mysteriously, builds that don't specify `--target` seem to fight over
66-
// the build cache with builds that use `--target`! This means that
67-
// alternating between i.e. `cargo run` and `cargo apple run` would
68-
// result in clean builds being made each time you switched... which is
69-
// pretty nightmarish. Specifying `build.target` in `.cargo/config`
70-
// fortunately has the same effect as specifying `--target`, so now we can
71-
// `cargo run` with peace of mind!
72-
//
73-
// This behavior could be explained here:
74-
// https://doc.rust-lang.org/cargo/reference/config.html#buildrustflags
75-
dot_cargo.set_default_target(util::host_target_triple()?);
76-
77-
dot_cargo.write(app).map_err(Into::into)
78-
}
79-
8039
pub fn exec(
8140
target: Target,
8241
wrapper: &TextWrapper,

tooling/cli/src/mobile/ios/build.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
// SPDX-License-Identifier: MIT
44

55
use super::{
6-
configure_cargo, detect_target_ok, ensure_init, env, get_app, get_config, inject_resources,
7-
load_pbxproj, log_finished, merge_plist, open_and_wait, project_config,
8-
synchronize_project_config, MobileTarget, OptionsHandle,
6+
detect_target_ok, ensure_init, env, get_app, get_config, inject_resources, load_pbxproj,
7+
log_finished, merge_plist, open_and_wait, project_config, synchronize_project_config,
8+
MobileTarget, OptionsHandle,
99
};
1010
use crate::{
1111
build::Options as BuildOptions,
@@ -186,7 +186,6 @@ pub fn command(options: Options, noise_level: NoiseLevel) -> Result<()> {
186186
merged_info_plist.to_file_xml(&info_plist_path)?;
187187

188188
let mut env = env()?;
189-
configure_cargo(&app, None)?;
190189

191190
let mut export_options_plist = plist::Dictionary::new();
192191
if let Some(method) = options.export_method {

tooling/cli/src/mobile/ios/dev.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// SPDX-License-Identifier: MIT
44

55
use super::{
6-
configure_cargo, device_prompt, ensure_init, env, get_app, get_config, inject_resources,
7-
merge_plist, open_and_wait, MobileTarget,
6+
device_prompt, ensure_init, env, get_app, get_config, inject_resources, merge_plist,
7+
open_and_wait, MobileTarget,
88
};
99
use crate::{
1010
dev::Options as DevOptions,
@@ -25,7 +25,6 @@ use cargo_mobile2::{
2525
config::Config as AppleConfig,
2626
device::{Device, DeviceKind},
2727
},
28-
config::app::App,
2928
env::Env,
3029
opts::{NoiseLevel, Profile},
3130
};
@@ -153,7 +152,7 @@ fn run_command(options: Options, noise_level: NoiseLevel) -> Result<()> {
153152
tauri_utils::platform::Target::Ios,
154153
options.config.as_ref().map(|c| &c.0),
155154
)?;
156-
let (interface, app, config) = {
155+
let (interface, config) = {
157156
let tauri_config_guard = tauri_config.lock().unwrap();
158157
let tauri_config_ = tauri_config_guard.as_ref().unwrap();
159158

@@ -167,7 +166,7 @@ fn run_command(options: Options, noise_level: NoiseLevel) -> Result<()> {
167166
&Default::default(),
168167
);
169168

170-
(interface, app, config)
169+
(interface, config)
171170
};
172171

173172
let tauri_path = tauri_dir();
@@ -199,7 +198,6 @@ fn run_command(options: Options, noise_level: NoiseLevel) -> Result<()> {
199198
tauri_config,
200199
device,
201200
env,
202-
&app,
203201
&config,
204202
noise_level,
205203
)
@@ -344,7 +342,6 @@ fn run_dev(
344342
tauri_config: ConfigHandle,
345343
device: Option<Device>,
346344
env: Env,
347-
app: &App,
348345
config: &AppleConfig,
349346
noise_level: NoiseLevel,
350347
) -> Result<()> {
@@ -371,8 +368,6 @@ fn run_dev(
371368

372369
let set_host = options.host.is_some();
373370

374-
configure_cargo(app, None)?;
375-
376371
let open = options.open;
377372
let exit_on_panic = options.exit_on_panic;
378373
let no_watch = options.no_watch;

tooling/cli/src/mobile/ios/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ use sublime_fuzzy::best_match;
2323
use tauri_utils::resources::ResourcePaths;
2424

2525
use super::{
26-
ensure_init, env, get_app,
27-
init::{command as init_command, configure_cargo},
28-
log_finished, read_options, CliOptions, OptionsHandle, Target as MobileTarget,
29-
MIN_DEVICE_MATCH_SCORE,
26+
ensure_init, env, get_app, init::command as init_command, log_finished, read_options, CliOptions,
27+
OptionsHandle, Target as MobileTarget, MIN_DEVICE_MATCH_SCORE,
3028
};
3129
use crate::{
3230
helpers::{

0 commit comments

Comments
 (0)