Skip to content

Commit 8ea74a3

Browse files
authored
Update Beam docs for rebar3 scaffold generation (#231)
Ref: fable-compiler/Fable#4387
1 parent cf1141c commit 8ea74a3

2 files changed

Lines changed: 37 additions & 26 deletions

File tree

docs/docs/beam/build-and-run.md

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ layout: standard
77
Added in v5.0.0-rc.1
88
</p>
99

10-
## Erlang/OTP Version
10+
## Prerequisites
1111

12-
Fable targets Erlang/OTP 25 or higher.
12+
- [Erlang/OTP](https://www.erlang.org/downloads) 25 or higher
13+
- [rebar3](https://rebar3.org/) (the standard Erlang build tool)
1314

1415
## Architecture
1516

@@ -27,7 +28,7 @@ Erlang AST
2728
.erl source files
2829
```
2930

30-
The generated `.erl` files are standard Erlang that can be compiled with `erlc` and run on the BEAM VM.
31+
The generated `.erl` files are standard Erlang that can be compiled with rebar3 and run on the BEAM VM.
3132

3233
## Compiling to Erlang
3334

@@ -43,42 +44,52 @@ dotnet fable --lang beam --outDir /path/to/output
4344

4445
## Output Structure
4546

46-
The output directory will contain:
47+
Fable automatically generates a complete [rebar3](https://rebar3.org/) project scaffold alongside the compiled `.erl` files. The output directory will contain:
4748

4849
```text
4950
output/
50-
program.erl # Your compiled F# modules
51+
rebar.config # rebar3 project config (auto-generated)
52+
src/
53+
program.erl # Your compiled F# modules
54+
my_project.app.src # OTP application resource file
5155
fable_modules/
5256
fable-library-beam/
53-
fable_list.erl # F# List runtime
54-
fable_map.erl # F# Map runtime
55-
fable_string.erl # String utilities
56-
fable_seq.erl # Seq/IEnumerable support
57-
... # Other runtime modules
57+
rebar.config # Per-dependency rebar3 config
58+
src/
59+
fable_library_beam.app.src # OTP app resource for the library
60+
fable_list.erl # F# List runtime
61+
fable_map.erl # F# Map runtime
62+
fable_string.erl # String utilities
63+
fable_seq.erl # Seq/IEnumerable support
64+
... # Other runtime modules
5865
```
5966

60-
## Compiling Erlang
67+
### Rebar3 Scaffold Details
6168

62-
After Fable generates `.erl` files, compile them with `erlc`:
69+
— if you create your own `rebar.config` (without the Fable marker), it will be left untouched (a warning is emitted)
70+
— project and dependency names are normalized to valid OTP application names (e.g., `Fable.Logging.0.10.0``fable_logging`, `fable-library-beam``fable_library_beam`)
71+
— the generated `rebar.config` uses `{project_app_dirs, [".", "fable_modules/*"]}` so rebar3 treats each NuGet dependency as a sub-application
6372

64-
```bash
65-
# Compile the runtime library
66-
erlc -o output/fable_modules/fable-library-beam output/fable_modules/fable-library-beam/*.erl
73+
## Compiling with rebar3
74+
75+
After Fable generates the scaffold, compile everything with rebar3:
6776

68-
# Compile your project files
69-
erlc -pa output/fable_modules/fable-library-beam -o output output/*.erl
77+
```bash
78+
rebar3 compile
7079
```
7180

81+
This compiles all `.erl` files (your project and all dependencies) and places `.beam` files in `_build/default/lib/*/ebin/`.
82+
7283
## Running Erlang Code
7384

7485
Run your compiled module using the Erlang shell:
7586

7687
```bash
77-
erl -pa output -pa output/fable_modules/fable-library-beam \
78-
-noshell -eval 'program:main(), halt().'
88+
erl -noshell -pa _build/default/lib/*/ebin \
89+
-eval 'program:main(), halt().'
7990
```
8091

81-
The `-pa` flag adds directories to the code path so Erlang can find both your modules and the Fable runtime library.
92+
The `-pa` flag adds the rebar3 output directories to the code path so Erlang can find both your modules and the Fable runtime library.
8293

8394
## Module Naming
8495

docs/docs/getting-started/beam.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ Please make sure you followed the [Fable setup guide](/docs/2-steps/your-first-f
1515

1616
## Prerequisites
1717

18-
You need [Erlang/OTP](https://www.erlang.org/downloads) 24 or higher installed. Verify with:
18+
You need [Erlang/OTP](https://www.erlang.org/downloads) 25 or higher and [rebar3](https://rebar3.org/) installed. Verify with:
1919

2020
```bash
2121
erl -eval 'erlang:display(erlang:system_info(otp_release)), halt().' -noshell
22+
rebar3 version
2223
```
2324

2425
<ul class="textual-steps">
@@ -31,17 +32,16 @@ Compile your project to Erlang:
3132
dotnet fable --lang beam
3233
```
3334

34-
This generates `.erl` files in the project directory (where the `.fsproj` is) by default.
35+
Fable generates `.erl` files in `src/` subdirectories and automatically creates a [rebar3](https://rebar3.org/) project scaffold (`rebar.config`, `.app.src` files).
3536

3637
</li>
3738

3839
<li>
3940

40-
Compile the generated Erlang files:
41+
Compile the generated Erlang files with rebar3:
4142

4243
```bash
43-
erlc -o output/fable_modules/fable-library-beam output/fable_modules/fable-library-beam/*.erl
44-
erlc -pa output/fable_modules/fable-library-beam -o output output/*.erl
44+
rebar3 compile
4545
```
4646

4747
</li>
@@ -51,7 +51,7 @@ erlc -pa output/fable_modules/fable-library-beam -o output output/*.erl
5151
Run your code:
5252

5353
```bash
54-
erl -pa output -pa output/fable_modules/fable-library-beam -noshell -eval 'program:main(), halt().'
54+
erl -noshell -pa _build/default/lib/*/ebin -eval 'program:main(), halt().'
5555
```
5656

5757
</li>

0 commit comments

Comments
 (0)