Cxx + cmake build works in release and debug locally, but not in github action
โ Rust ๐ 2025-09-29 ๐ค surdeus ๐๏ธ 6I'm trying to get a github action working for GitHub - lucasw/jolt_rust_cpp: Make a hybrid C++ & Rust Jolt physics engine application, wrap the C++ with cxx and it works for the debug buid, but not the release. On my local machine both work fine.
I'm building libJolt.a using cmake with the Jolt cmake file https://github.com/jrouwe/JoltPhysics/blob/master/Build/CMakeLists.txt:
    let dst = cmake::Config::new("../JoltPhysics/Build")
        .define("USE_ASSERTS", "ON")
        .build();
    println!("cargo:rustc-link-search=native={}", dst.display());
and then building with cxx like this:
    cxx_build::bridge("src/lib.rs")
        .file("src/misc.cpp")
        .include(dst.join("include"))
        // TODO(lucasw) any way to sync these with whatever Jolt.cmake used?
        .define("JPH_DEBUG_RENDERER", Some("1"))
        .define("JPH_ENABLE_ASSERTS", Some("1"))
        .define("JPH_OBJECT_STREAM", Some("1"))
        .define("JPH_PROFILE_ENABLED", Some("1"))
        .std("c++20")
        .compile("vehicle_jolt");
(jolt_rust_cpp/jolt_rust_cpp/build.rs at main ยท lucasw/jolt_rust_cpp ยท GitHub)
One issue is that I have to .define("USE_ASSERTS", "ON") and later .define("JPH_ENABLE_ASSERTS", Some("1")) and keep those in sync, otherwise I can't even build in release locally without getting the same error as in the github action.  I think if there was a cmake output header file I could feed into cxx that had all the defines set it could avoid this, maybe I'd have to modify the jolt cmake to generate one?  Ideally the asserts could be turned off in release and on in debug as is the original intent within Jolt.
This is a recent build failure: bring back manually synced defines ยท lucasw/jolt_rust_cpp@adee1ab ยท GitHub
   = note: rust-lld: error: undefined symbol: JPH::AssertFailed
           >>> referenced by misc.cpp
...
rust-lld: error: undefined symbol: JPH::AlignedFree
...
The AssertFailed only exists when USE_ASSERTS is on:
# Setting enable asserts flag
if (USE_ASSERTS)
  target_compile_definitions(Jolt PUBLIC JPH_ENABLE_ASSERTS)
endif()
(JoltPhysics/Jolt/Jolt.cmake at master ยท jrouwe/JoltPhysics ยท GitHub)
It seems like the github action issue is that those build.rs defines are getting ignored/overridden, but why would that happen only in the action? (my rustc is 1.89 and the action has 1.90, I'll try rustup locally next, but cxx is in the checked-in cargo.lock) I'll try it in a docker container next and see if it is the same.
1 post - 1 participant
๐ท๏ธ Rust_feed