docs(builder): unsafe is allowed where the builder calls the system itself, each block with its SAFETY #3250
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
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!3250
Loading…
Reference in a new issue
No description provided.
Delete branch "llun/Longshot:docs/builder-unsafe-rule"
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
The written rule for
unsafein the builder doesn't matchmain.docs/dev/standards.mdsays it is allowed only inbuild-core/src/sys.rs's Windows module andgame-files/src/disk.rs;docs/dev/reference/builder.mdnames threemodules; the lint's comment in
Cargo.tomlsays the same. Onmain, 31 files underbuilder/crateshave#[allow(unsafe_code)]: the sandboxes and the game's file service,pads.rs(SDL3),switch2.rs(WinUSB and HID),game_log.rs,crash_block.rs, the control channel, the network broker's sockets and others. 398 of the 410unsafeblocks there have a// SAFETY:comment right above them; the other 12 sit under one comment that covers ashort run of plain calls.
The stale sentence blocks reviews of code that follows the existing pattern: BeanBot's L3 on
PR 3245 (the GameCube adapter driver, modelled on
switch2.rs'smod os) asks for the rule to be changed "through the appropriate decision" or the code moved intosys.rs. This PR is that decision, for a maintainer to take or turn down.It rewrites the rule as the tree keeps it: the workspace denies
unsafe, but a module or function that calls thesystem or a C library itself (Win32, POSIX, WinUSB, SDL3, Vulkan's loader) allows it, and each
unsafeblock has a// SAFETY:comment saying why it holds (one may cover a short run of plain calls). Everything else is safe Rust.builder.mdlists the main places;Cargo.toml's comment points atstandards.md.Read:
docs/dev/standards.md("The builder is Rust"), thendocs/dev/reference/builder.md.Testing
Tested: docs and a comment only; nothing the game or the builder runs changes.
mise run test -- --changed origin/mainon Windows: 14 passed, 0 failed. The counts above come fromgit grepoverorigin/main'sbuilder/crates(7bc53f841).Still to test:
None.
Measurements
Nothing to measure: documentation and a
Cargo.tomlcomment only.Risks
A maintainer may want a tighter rule than the tree has (for example a list of allowed modules kept in a check). Then
this PR is closed, and PR 3245's driver moves its calls to
sys.rsinstead. Nothing changes for players.Checklist
Ready for review
main; the title is a Conventional Commit.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.When it applies
Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
@review
Recommendation: Approve. The rule better describes most existing builder code, but it still excludes legitimate existing unsafe operations. CI is also still running. Nothing blocking is left. Recommend approval; not approved on the forge.
The change broadens the documented unsafe policy and requires safety comments; it changes no executable behavior. The remaining gap can still lead reviewers to reject code following an existing builder pattern.
Should fix (1): not blocking, but worth doing before merging.
docs/dev/standards.md:48: The new exception still excludes existing unsafe operations that do not themselves call the system or a C library. (more on the line) Do: Extend the rule and the corresponding reference and Cargo comment to cover necessary unsafe Rust operations at system-resource boundaries, with their safety invariants documented.@fixcan do L1.Checks: Still running: 11 checks.
More: does it help, other systems, switches, what was read
Does it help: Not a perf change. The documented policy covers the listed system and C-library calls, but does not cover every existing unsafe operation.
Other systems: No game, builder, platform, or runtime behavior changes. The rule guides future builder reviews on Windows and Linux.
Switches: None.
Reviewed:
3836ff36a8against7bc53f8413: Read AGENTS.md, CONTRIBUTING.md, the pull request template, the diff and commit metadata, Cargo.toml, and docs/dev/standards.md. Skimmed docs/dev/reference/builder.md and searched the builder's unsafe allowances and representative call sites. docs/review-checklist.md and the adjacent Tooling checkout were absent. No recorded runs, translations, or generated files changed.; nothing run (a code review).Checked and fine:
Testing: No commands from the project or tests were run, as requested. The author reports 14 checks passed on Windows; the listed CI checks remain running.
Overlaps and merge order: PR 3245 is referenced as a consumer of this policy; no overlapping PR was established from the available information.
Automated code review by BeanBot (gpt-6.1-terra), asked for by llun. Nothing was run; a maintainer decides.
@ -48,3 +48,1 @@- **The builder is Rust, with few dependencies.** The workspace in `builder/` denies `unsafe` (allowed only in`build-core/src/sys.rs`'s Windows module and `game-files/src/disk.rs`'s system calls) and asks for docs on everypublic item; clippy runs with warnings as errors, and rustfmt checks the layout (`tests/test_lifter.py`). A new crate- **The builder is Rust, with few dependencies.** The workspace in `builder/` denies `unsafe`, but where code calls theL1 (should fix): The new exception still excludes existing unsafe operations that do not themselves call the system or a C library.
When: For example, build-driver's map_file calls the Rust memmap2 API, and its channel code uses BorrowedFd::borrow_raw; neither operation calls the system or a C library itself, so the new rule's 'Everything else is safe Rust' disallows these existing patterns.
Do: Extend the rule and the corresponding reference and Cargo comment to cover necessary unsafe Rust operations at system-resource boundaries, with their safety invariants documented.
Pushed
0cb2985b4for L1: the rule now covers Rust's own unsafe operations on what the system hands out (a raw handle or descriptor taken as owned or borrowed, a file mapped into memory), as build-driver's memmap2 mapping and channel's BorrowedFd::borrow_raw do, in standards.md, builder.md and Cargo.toml's comment. The changed checks pass (mise run test -- --changed origin/main).@review
Recommendation: Approve. The revised rule covers the existing raw-descriptor and file-mapping operations named by L1. It changes documentation and a manifest comment without changing player-facing behavior. Recommend approval; not approved on the forge.
The change aligns the builder’s written unsafe-code rule with its existing system-boundary practices. It clarifies where unsafe code is allowed and requires safety comments, without changing executable code.
Since the last review (on
3836ff36a8)Resolved: L1 (The new exception still excludes existing unsafe operations that do not themselves call th…)
Checks: Still running: 11 checks.
More: does it help, other systems, switches, what was read
Does it help: Not a perf change. The revised text addresses the documented mismatch; no performance measurements are needed.
Other systems: The changed files do not alter Windows, Linux, the builder, or the game at runtime.
Switches: None.
Reviewed:
0cb2985b4eagainst7bc53f8413: Read AGENTS.md, CONTRIBUTING.md, the pull request template, both diffs, commit list, changed passages, and the relevant file-mapping and descriptor-borrowing code. The rest of Cargo.toml, standards.md, and builder.md was not read in full. docs/review-checklist.md and ../Tooling/AGENTS.md were unavailable.; nothing run (a code review).Checked and fine:
Testing: No commands from the project were run. The author reports changed checks passing; CI is still running.
Overlaps and merge order: None found in the supplied context.
Automated code review by BeanBot (gpt-6.1-terra), asked for by llun. Nothing was run; a maintainer decides.