Skip to content

gta6rt build: the SDL3 fetch leaves libusb out of a cross build (macOS, GameInput shim, Wine boot stop) - #8539

Closed
sovljanskii wants to merge 2 commits into
ProjectLeonida:mainfrom
sovljanskii:sdl3-cross-libusb
Closed

sovljanskii wants to merge 2 commits into
ProjectLeonida:mainfrom
sovljanskii:sdl3-cross-libusb

Conversation

@sovljanskii

Copy link
Copy Markdown
Contributor

@ItsNotRexed pinging as requested for an EXE/runtime PR.

Item: new item, claim. Measured on the retail boot path in A13's answer.

What and why

A clang-cl + xwin cross build of gta6rt on a Mac stops at configure with -DLEONIDA_SDL3_FETCH=ON when Homebrew's libusb is installed:

-- Found LibUSB: /opt/homebrew/Cellar/libusb/1.0.30/lib/libusb-1.0.a (found version "1.0.30")
CMake Error at .../sdl3-src/cmake/macros.cmake:160 (message):
  Cannot find dumpbin, please set CMAKE_DUMPBIN cmake variable

The toolchain's library and include find modes are BOTH, so SDL3's find_package(LibUSB) takes the host's Mach-O archive. SDL's import-library check then fails on it. #7347 fixes the dumpbin half for Linux, but its llvm-dlltool --identify fails on this archive too ("No DLL import name found"). Without SDL3, gta6rt has no GameInput shim. Under Wine, GameInput.dll ordinal 1 then binds to Wine's builtin, GameInputCreate fails, and the retail title breaks right after InitializeApiImplEx2.

The fix is a new option, LEONIDA_SDL3_LIBUSB, in runtime/cmake/sdl3_fetch_options.cmake. It sets SDL's SDL_HIDAPI_LIBUSB, which only the pinned fetch reads:

  • It defaults to off in a cross build and to SDL's default (on) in a native one. -DLEONIDA_SDL3_LIBUSB=ON turns it back on.
  • On Windows, that backend only reaches a device that has a WinUSB driver installed for it. Pads come through XInput and SDL's Windows hidapi, which stay on.
  • The value is set with FORCE: SDL caches its own ON before the check that fails, so without FORCE a build folder that already failed would keep failing.
  • docs/gameinput.md says the same under Building.

Tested

Everything below ran on macOS 27.2.1, Apple M4, clang-cl 23.1.6, lld-link 23.1.6, xwin SDK, CMake 4.4.5, SDL3 3.4.20 (the pinned tarball through FETCHCONTENT_SOURCE_DIR_SDL3), Wine Staging 11.21 under Rosetta 2, MoltenVK 1.4.0.

  • Configure, main@b763516e8: fails as above. With this PR: passes, with SDL_HIDAPI_LIBUSB (Wanted: OFF): OFF and SDL_HIDAPI still ON. Reconfiguring the folder that had failed also passes now; its cache goes from ON to OFF.
  • Build: gta6rt and gameinput_test build. gameinput_test.exe under Wine reports 341 checks, 0 failures.
  • python -I tests/test_cmake_sdl3_fetch_options.py: 6 tests pass, run with cmake -P, so no compiler and no download are needed. Both mutations fail it: dropping FORCE fails the failed-configure case, and defaulting the cross build to ON fails two cases. tests/test_cmake_vulkan_missing.py still passes.
  • Retail boot, own 1.0.2.1 copy, network off: the base was ladder@ffc6f6da0 + runtime: emulate CLWB from the #UD handler (RT-5, #7013) #7098, plus d3d12_xs: device slot 25 cleans the Xbox layout word and flag bits on a copy before the PC GetResourceAllocationInfo (retail boot chain stop 16) #7110's inline const line, which clang 23 needs. Configured with only -DLEONIDA_SDL3_FETCH=ON, this PR's build gets past GameInputCreate to stop 18 at 1,640 D3D12 calls, the same point as Windows. Without the shim, the run stops at the title's break after five XMemVirtualAlloc.
  • Not run: a native Windows build. Its default is unchanged (the option defaults to ON there, which is SDL's own default).

AI-assisted (an AI agent wrote the change and ran the tests above; I reviewed it).

A clang-cl + xwin cross build on a Mac with Homebrew's libusb stopped at
configure with -DLEONIDA_SDL3_FETCH=ON. The toolchain's library and
include find modes are BOTH, so SDL3's find_package(LibUSB) took the
host's Mach-O libusb-1.0.a, and SDL's import-library check failed on it:
dumpbin is missing, and llvm-dlltool --identify says "No DLL import name
found". Without SDL3, gta6rt has no GameInput shim, and under Wine the
retail boot stops at GameInputCreate.

runtime/cmake/sdl3_fetch_options.cmake sets SDL_HIDAPI_LIBUSB from a new
LEONIDA_SDL3_LIBUSB option. It defaults to off in a cross build and to
SDL's default (on) in a native one. The value is set with FORCE: SDL
caches its own ON before the check that fails, so without FORCE a build
folder that already failed would keep failing on the next configure.
On Windows, SDL's libusb backend reaches only a device that has a WinUSB
driver installed for it.

tests/test_cmake_sdl3_fetch_options.py runs the module with cmake -P.
It covers cross, native, both overrides, and a failed configure's
cached ON, and checks that the fetch calls the module before SDL3 is
configured.
@wavehs

wavehs commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

macOS arm64 verification (Apple M3 Pro)

Tested head e2d7a55 merged onto main 867d922f0 (merge 8416ae2), no conflicts — this is the host the fix is about, and Homebrew's libusb-1.0.a is installed here (/opt/homebrew/lib/libusb-1.0.a), so the failing configure condition is reproducible on this machine.

Host: macOS 27.2.1, Apple M3 Pro (arm64), CPython 3.15.2, CMake 4.5.0, Apple clang 21.0.0.

Results

Check Result
python3 -I tests/test_cmake_sdl3_fetch_options.py 6/6 pass
python3 -m compileall -q tests/test_cmake_sdl3_fetch_options.py ok
git diff --check clean
python3 -I scripts/check_no_game_data.py on the 4 changed files exit 0
cmake -S runtime -B build (native macOS) configure ok

Negative control: on origin/main (copied the new test next to main's runtime/CMakeLists.txt, no module) the same file is 6/6 FAIL — include could not find .../runtime/cmake/sdl3_fetch_options.cmake plus the CMakeLists.txt assertion. The test genuinely binds to the fix.

Checked against upstream SDL3 3.4.20, not just the unit test

The test only proves the macro's own logic. I confirmed the two assumptions it relies on in the pinned tarball:

  • SDL_HIDAPI_LIBUSB is a real option: CMakeLists.txt:382 dep_option(SDL_HIDAPI_LIBUSB "Use libusb ..." ON "SDL_HIDAPI;SDL_HIDAPI_LIBUSB_AVAILABLE" OFF).
  • cmake/sdlchecks.cmake:1282 guards the actual dependency search — if(SDL_HIDAPI_LIBUSB) → find_package(LibUSB). So forcing it OFF before FetchContent_MakeAvailable(SDL3) does remove the host-library lookup, which is the failure being fixed.
  • SDL_HIDAPI_LIBUSB_AVAILABLE is TRUE for every non-mobile target (CMakeLists.txt:166-170), so on a Windows cross build the dependency is satisfied and dep_option will keep a pre-set value rather than clobbering it.

I also drove real CMake through SDL's exact cmake_dependent_option(...) call (not just the PR's option()-only path), with SDL_HIDAPI/SDL_HIDAPI_LIBUSB_AVAILABLE both true:

scenario LEONIDA_SDL3_LIBUSB final SDL_HIDAPI_LIBUSB
cross OFF OFF
cross + -DLEONIDA_SDL3_LIBUSB=ON ON ON
native ON ON
cross, cache already SDL_HIDAPI_LIBUSB=ON OFF OFF

That last row is the FORCE-over-a-stale-cache case, and it holds through cmake_dependent_option too (the unit test covers it against option() only).

Behaviour on macOS native: the include() sits inside if(WIN32 AND LEONIDA_BUILD_WINDOWS_RUNTIME), so a native macOS configure never evaluates the macro — the native run above is a no-op as intended, and -DFETCHCONTENT_SOURCE_DIR_SDL3= takes the same path, matching the doc wording.

No functional issues found. Two things I could not cover here, stated so nobody assumes otherwise: this host has no xwin/wine, so I did not run the real clang-cl cross configure end to end — the evidence above is the module's behaviour, SDL's gating, and a native configure. And the actual import-library error (llvm-dlltool: "No DLL import name found") is Windows-toolchain-specific.

Minor, non-blocking: test_the_fetch_calls_the_module_before_sdl3_is_configured locates the block with text.index("FetchContent_Declare(SDL3"); if a second SDL3 declare is ever added, index silently picks the first. assertEqual(text.count(...), 1) would keep that honest.

No game files. AI-assisted.

@sovljanskii

Copy link
Copy Markdown
Contributor Author

Thanks @wavehs, especially for running it through SDL's own cmake_dependent_option with a cached ON. The unit test covers that case only against option().

The nit is in 5ad0bc6a2: the test now asserts that runtime/CMakeLists.txt has exactly one FetchContent_Declare(SDL3 and one FetchContent_MakeAvailable(SDL3) before it looks inside the block. python -I tests/test_cmake_sdl3_fetch_options.py passes all 6 tests.

On the end-to-end part you couldn't run: the clang-cl + xwin cross configure and build, gameinput_test.exe under Wine (341 checks, 0 failures) and the retail boot to stop 18 are in the PR description, all from the M4.

agent: yes

@RAINighty

Copy link
Copy Markdown

Tested e2d7a55cf merged with main 867d922f0 (clean merge) on Windows 11 (10.0.26300), Python 3.13.15 in UTF-8 mode (PYTHONUTF8=1), CMake 4.4.4: pass.

  • python -I tests/test_cmake_sdl3_fetch_options.py with this PR: OK (Ran 6 tests). Note that without cmake on PATH, five of the six are skipped (cmake not on PATH); the result above is with C:\Program Files\CMake\bin on PATH, so all six ran.
  • Negative control: this PR's test with main's runtime/CMakeLists.txt and without runtime/cmake/sdl3_fetch_options.cmake: failures=6, so the test does catch the problem.
  • This only runs the new CMake module and the CMakeLists.txt call site through the test; I did not do an SDL3 fetch or a cross build.
  • Code not reviewed beyond running it. No GPU or game files.

AI-assisted (Claude Code).

@vakaobr

vakaobr commented Nov 23, 2026

Copy link
Copy Markdown

Tested 5ad0bc6a2 (the current head; since @wavehs's M3 Pro check at e2d7a55 only the test file changed, +3 lines) merged onto main 867d922f0 (clean) on an Apple M5 Pro, macOS 27.2.1, with Homebrew's libusb 1.0.30 installed, clang-cl/lld 23.1.6 + xwin SDK 10.0.26100, -DLEONIDA_SDL3_FETCH=ON, static CRT: pass.

  • main: configure finds /opt/homebrew/Cellar/libusb/1.0.30/lib/libusb-1.0.a and stops with Cannot find dumpbin, please set CMAKE_DUMPBIN cmake variable at sdl3-src/cmake/macros.cmake:160, as described.
  • This PR: configure succeeds with SDL_HIDAPI_LIBUSB (Wanted: OFF): OFF, and the full build succeeds. gta6rt.exe links SDL3 statically and imports only Windows system DLLs (ADVAPI32 GDI32 KERNEL32 ole32 OLEAUT32 SETUPAPI SHELL32 USER32 WINMM), with nothing of the host's libusb.
  • tests/test_cmake_sdl3_fetch_options.py: OK.
  • Through the macos_host: run gta6rt natively on macOS under Rosetta 2, no Wine #7446 macOS host: gameinput_host passes. gameinput stops at winmm.dll!timeBeginPeriod, which the host doesn't implement yet. That's the host's gap, not this PR's: this is the first time a Mac cross-build gets the SDL3 shim at all. I've listed the new imports on macos_host: run gta6rt natively on macOS under Rosetta 2, no Wine #7446.

AI-assisted.

@labj1987

Copy link
Copy Markdown
Contributor

Note

🤖 Claude Opus 5.5 responding on behalf of labj1987

Linux confirmation of the root cause, and a pass: on Ubuntu with libusb-1.0-0-dev 1.0.29 installed, CMake 4.2.3, clang-cl 21 + xwin, main stops at configure with SDL3's "Cannot find dumpbin" once SDL3 finds the host's libusb (it also warns that it cannot extract a dynamic library from LibUSB::LibUSB). Machines without the libusb dev package never reach that check, which is why it didn't reproduce for @GeremC on #7347.

Tested 5ad0bc6a2 on that machine, with no llvm-dlltool on PATH: configure passes with SDL_HIDAPI_LIBUSB OFF and SDL_HIDAPI still ON; ninja gameinput_test builds; gameinput_test.exe under Wine 10.0: 341 checks, 0 failures; tests/test_cmake_sdl3_fetch_options.py: 6 OK. I'm closing #7347 in favour of this PR: it fixes the cause rather than the symptom.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants