musikr: improve taglib buildscript
This commit is contained in:
parent
854164a523
commit
520e52b100
1 changed files with 36 additions and 33 deletions
|
@ -1,14 +1,9 @@
|
||||||
|
use cxx_build;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
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);
|
||||||
|
@ -21,21 +16,8 @@ fn main() {
|
||||||
// Determine if building for Android
|
// Determine if building for Android
|
||||||
let is_android = target.contains("android");
|
let is_android = target.contains("android");
|
||||||
|
|
||||||
// Get architecture
|
let arch_build_dir = taglib_build_dir.join(&target);
|
||||||
let arch = if target.contains("x86_64") {
|
let arch_pkg_dir = taglib_pkg_dir.join(&target);
|
||||||
"x86_64"
|
|
||||||
} else if target.contains("i686") {
|
|
||||||
"x86"
|
|
||||||
} else if target.contains("aarch64") {
|
|
||||||
"arm64-v8a"
|
|
||||||
} else if target.contains("arm") {
|
|
||||||
"armeabi-v7a"
|
|
||||||
} else {
|
|
||||||
"unknown"
|
|
||||||
};
|
|
||||||
|
|
||||||
let arch_build_dir = taglib_build_dir.join(arch);
|
|
||||||
let arch_pkg_dir = taglib_pkg_dir.join(arch);
|
|
||||||
|
|
||||||
// Prepare cmake command
|
// Prepare cmake command
|
||||||
let mut cmake_args = vec![
|
let mut cmake_args = vec![
|
||||||
|
@ -53,6 +35,19 @@ fn main() {
|
||||||
|
|
||||||
// Add Android-specific arguments if building for Android
|
// Add Android-specific arguments if building for Android
|
||||||
if is_android {
|
if is_android {
|
||||||
|
// Get architecture
|
||||||
|
let arch = if target == "x86_64-linux-android" {
|
||||||
|
"x86_64"
|
||||||
|
} else if target.contains("i686-linux-android") {
|
||||||
|
"x86"
|
||||||
|
} else if target.contains("aarch64-linux-android") {
|
||||||
|
"arm64-v8a"
|
||||||
|
} else if target.contains("armv7-linux-androideabi") {
|
||||||
|
"armeabi-v7a"
|
||||||
|
} else {
|
||||||
|
panic!("Unsupported Android target: {}", target);
|
||||||
|
};
|
||||||
|
|
||||||
let clang_path = env::var("CLANG_PATH").expect("CLANG_PATH env var not set");
|
let clang_path = env::var("CLANG_PATH").expect("CLANG_PATH env var not set");
|
||||||
let toolchains_marker = "/toolchains";
|
let toolchains_marker = "/toolchains";
|
||||||
let ndk_path = if let Some(pos) = clang_path.find(toolchains_marker) {
|
let ndk_path = if let Some(pos) = clang_path.find(toolchains_marker) {
|
||||||
|
@ -62,7 +57,7 @@ fn main() {
|
||||||
};
|
};
|
||||||
|
|
||||||
let ndk_toolchain = working_dir.join("android.toolchain.cmake");
|
let ndk_toolchain = working_dir.join("android.toolchain.cmake");
|
||||||
|
|
||||||
cmake_args.extend(vec![
|
cmake_args.extend(vec![
|
||||||
format!("-DANDROID_NDK_PATH={}", ndk_path),
|
format!("-DANDROID_NDK_PATH={}", ndk_path),
|
||||||
format!("-DCMAKE_TOOLCHAIN_FILE={}", ndk_toolchain.to_str().unwrap()),
|
format!("-DCMAKE_TOOLCHAIN_FILE={}", ndk_toolchain.to_str().unwrap()),
|
||||||
|
@ -77,7 +72,7 @@ fn main() {
|
||||||
.status()
|
.status()
|
||||||
.expect("Failed to run cmake configure");
|
.expect("Failed to run cmake configure");
|
||||||
if !status.success() {
|
if !status.success() {
|
||||||
panic!("cmake configure failed for arch {}", arch);
|
panic!("cmake configure failed for target {}", target);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build step
|
// Build step
|
||||||
|
@ -86,11 +81,14 @@ fn main() {
|
||||||
.arg(arch_build_dir.to_str().unwrap())
|
.arg(arch_build_dir.to_str().unwrap())
|
||||||
.arg("--config")
|
.arg("--config")
|
||||||
.arg("Release")
|
.arg("Release")
|
||||||
.arg(format!("-j{}", std::thread::available_parallelism().unwrap().get()))
|
.arg(format!(
|
||||||
|
"-j{}",
|
||||||
|
std::thread::available_parallelism().unwrap().get()
|
||||||
|
))
|
||||||
.status()
|
.status()
|
||||||
.expect("Failed to run cmake build");
|
.expect("Failed to run cmake build");
|
||||||
if !status.success() {
|
if !status.success() {
|
||||||
panic!("cmake build failed for arch {}", arch);
|
panic!("cmake build failed for target {}", target);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Install step
|
// Install step
|
||||||
|
@ -105,25 +103,29 @@ fn main() {
|
||||||
.status()
|
.status()
|
||||||
.expect("Failed to run cmake install");
|
.expect("Failed to run cmake install");
|
||||||
if !status.success() {
|
if !status.success() {
|
||||||
panic!("cmake install failed for arch {}", arch);
|
panic!("cmake install failed for arch {}", target);
|
||||||
}
|
}
|
||||||
|
|
||||||
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");
|
// println!("cargo:rustc-link-lib=cc++_static");
|
||||||
|
|
||||||
// Build the shim and cxx bridge together
|
// Build the shim and cxx bridge together
|
||||||
let mut builder = cxx_build::bridge("src/taglib/ffi.rs");
|
let mut builder = cxx_build::bridge("src/taglib/ffi.rs");
|
||||||
builder.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", target))
|
||||||
.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");
|
||||||
|
|
||||||
if is_android {
|
if is_android {
|
||||||
builder.cpp_link_stdlib("c++_static"); // Use shared C++ runtime for Android compatibility
|
builder.cpp_link_stdlib("c++_static"); // Use shared C++ runtime for Android compatibility
|
||||||
}
|
}
|
||||||
builder.compile("taglib_cxx_bindings");
|
builder.compile("taglib_cxx_bindings");
|
||||||
|
|
||||||
|
@ -135,4 +137,5 @@ fn main() {
|
||||||
println!("cargo:rerun-if-changed=shim/tk_shim.hpp");
|
println!("cargo:rerun-if-changed=shim/tk_shim.hpp");
|
||||||
println!("cargo:rerun-if-changed=shim/tk_shim.cpp");
|
println!("cargo:rerun-if-changed=shim/tk_shim.cpp");
|
||||||
println!("cargo:rerun-if-changed=src/taglib/ffi.rs");
|
println!("cargo:rerun-if-changed=src/taglib/ffi.rs");
|
||||||
|
println!("cargo:rerun-if-changed=taglib/");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue