A Go target for Haxe
Write Haxe and get Go source output you
can build with the standard go toolchain.
- Go interop - automatic extern generation, and interop between Haxe and Go types.
- Self compiled - the compiler runs on the Go target itself.
- Custom target - integrates through Haxe's
--custom-targetdefine; no forked compiler required. - Written in Haxe - entire compiler + stdlib code is written in Haxe.
- Concurrency - use goroutines, channels, and
select(go.Syntax.select).
⚠️ Experimental. hx2go is under active development. Expect rough edges and breaking changes.
- Haxe nightly
5.0.0-preview.1+957b2c7or newer
- Go
1.26or newer
Install the library via haxelib:
haxelib git hx2go https://github.com/go2hx/hx2goAdd the target flags to your .hxml:
-L hx2go
--custom-target go=output
# Build and run the generated module
--cmd go -C output/main run .Given a Main.hx:
function main() {
trace("Hello from Haxe, running on Go!");
}Compiling with the flags above generates a Go module under output/main and runs it.
Change go run to go build:
--cmd go build ./output/mainIt will create an executable located at ./output/main/main (on Windows OS with the extension .exe).
For example, to launch an HTTP file server, alter Main.hx to:
import go.net.Http;
import go.net.http.Dir;
function main() {
var port = ":8082";
trace('http file server: http://localhost$port');
var dir:Dir = ".";
var err = Http.listenAndServe(port, Http.fileServer(dir));
trace(err);
}For example, to print the ASCII graph below:
10.00 ┤ ╭╮
9.00 ┤ ╭╮ ││
8.00 ┤ ││ ╭╮││
7.00 ┤ ││ ││││╭╮
6.00 ┤ │╰╮ ││││││ ╭
5.00 ┤ │ │ ╭╯╰╯│││╭╯
4.00 ┤╭╯ │╭╯ ││││
3.00 ┼╯ ││ ││││
2.00 ┤ ╰╯ ╰╯╰╯
Add the target flag to your .hxml:
-D go-lib=github.com/guptarohit/asciigraphRun the Haxe compiler using the altered .hxml once before trying to access the externs to allow the compiler to generate them.
Alter Main.hx to:
import go.Fmt;
import go.github_com.guptarohit.Asciigraph;
function main() {
var data:go.Slice<Float> = [3, 4, 9, 6, 2, 4, 5, 8, 5, 10, 2, 7, 2, 5, 6];
var graph:String = Asciigraph.plot(data);
Fmt.println(graph);
}Contributions are welcome. Please open an issue to discuss substantial changes before sending a pull request.
git clone https://github.com/go2hx/hx2go --recursive
cd hx2go
haxelib dev hx2go .the tests require the utest library
Runs the tests found at ./tests
haxe Tests.hxmlRuns the Haxe compiler's unit tests
haxe scripts/haxeunit.hxml
hx2go is open-source software licensed under the MIT license.
Creators: Mikaib, Elliott Stoneham, PXshadow.