Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,18 @@ if(WIN32 AND LEONIDA_BUILD_WINDOWS_RUNTIME)
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>: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=<path> (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)")
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/xma2_decoder.cmake")
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.
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion runtime/xma_decoder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions tests/test_cmake_xma2_opt_in.py
Original file line number Diff line number Diff line change
@@ -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()
Loading