lukewilliamboswell/roc-platform-template-rust

lukewilliamboswell/roc-platform-template-rust

Rust platform template

Languages

  • Roc
  • Rust
  • Shell

Topics

  • roc-lang

Top Contributors

  • lukewilliamboswell (59 contributions)
  • kili-ilo (1 contributions)

README

Roc-Lang

Roc platform template for Rust

A template for building Roc platforms using Rust.

Requirements

Examples

The examples in this repo use the latest release bundle:

app [main!] { pf: platform "https://github.com/lukewilliamboswell/roc-platform-template-rust/releases/download/1.0.0/Bu7FVf57VbTwUrUSumuTmQNMJLLmGBmer6L5AarS4qnV.tar.zst" }

Run examples with interpreter: roc examples/.roc

Build standalone executable: roc build examples/.roc

Documentation

Platform API docs are published at.

Generate docs locally:

roc docs platform/main.roc --output=generated-docs --no-cache

Building

# Build for native platform only
./build.sh
 
# Build for all supported targets (cross-compilation)
./build.sh --all

Regenerating glue

When the platform API changes (e.g. adding or modifying hosted functions in platform/main.roc), regenerate the Rust ABI bindings:

roc glue <path-to>/RustGlue.roc ./src/ platform/main.roc

This overwrites src/roc_platform_abi.rs with updated type definitions and hosted symbol signatures.

Bundling

./bundle.sh

This creates a .tar.zst bundle containing all .roc files and prebuilt host libraries.

Running Tests

bash ci/all_tests.sh

This builds the platform and runs all examples using roc from your local PATH. For the local-platform pass, the script copies the examples to a temp directory and rewrites their release bundle dependency to this checkout’s platform/main.roc.

The script also creates a native-target platform bundle, serves it over localhost, rewrites temporary copies of the examples to use that package URL, and runs the examples again against the bundled package.

Useful focused runs:

# Skip the package URL pass
RUN_BUNDLE_TEST=0 bash ci/all_tests.sh
 
# Test only a package URL
RUN_LOCAL_TESTS=0 PACKAGE_URL="https://github.com/lukewilliamboswell/roc-platform-template-rust/releases/download/0.4/3q9Kou2yUcPovfn1NhRrsvtcdfHUWmzyCaGwiupYFXUk.tar.zst" bash ci/all_tests.sh

Supported Targets

TargetLibrary
x64macplatform/targets/x64mac/libhost.a
arm64macplatform/targets/arm64mac/libhost.a
x64muslplatform/targets/x64musl/libhost.a
arm64muslplatform/targets/arm64musl/libhost.a

Linux musl targets include statically linked runtime files (crt1.o, libc.a, libunwind.a) for standalone executables.

Platform API

This platform exposes:

  • Stdout.line! - Print a line to stdout
  • Stderr.line! - Print a line to stderr
  • Stdin.line! - Read a line from stdin

The main function receives command-line arguments as List(Str) and returns Try({}, [Exit(I32), ..]).