musikr: eliminate need for libc++_shared
This commit is contained in:
parent
7f84349f2e
commit
854164a523
4 changed files with 21 additions and 51 deletions
|
@ -56,52 +56,6 @@ cargo {
|
||||||
profile = "release"
|
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 {
|
dependencies {
|
||||||
// Kotlin
|
// Kotlin
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
|
1
musikr/src/main/jni/Cargo.lock
generated
1
musikr/src/main/jni/Cargo.lock
generated
|
@ -196,6 +196,7 @@ dependencies = [
|
||||||
"cxx",
|
"cxx",
|
||||||
"cxx-build",
|
"cxx-build",
|
||||||
"jni",
|
"jni",
|
||||||
|
"link-cplusplus",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -8,8 +8,14 @@ name = "metadatajni"
|
||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
link-cplusplus = { version = "1.0.9", features = ["nothing"] }
|
||||||
cxx = { version = "1.0.137", default-features = false, features = ["alloc"] }
|
cxx = { version = "1.0.137", default-features = false, features = ["alloc"] }
|
||||||
jni = { version = "0.21.1", default-features = false }
|
jni = { version = "0.21.1", default-features = false }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
cxx-build = "1.0.137"
|
cxx-build = "1.0.137"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
lto = true
|
||||||
|
codegen-units = 1
|
||||||
|
panic = "abort"
|
||||||
|
|
|
@ -4,6 +4,11 @@ use std::process::Command;
|
||||||
use cxx_build;
|
use cxx_build;
|
||||||
|
|
||||||
fn main() {
|
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 working_dir = env::current_dir().expect("Failed to get current working directory");
|
||||||
let target = env::var("TARGET").expect("TARGET env var not set");
|
let target = env::var("TARGET").expect("TARGET env var not set");
|
||||||
let working_dir = Path::new(&working_dir);
|
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-search=native={}/lib", arch_pkg_dir.display());
|
||||||
println!("cargo:rustc-link-lib=static=tag");
|
println!("cargo:rustc-link-lib=static=tag");
|
||||||
|
// println!("cargo:rustc-link-lib=c++_static");
|
||||||
|
|
||||||
// Build the shim and cxx bridge together
|
// Build the shim and cxx bridge together
|
||||||
cxx_build::bridge("src/taglib/ffi.rs")
|
let mut builder = cxx_build::bridge("src/taglib/ffi.rs");
|
||||||
.file("shim/iostream_shim.cpp")
|
builder.file("shim/iostream_shim.cpp")
|
||||||
.file("shim/file_shim.cpp")
|
.file("shim/file_shim.cpp")
|
||||||
.file("shim/tk_shim.cpp")
|
.file("shim/tk_shim.cpp")
|
||||||
.include(format!("taglib/pkg/{}/include", arch))
|
.include(format!("taglib/pkg/{}/include", arch))
|
||||||
.include("shim")
|
.include("shim")
|
||||||
.include(".") // Add the current directory to include path
|
.include(".") // Add the current directory to include path
|
||||||
.flag_if_supported("-std=c++14")
|
.flag_if_supported("-std=c++14");
|
||||||
.cpp_link_stdlib("c++_shared") // Use shared C++ runtime for Android compatibility
|
|
||||||
.compile("taglib_cxx_bindings");
|
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
|
// Rebuild if shim files change
|
||||||
println!("cargo:rerun-if-changed=shim/iostream_shim.hpp");
|
println!("cargo:rerun-if-changed=shim/iostream_shim.hpp");
|
||||||
|
|
Loading…
Reference in a new issue