build(ffi): game.h and host-sys ffi.rs generated (cbindgen, ffi-gen), checked in CI #2896
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2896
Loading…
Reference in a new issue
No description provided.
Delete branch "cleanup/area8-generated-decls"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
A call across the line between the game side's Rust and the host's C was declared by hand twice: in
game/game.h(159exports of
longshot-game) and in host-sys'sffi.rs(182 host functions and globals), againsthost/game_host.h. If asignature differed between the two languages, it still compiled and was undefined behaviour. Each side is now generated
from the other by a new dev tool,
game/tools/ffi-gen(mod-api cleanup survey, area 8; the user's decision Q4):game/game.hcomes from cbindgen run overlongshot-game's source. That is pure Rust, with no libclang. Itholds:
#[repr(C)]records those functions name;pub const GAME_*.The values the C named in
enums are nowGAME_*constants beside the code that uses them (menu.rs,post.rs,programs.rs,world.rs,builder_link/, and others). Values owned by another crate are checked against theirowners at compile time or in a test (pad routes, prompt binds, the texture packs' side, the curve's operations). The
lifted code's entry points (
tables.rs, and any export that takesCtx) are left out, since no C calls them.game/crates/host-sys/src/ffi.rsis read fromgame_host.h, below its new/* ==== ffi-gen:line. Every hostfunction and global the game's Rust calls is declared there once, as C, with the doc that
ffi.rsused to carry.ffi-genhas its own small C reader, which refuses anything it does not know. The hand-laid C records move tohost-sys/src/ffi_types.rs, andffi.rsre-exports them.Both files are checked in, so neither a player's build nor the game build runs the tool. They are compared with
ffi-gen --checkin CI'srustjob and inmise run rust, next toschema-gen --check, which nothing ran before.ffi-gen's own test compares them too.The generator forced a few changes at the line:
game_live_action, a Rust global the host stored into, is replaced by the functiongame_live_cheat(action).game_mod_toolandgame_start_argstakemain'schar **as it is.GameTextureReplacement.modis nowmod_id(vk_texture.cpp).hos_main_*andhos_ab_side_noware read as atomics.GAME_*enum constants are now#defines, and the unused type namesGamePassKindandGamePassPointare gone.hos_camera_scale,hos_oc_wait,hos_oc_last_kind.The tool is described in a new page,
docs/dev/reference/ffi.md("The C–Rust line"), with updates togame/README.md,game/DESIGN.md,architecture.mdandci.md.Read first:
game/tools/ffi-gen/src/host_rs.rs,game/tools/ffi-gen/src/game_h.rs, the restructuredhost/game_host.h.Testing
Tested: Linux, RTX 3090, on this PC's job queue (build mode):
cargo clippy -D warningsandcargo test, with modtool run separately, as CI runs them: pass.cargo fmt --check,schema-gen --checkandffi-gen --check: pass.tests/run_all.py: pass. The first run's 5 new failures were header text and fixture conflicts (aCtxtypedef ingame.h, an array parameter in a fixture, the switch table reading the generator's include guard). All are fixed and
each re-ran green.
host/nn_video.c, which fails the same way on mod-api@origin (this PC's tool store has no FFmpeg headers for Windows); unchanged here.dev.py pack+rt): built. Smoke run (shared queue, headless): kokiri-start into play, 1437 frames, Insert opened the menu (system/menu, Graphics).Against the old hand-written headers, checked with clang:
argvtypechanges.
-fdump-record-layouts) is identical.GAME_*value is identical (static asserts).game_host.hcompiles alone.Still to test:
checks the Windows-only
#[cfg(windows)]bindings andgame_builder_file(Test Farm: "@Beanstalk start the game onWindows, open Insert and the Mods tab").
Measurements
Nothing to measure:
ffi-genis a dev tool the game build never runs (its output is checked in, so game build time is unchanged), and the generated declarations keep the ABI identical (record layouts andGAME_*values compared with clang above). No switch is added or changed: theHOS_CHAIN,HOS_LOG_*,HOS_NET_*,HOS_MOD_TESTS,HOS_MOUSE_NATIVE,HOS_SHADOW_RES,HOS_WIDE_MAX_PXandLONGSHOT_SETnames the check sees are existing names in movedgame_host.hlines and generated doc comments, andLONGSHOT_GAME_GAME_His game.h's include guard.Risks
ffi.rs, the C reader maps typesthe way the old hand-written file did; the diff of the old and new signatures shows only parameter names and the
intended atomics and
*mut u32changes.GAME_HOOK_ANYandGAME_CURVE_INPUTSlost theirusuffix: cbindgen writes decimals. They are now a signedlong/long long; every current use is still correct. A future use in%uor~arithmetic would need a cast.appear by themselves from its Rust; area 1's deletion of
game/options.hmust dropoptions.hfromgame_h.rs'sincludes; area 2's
game_host.hedits go below or above the ffi-gen line.longshot_options.iniand the caches areuntouched).
Checklist
Ready for review
main; the title is a Conventional Commit. (ontomod-api)mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.(cbindgen is MPL-2.0, used only by a dev tool)
When it applies
tests/that reads changed source is updated, not weakened.Assisted-by:/Co-Authored-By:trailers.🤖 Generated with Claude Code
https://claude.ai/code/session_016o1k1SQVyAWsujjFVd8Wuc
Possibly related, for context:
Windows host compile (llvm-mingw, with tools.lock's FFmpeg 9.0.2 headers): every host unit compiles at this head; box ticked.
@review
Recommendation: Request changes. The generated boundary has passed a Linux smoke run and a Windows host compile, but its Windows game path has not been exercised. The review is also incomplete: not every changed code file and its callers were read in full. (It stands on L2: The check
PR description / Title and description (pull_request_target)fails on this head and passes on the base branch: Failing after 13s.)The change generates the C and Rust declarations at the game–host boundary and checks the generated files in CI. This reduces manual signature drift at the cost of maintaining a generator and its supported C syntax.
Blocking (1): must change before merging.
PR description / Title and description (pull_request_target)fails on this head and passes on the base branch: Failing after 13s.Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
@fixcan do L2.More: does it help, other systems, switches, what was read
Does it help: Unproven as a complete cross-platform change. The author reports a 1,437-frame Linux smoke run and successful declaration and layout comparisons; no Windows in-game result is reported. This is not a performance change.
Other systems: The declarations reach host and renderer calls throughout the game on Windows and Linux, including Windows-only builder file bindings. The reported Linux smoke run and Windows compilation cover part of that surface; Windows runtime behavior remains untested.
Switches: No switches added, changed, or removed.
Reviewed:
d433f6d3f6against12f42db5c1: Read the repository instructions, contribution rules, standards, PR template, commit log, generator sources, host-sys type definitions, and selected changed diffs. Skimmed portions of the generated declarations, host header, CI, tests, and longshot-game changes. The output for several large reads was truncated; remaining changed files and their surrounding callers were not read in full. The adjacent Tooling checkout and docs/review-checklist.md were unavailable.; nothing run (a code review).Checked and fine:
Testing: No commands from the project, builds, or tests were run during this read-only review.
Overlaps and merge order: Not checked; network access is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
L2: the description's Measurements is now the one line the check wants, and it says the HOS_*/LONGSHOT_SET names it flagged are moved
game_host.hlines and doc comments, not new switches (LONGSHOT_GAME_GAME_H is the include guard). No code change.L1: agreed, Windows runtime is still untested here (no Windows PC); it stays under Still to test for the Test Farm:
@Beanstalk start the game on Windows, open Insert and the Mods tab(a BigBean approves it).Beanstalk test farm
Commit
854713e· approved by nobody yet · dashboardA member of
BigBeanscan review this commit and comment@Beanstalkto test it.d433f6d3f6854713ee67Rebased onto mod-api
75bcd270(#2881): wasd433f6d3, now854713ee. game_host.h keeps #2881's hos_game_language_id in the ffi-gen section; game.h regenerated (picks up hos_mod_language). schema-gen --check, ffi-gen --check, fmt, clippy and the Linux host compile pass; run_all passes apart from two load flakes in code this PR doesn't touch (build-core's control socket test, modtool's TS system-mod tests), each passing on its own.Landed on mod-api as
8f00b801(one commit), after its review fixes and one batched build + game run of all six cleanup areas together. mod-api work now goes straight onto the branch once self-reviewed.Pull request closed