Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions .github/workflows/wasm-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,14 @@ jobs:
run: |
set -euxo pipefail
# Test compressed beams
node src/AtomVM.js ../../../../build/examples/erlang/hello_world.beam ../../../../build/libs/eavmlib/src/eavmlib.avm
node src/AtomVM.mjs ../../../../build/examples/erlang/hello_world.beam ../../../../build/libs/eavmlib/src/eavmlib.avm
# Run tests that pass
node src/AtomVM.js ../../../../build/tests/libs/alisp/test_alisp.avm
node src/AtomVM.js ../../../../build/tests/libs/estdlib/test_estdlib.avm
node src/AtomVM.mjs ../../../../build/tests/libs/alisp/test_alisp.avm
node src/AtomVM.mjs ../../../../build/tests/libs/estdlib/test_estdlib.avm
# test_eavmlib does not work with wasm due to http + ssl test
# node src/AtomVM.js ../../../../build/tests/libs/eavmlib/test_eavmlib.avm
node src/AtomVM.js ../../../../build/tests/libs/etest/test_etest.avm
node src/AtomVM.js ../../../../build/tests/erlang_tests/test_crypto.beam
# node src/AtomVM.mjs ../../../../build/tests/libs/eavmlib/test_eavmlib.avm
node src/AtomVM.mjs ../../../../build/tests/libs/etest/test_etest.avm
node src/AtomVM.mjs ../../../../build/tests/erlang_tests/test_crypto.beam

- name: Test (JIT)
if: matrix.jit != ''
Expand All @@ -203,19 +203,19 @@ jobs:
run: |
set -euxo pipefail
# Test hello_world with JIT compiler (runtime JIT compilation)
node src/AtomVM.js ../../../../build/examples/erlang/hello_world.beam ../../../../build/libs/atomvmlib-emscripten-wasm32.avm
node src/AtomVM.mjs ../../../../build/examples/erlang/hello_world.beam ../../../../build/libs/atomvmlib-emscripten-wasm32.avm
# Library tests with JIT compiler (jit-wasm32.avm included in test avms via pack_test)
node src/AtomVM.js ../../../../build/tests/libs/alisp/test_alisp.avm
node src/AtomVM.js ../../../../build/tests/libs/estdlib/test_estdlib.avm
node src/AtomVM.js ../../../../build/tests/libs/etest/test_etest.avm
node src/AtomVM.mjs ../../../../build/tests/libs/alisp/test_alisp.avm
node src/AtomVM.mjs ../../../../build/tests/libs/estdlib/test_estdlib.avm
node src/AtomVM.mjs ../../../../build/tests/libs/etest/test_etest.avm

- name: "Rename and write sha256sum (node)"
if: startsWith(github.ref, 'refs/tags/') && matrix.jit == ''
shell: bash
working-directory: src/platforms/emscripten/build/src
run: |
ATOMVM_JS=AtomVM-node-${{ github.ref_name }}.js
mv AtomVM.js "${ATOMVM_JS}"
ATOMVM_JS=AtomVM-node-${{ github.ref_name }}.mjs
mv AtomVM.mjs "${ATOMVM_JS}"
sha256sum "${ATOMVM_JS}" > "${ATOMVM_JS}.sha256"
ATOMVM_WASM=AtomVM-node-${{ github.ref_name }}.wasm
mv AtomVM.wasm "${ATOMVM_WASM}"
Expand All @@ -228,8 +228,8 @@ jobs:
draft: true
fail_on_unmatched_files: true
files: |
src/platforms/emscripten/build/src/AtomVM-node-${{ github.ref_name }}.js
src/platforms/emscripten/build/src/AtomVM-node-${{ github.ref_name }}.js.sha256
src/platforms/emscripten/build/src/AtomVM-node-${{ github.ref_name }}.mjs
src/platforms/emscripten/build/src/AtomVM-node-${{ github.ref_name }}.mjs.sha256
src/platforms/emscripten/build/src/AtomVM-node-${{ github.ref_name }}.wasm
src/platforms/emscripten/build/src/AtomVM-node-${{ github.ref_name }}.wasm.sha256

Expand Down Expand Up @@ -283,7 +283,7 @@ jobs:
name: atomvm-js-web
path: |
src/platforms/emscripten/build/**/*.wasm
src/platforms/emscripten/build/**/*.js
src/platforms/emscripten/build/**/*.mjs
retention-days: 1

wasm_test_web:
Expand Down Expand Up @@ -341,8 +341,8 @@ jobs:
shell: bash
working-directory: src/platforms/emscripten/build/src
run: |
ATOMVM_JS=AtomVM-web-${{ github.ref_name }}.js
mv AtomVM.js "${ATOMVM_JS}"
ATOMVM_JS=AtomVM-web-${{ github.ref_name }}.mjs
mv AtomVM.mjs "${ATOMVM_JS}"
sha256sum "${ATOMVM_JS}" > "${ATOMVM_JS}.sha256"
ATOMVM_WASM=AtomVM-web-${{ github.ref_name }}.wasm
mv AtomVM.wasm "${ATOMVM_WASM}"
Expand All @@ -355,7 +355,7 @@ jobs:
draft: true
fail_on_unmatched_files: true
files: |
src/platforms/emscripten/build/src/AtomVM-web-${{ github.ref_name }}.js
src/platforms/emscripten/build/src/AtomVM-web-${{ github.ref_name }}.js.sha256
src/platforms/emscripten/build/src/AtomVM-web-${{ github.ref_name }}.mjs
src/platforms/emscripten/build/src/AtomVM-web-${{ github.ref_name }}.mjs.sha256
src/platforms/emscripten/build/src/AtomVM-web-${{ github.ref_name }}.wasm
src/platforms/emscripten/build/src/AtomVM-web-${{ github.ref_name }}.wasm.sha256
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed
- Updated network type db() to dbm() to reflect the actual representation of the type
- Use ES6 modules for emscripten port, using .mjs suffix

### Fixed
- Stop using deprecated `term_from_int32` on STM32 platform
Expand Down
7 changes: 7 additions & 0 deletions UPDATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ standard Erlang/OTP API, that takes maps instead of proplists.
The `main.avm` offset is now `0x250000` for all images (previously `0x210000` for Erlang-only).
Update flashing offsets in your tooling, build scripts, and `mix.exs` or `rebar.config` if you
were using the `0x210000` offset.
- The emscripten port now uses ES6 modules (`.mjs` suffix). This is a breaking change for
existing web integrations:
* Replace `<script async src="AtomVM.js"></script>` with a module script
* Use `<script type="module">` and `import AtomVM from "AtomVM.mjs"`
* Instantiate with `const module = await AtomVM({ arguments: [...] })`
* The old implicit global-script pattern is no longer supported
* `AtomVM.worker.js` is no longer emitted; only `AtomVM.mjs` and `AtomVM.wasm` are needed

## v0.6.4 -> v0.6.5

Expand Down
6 changes: 3 additions & 3 deletions doc/src/build-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ $ emmake make -j
AtomVM can then be invoked as on Generic Unix with node:

```shell
$ node ./src/AtomVM.js
$ node ./src/AtomVM.mjs
```

### Running tests with NodeJS
Expand All @@ -1150,8 +1150,8 @@ Then execute the tests with:

```shell
$ cd src/platforms/emscripten/build/
$ node ./src/AtomVM.js ../../../../build/tests/libs/eavmlib/test_eavmlib.avm
$ node ./src/AtomVM.js ../../../../build/tests/libs/alisp/test_alisp.avm
$ node ./src/AtomVM.mjs ../../../../build/tests/libs/eavmlib/test_eavmlib.avm
$ node ./src/AtomVM.mjs ../../../../build/tests/libs/alisp/test_alisp.avm
```

### Building for the web
Expand Down
10 changes: 5 additions & 5 deletions doc/src/getting-started-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -559,23 +559,23 @@ Download the latest [release image](https://github.com/atomvm/AtomVM/releases) f

This image will generally take the form:

>`Atomvm-node-<atomvm-version>.js`
>`Atomvm-node-<atomvm-version>.mjs`

For example:

>`Atomvm-node-v0.6.0.js`
>`Atomvm-node-v0.6.0.mjs`

You will also find the sha256 hash for this file, which you should verify using the `sha256sum` command on your local operating system.

AtomVM's WebAssembly port for NodeJS may be run using `node` command and AtomVM.js, AtomVM.worker.js and AtomVM.wasm files.
AtomVM's WebAssembly port for NodeJS may be run using `node` command and AtomVM.mjs and AtomVM.wasm files.

```shell
$ node /path/to/Atomvm-node-v0.6.0.js /path/to/myapp.avm
$ node /path/to/Atomvm-node-v0.6.0.mjs /path/to/myapp.avm
```

### Getting Started with AtomVM WebAssembly port for browsers

AtomVM may also be run in modern browsers (Safari, Chrome and Chrome-based, Firefox) using AtomVM.js, AtomVM.worker.js and AtomVM.wasm files.
AtomVM may also be run in modern browsers (Safari, Chrome and Chrome-based, Firefox) using AtomVM.mjs and AtomVM.wasm files.

Please note that these files are different from the NodeJS ones.

Expand Down
9 changes: 5 additions & 4 deletions examples/emscripten/call_cast.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ <h1>Call &amp; cast example</h1>
<p>Call button was clicked <span id="call-counter">0</span> time(s).</p>
<p>Cast button was clicked <span id="cast-counter">0</span> time(s).</p>

<script>
<script type="module">
import AtomVM from "/AtomVM.mjs";

// Arguments are loaded using fetch API.
// wasm_webserver serves under /build/ files in build subdirectory.
var Module = {
window.Module = await AtomVM({
arguments: ["/build/examples/emscripten/call_cast.avm"],
};
});
</script>
<script async src="/AtomVM.js"></script>
</body>
</html>
9 changes: 5 additions & 4 deletions examples/emscripten/echo_websocket.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ <h1>Echo websocket example</h1>
<input type="text" name="text" id="send-text" disabled></input>
<button id="send-button" disabled>Send</button>

<script>
<script type="module">
import AtomVM from "/AtomVM.mjs";

// Arguments are loaded using fetch API.
// wasm_webserver serves under /build/ files in build subdirectory.
var Module = {
window.Module = await AtomVM({
arguments: ["/build/examples/emscripten/echo_websocket.avm"],
};
});
</script>
<script async src="/AtomVM.js"></script>
</body>
</html>
9 changes: 5 additions & 4 deletions examples/emscripten/hello_world_avm.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
<body>
<h1>Hello world (AVM version)</h1>
<p>Please check the console for hello_world output.</p>
<script>
<script type="module">
import AtomVM from "/AtomVM.mjs";

// Arguments are loaded using fetch API.
// wasm_webserver serves under /build/ files in build subdirectory.
var Module = {
window.Module = await AtomVM({
arguments: ["/build/examples/erlang/hello_world.avm"],
};
});
</script>
<script async src="/AtomVM.js"></script>
</body>
</html>
9 changes: 5 additions & 4 deletions examples/emscripten/hello_world_beam.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@ <h1>Hello world (Beam version)</h1>
in arguments, typically loading AtomVM library as a packed avm file.
</p>
<p>Please check the console for hello_world output.</p>
<script>
<script type="module">
import AtomVM from "/AtomVM.mjs";

// Arguments are loaded using fetch API.
// wasm_webserver serves under /build/ files in build subdirectory.
var Module = {
window.Module = await AtomVM({
arguments: [
"/build/examples/erlang/hello_world.beam",
"/build/libs/atomvmlib.avm",
],
};
});
</script>
<script async src="/AtomVM.js"></script>
</body>
</html>
9 changes: 5 additions & 4 deletions examples/emscripten/html5_events.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,14 @@ <h2>Event log</h2>
<tbody id="events"></tbody>
</table>

<script>
<script type="module">
import AtomVM from "/AtomVM.mjs";

// Arguments are loaded using fetch API.
// wasm_webserver serves under /build/ files in build subdirectory.
var Module = {
window.Module = await AtomVM({
arguments: ["/build/examples/emscripten/html5_events.avm"],
};
});
</script>
<script async src="/AtomVM.js"></script>
</body>
</html>
9 changes: 5 additions & 4 deletions examples/emscripten/run_script.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ <h1>Run script example</h1>
the main thread) using JS function.
</p>

<script>
<script type="module">
import AtomVM from "/AtomVM.mjs";

// Arguments are loaded using fetch API.
// wasm_webserver serves under /build/ files in build subdirectory.
var Module = {
window.Module = await AtomVM({
arguments: ["/build/examples/emscripten/run_script.avm"],
};
});
</script>
<script async src="/AtomVM.js"></script>
</body>
</html>
7 changes: 3 additions & 4 deletions examples/emscripten/wasm_webserver.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ handle_req(Method, Path, Conn) when Method =:= "GET" orelse Method =:= "HEAD" ->
case Path of
[] ->
"../examples/emscripten/index.html";
["AtomVM.js"] ->
"../src/platforms/emscripten/build/src/AtomVM.js";
["AtomVM.mjs"] ->
"../src/platforms/emscripten/build/src/AtomVM.mjs";
["AtomVM.wasm"] ->
"../src/platforms/emscripten/build/src/AtomVM.wasm";
["AtomVM.worker.js"] ->
"../src/platforms/emscripten/build/src/AtomVM.worker.js";
["tests", "build" | Tail] ->
lists:flatten([
"../src/platforms/emscripten/build/tests/src/" | lists:join($/, Tail)
Expand All @@ -60,6 +58,7 @@ handle_req(Method, Path, Conn) when Method =:= "GET" orelse Method =:= "HEAD" ->
MimeType =
case lists:reverse(Filename) of
"sj." ++ _ -> "text/javascript";
"sjm." ++ _ -> "text/javascript";
"lmth." ++ _ -> "text/html";
"msaw." ++ _ -> "application/wasm";
"mva." ++ _ -> "application/binary";
Expand Down
10 changes: 7 additions & 3 deletions src/platforms/emscripten/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
cmake_minimum_required (VERSION 3.13)

add_executable(AtomVM main.c)
set_target_properties(AtomVM PROPERTIES SUFFIX ".mjs")

target_compile_features(AtomVM PUBLIC c_std_11)

Expand All @@ -30,11 +31,14 @@ target_compile_options(libAtomVM PUBLIC -O3 -fno-exceptions -fno-rtti -pthread -
target_compile_definitions(libAtomVM PRIVATE WITH_ZLIB)
if (NOT AVM_DISABLE_JIT)
# JIT requires addFunction to register dynamically compiled WASM functions
set(JIT_LINK_FLAGS -sALLOW_TABLE_GROWTH -sEXPORTED_RUNTIME_METHODS=ccall,addFunction)
set(JIT_LINK_FLAGS
-sALLOW_TABLE_GROWTH
"-sEXPORTED_RUNTIME_METHODS=['ccall','addFunction','ENV']"
)
else()
set(JIT_LINK_FLAGS -sEXPORTED_RUNTIME_METHODS=ccall)
set(JIT_LINK_FLAGS "-sEXPORTED_RUNTIME_METHODS=['ccall','ENV']")
endif()
target_link_options(AtomVM PRIVATE ${JIT_LINK_FLAGS} -sUSE_ZLIB=1 -O3 -pthread -sFETCH -lwebsocket.js --pre-js ${CMAKE_CURRENT_SOURCE_DIR}/atomvm.pre.js -sINITIAL_MEMORY=67108864 -sALLOW_MEMORY_GROWTH)
target_link_options(AtomVM PRIVATE ${JIT_LINK_FLAGS} -sEXPORT_ES6 -sUSE_ZLIB=1 -O3 -pthread -sFETCH -lwebsocket.js --pre-js ${CMAKE_CURRENT_SOURCE_DIR}/atomvm.pre.js --extern-post-js ${CMAKE_CURRENT_SOURCE_DIR}/atomvm.extern-post.js -sINITIAL_MEMORY=67108864 -sALLOW_MEMORY_GROWTH)

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
target_link_options(AtomVM PRIVATE -sASSERTIONS=2 -sSAFE_HEAP -sSTACK_OVERFLOW_CHECK)
Expand Down
27 changes: 27 additions & 0 deletions src/platforms/emscripten/src/atomvm.extern-post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* This file is part of AtomVM.
*
* Copyright 2026 Paul Guyot <pguyot@kallisys.net>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
*/
if (typeof process === "object" && process.versions?.node && process.argv[1]) {
const { pathToFileURL } = await import("url");
const { realpathSync } = await import("fs");

if (import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {
await Module();
}
}
9 changes: 5 additions & 4 deletions src/platforms/emscripten/tests/src/test_atomvm.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,20 @@
<div id="random"></div>
<div id="pi"></div>
<div id="pierror"></div>
<script>
<script type="module">
import AtomVM from "/AtomVM.mjs";

// Arguments are loaded using fetch API.
// wasm_webserver serves under /tests/build/ files in src/platform/escripten/build/tests/src subdirectory
// and under /build/ files in build/ subdirectory.
var Module = {
window.Module = await AtomVM({
arguments: [
"/tests/build/test_atomvm.beam",
"/build/libs/estdlib/src/estdlib.avm",
"/build/libs/eavmlib/src/eavmlib.avm",
"/build/libs/avm_emscripten/src/avm_emscripten.avm",
],
};
});
</script>
<script async src="/AtomVM.js"></script>
</body>
</html>
9 changes: 5 additions & 4 deletions src/platforms/emscripten/tests/src/test_call.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
<button id="call-button" disabled>Call</button>
<div id="result"></div>
<div id="error"></div>
<script>
<script type="module">
import AtomVM from "/AtomVM.mjs";

// Arguments are loaded using fetch API.
// wasm_webserver serves under /tests/build/ files in src/platform/escripten/build/tests/src subdirectory
// and under /build/ files in build/ subdirectory.
var Module = {
window.Module = await AtomVM({
arguments: ['/tests/build/test_call.beam', '/build/libs/eavmlib/src/eavmlib.avm', '/build/libs/avm_emscripten/src/avm_emscripten.avm']
}
});
</script>
<script async src="/AtomVM.js"></script>
</body>
</html>
Loading
Loading