Skip to content

Commit

Permalink
Merge branch 'ndk-fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
madadam committed Nov 7, 2024
2 parents 6f4696d + dafe370 commit a121ed5
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 187 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ jobs:
name: [android, linux, windows]
include:
- name: android
os: ubuntu-latest
os: ubuntu-24.04
cargo-command: cross
cargo-dir: ~/.cargo
target: aarch64-linux-android

- name: linux
os: ubuntu-latest
os: ubuntu-24.04
cargo-command: cargo
cargo-dir: ~/.cargo

Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:

check_kotlin_bindings:
name: check kotlin bindings
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -147,11 +147,11 @@ jobs:

- name: Build the example app
working-directory: bindings/kotlin
run: ./gradlew example:assembleDebug
run: ./gradlew --stacktrace example:assembleDebug

check_dart_bindings:
name: check dart bindings
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4

Expand Down
265 changes: 119 additions & 146 deletions bindings/dart/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,146 +1,119 @@
group = "org.equalitie.ouisync.lib"
version = "1.0-SNAPSHOT"

buildscript {
ext.kotlin_version = "2.0.20"
repositories {
google()
mavenCentral()

maven {
url "https://plugins.gradle.org/m2/"
}
}

dependencies {
classpath("com.android.tools.build:gradle:8.5.2")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
classpath("org.mozilla.rust-android-gradle:plugin:0.9.4")
}
}

allprojects {
repositories {
google()
mavenCentral()
}
}

apply plugin: "com.android.library"
apply plugin: "kotlin-android"
apply plugin: "org.mozilla.rust-android-gradle.rust-android"

android {
if (project.android.hasProperty("namespace")) {
namespace = "org.equalitie.ouisync.lib"
}

compileSdk = 34
// TODO: The default NDK version should be the lowest possible.
ndkVersion = System.getenv("OUISYNC_ANDROID_NDK_VERSION") ?: "27.0.12077973"

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_17
}

sourceSets {
main.java.srcDirs += "src/main/kotlin"
test.java.srcDirs += "src/test/kotlin"
}

defaultConfig {
minSdk = 21
targetSdkVersion = 35
}

buildTypes {
debug {
android.packagingOptions.doNotStrip '**.so'
}
profile {
}
}

dependencies {
testImplementation("org.jetbrains.kotlin:kotlin-test")
testImplementation("org.mockito:mockito-core:5.10.0")
}

testOptions {
unitTests.all {
useJUnitPlatform()

testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
outputs.upToDateWhen {false}
showStandardStreams = true
}
}
}
}

def abiTargets = {
if (project.hasProperty("target-platform")) {
// https://github.com/flutter/flutter/blob/37dbe030feb47cdf15f3d4c1921857dbbac8aedf/packages/flutter_tools/gradle/flutter.gradle#L78-L82
return project.property("target-platform").split(',').collect{
if (it == "android-arm") {
return "arm"
} else if (it == "android-arm64") {
return "arm64"
} else if (it == "android-x86") {
return "x86"
} else if (it == "android-x64") {
return "x86_64"
} else {
println("Unknown target platform: " + it)
System.exit(1)
}
}
}
else {
// NOTE: x86 is not added by default when invoking `flutter build aar`
// so we don't include it here neither.
return ["arm", "arm64", /* "x86", */ "x86_64"]
}
}()

cargo {
// MacOS no longer has `python` (only has `python3`) and `python3` is present on all other
// systems.
pythonCommand = "python3"
module = "../../.."
libname = "ouisync_ffi"
targets = abiTargets
profile = gradle.startParameter.taskNames.any{it.toLowerCase().contains("debug")} ? "debug" : "release"

extraCargoBuildArguments = ['-p', 'ouisync-ffi']

// HACK: Recent NDK (since r23) no longer links `libgcc`, which breaks some libraries since
// they depended on the symbols from `libclang_rt.builtins-x86_64-android`
// (e.g. `__extenddftf2`, ...). To work around it, we link the library explicitly by setting
// it through the RUSTFLAGS env variable.
// More info: https://github.com/bbqsrc/cargo-ndk/issues/94.
exec { spec, toolchain ->
if (toolchain.target == 'x86_64-linux-android') {
def os_toolchain
if (System.properties['os.name'].toLowerCase().contains('windows')) {
os_toolchain = 'windows-x86_64'
} else {
os_toolchain = 'linux-x86_64'
}


def clangVersion = '18'
def libDir = "${android.sdkDirectory}/ndk/${android.ndkVersion}/toolchains/llvm/prebuilt/${os_toolchain}/lib/clang/${clangVersion}/lib/linux"

spec.environment('RUSTFLAGS', "-L${libDir} -lstatic=clang_rt.builtins-x86_64-android")
}
}
}

preBuild.dependsOn 'cargoBuild'
buildscript {
ext.kotlin_version = "2.0.20"
repositories {
google()
mavenCentral()

maven {
url "https://plugins.gradle.org/m2/"
}
}

dependencies {
classpath("com.android.tools.build:gradle:8.7.2")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
}
}

plugins {
id "com.android.library"
id "kotlin-android"
id "org.mozilla.rust-android-gradle.rust-android" version '0.9.4'
}

allprojects {
repositories {
google()
mavenCentral()
}
}

group = "org.equalitie.ouisync.lib"
version = "1.0-SNAPSHOT"

android {
if (project.android.hasProperty("namespace")) {
namespace = "org.equalitie.ouisync.lib"
}

compileSdk = 34
ndkVersion = '27.2.12479018'

sourceSets {
main.java.srcDirs += "src/main/kotlin"
test.java.srcDirs += "src/test/kotlin"
}

defaultConfig {
minSdk = 21
targetSdkVersion = 34
}

kotlin {
jvmToolchain(17)
}

buildTypes {
debug {
android.packagingOptions.doNotStrip '**.so'
}
profile {
}
}

dependencies {
testImplementation("org.jetbrains.kotlin:kotlin-test")
testImplementation("org.mockito:mockito-core:5.10.0")
}

testOptions {
unitTests.all {
useJUnitPlatform()

testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
outputs.upToDateWhen {false}
showStandardStreams = true
}
}
}
}

def abiTargets = {
if (project.hasProperty("target-platform")) {
// https://github.com/flutter/flutter/blob/37dbe030feb47cdf15f3d4c1921857dbbac8aedf/packages/flutter_tools/gradle/flutter.gradle#L78-L82
return project.property("target-platform").split(',').collect{
if (it == "android-arm") {
return "arm"
} else if (it == "android-arm64") {
return "arm64"
} else if (it == "android-x86") {
return "x86"
} else if (it == "android-x64") {
return "x86_64"
} else {
println("Unknown target platform: " + it)
System.exit(1)
}
}
}
else {
// NOTE: x86 is not added by default when invoking `flutter build aar`
// so we don't include it here neither.
return ["arm", "arm64", /* "x86", */ "x86_64"]
}
}()

cargo {
// MacOS no longer has `python` (only has `python3`) and `python3` is present on all other
// systems.
pythonCommand = "python3"
module = "../../.."
libname = "ouisync_ffi"
targets = abiTargets
profile = gradle.startParameter.taskNames.any{it.toLowerCase().contains("debug")} ? "debug" : "release"

extraCargoBuildArguments = ['-p', 'ouisync-ffi']
}

preBuild.dependsOn 'cargoBuild'
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion bindings/kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:8.7.0'
classpath 'com.android.tools.build:gradle:8.7.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
2 changes: 1 addition & 1 deletion bindings/kotlin/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
38 changes: 5 additions & 33 deletions bindings/kotlin/lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ version = rootProject.version
group = rootProject.group

android {
compileSdkVersion 34

// TODO: The default NDK version should be the lowest possible.
ndkVersion = System.getenv("OUISYNC_ANDROID_NDK_VERSION") ?: '26.3.11579264'

namespace 'org.equalitie.ouisync.lib'

compileSdk = 34
ndkVersion = '27.2.12479018'

sourceSets {
main {
kotlin {
Expand All @@ -44,13 +42,8 @@ android {
versionName version
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = '17'
kotlin {
jvmToolchain(17)
}

testOptions {
Expand Down Expand Up @@ -103,27 +96,6 @@ cargo {
absTargetDir = "$projectDir/$relTargetDir"
}
}

exec { spec, toolchain ->
// HACK: rust.cargoTargetDir local property is not passed to cargo for some reason
// (https://github.com/mozilla/rust-android-gradle?tab=readme-ov-file#targetdirectory).
// Force it:
if (absTargetDir != null) {
spec.environment('CARGO_TARGET_DIR', absTargetDir)
}

// HACK: Recent NDK (since r23) no longer links `libgcc`, which breaks some libraries since
// they depended on the symbols from `libclang_rt.builtins-x86_64-android`
// (e.g. `__extenddftf2`, ...). To work around it, we link the library explicitly by
// setting it through the RUSTFLAGS env variable. More info:
// https://github.com/bbqsrc/cargo-ndk/issues/94.
if (toolchain.target == 'x86_64-linux-android') {
def clangVersion = '17'
def libDir = "${android.sdkDirectory}/ndk/${android.ndkVersion}/toolchains/llvm/prebuilt/linux-x86_64/lib/clang/${clangVersion}/lib/linux"

spec.environment('RUSTFLAGS', "-L${libDir} -lstatic=clang_rt.builtins-x86_64-android")
}
}
}

tasks.register('generateBindings', Exec) {
Expand Down

0 comments on commit a121ed5

Please sign in to comment.