mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-22 01:36:42 +08:00
77 lines
2.5 KiB
Rust
77 lines
2.5 KiB
Rust
use std::env;
|
|
use std::path::PathBuf;
|
|
|
|
fn main() {
|
|
let target = env::var("TARGET").unwrap();
|
|
let is_wasm = target.starts_with("wasm32");
|
|
|
|
// Build spine-cpp with no-cpprt variant
|
|
let spine_cpp_dir = PathBuf::from("../../../spine-cpp");
|
|
let spine_c_dir = PathBuf::from("../..");
|
|
|
|
let mut cpp_build = cc::Build::new();
|
|
cpp_build
|
|
.cpp(true)
|
|
.include(spine_cpp_dir.join("include"))
|
|
.include(spine_c_dir.join("include"))
|
|
.include(spine_c_dir.join("src"))
|
|
.flag("-std=c++11");
|
|
|
|
// Always avoid C++ runtime (consistent with no-cpprt approach)
|
|
cpp_build
|
|
.flag("-fno-exceptions")
|
|
.flag("-fno-rtti");
|
|
|
|
// Always avoid C++ runtime (consistent with no-cpprt approach)
|
|
cpp_build.flag("-nostdlib++");
|
|
|
|
if is_wasm {
|
|
// For WASM, we may need additional setup, but let's first try without extra flags
|
|
// The target is already handled by cc-rs when building for wasm32-unknown-unknown
|
|
}
|
|
|
|
// Add spine-cpp source files (no-cpprt variant = all sources + no-cpprt.cpp)
|
|
let spine_cpp_src = spine_cpp_dir.join("src");
|
|
for entry in std::fs::read_dir(&spine_cpp_src).unwrap() {
|
|
let entry = entry.unwrap();
|
|
let path = entry.path();
|
|
if path.extension().map_or(false, |ext| ext == "cpp") {
|
|
cpp_build.file(&path);
|
|
}
|
|
}
|
|
|
|
// Add spine-cpp subdirectories
|
|
for subdir in &["spine", "spine-c", "utils"] {
|
|
let subdir_path = spine_cpp_src.join(subdir);
|
|
if subdir_path.exists() {
|
|
for entry in std::fs::read_dir(&subdir_path).unwrap() {
|
|
let entry = entry.unwrap();
|
|
let path = entry.path();
|
|
if path.extension().map_or(false, |ext| ext == "cpp") {
|
|
cpp_build.file(&path);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Add spine-c generated sources
|
|
let spine_c_generated = spine_c_dir.join("src/generated");
|
|
for entry in std::fs::read_dir(&spine_c_generated).unwrap() {
|
|
let entry = entry.unwrap();
|
|
let path = entry.path();
|
|
if path.extension().map_or(false, |ext| ext == "cpp") {
|
|
cpp_build.file(&path);
|
|
}
|
|
}
|
|
|
|
// Add spine-c extensions
|
|
cpp_build.file(spine_c_dir.join("src/extensions.cpp"));
|
|
|
|
cpp_build.compile("spine");
|
|
|
|
// Link libraries - no C++ stdlib since we're using no-cpprt variant
|
|
// The no-cpprt.cpp provides minimal runtime stubs
|
|
|
|
println!("cargo:rerun-if-changed=../../spine-cpp/src");
|
|
println!("cargo:rerun-if-changed=../../src");
|
|
} |