Scripts: harden gen_d3d12_layout CLI argument handling and output option #1326

Open
heditrigui wants to merge 1 commit from upstream-pr/1336 into main
heditrigui commented 2026-11-24 14:58:04 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by heditrigui on 2026-11-24T14:58:04Z.


Harden scripts/gen_d3d12_layout.py argument parsing and output configuration:

  • Support -h and --help flags, printing the script's docstring usage and exiting with code 0.
  • Print usage and exit with code 2 when invoked without arguments, avoiding an unhandled IndexError.
  • Validate input file existence and report diagnostic errors to sys.stderr when <d3d12.h> is missing or contains no ID3D12 interfaces (exit code 1) instead of crashing with unhandled tracebacks.
  • Accept an optional second argument [out_rs] to write output to a custom destination, defaulting to crates/xcl/src/hle/d3d12_layout.rs.
  • Add scripts/test_gen_d3d12_layout.py covering CLI help, missing argument handling, invalid file reporting, custom output path writing, and interface parsing/method deduplication.

Tested

  • python -B -m unittest discover -s scripts -p "test_*.py" -v: 16 passed, 0 failed.
  • Tested scripts/gen_d3d12_layout.py --help (exits 0 with usage docstring).
  • Tested scripts/gen_d3d12_layout.py with no args (exits 2 with usage docstring).
  • Tested scripts/gen_d3d12_layout.py nonexistent.h (exits 1 with clear diagnostic).
  • Validated PR description and changed files with scripts/pr_check.py --local.

Not tested

  • Retail game smoke tests: this PR modifies only offline code generator tooling in scripts/ and does not touch runtime code or dependencies.

AI use
Antigravity (Gemini 3.8 Flash (High)) designed the CLI argument handling and optional output destination, implemented unit tests in scripts/test_gen_d3d12_layout.py, ran the test suite, and verified PR conventions.

<!-- greyfinch-sync:ivall/xcl:issue:5474612325 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1336). Originally posted by [heditrigui](https://github.com/heditrigui) on 2026-11-24T14:58:04Z. --- Harden `scripts/gen_d3d12_layout.py` argument parsing and output configuration: - Support `-h` and `--help` flags, printing the script's docstring usage and exiting with code 0. - Print usage and exit with code 2 when invoked without arguments, avoiding an unhandled `IndexError`. - Validate input file existence and report diagnostic errors to `sys.stderr` when `<d3d12.h>` is missing or contains no ID3D12 interfaces (exit code 1) instead of crashing with unhandled tracebacks. - Accept an optional second argument `[out_rs]` to write output to a custom destination, defaulting to `crates/xcl/src/hle/d3d12_layout.rs`. - Add `scripts/test_gen_d3d12_layout.py` covering CLI help, missing argument handling, invalid file reporting, custom output path writing, and interface parsing/method deduplication. **Tested** - `python -B -m unittest discover -s scripts -p "test_*.py" -v`: 16 passed, 0 failed. - Tested `scripts/gen_d3d12_layout.py --help` (exits 0 with usage docstring). - Tested `scripts/gen_d3d12_layout.py` with no args (exits 2 with usage docstring). - Tested `scripts/gen_d3d12_layout.py nonexistent.h` (exits 1 with clear diagnostic). - Validated PR description and changed files with `scripts/pr_check.py --local`. **Not tested** - Retail game smoke tests: this PR modifies only offline code generator tooling in `scripts/` and does not touch runtime code or dependencies. **AI use** Antigravity (Gemini 3.8 Flash (High)) designed the CLI argument handling and optional output destination, implemented unit tests in `scripts/test_gen_d3d12_layout.py`, ran the test suite, and verified PR conventions.
futurepro62 commented 2026-11-24 15:06:13 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T15:02:58Z.


Tested exact head 898e5cc, script tests only, since this PR has no test report yet.

Tested

  • Windows 11 Home 26300, Python 3.14.3 with pytest 9.0.3.
  • python -m pytest scripts/test_gen_d3d12_layout.py at the head: 7 passed, 2 subtests passed.
  • The PR's test file against current main's script (930e8b4): does not get to run, ImportError: cannot import name 'generate' from 'gen_d3d12_layout', since this PR adds generate(). So it can't show the old behaviour failing; it does cover the new CLI handling.

Not tested

  • Running the generator on real D3D12 headers, a game (no runtime code changed).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:ivall/xcl:comment:7135373662 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1336#issuecomment-7135373662). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-24T15:02:58Z. --- Tested exact head `898e5cc`, script tests only, since this PR has no test report yet. **Tested** - Windows 11 Home 26300, Python 3.14.3 with pytest 9.0.3. - `python -m pytest scripts/test_gen_d3d12_layout.py` at the head: 7 passed, 2 subtests passed. - The PR's test file against current main's script (`930e8b4`): does not get to run, `ImportError: cannot import name 'generate' from 'gen_d3d12_layout'`, since this PR adds `generate()`. So it can't show the old behaviour failing; it does cover the new CLI handling. **Not tested** - Running the generator on real D3D12 headers, a game (no runtime code changed). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
DavidM1911 commented 2026-11-24 16:06:55 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T15:10:03Z.


Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: 708 passed, 0 failed, 21 ignored.

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7135568420 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1336#issuecomment-7135568420). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T15:10:03Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: 708 passed, 0 failed, 21 ignored. Thanks!
RavenCurseBurg commented 2026-11-25 16:12:23 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by RavenCurseBurg on 2026-11-25T16:06:53Z.


I’ll check generation against a pinned public Microsoft DirectX-Headers d3d12.h, compare the parent and this revision byte for byte, and check inherited method order and interface counts independently of the generator.

Base: 898e5cc42c. OpenAI Codex (GPT-6) will run these checks on Windows.

<!-- greyfinch-sync:ivall/xcl:comment:7167605570 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1336#issuecomment-7167605570). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-25T16:06:53Z. --- I’ll check generation against a pinned public Microsoft DirectX-Headers d3d12.h, compare the parent and this revision byte for byte, and check inherited method order and interface counts independently of the generator. Base: 898e5cc42c4eaaab42f63b954505d3c5fe792533. OpenAI Codex (GPT-6) will run these checks on Windows.
RavenCurseBurg commented 2026-11-25 17:07:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by RavenCurseBurg on 2026-11-25T16:14:53Z.


I checked the generator on the Microsoft desktop header from DirectX-Headers v1.614.1 at 48a762973271c5a75869946bf1fdbc489a628a5c. Pinned d3d12.h.

Tested on Windows 11 26100.9711 (i7-13700, RTX 4060), Python 3.14.3. I ran python -I scripts/gen_d3d12_layout.py <header> <output> from the parent 930e8b49c1c2ec683d22c724a398b39111cd0e56 and PR head 898e5cc42c4eaaab42f63b954505d3c5fe792533. Both produced the same 60,453 bytes (SHA-256 63f7308f28feb3b90cfa7b0cf0e8ef196b1c84ec6614d61e5bd61e20a19b2c0e). The new CLI created the requested output in a new directory containing a space.

As an independent check on slot order, I read the header’s COBJMACROS definitions and compared their method names in order with the generated Rust arrays, counting each alternate platform signature once. All 74 interfaces and 2,269 slots matched. All 59 interfaces with a generated parent retained that parent’s complete method prefix. ID3D12Device14 had 83 methods. The seven focused unit tests passed (python -B -m unittest discover -s scripts -p test_gen_d3d12_layout.py).

Not tested: other header versions, Rust compilation, GPU or game. OpenAI Codex (GPT-6) ran the checks and prepared this report.

Follow-up on the review at 898e5cc42c4e. Tested candidate c68f99eb8. I carried the device checks from #1002 into the callable CLI. A synthetic header with Debug interfaces and no device returned 0 on this head. The candidate returned 1, preserved an existing output byte for byte and left a missing destination absent. An empty device vtable also raised the expected diagnostic. All 18 script tests passed.

Command on the candidate: python -B -m unittest discover -s scripts -p "test_*.py". Windows 11 build 26100, Core i7-13700, Python 3.14.3. OpenAI Codex (GPT-6) prepared the patch and ran the tests with synthetic inputs. I did not run the full Rust/GPU suite.

<!-- greyfinch-sync:ivall/xcl:comment:7167721348 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1336#issuecomment-7167721348). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-25T16:14:53Z. --- I checked the generator on the Microsoft desktop header from DirectX-Headers v1.614.1 at `48a762973271c5a75869946bf1fdbc489a628a5c`. [Pinned d3d12.h](https://github.com/microsoft/DirectX-Headers/blob/48a762973271c5a75869946bf1fdbc489a628a5c/include/directx/d3d12.h). **Tested** on Windows 11 26100.9711 (i7-13700, RTX 4060), Python 3.14.3. I ran `python -I scripts/gen_d3d12_layout.py <header> <output>` from the parent `930e8b49c1c2ec683d22c724a398b39111cd0e56` and PR head `898e5cc42c4eaaab42f63b954505d3c5fe792533`. Both produced the same 60,453 bytes (SHA-256 `63f7308f28feb3b90cfa7b0cf0e8ef196b1c84ec6614d61e5bd61e20a19b2c0e`). The new CLI created the requested output in a new directory containing a space. As an independent check on slot order, I read the header’s COBJMACROS definitions and compared their method names in order with the generated Rust arrays, counting each alternate platform signature once. All 74 interfaces and 2,269 slots matched. All 59 interfaces with a generated parent retained that parent’s complete method prefix. ID3D12Device14 had 83 methods. The seven focused unit tests passed (`python -B -m unittest discover -s scripts -p test_gen_d3d12_layout.py`). **Not tested:** other header versions, Rust compilation, GPU or game. OpenAI Codex (GPT-6) ran the checks and prepared this report. Follow-up on [the review](https://github.com/xcl-dev/xcl/pull/1336#pullrequestreview-6071891322) at `898e5cc42c4e`. [Tested candidate c68f99eb8](https://github.com/RavenCurseBurg/xcl/commit/c68f99eb8d07c9e4b775b61c5d9d204e114e110e). I carried the device checks from #1002 into the callable CLI. A synthetic header with Debug interfaces and no device returned 0 on this head. The candidate returned 1, preserved an existing output byte for byte and left a missing destination absent. An empty device vtable also raised the expected diagnostic. All 18 script tests passed. Command on the candidate: `python -B -m unittest discover -s scripts -p "test_*.py"`. Windows 11 build 26100, Core i7-13700, Python 3.14.3. OpenAI Codex (GPT-6) prepared the patch and ran the tests with synthetic inputs. I did not run the full Rust/GPU suite.
luckyteagirl commented 2026-11-26 09:52:29 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-26T09:52:29Z.

Review: COMMENTED


On 898e5cc, a header with a valid ID3D12Debug interface but no ID3D12Device now exits 0 after writing an incomplete layout file. I reproduced this with a temporary minimal MIDL header: gen_d3d12_layout.py printed 1 interfaces; no device interface, overwrote an existing sentinel, and also created a new 426-byte Debug-only output when the destination did not exist. The PR base and current main also wrote that incomplete file but exited 1; the false success is new here. With the new default output path, an accidental wrong-header invocation can quietly replace the checked-in table.

Open #1002 already validates that an ID3D12Device vtable exists before opening output; its exact head rejected the same fixture with exit 1, preserved the sentinel, and left a nonexistent destination absent. Could that guard and its regression test be carried into whichever branch lands? This was a CPU-only exact-blob differential; I did not run a full Windows SDK regeneration or GPU tests.

<!-- greyfinch-sync:ivall/xcl:review:6071891322 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1336#pullrequestreview-6071891322). Originally posted by [luckyteagirl](https://github.com/luckyteagirl) on 2026-11-26T09:52:29Z. **Review:** COMMENTED --- On `898e5cc`, a header with a valid `ID3D12Debug` interface but no `ID3D12Device` now exits 0 after writing an incomplete layout file. I reproduced this with a temporary minimal MIDL header: `gen_d3d12_layout.py` printed `1 interfaces; no device interface`, overwrote an existing sentinel, and also created a new 426-byte Debug-only output when the destination did not exist. The PR base and current main also wrote that incomplete file but exited 1; the **false success** is new here. With the new default output path, an accidental wrong-header invocation can quietly replace the checked-in table. Open #1002 already validates that an `ID3D12Device` vtable exists *before* opening output; its exact head rejected the same fixture with exit 1, preserved the sentinel, and left a nonexistent destination absent. Could that guard and its regression test be carried into whichever branch lands? This was a CPU-only exact-blob differential; I did not run a full Windows SDK regeneration or GPU tests.
github-actions[bot] commented 2026-12-01 02:33:54 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-12-01T02:33:54Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7298751996 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1336#issuecomment-7298751996). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-12-01T02:33:54Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 05:27:55 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:27:55Z.


Triage (#1607) – head 898e5cc

#1002 also changes how scripts/gen_d3d12_layout.py handles a bad header, and also adds scripts/test_gen_d3d12_layout.py, so the two PRs conflict. They solve it differently. #1002 refuses a header with no ID3D12Device (or none with parsed methods) before writing anything. This PR refuses only a header with no ID3D12 interfaces at all. With a header like d3d12sdklayers.h, which has ID3D12 interfaces but no device, it still overwrites d3d12_layout.rs and prints "no device interface". It would be safer to refuse that case as well. The generated output is otherwise unchanged ("];\n" with no trailing newline in the join). #1440 shares only test boilerplate (a different script).
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7301798062 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1336#issuecomment-7301798062). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T05:27:55Z. --- **Triage (#1607)** – head 898e5cc #1002 also changes how `scripts/gen_d3d12_layout.py` handles a bad header, and also adds `scripts/test_gen_d3d12_layout.py`, so the two PRs conflict. They solve it differently. #1002 refuses a header with no `ID3D12Device` (or none with parsed methods) before writing anything. This PR refuses only a header with no ID3D12 interfaces at all. With a header like `d3d12sdklayers.h`, which has ID3D12 interfaces but no device, it still overwrites `d3d12_layout.rs` and prints "no device interface". It would be safer to refuse that case as well. The generated output is otherwise unchanged (`"];\n"` with no trailing newline in the join). #1440 shares only test boilerplate (a different script). Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1336:upstream-pr/1336'
git switch 'upstream-pr/1336'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1336'
git switch 'upstream-pr/1336'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1336'
git switch 'upstream-pr/1336'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1336'
git switch 'main'
git merge --squash 'upstream-pr/1336'
git switch 'main'
git merge --ff-only 'upstream-pr/1336'
git switch 'main'
git merge 'upstream-pr/1336'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!1326
No description provided.