-
-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add extra documentation around glue #7174
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# 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 some it requires some finesse to let other languages to read and write Roc types like records and unions in a way 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 fora particular language. You can find some examples in the src/ subdirectory: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "fora" typo |
||
|
||
- **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. | ||
|
||
|
||
```roc | ||
platform "glue-types" | ||
requires {} { main : _ } | ||
exposes [] | ||
packages {} | ||
imports [] | ||
provides [mainForHost] | ||
|
||
GlueTypes : { | ||
a : SomeType, | ||
b : AnotherType, | ||
} | ||
|
||
mainForHost : GlueTypes | ||
mainForHost = main | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
app [makeGlue] { pf: platform "../platform/main.roc" } | ||
|
||
import pf.Types exposing [Types] | ||
import pf.File exposing [File] | ||
|
||
makeGlue : List Types -> Result (List File) Str | ||
makeGlue = \types -> | ||
Ok [ | ||
{ | ||
name: "types.txt", | ||
content: List.map types Inspect.toStr |> Str.joinWith "\n", | ||
}, | ||
] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second sentence had a few typos. In the rewording below, I dropped the first "some" and added a "that's", which hopefully still has the meaning that you intended:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You missed another typo :)
The second "to" in "to let other languages to read" should be dropped.