roc/crates/glue
2025-05-12 17:51:58 +02:00
..
platform Move to new interpolation syntax 2025-01-10 10:29:20 -08:00
src Remove run anyway tip (#7782) 2025-05-12 17:51:58 +02:00
static Have RustGlue bundle roc_std 2023-06-26 09:48:27 -04:00
templates REVERT ME - add some debug info 2022-11-16 17:07:04 -05:00
tests Fix glue test 2025-01-05 05:56:14 -08:00
Cargo.toml replace cargo deps with workspace in docs_cli, fs, glue 2024-11-29 10:47:36 +11:00
README.md Progress on updating entire compiler for snake_case 2025-01-05 03:48:03 -08:00
writing_a_glue_plugin.md typos 2025-02-22 13:02:28 +11:00

Glue

Glue is a bit of tooling built into Roc to help with platform development. Roc platforms are written in a different language than Roc, and it requires some finesse to let other languages read and write Roc types like records and unions in a way that's compatible with how Roc uses those types.

The roc glue command generates code in other languages for interacting with the Roc types used by your platform. It takes three arguments:

  1. A 'glue spec', this is a Roc file specifying how to output type helpers for a particular language. You can find some examples in the src/ subdirectory:

    • RustGlue.roc: Generates Roc bindings for rust platforms.
    • ZigGlue.roc: Generates Roc bindings for zig platforms (out of date).
    • DescribeGlue.roc: Does not generate Roc bindings, but outputs some information about the types that assist writing compatible types in other languages by hand.
  2. A 'glue dir', specifying where glue should place generated files. Pass any directory you want here.

  3. A .roc file exposing some types that glue should generate code for. You can extend the template below.

platform "glue-types"
    requires {} { main : _ }
    exposes []
    packages {}
    imports []
    provides [main_for_host]

GlueTypes : {
    a : SomeType,
    b : AnotherType,
}

main_for_host : GlueTypes
main_for_host = main