Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only build specified rust targets for aab/apk build #6625

Merged
merged 7 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/cli-android-specified-targets-only.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'cli.rs': 'patch'
'cli.js': 'patch'
---

Build only specified rust targets for `tauri android build` instead of all.
4 changes: 2 additions & 2 deletions tooling/cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tooling/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ path = "src/main.rs"
openssl-vendored = [ "tauri-mobile/openssl-vendored" ]

[dependencies]
tauri-mobile = { version = "0.2.5", default-features = false }
tauri-mobile = { version = "0.3", default-features = false }
textwrap = { version = "0.11.0", features = [ "term_size" ] }
jsonrpsee = { version = "0.16", features = [ "server" ] }
jsonrpsee-core = "0.16"
Expand Down
21 changes: 8 additions & 13 deletions tooling/cli/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,20 +240,15 @@ pub fn command(mut options: Options, verbosity: u8) -> Result<()> {
}

pub fn setup(options: &mut Options, mobile: bool) -> Result<AppInterface> {
let (merge_config, merge_config_path) = if let Some(config) = &options.config {
if config.starts_with('{') {
(Some(config.to_string()), None)
} else {
(
Some(
std::fs::read_to_string(config).with_context(|| "failed to read custom configuration")?,
),
Some(config.clone()),
)
}
} else {
(None, None)
let (merge_config, merge_config_path) = match &options.config {
Some(config) if config.starts_with('{') => (Some(config.to_string()), None),
Some(config) => (
Some(std::fs::read_to_string(config).with_context(|| "failed to read custom configuration")?),
Some(config.clone()),
),
None => (None, None),
};

options.config = merge_config;

let tauri_path = tauri_dir();
Expand Down
46 changes: 21 additions & 25 deletions tooling/cli/src/mobile/android/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ fn run_build(
env,
noise_level,
profile,
get_targets_or_all(Vec::new())?,
get_targets(options.targets.clone().unwrap_or_default())?,
options.split_per_abi,
)?
} else {
Expand All @@ -194,7 +194,7 @@ fn run_build(
env,
noise_level,
profile,
get_targets_or_all(Vec::new())?,
get_targets(options.targets.unwrap_or_default())?,
options.split_per_abi,
)?
} else {
Expand All @@ -207,28 +207,24 @@ fn run_build(
Ok(())
}

fn get_targets_or_all<'a>(targets: Vec<String>) -> Result<Vec<&'a Target<'a>>> {
if targets.is_empty() {
Ok(Target::all().iter().map(|t| t.1).collect())
} else {
let mut outs = Vec::new();

let possible_targets = Target::all()
.keys()
.map(|key| key.to_string())
.collect::<Vec<String>>()
.join(",");

for t in targets {
let target = Target::for_name(&t).ok_or_else(|| {
anyhow::anyhow!(
"Target {} is invalid; the possible targets are {}",
t,
possible_targets
)
})?;
outs.push(target);
}
Ok(outs)
fn get_targets<'a>(targets: Vec<String>) -> Result<Vec<&'a Target<'a>>> {
let mut outs = Vec::new();

let possible_targets = Target::all()
.keys()
.map(|key| key.to_string())
.collect::<Vec<String>>()
.join(",");

for t in targets {
let target = Target::for_name(&t).ok_or_else(|| {
anyhow::anyhow!(
"Target {} is invalid; the possible targets are {}",
t,
possible_targets
)
})?;
outs.push(target);
}
Ok(outs)
}
18 changes: 8 additions & 10 deletions tooling/cli/templates/mobile/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ android {
isMinifyEnabled = false
packagingOptions {
{{~#each targets}}

jniLibs.keepDebugSymbols.add("*/{{this.abi}}/*.so")
{{/each}}
}
Expand All @@ -46,17 +45,14 @@ android {
flavorDimensions.add("abi")
productFlavors {
create("universal") {
val abiList = findProperty("abiList") as? String

dimension = "abi"
ndk {
abiFilters += abiList?.split(",")?.map { it.trim() } ?: listOf(
abiFilters += (findProperty("abiList") as? String)?.split(",") ?: listOf(
{{~#each targets}}
"{{this.abi}}",{{/each}}
)
}
}

{{~#each targets}}

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

rust {
rootDirRel = "{{root-dir-rel}}"
targets = listOf({{quote-and-join target-names}})
arches = listOf({{quote-and-join arches}})
targets = (findProperty("targetList") as? String)?.split(",") ?: listOf({{quote-and-join target-names}})
arches = (findProperty("archList") as? String)?.split(",") ?: listOf({{quote-and-join arches}})
}

dependencies {
Expand All @@ -98,9 +94,11 @@ afterEvaluate {
android.applicationVariants.all {
tasks["mergeUniversalReleaseJniLibFolders"].dependsOn(tasks["rustBuildRelease"])
tasks["mergeUniversalDebugJniLibFolders"].dependsOn(tasks["rustBuildDebug"])
productFlavors.filter{ it.name != "universal" }.forEach { _ ->
val archAndBuildType = name.capitalize()
tasks["merge${archAndBuildType}JniLibFolders"].dependsOn(tasks["rustBuild${archAndBuildType}"])
if (findProperty("targetList") == null) {
productFlavors.filter{ it.name != "universal" }.forEach { _ ->
val archAndBuildType = name.capitalize()
tasks["merge${archAndBuildType}JniLibFolders"].dependsOn(tasks["rustBuild${archAndBuildType}"])
}
}
}
}