Skip to content

Commit d03e47d

Browse files
fix: only build specified rust targets for aab/apk build (#6625)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent 052c582 commit d03e47d

File tree

7 files changed

+47
-51
lines changed

7 files changed

+47
-51
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'cli.rs': 'patch'
3+
'cli.js': 'patch'
4+
---
5+
6+
Build only specified rust targets for `tauri android build` instead of all.

tooling/cli/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tooling/cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ path = "src/main.rs"
4242
openssl-vendored = [ "tauri-mobile/openssl-vendored" ]
4343

4444
[dependencies]
45-
tauri-mobile = { version = "0.2.5", default-features = false }
45+
tauri-mobile = { version = "0.3", default-features = false }
4646
textwrap = { version = "0.11.0", features = [ "term_size" ] }
4747
jsonrpsee = { version = "0.16", features = [ "server" ] }
4848
jsonrpsee-core = "0.16"

tooling/cli/src/build.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -240,20 +240,15 @@ pub fn command(mut options: Options, verbosity: u8) -> Result<()> {
240240
}
241241

242242
pub fn setup(options: &mut Options, mobile: bool) -> Result<AppInterface> {
243-
let (merge_config, merge_config_path) = if let Some(config) = &options.config {
244-
if config.starts_with('{') {
245-
(Some(config.to_string()), None)
246-
} else {
247-
(
248-
Some(
249-
std::fs::read_to_string(config).with_context(|| "failed to read custom configuration")?,
250-
),
251-
Some(config.clone()),
252-
)
253-
}
254-
} else {
255-
(None, None)
243+
let (merge_config, merge_config_path) = match &options.config {
244+
Some(config) if config.starts_with('{') => (Some(config.to_string()), None),
245+
Some(config) => (
246+
Some(std::fs::read_to_string(config).with_context(|| "failed to read custom configuration")?),
247+
Some(config.clone()),
248+
),
249+
None => (None, None),
256250
};
251+
257252
options.config = merge_config;
258253

259254
let tauri_path = tauri_dir();

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

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ fn run_build(
181181
env,
182182
noise_level,
183183
profile,
184-
get_targets_or_all(Vec::new())?,
184+
get_targets(options.targets.clone().unwrap_or_default())?,
185185
options.split_per_abi,
186186
)?
187187
} else {
@@ -194,7 +194,7 @@ fn run_build(
194194
env,
195195
noise_level,
196196
profile,
197-
get_targets_or_all(Vec::new())?,
197+
get_targets(options.targets.unwrap_or_default())?,
198198
options.split_per_abi,
199199
)?
200200
} else {
@@ -207,28 +207,24 @@ fn run_build(
207207
Ok(())
208208
}
209209

210-
fn get_targets_or_all<'a>(targets: Vec<String>) -> Result<Vec<&'a Target<'a>>> {
211-
if targets.is_empty() {
212-
Ok(Target::all().iter().map(|t| t.1).collect())
213-
} else {
214-
let mut outs = Vec::new();
215-
216-
let possible_targets = Target::all()
217-
.keys()
218-
.map(|key| key.to_string())
219-
.collect::<Vec<String>>()
220-
.join(",");
221-
222-
for t in targets {
223-
let target = Target::for_name(&t).ok_or_else(|| {
224-
anyhow::anyhow!(
225-
"Target {} is invalid; the possible targets are {}",
226-
t,
227-
possible_targets
228-
)
229-
})?;
230-
outs.push(target);
231-
}
232-
Ok(outs)
210+
fn get_targets<'a>(targets: Vec<String>) -> Result<Vec<&'a Target<'a>>> {
211+
let mut outs = Vec::new();
212+
213+
let possible_targets = Target::all()
214+
.keys()
215+
.map(|key| key.to_string())
216+
.collect::<Vec<String>>()
217+
.join(",");
218+
219+
for t in targets {
220+
let target = Target::for_name(&t).ok_or_else(|| {
221+
anyhow::anyhow!(
222+
"Target {} is invalid; the possible targets are {}",
223+
t,
224+
possible_targets
225+
)
226+
})?;
227+
outs.push(target);
233228
}
229+
Ok(outs)
234230
}

tooling/cli/src/mobile/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ fn ensure_init(project_dir: PathBuf, target: Target) -> Result<()> {
316316
target.command_name(),
317317
)
318318
} else {
319+
#[allow(irrefutable_let_patterns)]
319320
if let Target::Android = target {
320321
create_dir_all(project_dir.join(".tauri").join("plugins"))?;
321322
}

tooling/cli/templates/mobile/android/app/build.gradle.kts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ android {
3030
isMinifyEnabled = false
3131
packagingOptions {
3232
{{~#each targets}}
33-
3433
jniLibs.keepDebugSymbols.add("*/{{this.abi}}/*.so")
3534
{{/each}}
3635
}
@@ -46,17 +45,14 @@ android {
4645
flavorDimensions.add("abi")
4746
productFlavors {
4847
create("universal") {
49-
val abiList = findProperty("abiList") as? String
50-
5148
dimension = "abi"
5249
ndk {
53-
abiFilters += abiList?.split(",")?.map { it.trim() } ?: listOf(
50+
abiFilters += (findProperty("abiList") as? String)?.split(",") ?: listOf(
5451
{{~#each targets}}
5552
"{{this.abi}}",{{/each}}
5653
)
5754
}
5855
}
59-
6056
{{~#each targets}}
6157

6258
create("{{this.arch}}") {
@@ -74,8 +70,8 @@ android {
7470

7571
rust {
7672
rootDirRel = "{{root-dir-rel}}"
77-
targets = listOf({{quote-and-join target-names}})
78-
arches = listOf({{quote-and-join arches}})
73+
targets = (findProperty("targetList") as? String)?.split(",") ?: listOf({{quote-and-join target-names}})
74+
arches = (findProperty("archList") as? String)?.split(",") ?: listOf({{quote-and-join arches}})
7975
}
8076

8177
dependencies {
@@ -98,9 +94,11 @@ afterEvaluate {
9894
android.applicationVariants.all {
9995
tasks["mergeUniversalReleaseJniLibFolders"].dependsOn(tasks["rustBuildRelease"])
10096
tasks["mergeUniversalDebugJniLibFolders"].dependsOn(tasks["rustBuildDebug"])
101-
productFlavors.filter{ it.name != "universal" }.forEach { _ ->
102-
val archAndBuildType = name.capitalize()
103-
tasks["merge${archAndBuildType}JniLibFolders"].dependsOn(tasks["rustBuild${archAndBuildType}"])
97+
if (findProperty("targetList") == null) {
98+
productFlavors.filter{ it.name != "universal" }.forEach { _ ->
99+
val archAndBuildType = name.capitalize()
100+
tasks["merge${archAndBuildType}JniLibFolders"].dependsOn(tasks["rustBuild${archAndBuildType}"])
101+
}
104102
}
105103
}
106104
}

0 commit comments

Comments
 (0)