Skip to main content

Module build_game

Module build_game 

Source
Expand description

“Build Game” — packs the project’s assets and stages a runnable binary.

Two strategies, picked deterministically from the project’s contents:

  • Runtime stamp (default, project has no Cargo.toml):

    1. khora_io::PackBuilder produces index.bin + data.pack from <project>/assets/.
    2. The pre-built khora-runtime binary for the chosen target is copied into the output directory and renamed to the project name.
    3. A runtime.json companion file is written so the runtime knows which scene to auto-load.

    This path is cross-platform trivial — the runtime binary already exists for every target (built by release.yml), so building Linux from a Windows host is just a file copy.

  • Cargo build (project has Cargo.toml — opted in via the hub’s “Add Native Code” button):

    1. Same PackBuilder step.
    2. cargo build --release --manifest-path <project>/Cargo.toml compiles the user’s binary (which depends on khora-sdk and registers their custom components / agents / lanes).
    3. The compiled binary is copied into the output directory.
    4. Same runtime.json companion is written.

    This path is host-only in v1 because Rust cross-compilation needs per-target toolchains; running the editor on each target is the simplest workaround. Future work can integrate cross for Docker-based cross-compilation.

Output layout (identical between the two strategies):

<project>/dist/<target>/
├── <project_name>{.exe}   # renamed runtime OR compiled user binary
├── data.pack              # asset blobs
├── index.bin              # asset metadata (UUIDs → packed offsets)
└── runtime.json           # project name + default scene rel path

The user can therefore start data-only, ship cross-platform via the stamp strategy, and “graduate” to native Rust without changing how Build Game is invoked — the editor switches strategies automatically based on Cargo.toml’s presence.

Structs§

BuildOutcome
Result of a successful build, returned to the caller (the editor’s menu dispatcher logs + banners off these fields).
RuntimeConfig 🔒
What we write next to the staged runtime so it knows which scene to auto-load. Mirrors the schema khora_runtime::RuntimeConfig reads.

Enums§

BuildPreset
Build profile selecting compression / manifest / runtime-validation trade-offs in one place. Callers pick the preset; the build pipeline reads the resolved settings off it.
BuildStrategy
Which build strategy was used to produce a BuildOutcome.
BuildTarget
One of the platforms the editor knows how to stage a build for.

Functions§

build_for_host
Stages a build for the host OS using the Release preset by default. Convenience wrapper for the menu’s “Build Game…” entry.
build_for_target
Stages a build for any target with an explicit preset. v1 only invokes this with the host; non-host targets fail at the runtime-binary lookup (or, for the cargo path, are explicitly refused — see stage_with_cargo_build) until cross-compile lands.
dirs_home 🔒
engine_cache_dir 🔒
Returns ~/.khora/engines/ if accessible. The hub manages this directory; the editor reads from it.
find_compiled_binary 🔒
Walks target/release/ for the first regular file with the host’s executable suffix, ignoring cargo metadata files (.d, .rlib, etc).
find_file_recursive 🔒
Recursive file search. Returns Some(path) for the first hit.
locate_runtime_binary 🔒
Looks for the khora-runtime binary for target in:
sanitize_binary_name 🔒
Replaces filesystem-unsafe characters in the project name with underscores so we can use it as a binary filename.
set_executable_bit 🔒
stage_with_cargo_build 🔒
Invokes cargo build --release against <project>/Cargo.toml, streams stdout+stderr into the editor log, and copies the resulting binary into output_dir renamed to the project name.
stage_with_runtime_stamp 🔒
Stamps the pre-built khora-runtime into output_dir, renamed to the project name. Returns the absolute path of the staged binary.
workspace_root_from_target_dir 🔒
Returns the workspace root if target_dir is a target/<profile>/ subdirectory of one. Detection: parent must be named target, and the grandparent must contain a Cargo.toml.
write_runtime_config 🔒