[PR #92] [MERGED] Prepare resources in Rust: horizon-prepare replaces the Python preparer #2322

Closed
opened 2026-11-02 15:54:57 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/92
Author: @ludovic111
Created: 10/14/2026
Status: ✅ Merged
Merged: 10/14/2026
Merged by: @ludovic111

Base: main ← Head: rust/prepare


📝 Commits (3)

  • 9fa3a68 horizon-prepare: the resource preparation in Rust
  • a995fd3 Prepare with horizon-prepare: launcher, release folders, messages and docs
  • 63bb9bc compare_prepare.py: a tar of the Python tree for machines without the repository; launcher formatting

📊 Changes

34 files changed (+3642 additions, -519 deletions)

View changed files

📝 .github/workflows/release.yml (+5 -3)
📝 Cargo.lock (+184 -0)
📝 Cargo.toml (+1 -1)
📝 README.md (+1 -1)
📝 crates/horizon-client/src/game.rs (+3 -3)
📝 crates/horizon-client/src/game/remote.rs (+1 -1)
📝 crates/horizon-client/src/vanillagen.rs (+1 -1)
➕ crates/horizon-prepare/Cargo.toml (+19 -0)
➕ crates/horizon-prepare/build.rs (+38 -0)
➕ crates/horizon-prepare/src/artifacts.rs (+681 -0)
➕ crates/horizon-prepare/src/inventory.rs (+177 -0)
➕ crates/horizon-prepare/src/java.rs (+179 -0)
➕ crates/horizon-prepare/src/lib.rs (+1134 -0)
➕ crates/horizon-prepare/src/main.rs (+109 -0)
➕ crates/horizon-prepare/src/pyjson.rs (+541 -0)
➕ crates/horizon-prepare/src/survival.rs (+146 -0)
📝 crates/horizon-world/src/level/mod.rs (+1 -1)
📝 crates/horizon-world/src/worldgen/generator_blocks.rs (+1 -1)
📝 docs/native-client.md (+9 -4)
📝 docs/parity/meshing.md (+1 -1)

...and 14 more files

📄 Description

Everything player-facing in preparing resources is Rust now. The launcher no longer needs Python, which also fixes preparing on macOS: the system Python 3.9 has no hashlib.file_digest, so the Python preparer has failed on Macs since 2026-10-03 (reproduced on the Mac mini: AttributeError: module 'hashlib' has no attribute 'file_digest').

What moved

crates/horizon-prepare (library + horizon-prepare binary) ports tools/prepare_native_client.py --prepare and every helper that path used:

  • lab.prepare: import and check the version JSON, client jar, client libraries (OS/arch rules, ARM natives) and server jar against research-lock.json; unpack the server bundle; class inventories (reports/*-inventory.json) and prepared.json.
  • verify_artifacts, source_hashes, tag_resources, client_libraries, bind_definitions (survival rules), the worldgen bundle, every exporter step, the data generator run, and the manifest, with the same sha256-keyed skips.
  • pyjson: JSON written as Python's json writes it (key order, ensure_ascii escapes, repr floats, indent/separators, CRLF on Windows like write_text).
  • Java: the exporters (mods/horizon/src/test/java/.../Vanilla*) stay Java, since they call Mojang's code. java::find uses JAVA_HOME, then javac/java on the PATH, then /usr/libexec/java_home -v <major> on macOS, and checks javac -version against java_major. Its errors say what it found.
  • One deliberate omission: the Vineflower decompiler download. It is a decompilation tool, preparing never used it, and tools/lab.py prepare still fetches it for development.
  • CLI: --prepare, --server-jar, --minecraft-dir as before, plus --root (defaults to the folder the binary is in, else the nearest folder with research-lock.json).

The manifest schema stays 7 because the output is the same.

Launcher

backend::preparer picks how to prepare a version:

  • in-process, using the linked library and logging into the launcher's log, when the version folder ships horizon-prepare with the same preparer sources (crates/horizon-prepare, digested by build.rs). Preparing is per version, as the Python script was, so a launcher built from another commit never prepares a version with logic that version doesn't have;
  • the version's own horizon-prepare when its sources differ (a newer or older release);
  • its Python script, only for versions released before this change (no binary).

Release folders (packaging/package.sh, release.yml) ship horizon-prepare and its sources. resources_compatible compares the preparer sources too, so two versions only share prepared resources when they have the same preparer. A Python-prepared version and a Rust-prepared one are not shared (conservative), and the tests cover that. The game's messages, PLAY.txt, README/docs and the MCP description now name horizon-prepare. tools/prepare_native_client.py is a thin wrapper of the binary for the dev tools that call it.

Proof of identical output

tools/compare_prepare.py prepares the same jars three times in fresh folders made from the same tree (research-lock + exporters of the last Python commit 66ce394d): Python twice and Rust once. It compares every file under .local/ by sha256, leaving out compiled classes, logs and the data generator's dated .cache. Then each preparer runs again over the other's output.

Linux (desktop):

  • 24,906 files. 24,900 are byte-identical in all three runs.
  • The other 5 differ between the two Python runs as well, so they are Java exporter noise and not the port: block-behaviours.json (lambda addresses), creative-inventory.json (tag set order), render-definitions.json and its export copy (key order), and the manifest. The manifest's only difference is the recorded hash of render-definitions.json, which matches that run's own file.
  • Port differences: 0. Manifest differences: 0.
  • Rust over the Python tree, and Python over the Rust tree: 0 resource files changed. Rust re-exported only the two steps the script always reruns.
  • Times: Python 104 s and 106 s, Rust 104 s. Reruns: 12 s and 14 s.

macOS (Mac mini, Apple silicon, the Mac's own jars; reference: Homebrew Python 3.13, since the system 3.9 can't run the old script):

  • 24,908 files. 24,902 are byte-identical in all three runs; the same 5 files are exporter noise.
  • Port differences: 0. Manifest differences: 0.
  • Cross reruns: 0 resource files changed.
  • Times: Python 73.1 s and 74.0 s, Rust 72.8 s. Reruns: 18 s and 19 s.

End to end

Linux: I packaged a release folder with packaging/package.sh and installed it into an isolated launcher home (HORIZON_LAUNCHER_HOME). Then I ran horizon-launcher prepare:

  • In-process: the launcher downloaded the 26.3 server jar from Mojang and prepared from scratch in 71 s. The version's horizon-prepare had been swapped for a stub that fails if run, and it was never run.
  • Version binary: after editing the version's crate sources, the launcher ran that version's own horizon-prepare. It was an incremental run.
  • Python fallback: an old-style version folder (66ce394d tree) prepared with its Python script in 81 s.
  • Game: the client started from a scratch HORIZON_HOME (HORIZON_NO_AUDIO=1, on vscreen) with the Rust-prepared resources: "resources loaded in 2.4s; 35723 block states, 1658 items, 67 biomes". With seed 42, teleporting to the plains village gave the same frame as the Python-prepared resources.

macOS (Mac mini):

  • The broken case first: the old script under the system /usr/bin/python3 (3.9.6) fails with AttributeError: module 'hashlib' has no attribute 'file_digest'.
  • In-process: horizon-launcher prepare on an installed release-style folder downloaded the server jar and prepared from scratch in 79 s. It found the JDK on its own (PATH javac 25, Temurin), and the version's stub binary never ran.
  • Version binary: the version-binary path works too.
  • Game: the client started from a scratch home (HORIZON_NO_AUDIO=1): "resources loaded in 3.1s; 35723 block states, 1658 items, 67 biomes", Metal renderer on the M4 Pro. Over horizon-ctl, the same teleport put the player on the same village roof (oak planks at 639 88 -329), then quit.
  • No screenshot from the Mac: its window drew no frames over SSH (the session is occluded), so horizon-ctl screenshot stayed pending.
  • The Mac mini has no Metal toolchain, so the launcher there was built with --features gpui/runtime_shaders. Release CI builds it as before.

Checks

  • cargo fmt --all --check, clippy -D warnings on all targets (workspace and launcher), cargo test -p horizon-prepare (8), launcher cargo test --release --lib (9, including the new preparer-sources reuse cases), python tools/check_public_tree.py, python -m unittest discover -s tests.

Left

  • tools/fetch_sounds.py (optional sounds, mentioned in PLAY.txt) is still Python.
  • Windows was not run (Linux and macOS only, per the usual rule). release.yml builds and import-checks horizon-prepare.exe.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/92 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/14/2026 **Status:** ✅ Merged **Merged:** 10/14/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `rust/prepare` --- ### 📝 Commits (3) - [`9fa3a68`](https://github.com/horizon-rust/horizon/commit/9fa3a684c6bc5c45d456b54fb5ec7d388d7abb42) horizon-prepare: the resource preparation in Rust - [`a995fd3`](https://github.com/horizon-rust/horizon/commit/a995fd3b46a1e65650b0a3c8f4fdf5385ce8b672) Prepare with horizon-prepare: launcher, release folders, messages and docs - [`63bb9bc`](https://github.com/horizon-rust/horizon/commit/63bb9bc37c4bebcee93c3c55f3f51af6646f4350) compare_prepare.py: a tar of the Python tree for machines without the repository; launcher formatting ### 📊 Changes **34 files changed** (+3642 additions, -519 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/release.yml` (+5 -3) 📝 `Cargo.lock` (+184 -0) 📝 `Cargo.toml` (+1 -1) 📝 `README.md` (+1 -1) 📝 `crates/horizon-client/src/game.rs` (+3 -3) 📝 `crates/horizon-client/src/game/remote.rs` (+1 -1) 📝 `crates/horizon-client/src/vanillagen.rs` (+1 -1) ➕ `crates/horizon-prepare/Cargo.toml` (+19 -0) ➕ `crates/horizon-prepare/build.rs` (+38 -0) ➕ `crates/horizon-prepare/src/artifacts.rs` (+681 -0) ➕ `crates/horizon-prepare/src/inventory.rs` (+177 -0) ➕ `crates/horizon-prepare/src/java.rs` (+179 -0) ➕ `crates/horizon-prepare/src/lib.rs` (+1134 -0) ➕ `crates/horizon-prepare/src/main.rs` (+109 -0) ➕ `crates/horizon-prepare/src/pyjson.rs` (+541 -0) ➕ `crates/horizon-prepare/src/survival.rs` (+146 -0) 📝 `crates/horizon-world/src/level/mod.rs` (+1 -1) 📝 `crates/horizon-world/src/worldgen/generator_blocks.rs` (+1 -1) 📝 `docs/native-client.md` (+9 -4) 📝 `docs/parity/meshing.md` (+1 -1) _...and 14 more files_ </details> ### 📄 Description Everything player-facing in preparing resources is Rust now. The launcher no longer needs Python, which also fixes preparing on macOS: the system Python 3.9 has no `hashlib.file_digest`, so the Python preparer has failed on Macs since 2026-10-03 (reproduced on the Mac mini: `AttributeError: module 'hashlib' has no attribute 'file_digest'`). ## What moved `crates/horizon-prepare` (library + `horizon-prepare` binary) ports `tools/prepare_native_client.py --prepare` and every helper that path used: - `lab.prepare`: import and check the version JSON, client jar, client libraries (OS/arch rules, ARM natives) and server jar against `research-lock.json`; unpack the server bundle; class inventories (`reports/*-inventory.json`) and `prepared.json`. - `verify_artifacts`, `source_hashes`, `tag_resources`, `client_libraries`, `bind_definitions` (survival rules), the worldgen bundle, every exporter step, the data generator run, and the manifest, with the same sha256-keyed skips. - `pyjson`: JSON written as Python's `json` writes it (key order, `ensure_ascii` escapes, `repr` floats, indent/separators, CRLF on Windows like `write_text`). - Java: the exporters (`mods/horizon/src/test/java/.../Vanilla*`) stay Java, since they call Mojang's code. `java::find` uses `JAVA_HOME`, then `javac`/`java` on the PATH, then `/usr/libexec/java_home -v <major>` on macOS, and checks `javac -version` against `java_major`. Its errors say what it found. - One deliberate omission: the Vineflower decompiler download. It is a decompilation tool, preparing never used it, and `tools/lab.py prepare` still fetches it for development. - CLI: `--prepare`, `--server-jar`, `--minecraft-dir` as before, plus `--root` (defaults to the folder the binary is in, else the nearest folder with `research-lock.json`). The manifest `schema` stays 7 because the output is the same. ## Launcher `backend::preparer` picks how to prepare a version: - **in-process**, using the linked library and logging into the launcher's log, when the version folder ships `horizon-prepare` with the same preparer sources (`crates/horizon-prepare`, digested by `build.rs`). Preparing is per version, as the Python script was, so a launcher built from another commit never prepares a version with logic that version doesn't have; - **the version's own `horizon-prepare`** when its sources differ (a newer or older release); - **its Python script**, only for versions released before this change (no binary). Release folders (`packaging/package.sh`, `release.yml`) ship `horizon-prepare` and its sources. `resources_compatible` compares the preparer sources too, so two versions only share prepared resources when they have the same preparer. A Python-prepared version and a Rust-prepared one are not shared (conservative), and the tests cover that. The game's messages, PLAY.txt, README/docs and the MCP description now name `horizon-prepare`. `tools/prepare_native_client.py` is a thin wrapper of the binary for the dev tools that call it. ## Proof of identical output `tools/compare_prepare.py` prepares the same jars three times in fresh folders made from the same tree (research-lock + exporters of the last Python commit 66ce394d): Python twice and Rust once. It compares every file under `.local/` by sha256, leaving out compiled classes, logs and the data generator's dated `.cache`. Then each preparer runs again over the other's output. **Linux (desktop):** - 24,906 files. 24,900 are byte-identical in all three runs. - The other 5 differ between the two Python runs as well, so they are Java exporter noise and not the port: `block-behaviours.json` (lambda addresses), `creative-inventory.json` (tag set order), `render-definitions.json` and its export copy (key order), and the manifest. The manifest's only difference is the recorded hash of `render-definitions.json`, which matches that run's own file. - **Port differences: 0. Manifest differences: 0.** - Rust over the Python tree, and Python over the Rust tree: 0 resource files changed. Rust re-exported only the two steps the script always reruns. - Times: Python 104 s and 106 s, Rust 104 s. Reruns: 12 s and 14 s. **macOS (Mac mini, Apple silicon, the Mac's own jars; reference: Homebrew Python 3.13, since the system 3.9 can't run the old script):** - 24,908 files. 24,902 are byte-identical in all three runs; the same 5 files are exporter noise. - **Port differences: 0. Manifest differences: 0.** - Cross reruns: 0 resource files changed. - Times: Python 73.1 s and 74.0 s, Rust 72.8 s. Reruns: 18 s and 19 s. ## End to end **Linux:** I packaged a release folder with `packaging/package.sh` and installed it into an isolated launcher home (`HORIZON_LAUNCHER_HOME`). Then I ran `horizon-launcher prepare`: - **In-process:** the launcher downloaded the 26.3 server jar from Mojang and prepared from scratch in 71 s. The version's `horizon-prepare` had been swapped for a stub that fails if run, and it was never run. - **Version binary:** after editing the version's crate sources, the launcher ran that version's own `horizon-prepare`. It was an incremental run. - **Python fallback:** an old-style version folder (66ce394d tree) prepared with its Python script in 81 s. - **Game:** the client started from a scratch `HORIZON_HOME` (`HORIZON_NO_AUDIO=1`, on `vscreen`) with the Rust-prepared resources: "resources loaded in 2.4s; 35723 block states, 1658 items, 67 biomes". With seed 42, teleporting to the plains village gave the same frame as the Python-prepared resources. **macOS (Mac mini):** - **The broken case first:** the old script under the system `/usr/bin/python3` (3.9.6) fails with `AttributeError: module 'hashlib' has no attribute 'file_digest'`. - **In-process:** `horizon-launcher prepare` on an installed release-style folder downloaded the server jar and prepared from scratch in 79 s. It found the JDK on its own (PATH `javac` 25, Temurin), and the version's stub binary never ran. - **Version binary:** the version-binary path works too. - **Game:** the client started from a scratch home (`HORIZON_NO_AUDIO=1`): "resources loaded in 3.1s; 35723 block states, 1658 items, 67 biomes", Metal renderer on the M4 Pro. Over `horizon-ctl`, the same teleport put the player on the same village roof (oak planks at 639 88 -329), then `quit`. - No screenshot from the Mac: its window drew no frames over SSH (the session is occluded), so `horizon-ctl screenshot` stayed pending. - The Mac mini has no Metal toolchain, so the launcher there was built with `--features gpui/runtime_shaders`. Release CI builds it as before. ## Checks - `cargo fmt --all --check`, clippy `-D warnings` on all targets (workspace and launcher), `cargo test -p horizon-prepare` (8), launcher `cargo test --release --lib` (9, including the new preparer-sources reuse cases), `python tools/check_public_tree.py`, `python -m unittest discover -s tests`. ## Left - `tools/fetch_sounds.py` (optional sounds, mentioned in PLAY.txt) is still Python. - Windows was not run (Linux and macOS only, per the usual rule). `release.yml` builds and import-checks `horizon-prepare.exe`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 15:54:57 +07:00
Sign in to join this conversation.
No milestone
No project
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.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#2322
No description provided.