Skip to content

feat: cross-compilation and multi-target hew builds #254

@slepp

Description

@slepp

Summary

Enable hew to cross-compile programs for any supported target from a single host, similar to GOOS=windows go build. This also simplifies the release pipeline by eliminating the need for native CI runners on every platform.

Background

Building Hew programs for a different native target requires a native toolchain on the target platform because:

  1. libhew.a (the runtime) must be built for the target — requires cargo build --target <triple>
  2. The linker invocation in link.rs calls the system cc/clang, which only links for the host
  3. find_hew_lib() has no target-aware path resolution for native architectures

Current state

Phase 1: Multi-target hew-codegen ✅ COMPLETE (PR #261)

  • hew-codegen is now embedded in the hew binary via C API (no subprocess)
  • LLVM is built with all target backends (AllTargetsCodeGens)
  • Target triple wires through from CLI --target flag to LLVM via the C API
  • WASM target (--target wasm32-wasip1) is production-ready with dedicated linker path
  • Native cross-target code emission works (LLVM generates correct object files)

Phase 2: Pre-built libhew.a per target

  • Cross-compile hew-lib for each supported target using Cargo cross-compilation
  • Ship pre-built libhew.a archives per platform in the distribution (or download on demand)
  • Store in lib/<target>/libhew.a (pattern already exists for WASM: lib/wasm32-wasip1/)

Phase 3: Universal linker via lld

  • Replace platform cc with lld (LLVM linker) which handles all targets from a single binary
  • link.rs selects the right libhew.a and platform libs based on --target
  • find_hew_lib() needs target-aware path resolution
  • User experience: hew build --target windows-x86_64 main.hew

Phase 4: Simplified release pipeline

  • Build hew once on Linux with all LLVM targets
  • Cross-link for every platform without native runners
  • Native runners only needed for platform-specific testing, not building

Benefits

  • Developers on macOS can build Windows/Linux binaries locally
  • CI releases go from 3 hours (LLVM builds) to ~15 minutes
  • Enables embedded/IoT targets (ARM, RISC-V) without dedicated hardware
  • Aligns with the actor model vision — actors should be deployable anywhere

Prior art

  • Go: GOOS=windows GOARCH=amd64 go build
  • Zig: zig build-exe -target x86_64-windows
  • Rust: cargo build --target x86_64-pc-windows-msvc (with linker toolchain)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions