From 58972fbe31b293711b1fb9c16198eb427f2b8a30 Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Sat, 20 Apr 2024 17:18:10 -0400 Subject: [PATCH] Build JoltC and Jolt using CMake instead of cc directly --- crates/jolt-sys/JoltC | 2 +- crates/jolt-sys/build.rs | 83 ++++++++++++---------------------------- 2 files changed, 25 insertions(+), 60 deletions(-) diff --git a/crates/jolt-sys/JoltC b/crates/jolt-sys/JoltC index 45b0f81..200414c 160000 --- a/crates/jolt-sys/JoltC +++ b/crates/jolt-sys/JoltC @@ -1 +1 @@ -Subproject commit 45b0f815cabdc9109253417e7638fc3fd7f17f62 +Subproject commit 200414c9163dadd18ac59cfdca4d5f4b87b4038e diff --git a/crates/jolt-sys/build.rs b/crates/jolt-sys/build.rs index 84e31ec..a673566 100644 --- a/crates/jolt-sys/build.rs +++ b/crates/jolt-sys/build.rs @@ -2,93 +2,58 @@ use std::env; use std::path::Path; use anyhow::Context; -use walkdir::WalkDir; fn main() { let flags = build_flags(); - build_jolt(&flags); - build_joltc(&flags); + build_joltc(); link(); generate_bindings(&flags).unwrap(); } -fn build_flags() -> Vec<(&'static str, &'static str)> { - let mut flags = Vec::new(); +fn build_joltc() { + let mut config = cmake::Config::new("JoltC"); - flags.push(("JPH_DEBUG_RENDERER", "ON")); + if cfg!(windows) { + config.cxxflag("/EHsc"); + } if cfg!(feature = "double-precision") { - flags.push(("JPC_DOUBLE_PRECISION", "ON")); - flags.push(("JPH_DOUBLE_PRECISION", "ON")); + config.configure_arg("-DDOUBLE_PRECISION=ON"); } if cfg!(feature = "object-layer-u32") { - flags.push(("JPC_OBJECT_LAYER_BITS", "32")); - flags.push(("JPH_OBJECT_LAYER_BITS", "32")); + config.configure_arg("-DOBJECT_LAYER_BITS=32"); } - flags -} - -fn build_joltc(flags: &[(&'static str, &'static str)]) { - let mut build = cc::Build::new(); - - for entry in WalkDir::new("JoltC/JoltC") { - let entry = entry.unwrap(); - let file_name = entry - .file_name() - .to_str() - .expect("file was not valid UTF-8"); - - if file_name.ends_with(".cpp") { - build.file(entry.path()); - } - } + let dst = config.build(); - for (key, value) in flags { - build.define(key, *value); - } + println!("cargo:rustc-link-search=native={}", dst.display()); +} - build - .std("c++17") - .include("JoltC") - .include("JoltC/JoltPhysics") - .cpp(true) - .compile("JoltC"); +fn link() { + println!("cargo:rustc-link-lib=Jolt"); + println!("cargo:rustc-link-lib=joltc"); } -fn build_jolt(flags: &[(&'static str, &'static str)]) { - let mut build = cc::Build::new(); +fn build_flags() -> Vec<(&'static str, &'static str)> { + let mut flags = Vec::new(); - for entry in WalkDir::new("JoltC/JoltPhysics/Jolt") { - let entry = entry.unwrap(); - let file_name = entry - .file_name() - .to_str() - .expect("file was not valid UTF-8"); + flags.push(("JPH_DEBUG_RENDERER", "ON")); - if file_name.ends_with(".cpp") { - build.file(entry.path()); - } + if cfg!(feature = "double-precision") { + flags.push(("JPC_DOUBLE_PRECISION", "ON")); + flags.push(("JPH_DOUBLE_PRECISION", "ON")); } - for (key, value) in flags { - build.define(key, *value); + if cfg!(feature = "object-layer-u32") { + flags.push(("JPC_OBJECT_LAYER_BITS", "32")); + flags.push(("JPH_OBJECT_LAYER_BITS", "32")); } - build - .std("c++17") - .include("JoltC/JoltPhysics") - .cpp(true) - .compile("Jolt"); -} - -fn link() { - println!("cargo:rustc-link-lib=Jolt"); - println!("cargo:rustc-link-lib=JoltC"); + flags } fn generate_bindings(flags: &[(&'static str, &'static str)]) -> anyhow::Result<()> {