musikr: eliminate need for libc++_shared

This commit is contained in:
Alexander Capehart 2025-02-12 17:44:50 -07:00
parent 7f84349f2e
commit 854164a523
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
4 changed files with 21 additions and 51 deletions

View file

@ -56,52 +56,6 @@ cargo {
profile = "release"
}
tasks.whenTaskAdded { task ->
if (task.name == 'mergeDebugJniLibFolders' || task.name == 'mergeReleaseJniLibFolders') {
task.dependsOn 'cargoBuild'
}
for (target in cargo.targets) {
if (task.name == "cargoBuild${target.capitalize()}") {
task.dependsOn "copy_libc++_shared${target.capitalize()}"
}
}
}
for (target in cargo.targets) {
tasks.register("copy_libc++_shared${target.capitalize()}", Copy) {
def ndkDir = android.ndkDirectory
// hostTag, abi and archTriple from: https://developer.android.com/ndk/guides/other_build_systems
def hostTag
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
if (Os.isArch("x86_64") || Os.isArch("amd64")) {
hostTag = "windows-x86_64"
} else {
hostTag = "windows"
}
} else if (Os.isFamily(Os.FAMILY_MAC)) {
hostTag = "darwin-x86_64"
} else {
hostTag = "linux-x86_64"
}
def (abi, archTriple) = [
arm: ['armeabi-v7a', 'arm-linux-androideabi'],
arm64: ['arm64-v8a', 'aarch64-linux-android'],
x86: ['x86', 'i686-linux-android'],
x86_64: ['x86_64', 'x86_64-linux-android'],
][target]
def from_path = "$ndkDir/toolchains/llvm/prebuilt/$hostTag/sysroot/usr/lib/$archTriple/libc++_shared.so"
def into_path = layout.buildDirectory.dir("rustJniLibs/android/$abi")
assert file(from_path).exists()
from from_path
into into_path
}
}
dependencies {
// Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

View file

@ -196,6 +196,7 @@ dependencies = [
"cxx",
"cxx-build",
"jni",
"link-cplusplus",
]
[[package]]

View file

@ -8,8 +8,14 @@ name = "metadatajni"
crate-type = ["cdylib"]
[dependencies]
link-cplusplus = { version = "1.0.9", features = ["nothing"] }
cxx = { version = "1.0.137", default-features = false, features = ["alloc"] }
jni = { version = "0.21.1", default-features = false }
[build-dependencies]
cxx-build = "1.0.137"
[profile.release]
lto = true
codegen-units = 1
panic = "abort"

View file

@ -4,6 +4,11 @@ use std::process::Command;
use cxx_build;
fn main() {
// List all envs
for (key, value) in env::vars() {
println!("{}: {}", key, value);
}
let working_dir = env::current_dir().expect("Failed to get current working directory");
let target = env::var("TARGET").expect("TARGET env var not set");
let working_dir = Path::new(&working_dir);
@ -105,18 +110,22 @@ fn main() {
println!("cargo:rustc-link-search=native={}/lib", arch_pkg_dir.display());
println!("cargo:rustc-link-lib=static=tag");
// println!("cargo:rustc-link-lib=c++_static");
// Build the shim and cxx bridge together
cxx_build::bridge("src/taglib/ffi.rs")
.file("shim/iostream_shim.cpp")
let mut builder = cxx_build::bridge("src/taglib/ffi.rs");
builder.file("shim/iostream_shim.cpp")
.file("shim/file_shim.cpp")
.file("shim/tk_shim.cpp")
.include(format!("taglib/pkg/{}/include", arch))
.include("shim")
.include(".") // Add the current directory to include path
.flag_if_supported("-std=c++14")
.cpp_link_stdlib("c++_shared") // Use shared C++ runtime for Android compatibility
.compile("taglib_cxx_bindings");
.flag_if_supported("-std=c++14");
if is_android {
builder.cpp_link_stdlib("c++_static"); // Use shared C++ runtime for Android compatibility
}
builder.compile("taglib_cxx_bindings");
// Rebuild if shim files change
println!("cargo:rerun-if-changed=shim/iostream_shim.hpp");