From 9c2cb8ead48b763ae29e921997affdf56cd16f6f Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Thu, 21 Sep 2023 21:20:33 +0200 Subject: [PATCH] Added support for Linux aarch64 when building the rust part --- build.gradle.kts | 33 +++++++++++++++++++++++++-------- rs/.cargo/config.toml | 2 ++ 2 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 rs/.cargo/config.toml diff --git a/build.gradle.kts b/build.gradle.kts index 705d10d..a7cc0fa 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,6 +3,7 @@ import org.jetbrains.compose.compose import org.jetbrains.kotlin.gradle.tasks.KotlinCompile val javaLanguageVersion = JavaLanguageVersion.of(17) +val linuxArmTarget = "aarch64-unknown-linux-gnu" plugins { // Kotlin version must match compose version @@ -21,6 +22,9 @@ val rustGeneratedSource = "${buildDir}/generated/source/uniffi/main/com/jetpackd group = "com.jetpackduba" version = projectVersion +val isLinuxAarch64 = (properties.getOrDefault("isLinuxAarch64", "false") as String).toBoolean() + + sourceSets.getByName("main") { kotlin.sourceSets.main.get().kotlin.srcDir(rustGeneratedSource) } @@ -35,11 +39,11 @@ repositories { dependencies { val jgit = "6.7.0.202309050840-r" - - implementation(compose.desktop.currentOs) - when (currentOs()) { - OS.LINUX -> implementation(compose.desktop.linux_arm64) // Include arm for linux builds - else -> {} + println("isLinuxAarch64=$isLinuxAarch64") + if (currentOs() == OS.LINUX && isLinuxAarch64) { + implementation(compose.desktop.linux_arm64) + } else { + implementation(compose.desktop.currentOs) } @OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class) @@ -215,17 +219,30 @@ fun generateKotlinFromUdl() { fun buildRust() { exec { println("Build rs called") - workingDir = File(project.projectDir, "rs") - commandLine = listOf( + val params = mutableListOf( "cargo", "build", "--release", "--features=uniffi/cli", ) + + if (currentOs() == OS.LINUX && isLinuxAarch64) { + params.add("--target=$linuxArmTarget") + } + + workingDir = File(project.projectDir, "rs") + commandLine = params } } fun copyRustBuild() { val outputDir = "${buildDir}/classes/kotlin/main" println("Copy rs build called") - val workingDir = File(project.projectDir, "rs/target/release") + + val workingDirPath = if (currentOs() == OS.LINUX && isLinuxAarch64) { + "rs/target/$linuxArmTarget/release" + } else { + "rs/target/release" + } + + val workingDir = File(project.projectDir, workingDirPath) val directory = File(outputDir) directory.mkdirs() diff --git a/rs/.cargo/config.toml b/rs/.cargo/config.toml new file mode 100644 index 0000000..3c32d25 --- /dev/null +++ b/rs/.cargo/config.toml @@ -0,0 +1,2 @@ +[target.aarch64-unknown-linux-gnu] +linker = "aarch64-linux-gnu-gcc"