Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b22f6f4
Showing
5 changed files
with
137 additions
and
0 deletions.
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,125 @@ | ||
# Minimal Reason native project | ||
|
||
This is the smallest possible Reason native project. To use, run | ||
|
||
``` | ||
git clone https://github.com/aantron/reason-native-hello.git | ||
cd reason-native-hello | ||
npx esy install | ||
npx esy dune exec ./hello.exe | ||
``` | ||
|
||
This will print | ||
|
||
``` | ||
Hello, world! | ||
``` | ||
|
||
The first time you run this, esy will take a while building all the | ||
dependencies. After that, esy will load the built dependencies from its cache. | ||
|
||
<br> | ||
<br> | ||
<br> | ||
|
||
## Explanation | ||
|
||
We are using four tools here: | ||
|
||
1. [**Reason**][reason] will parse our `hello.re` file for the compiler. | ||
2. The [**OCaml compiler**][ocaml] will translate our parsed `hello.re` into | ||
native code. | ||
3. [**Dune**][dune] is the OCaml build system. It knows how to call into Reason | ||
and OCaml in the right way to build our executable. We tell it what we want | ||
in the [`dune` file][dune-file]: | ||
|
||
``` | ||
(executable | ||
(name hello)) | ||
``` | ||
|
||
4. [**esy**][esy] is a package manager that is able to download, build, and | ||
organize all of the above. Hence, [`esy.json`][esy.json] looks like this: | ||
|
||
```json | ||
{ | ||
"dependencies": { | ||
"@opam/dune": "^2.9", | ||
"@opam/reason": "^3.7.0", | ||
"ocaml": "^4.12" | ||
} | ||
} | ||
``` | ||
|
||
The `@opam/***` package namespace refers to the [**opam package | ||
repository**](https://opam.ocaml.org/), which has a lot of useful OCaml | ||
packages. However, we are not using the opam *tool* — we are using esy | ||
itself to connect directly to the opam repository. | ||
|
||
Reason libraries are also [found][npm-reason] in npm. However, many of those | ||
target JavaScript — though some target both or only native code. | ||
|
||
<br> | ||
|
||
## Next steps | ||
|
||
- You can make a multi-file project by just creating another `.re` file, for | ||
example `another.re`: | ||
|
||
```reason | ||
let how_are_you = | ||
"amazing!" | ||
``` | ||
|
||
You can refer to this value from `hello.re` like this: | ||
|
||
```reason | ||
let () = | ||
print_endline(Another.how_are_you) | ||
``` | ||
|
||
- To depend on a library, say [Dream][dream], tell esy to download it: | ||
|
||
```json | ||
{ | ||
"dependencies": { | ||
"@opam/dream": "*", | ||
"@opam/dune": "^2.9", | ||
"@opam/reason": "^3.7.0", | ||
"ocaml": "^4.12" | ||
} | ||
} | ||
``` | ||
|
||
and Dune to link it: | ||
|
||
``` | ||
(executable | ||
(name hello) | ||
(libraries dream)) | ||
``` | ||
|
||
- Reason can do a lot more. If you want to do full-stack Reason, meaning | ||
compile Reason to both native code and JavaScript, get | ||
[**ReScript**][rescript], which can compile Reason code to JS, and see the | ||
[Full-stack ReScript][fullstack] example. | ||
|
||
<br> | ||
|
||
## Contact | ||
|
||
Visit the [Reason Discord][discord] and chat with us! Edits/suggestions for this | ||
repo are welcome. Open an issue, PR, or highlight @antron in Discord! | ||
|
||
[reason]: https://reasonml.github.io/ | ||
[ocaml]: https://ocaml.org/ | ||
[dune]: https://dune.build/ | ||
[dune-file]: https://github.com/aantron/reason-native-hello/blob/master/dune | ||
[esy]: https://esy.sh/ | ||
[esy.json]: https://github.com/aantron/reason-native-hello/blob/master/esy.json | ||
[opam]: https://opam.ocaml.org/packages/ | ||
[npm-reason]: https://www.npmjs.com/search?q=reason | ||
[dream]: https://github.com/aantron/dream | ||
[discord]: https://discord.gg/Hrz3qKsK | ||
[rescript]: https://rescript-lang.org/ | ||
[fullstack]: https://github.com/aantron/dream/tree/master/example/w-fullstack-rescript#files |
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,2 @@ | ||
(executable | ||
(name hello)) |
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 @@ | ||
(lang dune 2.9) |
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,7 @@ | ||
{ | ||
"dependencies": { | ||
"@opam/dune": "^2.9", | ||
"@opam/reason": "^3.7.0", | ||
"ocaml": "^4.12" | ||
} | ||
} |
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,2 @@ | ||
let () = | ||
print_endline("Hello, world!"); |