hxn

TUTORIAL / 01

Create, run and package

Use the CLI to build your first library, compare runtimes and share a haxelib.

1. Create a library

Install Rust, Haxe and HashLink or hxcpp from git. Install hxn, then check your tools:

Create and run
hxn doctor
hxn new greeter
cd greeter
hxn run hl

src/lib.rs is your Rust API; haxe/Main.hx is the program using it. The starter includes a constructor, methods and a fallible call. See the complete Quick Start.

2. Run the same code on two runtimes

Compare HashLink and hxcpp
hxn run cpp
hxn check hl cpp

check requires both runs to succeed and print the same output. Commit the generated greeter.hxn.json with API changes; check stops if the manifest is out of date. Use hxn build hl to generate and compile without running.

3. Package and use a haxelib

From the greeter crate, build both host bindings into one package and register it with haxelib:

Create the haxelib
hxn package hl cpp --release --out ../greeter-haxelib
haxelib dev greeter ../greeter-haxelib

The directory contains haxelib.json, generated Haxe classes, headers and native/<triple>/ libraries. To include just one runtime, use hxn package hl or hxn package cpp with the same output option.

Compile a separate Haxe app against that package. Copy the starter’s Haxe file; the new app does not need the Rust source:

Use the package in another app
mkdir ../greeter-app
cp haxe/Main.hx ../greeter-app/Main.hx
cd ../greeter-app
haxe -lib greeter -cp . -main Main -hl main.hl
hl main.hl
cd ../greeter

With Ash installed instead of HashLink, run ash main.hl. -lib greeter selects the binding and copies its native library beside the program. For hxcpp, compile with -cpp out instead of -hl main.hl.

Before publishing, set repository and license under Cargo’s [package], and contributors and releasenote under [package.metadata.hxn]. Packaging reports missing haxelib metadata.

4. Build for another target

Ash or CPPIA
hxn run hl --vm "ash --mode jit"
hxn run cppia

For native binding builds, wasm, iOS, Android and other Rust triples, follow Build for other targets. It covers build commands, tool requirements and packaging mobile targets with both HashLink through Ash and hxcpp.