diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 0947b53031..4dca2695d9 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -106,9 +106,10 @@ if(WIN32 AND LEONIDA_BUILD_WINDOWS_RUNTIME) MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>" ) - # Rust XMA2 decoder (runtime/xma_decoder), built at configure time when cargo is on PATH, + # Rust XMA2 decoder (runtime/xma_decoder), opt-in at configure time when cargo is on PATH, # or supplied prebuilt via -DLEONIDA_XMA2_DECODER_LIB= (skipping cargo at configure time). # Without it (or if the cargo build fails) the runtime still builds and XMA voices output silence. + option(LEONIDA_XMA2_DECODER "Build the Rust XMA2 decoder at configure time" OFF) option(LEONIDA_REQUIRE_XMA2_DECODER "Fail configure if the Rust XMA2 decoder is unavailable" OFF) set(LEONIDA_XMA2_DECODER_LIB "" CACHE FILEPATH "Prebuilt leonida_xma2_decoder.lib (skips running cargo at configure time)") @@ -116,7 +117,7 @@ if(WIN32 AND LEONIDA_BUILD_WINDOWS_RUNTIME) leonida_resolve_prebuilt_xma2_decoder("${LEONIDA_XMA2_DECODER_LIB}" "${CMAKE_BINARY_DIR}" _xma_lib_resolved) if(_xma_lib_resolved) message(STATUS "Using prebuilt Rust XMA2 decoder: ${_xma_lib_resolved}") - else() + elseif(LEONIDA_XMA2_DECODER OR LEONIDA_REQUIRE_XMA2_DECODER) find_program(LEONIDA_CARGO cargo) if(LEONIDA_CARGO) # Cargo's host (or configured default target) can differ from the runtime's MSVC ABI. @@ -141,6 +142,8 @@ if(WIN32 AND LEONIDA_BUILD_WINDOWS_RUNTIME) else() message(STATUS "cargo not found: runtime/xma_decoder not built, XMA voices will be silent") endif() + else() + message(STATUS "LEONIDA_XMA2_DECODER is OFF: runtime/xma_decoder not built, XMA voices will be silent") endif() if(_xma_lib_resolved) add_library(leonida_xma2_decoder STATIC IMPORTED) diff --git a/runtime/xma_decoder/README.md b/runtime/xma_decoder/README.md index f02bdcb0cb..287742f07d 100644 --- a/runtime/xma_decoder/README.md +++ b/runtime/xma_decoder/README.md @@ -25,7 +25,7 @@ The `xma2-decoder` workflow builds and runs the C++ smoke test with MSVC. It lin `runtime/shims/acphal.cpp` uses `leonida_xma2_decoder_create_hardware` and decodes whole 2048-byte packets, so loop points are rounded to packets. The shim creates a fresh decoder after a loop rewind or a decoder error. Without `cargo`, when that build fails, or with the cl.exe fallback of `scripts/build_runtime.ps1`, XMA voices output silence. -Use `-DLEONIDA_REQUIRE_XMA2_DECODER=ON` to require the decoder in a CMake build, as the Windows runtime CI does. +Use `-DLEONIDA_XMA2_DECODER=ON` to opt in to building the decoder during a CMake configure, or `-DLEONIDA_REQUIRE_XMA2_DECODER=ON` to require it (as the Windows runtime CI does). To link an already-built `leonida_xma2_decoder.lib` without invoking `cargo` during CMake configure (for offline builds or Linux cross-builds whose distribution `rustc` omits the `x86_64-pc-windows-msvc` standard library), pass diff --git a/tests/test_cmake_xma2_opt_in.py b/tests/test_cmake_xma2_opt_in.py new file mode 100644 index 0000000000..ecaa563dcd --- /dev/null +++ b/tests/test_cmake_xma2_opt_in.py @@ -0,0 +1,26 @@ +"""Verify that runtime/CMakeLists.txt gates the configure-time Cargo XMA2 build behind opt-in.""" +from pathlib import Path +import re +import unittest + +ROOT = Path(__file__).resolve().parents[1] +CMAKE = ROOT / "runtime" / "CMakeLists.txt" + + +class CMakeXma2OptInTest(unittest.TestCase): + def test_cargo_build_is_gated_by_opt_in(self): + text = CMAKE.read_text(encoding="utf-8") + self.assertRegex( + text, + r'option\(LEONIDA_XMA2_DECODER\s+"[^"]+"\s+OFF\)', + ) + self.assertIn("if(LEONIDA_XMA2_DECODER OR LEONIDA_REQUIRE_XMA2_DECODER)", text) + opt_pos = text.index("if(LEONIDA_XMA2_DECODER OR LEONIDA_REQUIRE_XMA2_DECODER)") + cargo_pos = text.index("find_program(LEONIDA_CARGO cargo)") + exec_pos = text.index("COMMAND ${LEONIDA_CARGO} build") + self.assertLess(opt_pos, cargo_pos) + self.assertLess(cargo_pos, exec_pos) + + +if __name__ == "__main__": + unittest.main()