Skip to content

Latest commit

 

History

History
200 lines (152 loc) · 7 KB

getting-started.md

File metadata and controls

200 lines (152 loc) · 7 KB

Getting Started

This guide contains the setup and compiler details intentionally kept out of the project README. Start with the source checkout when evaluating the current major-zero release line; packaged installation is covered in Packages And Installation.

Choose An Adoption Direction

  • Haxe-first: use Haxe as the normal source language for a Ruby library or CLI, or for a Rails application. Start with the smallest Ruby program, then use the text-report library/CLI for a complete non-Rails workflow. For Rails, the todo application shows nearly all owned app source in Haxe/HHX.
  • Ruby-first: keep an existing Ruby or Rails system authoritative and add a typed component or boundary. Start with Ruby interop or the gradual-adoption example below.

Both paths emit ordinary Ruby artifacts and use the normal Ruby runtime and ecosystem. Haxe-first minimizes day-to-day Ruby authoring, but target-level Ruby knowledge remains useful for gem integration, operations, and debugging.

Prerequisites

The exact supported versions live in the Compatibility Matrix. The current CI baseline is:

  • Haxe 4.3.7
  • Node.js >= 22.14.0 and < 23 with npm >= 10.9.2 and < 11; canonical release jobs use Node 22.23.1 with npm 10.9.8
  • MRI Ruby 3.3, 3.4, or 4.0; Ruby 3.3 is transitional and the local development pin uses primary Ruby 3.4.10
  • Rails 8.1 for RailsHx workflows; canonical CI locks Rails 8.1.3.1, while other Rails lines remain permitted but unverified

The Rails examples also need the generated app bundles. The mandatory Rails runtime task installs them when needed.

Try The Smallest Ruby Program

From a source checkout:

npm install
npm run test:hello-world

The command compiles examples/hello_world/Main.hx, runs the generated Ruby entrypoint, and compares real stdout with the committed fixture.

For a multi-file Haxe-first library and CLI with filesystem input, typed JSON, failure exit codes, and a handwritten Ruby caller, run:

npm run test:rubyhx-cli

See examples/rubyhx_cli. The Haxelib package gate also installs the current candidate ZIP into an isolated repository and compiles that project through -lib reflaxe.ruby.

Run the broad default suite with:

npm test

Compile A Haxe Entrypoint Directly

Set ruby_output, include the compiler and vendored Reflaxe source, load the bootstrap/init macros, and select the Haxe main class:

haxe \
  -D ruby_output=out/ruby \
  -D reflaxe_runtime \
  -cp src \
  -cp examples/hello_world \
  -cp vendor/reflaxe/src \
  --macro "reflaxe.ruby.CompilerBootstrap.Start()" \
  --macro "reflaxe.ruby.CompilerInit.Start()" \
  -main Main

ruby out/ruby/main.rb

For an installed Haxelib-compatible package, use -lib reflaxe.ruby instead of source-checkout classpaths and macro wiring. See Haxelib Packaging for the exact consumer form.

Compiler Defines

  • ruby: injected automatically so application/library code can use conventional #if ruby target branches.
  • ruby_output=<dir>: generated Ruby output directory.
  • reflaxe_runtime: emits/copies required hxruby helpers.
  • reflaxe_ruby_profile=ruby_first|portable: selects the semantic profile. ruby_first is the default; idiomatic remains a compatibility alias.
  • reflaxe_ruby_rails: enables Rails artifact layout under app/haxe_gen and emits the Rails autoload initializer.
  • reflaxe_ruby_rails_output_root=<path>: chooses a safe relative Rails output root, including engine/plugin layouts.
  • reflaxe_ruby_strict_examples: rejects raw __ruby__ injection in repository examples and snapshots.
  • reflaxe_ruby_strict: rejects raw __ruby__ injection in user/project sources.
  • reflaxe_ruby_strict_policy=auto|on|off: controls the strict boundary policy.

See Ruby Profiles before choosing a non-default profile and Compiler Metadata before using target metadata.

Try Ruby Interop

The callable example proves Haxe-owned APIs can expose ordinary Ruby blocks, keywords, forwarding, and method values to handwritten Ruby callers:

npm run test:ruby-callable-abi-example

Continue with:

Try RailsHx

To use RailsHx as a Haxe-first authoring path, prepare and run the canonical generated Rails app:

rake todoapp:start

For the integrated edit loop:

rake todoapp:dev

The reference app demonstrates a workflow where nearly all owned application source is Haxe/HHX: models, controllers, migrations, routes, HHX views, Devise-backed auth, Turbo/ActionCable, Haxe-authored browser code, Rails tests, Playwright, and a production build. See the RailsHx Skeleton And Todoapp Tutorial.

Two focused guides explain the less familiar authoring layers:

  • Typed Views And HHX shows how TSX-like HHX catches markup, expression, locals, helper, route, field, and component mistakes before emitting normal Rails ERB.
  • Client JavaScript And Genes explains why the canonical browser build uses the Genes custom ES-module generator rather than Reflaxe.Ruby or Haxe's stock JavaScript emitter.

To prove gradual adoption instead:

npm run test:rails-interop

That example keeps existing Ruby/ERB source authoritative while typed Haxe consumes it and Ruby callers consume generated Haxe artifacts. See RailsHx Gradual Adoption.

Generate Or Adopt An App

Rails-facing commands are normal Rails generators and Rake tasks. Common entrypoints are:

bin/rails generate hxruby:install MyApp
bin/rails generate hxruby:scaffold Todo title:String isCompleted:Bool --controller
bin/rails generate hxruby:adopt --service LegacyPriceFormatter
bin/railshx-dev # or: bundle exec rake hxruby:dev
bundle exec rake hxruby:doctor
bundle exec rake hxruby:check
RAILS_ENV=production bundle exec rake hxruby:production

The complete command and ownership contract lives in RailsHx Generator Workflows.

For failures, use Haxe/HHX locations from compile diagnostics and generated Ruby/ERB paths from server backtraces. Debugging Generated Applications documents the ownership lookup, browser source maps, and current source-correlation limits.

Where To Go Next