Choose the Rust path when the deliverable should be one native executable for the build machine's operating system and architecture. Rust remains a build target; Rust tokens never become Topaz syntax.
Prerequisites
- Complete the
study-planpackage from First Application. - Keep its
topaz.toml,topaz.lock,src/plan.tpz,src/main.tpz, and selected test together. - Install a compatible Rust toolchain with Cargo on the build machine.
- Run the following commands from the
study-plandirectory.
The final executable needs neither Topaz, Cargo, nor .tpz files at runtime.
It is still specific to the OS and architecture for which it was built.
Shared checked package
The same two Topaz modules are used on the Python page. First,
src/plan.tpz:
export record StudyTask {
title: string,
minutes: int,
done: bool = false,
}
function parseMinutes(text: string) -> Result<int, string> {
match toInt(text) {
case Some(value) if value > 0 => Ok(value)
case _ => Err("minutes must be a positive integer")
}
}
export function makeTask(
title: string,
minuteText: string,
done: bool = false,
) -> Result<StudyTask, string> {
let minutes = parseMinutes(minuteText)?
Ok(StudyTask { title: title, minutes: minutes, done: done })
}
export function summarize(tasks: Array<StudyTask>) -> string {
let mut remaining = 0
for task in tasks {
if !task.done {
remaining = remaining + task.minutes
}
}
"tasks={tasks.length}, remaining={remaining} minutes"
}The package entry src/main.tpz:
import src.plan { StudyTask, makeTask, summarize }
export function main(args: Array<string>, stdin: string) -> Result<int, string> {
let tasks: Array<StudyTask> = [
makeTask("Run first program", "10", true)?,
makeTask("Build application", "25", false)?,
]
print(summarize(tasks))
Ok(0)
}Verify the Topaz source
Check the package, run the selected test, and establish the reference output:
topaz check --root . --locked
topaz test tests/plan.tpz --root . --locked
topaz run --root . --locked
The test reports tests/plan.tpz: test-ok. The run prints:
tasks=2, remaining=25 minutesEmit for inspection, build for delivery
Use emit only when you need to inspect or integrate the generated Cargo
source set:
topaz emit --target rust --root . --locked --out-dir ../dist/rust-source
Use build for the managed native product:
topaz build --target native --root . --locked --out-dir ../dist/native
build --target rust is not a valid command. rust names an emit target;
native names the deployable build target.
Inspect the managed product
A default debug build contains:
dist/native/
├── GENERATED-OUTPUT-NOTICE.txt
├── LICENSE
├── NOTICE
├── target
│ └── debug
│ └── program[.exe]
└── topaz-artifact.jsontopaz-artifact.json records target native, the OS/architecture runtime
requirement, invocation, and the size and SHA-256 of every managed file.
Topaz writes the manifest last and rejects a changed managed file, an unsafe
collision, or a different target in the same output directory.
Run after the Topaz source is unavailable
Because dist is outside the package, move the source package aside and run
only the product:
cd ..
mv study-plan source-unavailable
./dist/native/target/debug/program
On Windows, use Rename-Item study-plan source-unavailable, then run
.\dist\native\target\debug\program.exe. The product exits with code 0 and
prints the same output shown above.
Target-specific recovery
- A missing or incompatible Cargo toolchain is a build-machine problem; repair it and rebuild.
--releaseproducestarget/release/program[.exe]; it changes the build profile, not Topaz semantics.- Default lowering uses the boxed Rust runtime. Optional
--backend nativespecializes proven regions and keeps unsupported shapes boxed instead of guessing. - Do not copy a native executable to another OS or architecture and call that a supported deployment.
Exact boundary
Generated Rust and its runtime closure are replaceable artifacts, not a handwritten extension API or source-level Rust FFI. Treat the successful run as evidence for this program's output and exit code on this target. Review a user-written wrapper under its own host-code contract.
Continue with Interop Boundaries, Python Backend, Interpreter & Backends, or Artifacts & Deployment.