beam.com 0.1.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +97 -0
  3. package/README.md +369 -0
  4. package/js/beam.com.mjs +33 -0
  5. package/js/download.mjs +78 -0
  6. package/js/node.mjs +75 -0
  7. package/package.json +36 -0
  8. package/runtime/app-com.js +203 -0
  9. package/runtime/beam.mjs +2 -0
  10. package/runtime/beam.wasm +0 -0
  11. package/runtime/browser/beam-wasm.js +2 -0
  12. package/runtime/browser/net.js +7 -0
  13. package/runtime/browser/none.js +4 -0
  14. package/runtime/browser.js +161 -0
  15. package/runtime/cloudflare/durable.js +361 -0
  16. package/runtime/cloudflare/index.js +76 -0
  17. package/runtime/cloudflare/release.js +42 -0
  18. package/runtime/cloudflare/snapshot.js +3 -0
  19. package/runtime/cloudflare/worker.js +1891 -0
  20. package/runtime/deno/app.js +8 -0
  21. package/runtime/deno/beam-wasm.js +3 -0
  22. package/runtime/deno/none.js +3 -0
  23. package/runtime/deno/release-bin.js +46 -0
  24. package/runtime/deno/snapshot-bin.js +11 -0
  25. package/runtime/deno/worker.js +1891 -0
  26. package/runtime/deno.js +346 -0
  27. package/runtime/deno.json +5 -0
  28. package/runtime/durable-global.js +40 -0
  29. package/runtime/durable.js +361 -0
  30. package/runtime/global.js +26 -0
  31. package/runtime/licenses/LICENSE +202 -0
  32. package/runtime/licenses/NOTICE +97 -0
  33. package/runtime/licenses/bcrypt_elixir.txt +87 -0
  34. package/runtime/licenses/cosmopolitan.txt +16 -0
  35. package/runtime/licenses/elixir/Apache-2.0.txt +73 -0
  36. package/runtime/licenses/elixir/LicenseRef-elixir-trademark-policy.txt +98 -0
  37. package/runtime/licenses/elixir/LicenseRef-scancode-unicode.txt +58 -0
  38. package/runtime/licenses/emscripten.txt +102 -0
  39. package/runtime/licenses/exqlite.txt +21 -0
  40. package/runtime/licenses/llvm.txt +311 -0
  41. package/runtime/licenses/musl.txt +193 -0
  42. package/runtime/licenses/otp/BSD-2-Clause.txt +22 -0
  43. package/runtime/licenses/otp/BSD-3-Clause.txt +25 -0
  44. package/runtime/licenses/otp/LicenseRef-IETF-MIB.txt +9 -0
  45. package/runtime/licenses/otp/LicenseRef-RSA-PKCS3.txt +23 -0
  46. package/runtime/licenses/otp/LicenseRef-RSA-PKCS5v2-0.txt +17 -0
  47. package/runtime/licenses/otp/LicenseRef-scancode-ietf-trust.txt +296 -0
  48. package/runtime/licenses/otp/LicenseRef-scancode-ietf.txt +23 -0
  49. package/runtime/licenses/otp/LicenseRef-scancode-w3c-docs-19990405.txt +26 -0
  50. package/runtime/licenses/otp/LicenseRef-scancode-wxwindows-free-doc-3.txt +57 -0
  51. package/runtime/licenses/otp/MIT.txt +17 -0
  52. package/runtime/licenses/otp/SGI-B-2.0.txt +25 -0
  53. package/runtime/licenses/otp/W3C-19980720.txt +55 -0
  54. package/runtime/licenses/picosat.txt +19 -0
  55. package/runtime/licenses/wamr.txt +219 -0
  56. package/runtime/nifs.js +2 -0
  57. package/runtime/package.json +1 -0
  58. package/runtime/page/404.html +49 -0
  59. package/runtime/page/app-com.js +203 -0
  60. package/runtime/page/beam.mjs +2 -0
  61. package/runtime/page/browser/beam-wasm.js +2 -0
  62. package/runtime/page/browser/net.js +7 -0
  63. package/runtime/page/browser/none.js +4 -0
  64. package/runtime/page/browser.js +161 -0
  65. package/runtime/page/index.html +50 -0
  66. package/runtime/page/licenses/LICENSE +202 -0
  67. package/runtime/page/licenses/NOTICE +97 -0
  68. package/runtime/page/licenses/bcrypt_elixir.txt +87 -0
  69. package/runtime/page/licenses/cosmopolitan.txt +16 -0
  70. package/runtime/page/licenses/elixir/Apache-2.0.txt +73 -0
  71. package/runtime/page/licenses/elixir/LicenseRef-elixir-trademark-policy.txt +98 -0
  72. package/runtime/page/licenses/elixir/LicenseRef-scancode-unicode.txt +58 -0
  73. package/runtime/page/licenses/emscripten.txt +102 -0
  74. package/runtime/page/licenses/exqlite.txt +21 -0
  75. package/runtime/page/licenses/llvm.txt +311 -0
  76. package/runtime/page/licenses/musl.txt +193 -0
  77. package/runtime/page/licenses/otp/BSD-2-Clause.txt +22 -0
  78. package/runtime/page/licenses/otp/BSD-3-Clause.txt +25 -0
  79. package/runtime/page/licenses/otp/LicenseRef-IETF-MIB.txt +9 -0
  80. package/runtime/page/licenses/otp/LicenseRef-RSA-PKCS3.txt +23 -0
  81. package/runtime/page/licenses/otp/LicenseRef-RSA-PKCS5v2-0.txt +17 -0
  82. package/runtime/page/licenses/otp/LicenseRef-scancode-ietf-trust.txt +296 -0
  83. package/runtime/page/licenses/otp/LicenseRef-scancode-ietf.txt +23 -0
  84. package/runtime/page/licenses/otp/LicenseRef-scancode-w3c-docs-19990405.txt +26 -0
  85. package/runtime/page/licenses/otp/LicenseRef-scancode-wxwindows-free-doc-3.txt +57 -0
  86. package/runtime/page/licenses/otp/MIT.txt +17 -0
  87. package/runtime/page/licenses/otp/SGI-B-2.0.txt +25 -0
  88. package/runtime/page/licenses/otp/W3C-19980720.txt +55 -0
  89. package/runtime/page/licenses/picosat.txt +19 -0
  90. package/runtime/page/licenses/wamr.txt +219 -0
  91. package/runtime/page/main.js +176 -0
  92. package/runtime/page/runtime-id.js +3 -0
  93. package/runtime/page/scope.js +17 -0
  94. package/runtime/page/sw.js +111 -0
  95. package/runtime/page/vm.js +148 -0
  96. package/runtime/page/worker.js +1891 -0
  97. package/runtime/page/ws-shim.js +143 -0
  98. package/runtime/release/app.js +17 -0
  99. package/runtime/release.json +1 -0
  100. package/runtime/runtime-id.js +3 -0
  101. package/runtime/tcp-proxy.mjs +30 -0
  102. package/runtime/worker.js +1891 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,97 @@
1
+ BEAM.com
2
+ Copyright 2026 Sơn Trần-Nguyễn
3
+
4
+ This product is licensed under the Apache License, Version 2.0 (see
5
+ LICENSE).
6
+
7
+ The file beam.com contains the software below, and each program that
8
+ beam.com makes contains a part of it. The file keeps these notices and the license texts in its
9
+ zip, in the directory licenses/ ("unzip -l beam.com licenses/*" lists
10
+ them). The source of this repository keeps the texts in licenses/.
11
+
12
+ Erlang/OTP 29.1.1 (ERTS and the OTP applications in the zip)
13
+ Copyright Ericsson AB and the contributors of Erlang/OTP.
14
+ Apache License 2.0 (LICENSE). ERTS also contains code of other
15
+ projects (for example zlib, PCRE2, Zstandard, AsmJit and Ryu) under
16
+ the licenses that the headers of the OTP source files name. The zip
17
+ has the license texts of the LICENSES directory of OTP in
18
+ licenses/otp/.
19
+ https://github.com/erlang/otp
20
+
21
+ Elixir 1.20.4 (the elixir, eex, ex_unit, iex, logger and mix
22
+ applications)
23
+ Copyright The Elixir Team.
24
+ Apache License 2.0 (LICENSE), and the license texts of its source in
25
+ licenses/elixir/.
26
+ https://github.com/elixir-lang/elixir
27
+
28
+ Cosmopolitan Libc 4.0.2 (the C runtime of the APE file)
29
+ Copyright 2020 Justine Alexandra Roberts Tunney.
30
+ ISC License (licenses/cosmopolitan.txt). Cosmopolitan also links code
31
+ of other projects (for example musl, FreeBSD and zlib). Its linker puts
32
+ their notices into the file: "strings beam.com | grep -i copyright"
33
+ shows them.
34
+ https://github.com/jart/cosmopolitan
35
+
36
+ OpenSSL 4.0.2 (libcrypto, for the crypto NIF)
37
+ Copyright The OpenSSL Project Authors.
38
+ Apache License 2.0 (LICENSE).
39
+ https://github.com/openssl/openssl
40
+
41
+ SQLite 3.53.4
42
+ Public domain. https://sqlite.org/copyright.html
43
+
44
+ esqlite (the SQLite NIF of Erlang)
45
+ Copyright Maas-Maarten Zeeman.
46
+ Apache License 2.0 (LICENSE).
47
+ https://github.com/mmzeeman/esqlite
48
+
49
+ WebAssembly Micro Runtime (WAMR) 2.4.5 (the interpreter of the wasm
50
+ application)
51
+ Copyright The Bytecode Alliance.
52
+ Apache License 2.0 with LLVM Exceptions (licenses/wamr.txt).
53
+ https://github.com/bytecodealliance/wasm-micro-runtime
54
+
55
+ exqlite 0.41.0 (its NIF, for ecto_sqlite3)
56
+ Copyright 2021 Matthew A. Johnston.
57
+ MIT License (licenses/exqlite.txt).
58
+ https://github.com/elixir-sqlite/exqlite
59
+
60
+ bcrypt_elixir 3.3.2 (its NIF, for phx.gen.auth)
61
+ BSD-3-Clause, ISC and BSD-4-Clause licenses (licenses/bcrypt_elixir.txt).
62
+ This product includes software developed by Niels Provos.
63
+ https://github.com/riverrun/bcrypt_elixir
64
+
65
+ argon2_elixir 4.1.3 (its NIF, for phx.gen.auth --hashing-lib argon2)
66
+ Apache License 2.0 (LICENSE). The Argon2 reference code: Copyright
67
+ 2015 Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson and
68
+ Samuel Neves, under CC0 1.0 or the Apache License 2.0.
69
+ https://github.com/riverrun/argon2_elixir
70
+
71
+ lazy_html 0.1.13, fine 0.1.6 and lexbor (the NIF library in WebAssembly
72
+ of lazy_html in lib/beam_com/priv/nifs; only a program with lazy_html
73
+ 0.1.13 contains it)
74
+ lazy_html and fine: Apache License 2.0 (LICENSE).
75
+ https://github.com/dashbitco/lazy_html https://github.com/elixir-nx/fine
76
+ lexbor: Copyright 2018-2020 Alexander Borisov. Apache License 2.0
77
+ (LICENSE). https://github.com/lexbor/lexbor
78
+
79
+ The WebAssembly runtime (beam.wasm and beam.mjs in the zip, for
80
+ --target wasm32)
81
+ Erlang/OTP 29.1.1 and OpenSSL 4.0.2, as above, compiled with
82
+ Emscripten. The runtime contains the system libraries of Emscripten:
83
+ - Emscripten: MIT License and University of Illinois/NCSA Open Source
84
+ License (licenses/emscripten.txt). https://github.com/emscripten-core/emscripten
85
+ - musl: MIT License (licenses/musl.txt). https://musl.libc.org
86
+ - LLVM libc++, libc++abi and compiler-rt: Apache License 2.0 with LLVM
87
+ Exceptions (licenses/llvm.txt). https://llvm.org
88
+
89
+ Custom builds (build.sh) can also contain:
90
+ - Hex (HEX=1) and rebar3 (REBAR3=1): Apache License 2.0. The rebar3
91
+ escript also contains its dependencies, each with its own license
92
+ (for example certifi: MPL-2.0); see
93
+ https://github.com/erlang/rebar3/tree/main/vendor.
94
+ - picosat_elixir (EXTRA_NIFS): Apache License 2.0, with PicoSAT (MIT
95
+ License, Copyright 2006-2015 Armin Biere, Johannes Kepler University;
96
+ licenses/picosat.txt).
97
+ - More OTP applications (OTP_APPS): as Erlang/OTP above.
package/README.md ADDED
@@ -0,0 +1,369 @@
1
+ # BEAM.com
2
+
3
+ Erlang/OTP 29 and Elixir 1.20 in one executable file. The same file runs
4
+ on Linux, macOS, Windows, FreeBSD, NetBSD and OpenBSD, on x86_64 and
5
+ aarch64.
6
+
7
+ `beam.com` is the Erlang runtime system (ERTS, with the JIT) as one
8
+ [Actually Portable Executable](https://justine.lol/ape.html), made with
9
+ [Cosmopolitan Libc](https://github.com/jart/cosmopolitan). The file is
10
+ also a zip file: the OTP applications, Elixir and your program are in
11
+ it, and they run from there. Nothing is installed, and nothing is
12
+ extracted.
13
+
14
+ With `beam.com` you can:
15
+
16
+ - **Run and build programs** with no Erlang or Elixir on the computer: a
17
+ `.erl` or `.ex` file, or a rebar3 or Mix project with Hex packages.
18
+ `beam.com INPUT -o OUTPUT` makes one executable that runs on all these
19
+ systems.
20
+ - **Use Elixir and its tools** from one file: `mix.com`, `iex.com`,
21
+ `elixir.com`. A Phoenix app with SQLite and `phx.gen.auth` runs from
22
+ its source, with no C compiler.
23
+ - **Deploy to Cloudflare Workers, Deno Deploy or a web page**:
24
+ `beam.com INPUT -o DIR --target wasm32` makes one directory that runs
25
+ the same program on all three, with a second runtime: ERTS compiled to
26
+ WebAssembly.
27
+
28
+ The file has the compiler, `crypto` and `ssl` (with OpenSSL), SQLite, and
29
+ a WebAssembly runtime (WAMR). It is about 50 MB.
30
+
31
+ ## Live demos
32
+
33
+ These run from the WebAssembly runtime of `beam.com`, on the free plans:
34
+
35
+ - <https://phoenix.fifo.workers.dev> (Cloudflare Workers) and
36
+ <https://phoenix.one.deno.net> (Deno Deploy): a Phoenix LiveView
37
+ app with `phx.gen.auth`, Ecto SQLite, PubSub and Presence, from one
38
+ build ([`examples/phoenix_demo`](examples/phoenix_demo)).
39
+ - <https://livebook.fifo.workers.dev> (Cloudflare Workers, an instance
40
+ for each visitor) and <https://livebook.one.deno.net> (Deno Deploy):
41
+ Livebook, with the notebooks of beam.com
42
+ ([`wasm/livebook`](wasm/livebook)).
43
+ - <https://phx.fifo.workers.dev> (Cloudflare Workers, an instance for
44
+ each visitor) and <https://sntran.github.io/BEAM.com/phx/> (in the
45
+ page): `mix phx.new` and a Phoenix app, with nothing to install
46
+ ([`examples/studio`](examples/studio)).
47
+ - <https://beam.one.deno.net> (Deno Deploy): the Erlang shell, with the
48
+ VM on the server and a restricted shell for all the visitors
49
+ ([`examples/worker`](examples/worker)).
50
+
51
+ ## Download
52
+
53
+ ```sh
54
+ curl -fLO https://github.com/sntran/BEAM.com/releases/latest/download/beam.com
55
+ sh ./beam.com --version
56
+ ```
57
+
58
+ On Windows, save the file as `beam.exe`. Each release has `beam.com`
59
+ (with the JIT), `beam-emu.com` (the interpreter: a smaller file that
60
+ starts faster) and `SHA256SUMS`. The prerelease
61
+ [`edge`](https://github.com/sntran/BEAM.com/releases/tag/edge) has the
62
+ `beam.com` of the last merge to `main`.
63
+
64
+ To check where the file comes from, use the
65
+ [GitHub CLI](https://cli.github.com/): CI signs each `beam.com` of a
66
+ release and of `edge`.
67
+
68
+ ```sh
69
+ gh attestation verify beam.com --repo sntran/BEAM.com
70
+ ```
71
+
72
+ On NetBSD and OpenBSD, start the file with the APE loader
73
+ (`ape-x86_64.elf ./beam.com`): see [`docs/PLATFORMS.md`](docs/PLATFORMS.md).
74
+
75
+ ### A custom build
76
+
77
+ Do you need more OTP applications (for example `ssh` or `mnesia`), Hex and
78
+ rebar3 in the file, or a file without Elixir, SQLite or WebAssembly? Open
79
+ an issue with the form
80
+ [A custom build of beam.com](https://github.com/sntran/BEAM.com/issues/new?template=custom_build.yml).
81
+ CI builds and tests the file with your choices, and puts it on the issue.
82
+ You need no toolchain. See "A custom build" in
83
+ [`docs/BUILDING.md`](docs/BUILDING.md).
84
+
85
+ ## Quick start
86
+
87
+ Run a program, and make an executable of it:
88
+
89
+ ```
90
+ $ sh ./beam.com examples/hashsum.erl -- abc
91
+ ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad abc
92
+ $ sh ./beam.com examples/hashsum.erl -o hashsum.com
93
+ beam.com: wrote hashsum.com (25304313 bytes)
94
+ release: hashsum 0.1.0
95
+ applications: beam_com_script kernel stdlib crypto
96
+ edge: 13 files (62171 bytes) for the WebAssembly runtime
97
+ $ sh ./hashsum.com abc
98
+ ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad abc
99
+ ```
100
+
101
+ The same for a project: an application directory, a rebar3 project, or a
102
+ Mix project. `beam.com` alone runs the project of the directory.
103
+
104
+ ```sh
105
+ beam.com examples/hexweb -o hexweb.com # rebar3, with cowboy and jsx from hex.pm
106
+ beam.com examples/greeter_ex -o greeter_ex.com # Mix, with jason
107
+ beam.com hello.ex -- Alice # one Elixir file
108
+ ```
109
+
110
+ Use it as an Elixir installation. A copy or a link of the file with the
111
+ name of a tool is that tool:
112
+
113
+ ```sh
114
+ ln -s beam.com mix.com && ln -s beam.com iex.com
115
+ ./mix.com local.hex --force && ./mix.com archive.install hex phx_new --force
116
+ ./mix.com phx.new hello --database sqlite3
117
+ cd hello && ../mix.com deps.get && ../mix.com ecto.migrate
118
+ ../iex.com -S mix phx.server # http://localhost:4000
119
+ ```
120
+
121
+ Make Cloudflare Workers of a program. The same directory runs on Deno:
122
+
123
+ ```sh
124
+ beam.com examples/worker -o worker --target wasm32
125
+ cd worker
126
+ npx workerd serve worker.capnp # test on this computer (Workers)
127
+ deno serve -A deno.js # or on Deno
128
+ ```
129
+
130
+ One file runs natively and in the WebAssembly runtime. Each executable of
131
+ `-o` also has its edge part, of 40 to 180 KB (`--no-edge` leaves it out).
132
+ A release directory of `mix release` is an input too:
133
+
134
+ ```sh
135
+ beam.com _build/prod/rel/my_app -o my_app.com # a Phoenix app
136
+ PHX_SERVER=true ./my_app.com # natively
137
+ cd worker && BEAM_APP=../my_app.com deno serve -A deno.js # the same file on Deno
138
+ ```
139
+
140
+ The npm package `beam.com` has the runtime for Node.js, and `npx
141
+ beam.com` (see [npm](#npm)).
142
+
143
+ See "One file, natively and at the edge" in [`docs/WORKERS.md`](docs/WORKERS.md).
144
+
145
+ ## Publish on GitHub Pages
146
+
147
+ An Erlang or Elixir app can run in the browser of each visitor, at
148
+ `https://USER.github.io/REPO/`. The code of the app does not change, and
149
+ you need no Erlang, Elixir or Node.js on your computer. Add this file to
150
+ the repository of the app:
151
+
152
+ ```yaml
153
+ # .github/workflows/pages.yml
154
+ name: Pages
155
+ on:
156
+ push:
157
+ branches: [main]
158
+ workflow_dispatch:
159
+ permissions:
160
+ contents: read
161
+ pages: write
162
+ id-token: write
163
+ jobs:
164
+ pages:
165
+ uses: sntran/BEAM.com/.github/workflows/pages-app.yml@v0.1.0
166
+ ```
167
+
168
+ Then turn on Pages one time: Settings, Pages, Source "GitHub Actions". The
169
+ `GITHUB_TOKEN` cannot do this step. Until the first release (`v0.1.0`),
170
+ use `@main` in place of `@v0.1.0`: the workflow then uses the `edge`
171
+ build of `beam.com`.
172
+
173
+ The workflow ([`pages-app.yml`](.github/workflows/pages-app.yml)) builds
174
+ the app with `beam.com --target wasm32`, and publishes the static site
175
+ `DIR/page/`. A Mix project with Phoenix becomes a release first
176
+ (`mix.com release`). Its inputs:
177
+
178
+ | Input | Default | What |
179
+ |---|---|---|
180
+ | `path` | `.` | The directory of the app. |
181
+ | `beam-com` | the tag of the workflow, else `edge` | The version of `beam.com`. |
182
+ | `deploy` | `true` | `false`: build the site, and do not publish it. |
183
+
184
+ The workflow that calls it must give `pages: write` and `id-token: write`,
185
+ also with `deploy: false`: else GitHub refuses the run when it starts.
186
+ When the workflow uses `edge` (a pin to a branch, such as `@main`), the
187
+ run shows a warning. A pin to a commit SHA uses the release of that
188
+ commit, and stops with an error when the commit has no release tag.
189
+ Before the build, the workflow checks the SHA-256 of `beam.com` and its
190
+ provenance (`gh attestation verify`). The check stops the build when
191
+ `build.yml` of BEAM.com did not make the file, or when the check cannot
192
+ reach GitHub or Sigstore. It needs no other
193
+ permission.
194
+
195
+ The app needs an HTTP listener on `PORT` (4000 by default), and only the
196
+ NIFs of the WebAssembly runtime. The limits:
197
+
198
+ - Each browser has its own copy of the app. Two visitors do not share
199
+ data.
200
+ - The data stays in the memory of the VM. 30 s after the last tab of the
201
+ site closes, the data goes, and the next visit starts from the snapshot
202
+ of the boot.
203
+ - No outgoing TCP: a connection of Erlang gets `econnrefused`.
204
+ - The first visit downloads `beam.wasm` (about 6.5 MB) and `release.bin`
205
+ (3.5 to 14 MB for a Phoenix app).
206
+ - The browser needs JSPI: Chrome and Edge 137 or later, or Firefox 153
207
+ or later.
208
+
209
+ Caution: all the project sites of one GitHub account share one origin
210
+ (`USER.github.io`), also the user site. A page of another site of the
211
+ same account can read the data of the app in the browser: its secret,
212
+ the snapshot of its VM, and its frame. Give an app with private data its
213
+ own custom domain (Settings, Pages, Custom domain).
214
+
215
+ See "A static site for any app" in [`docs/WORKERS.md`](docs/WORKERS.md).
216
+
217
+ ## npm
218
+
219
+ This repository is also the npm package `beam.com`, of the same version
220
+ as `beam.com`:
221
+
222
+ ```sh
223
+ npx beam.com app.erl -o app.com
224
+ npx beam.com mix phx.server
225
+ ```
226
+
227
+ The package does not hold `beam.com` (about 50 MB). At the first run,
228
+ `npx beam.com` downloads `beam.com` of the same version from the GitHub
229
+ release, and checks its SHA-256 against the value that the package
230
+ holds. Then the file stays in the cache (`~/.cache/beam.com/npm/`). A
231
+ host that only uses the runtime never downloads it.
232
+
233
+ - `BEAM_COM`: the path of a `beam.com` to use. Then nothing is
234
+ downloaded.
235
+ - `BEAM_COM_DOWNLOAD`: the URL of a directory with the file `beam.com`,
236
+ in place of the GitHub release.
237
+ - `BEAM_COM_CACHE`: the cache directory.
238
+
239
+ The package also has the WebAssembly runtime, for a native `app.com`.
240
+ In Node.js 25 or later (for JSPI):
241
+
242
+ ```js
243
+ import { boot } from 'beam.com';
244
+
245
+ const vm = await boot('app.com', { env: { PORT: '4000' } });
246
+ const response = await vm.fetch(new Request('http://localhost/'));
247
+ ```
248
+
249
+ The file must come from `beam.com` of the version of the package: a file
250
+ for another runtime is an error. `release(app)` gives the release of the
251
+ file, without a VM.
252
+
253
+ `import ... from 'beam.com'` gives the module of the runtime that
254
+ imports it (the conditions of `exports` in `package.json`):
255
+
256
+ | Runtime (condition) | What |
257
+ |---|---|
258
+ | Cloudflare Workers, with Wrangler (`workerd`) | `serve(app)`, the engine that serves the `app.com` of the project, and the Durable Object `Beam`. |
259
+ | Deno (`deno`) | `serve(app)`, with the same API: the same entry runs on both hosts. |
260
+ | Node.js (`node`) | `boot`, `release`, `appRelease` and `runtimeId`. |
261
+
262
+ The other modules of the package:
263
+
264
+ | Import | What |
265
+ |---|---|
266
+ | `beam.com/app-com` | The reader of an `app.com`, for any host: `appRelease(read, size, { runtime })`. |
267
+ | `beam.com/runtime-id` | The identity of this runtime, for `appRelease`. |
268
+ | `beam.com/worker` | The runtime (`worker.js` of Cloudflare Workers). |
269
+ | `beam.com/beam.wasm` | The VM: ERTS built for WebAssembly. |
270
+
271
+ The same `app.com` runs on Cloudflare Workers, on Deno Deploy and in a
272
+ web page, with the runtime of the package. One entry runs on both hosts:
273
+
274
+ ```js
275
+ import app from './app.com' with { type: 'bytes' };
276
+ import { serve } from 'beam.com';
277
+ export { Beam } from 'beam.com'; // stateful only
278
+
279
+ const beam = serve(app);
280
+
281
+ export default {
282
+ fetch(request, env, ctx) {
283
+ return beam.fetch(request, env, ctx);
284
+ },
285
+ };
286
+ ```
287
+
288
+ With the Durable Object `Beam` and its binding, the app is stateful: one
289
+ VM serves all the requests, its timers run between requests, and its
290
+ SQLite storage keeps the database. With no binding, it is stateless:
291
+ each isolate runs its own VM. A project deploys at each git push: the
292
+ build step of the host makes `app.com` (`npx beam.com`), and the host
293
+ runs it. A Phoenix app needs no secret and no variable: the VM
294
+ makes `SECRET_KEY_BASE` one time and keeps it, and `PHX_HOST` is the
295
+ host of the first request. [`examples/phoenix_demo`](examples/phoenix_demo)
296
+ (stateful) and [`examples/worker`](examples/worker) (stateless) are such
297
+ projects, with one-click buttons for both hosts. See "Deploy at
298
+ each git push" in [`docs/WORKERS.md`](docs/WORKERS.md).
299
+
300
+ The release job of CI makes the generated part of the package
301
+ (`runtime/`, with `scripts/npm.sh`) and publishes it with each tag `v*`.
302
+
303
+ ## Documentation
304
+
305
+ The site <https://sntran.github.io/BEAM.com/> is Livebook in your
306
+ browser, with these pages as notebooks that run (see
307
+ [`docs/NOTEBOOKS.md`](docs/NOTEBOOKS.md)). The same pages are at
308
+ [`docs/`](https://sntran.github.io/BEAM.com/docs/) as static pages, and
309
+ the Erlang shell in your browser is at
310
+ [`repl/`](https://sntran.github.io/BEAM.com/repl/).
311
+
312
+ | File | What |
313
+ |---|---|
314
+ | [`docs/PROGRAMS.md`](docs/PROGRAMS.md) | Run and build programs: the inputs, Hex packages, command line programs, native files (`--target`), distributed Erlang, a release in the zip, debugging. |
315
+ | [`docs/ELIXIR.md`](docs/ELIXIR.md) | Elixir programs, the tools (`mix`, `iex`, `elixir`), Phoenix from source, the file watcher. |
316
+ | [`docs/WORKERS.md`](docs/WORKERS.md) | Cloudflare Workers, Deno Deploy and web pages (`--target wasm32`): Durable Objects, Ecto SQLite, snapshots, tenants, limits. |
317
+ | [`docs/NOTEBOOKS.md`](docs/NOTEBOOKS.md) | The documentation as notebooks that run in your browser: a tour of beam.com, the WebAssembly VM, the anatomy of the file, WebAssembly programs, hosts and storage, networking, and building programs. |
318
+ | [`docs/LIBRARIES.md`](docs/LIBRARIES.md) | Crypto and TLS, SQLite, and WebAssembly in Erlang code. |
319
+ | [`docs/SANDBOX.md`](docs/SANDBOX.md) | `--allow-read`, `--allow-write`, `--allow-net`, `--allow-run`: a program that gives up what it does not need. |
320
+ | [`docs/PLATFORMS.md`](docs/PLATFORMS.md) | The status of each system, and the known limits. |
321
+ | [`docs/INTERNALS.md`](docs/INTERNALS.md) | How one file runs everywhere, and the changes to OTP. |
322
+ | [`docs/JIT.md`](docs/JIT.md), [`docs/BENCHMARKS.md`](docs/BENCHMARKS.md) | The JIT in one file for two CPUs, and what each part costs. |
323
+ | [`docs/BUILDING.md`](docs/BUILDING.md), [`docs/TESTING.md`](docs/TESTING.md) | Build BEAM.com, a custom build, CI and the tests. |
324
+ | [`docs/UPSTREAM.md`](docs/UPSTREAM.md) | The problems found in Cosmopolitan, OTP, Emscripten and other projects, with reproducers and fixes. |
325
+ | [`docs/ROADMAP.md`](docs/ROADMAP.md) | What comes next. |
326
+
327
+ ## Examples
328
+
329
+ | Example | What it shows |
330
+ |---|---|
331
+ | [`examples/hashsum.erl`](examples/hashsum.erl) | A program in one `.erl` file. |
332
+ | [`examples/greeter`](examples/greeter) | An application with a supervisor, as a rebar3 release in the zip of `beam.com`. |
333
+ | [`examples/hexweb`](examples/hexweb) | A web server with Hex packages (cowboy, jsx). |
334
+ | [`examples/greeter_ex`](examples/greeter_ex) | A Mix project with a Hex package in Elixir. |
335
+ | [`examples/toolbox`](examples/toolbox) | A command line program: its entry, `priv` files, and a second VM from its own file. |
336
+ | [`examples/counter`](examples/counter) | Distributed Erlang: a remote shell into a running program. |
337
+ | [`examples/worker`](examples/worker) | The Erlang shell (`shell` of stdlib) on the web, with Cowboy: natively, on Workers, on Deno, and in a web page ([`pages.sh`](examples/worker/pages.sh)). |
338
+ | [`examples/notes`](examples/notes) | Ecto SQLite on a computer, and on Workers with D1 or a Durable Object. |
339
+ | [`examples/phoenix_demo`](examples/phoenix_demo) | Phoenix LiveView with `phx.gen.auth` in a Durable Object. |
340
+
341
+ ## Platforms
342
+
343
+ | System | Status |
344
+ |---|---|
345
+ | Linux x86_64 and aarch64, WSL2 | ✅ |
346
+ | macOS arm64 and x86_64 | ✅ |
347
+ | Windows x86_64 | ✅ (no port programs) |
348
+ | FreeBSD, NetBSD, OpenBSD 7.3 | ✅ |
349
+ | OpenBSD 7.4 and later | ❌ (not supported by Cosmopolitan) |
350
+
351
+ CI runs the tests on each system. See
352
+ [`docs/PLATFORMS.md`](docs/PLATFORMS.md) for the details and the known
353
+ limits. The main limits: a native NIF works only when it is linked into
354
+ `beam.com` (another NIF can be a `.wasm` file: see
355
+ [`docs/NIFS.md`](docs/NIFS.md)), and Hex packages are the only
356
+ dependencies of a build (no git dependencies).
357
+
358
+ ## Contributing
359
+
360
+ See [`CONTRIBUTING.md`](CONTRIBUTING.md). Report a security problem in
361
+ private: see [`SECURITY.md`](SECURITY.md).
362
+
363
+ ## License
364
+
365
+ BEAM.com is licensed under the [Apache License 2.0](LICENSE). The file
366
+ `beam.com` contains Erlang/OTP, Elixir, Cosmopolitan Libc, OpenSSL,
367
+ SQLite, WAMR and other software, under their own licenses:
368
+ [`NOTICE`](NOTICE) names them, and the license texts are in
369
+ [`licenses/`](licenses) and in the zip of each file.