Skip to content

Commit 5fcd6fa

Browse files
committed
Add gleam example and minimal gleam library
Signed-off-by: Paul Guyot <pguyot@kallisys.net>
1 parent 2c82f47 commit 5fcd6fa

19 files changed

+449
-10
lines changed

.github/workflows/build-and-test-macos.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ jobs:
4949

5050
- name: "Install deps"
5151
if: matrix.otp != '24'
52-
run: HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 brew install gperf doxygen erlang@${{ matrix.otp }} ninja mbedtls rebar3
52+
run: HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 brew install gperf doxygen erlang@${{ matrix.otp }} gleam ninja mbedtls rebar3
5353

5454
- name: "Install deps"
5555
if: matrix.otp == '24'
5656
run: |
57-
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 brew install gperf doxygen erlang@${{ matrix.otp }} ninja mbedtls
57+
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 brew install gperf doxygen erlang@${{ matrix.otp }} gleam ninja mbedtls
5858
wget https://github.com/erlang/rebar3/releases/download/3.23.0/rebar3
5959
chmod +x rebar3
6060
if [ -e /usr/local/opt/erlang@24/bin/ ] ; then

.github/workflows/build-and-test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
cc: ["gcc-9", "gcc-11", "gcc-13", "clang-10", "clang-14", "clang-18"]
5252
cflags: ["-O3"]
5353
otp: ["25", "26", "27"]
54+
gleam_version: ["1.8.0"]
5455

5556
include:
5657
- cc: "gcc-7"
@@ -301,6 +302,7 @@ jobs:
301302
otp-version: ${{ matrix.otp }}
302303
elixir-version: ${{ matrix.elixir_version }}
303304
rebar3-version: ${{ matrix.rebar3_version }}
305+
gleam-version: ${{ matrix.gleam_version }}
304306
hexpm-mirrors: |
305307
https://builds.hex.pm
306308
https://repo.hex.pm

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
*.o
99
build/**
1010
xcode/**
11+
examples/**/build
12+
libs/**/build
1113
src/platforms/esp32/build/**
1214
src/platforms/esp32/build/**/*.d
1315
src/platforms/esp32/test/build/**

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules)
2525

2626
find_package(Dialyzer)
2727
find_package(Elixir)
28+
find_package(Gleam)
2829

2930
option(AVM_DISABLE_FP "Disable floating point support." OFF)
3031
option(AVM_DISABLE_SMP "Disable SMP." OFF)

CMakeModules/BuildErlang.cmake

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ endmacro()
6161
macro(pack_lib avm_name)
6262

6363
foreach(archive_name ${ARGN})
64-
if(NOT ${archive_name} STREQUAL "exavmlib")
65-
set(pack_lib_${avm_name}_archives ${pack_lib_${avm_name}_archives} ${CMAKE_BINARY_DIR}/libs/${archive_name}/src/${archive_name}.avm)
66-
else()
64+
if(${archive_name} STREQUAL "exavmlib")
6765
set(pack_lib_${avm_name}_archives ${pack_lib_${avm_name}_archives} ${CMAKE_BINARY_DIR}/libs/${archive_name}/lib/${archive_name}.avm)
66+
elseif(${archive_name} STREQUAL "gleam_avm")
67+
set(pack_lib_${avm_name}_archives ${pack_lib_${avm_name}_archives} ${CMAKE_BINARY_DIR}/libs/${archive_name}/${archive_name}.avm)
68+
else()
69+
set(pack_lib_${avm_name}_archives ${pack_lib_${avm_name}_archives} ${CMAKE_BINARY_DIR}/libs/${archive_name}/src/${archive_name}.avm)
6870
endif()
6971
set(pack_lib_${avm_name}_archive_targets ${pack_lib_${avm_name}_archive_targets} ${archive_name})
7072
endforeach()

CMakeModules/BuildGleam.cmake

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#
2+
# This file is part of AtomVM.
3+
#
4+
# Copyright 2025 Paul Guyot <pguyot@kallisys.net>
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
# SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
19+
#
20+
21+
macro(pack_gleam_archive avm_name)
22+
find_package(Gleam REQUIRED)
23+
24+
foreach(module_name ${ARGN})
25+
string(REPLACE "/" "@" beam_name ${module_name})
26+
list(APPEND SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/${module_name}.gleam)
27+
list(APPEND BEAMS ${CMAKE_CURRENT_BINARY_DIR}/build/prod/erlang/gleam_avm/ebin/${beam_name}.beam)
28+
endforeach()
29+
30+
if(AVM_RELEASE)
31+
set(INCLUDE_LINES "")
32+
else()
33+
set(INCLUDE_LINES "-i")
34+
endif()
35+
36+
add_custom_command(
37+
OUTPUT ${avm_name}.avm
38+
DEPENDS ${SOURCES} PackBEAM
39+
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/gleam.toml ${CMAKE_CURRENT_SOURCE_DIR}/manifest.toml ${CMAKE_CURRENT_BINARY_DIR}/
40+
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/src
41+
COMMAND gleam export erlang-shipment
42+
COMMAND ${CMAKE_BINARY_DIR}/tools/packbeam/PackBEAM -a ${INCLUDE_LINES} ${avm_name}.avm ${BEAMS}
43+
COMMENT "Packing gleam archive ${avm_name}.avm"
44+
VERBATIM
45+
)
46+
add_custom_target(${avm_name} ALL DEPENDS ${avm_name}.avm)
47+
48+
endmacro()
49+
50+
macro(pack_gleam_runnable avm_name main)
51+
find_package(Gleam REQUIRED)
52+
53+
list(APPEND SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/${main}.gleam)
54+
list(APPEND BEAMS ${CMAKE_CURRENT_BINARY_DIR}/build/prod/erlang/${main}/ebin/${main}.beam)
55+
56+
if(AVM_RELEASE)
57+
set(INCLUDE_LINES "")
58+
else()
59+
set(INCLUDE_LINES "-i")
60+
endif()
61+
62+
foreach(archive_name ${ARGN})
63+
if(${archive_name} STREQUAL "gleam_avm")
64+
set(ARCHIVES ${ARCHIVES} ${CMAKE_BINARY_DIR}/libs/${archive_name}/${archive_name}.avm)
65+
else()
66+
set(ARCHIVES ${ARCHIVES} ${CMAKE_BINARY_DIR}/libs/${archive_name}/src/${archive_name}.avm)
67+
endif()
68+
set(ARCHIVE_TARGETS ${ARCHIVE_TARGETS} ${archive_name})
69+
endforeach()
70+
71+
add_custom_command(
72+
OUTPUT ${avm_name}.avm
73+
DEPENDS ${SOURCES} PackBEAM
74+
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/gleam.toml ${CMAKE_CURRENT_SOURCE_DIR}/manifest.toml ${CMAKE_CURRENT_BINARY_DIR}/
75+
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/src
76+
COMMAND gleam export erlang-shipment
77+
COMMAND ${CMAKE_BINARY_DIR}/tools/packbeam/PackBEAM ${INCLUDE_LINES} ${avm_name}.avm ${BEAMS} build/prod/erlang/gleam_stdlib/ebin/*.beam ${ARCHIVES}
78+
COMMENT "Packing gleam runnable ${avm_name}.avm"
79+
)
80+
81+
add_custom_target(${avm_name} ALL DEPENDS ${avm_name}.avm ${ARCHIVE_TARGETS})
82+
83+
endmacro()

CMakeModules/FindGleam.cmake

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# This file is part of AtomVM.
3+
#
4+
# Copyright 2025 Paul Guyot <pguyot@kallisys.net>
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
# SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
19+
#
20+
21+
find_program(GLEAM_EXECUTABLE gleam)
22+
23+
include(FindPackageHandleStandardArgs)
24+
25+
find_package_handle_standard_args(Gleam
26+
REQUIRED_VARS GLEAM_EXECUTABLE)

examples/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,17 @@ project(libs)
2222

2323
add_subdirectory(erlang)
2424
add_subdirectory(emscripten)
25+
26+
find_package(Elixir)
27+
find_package(Gleam)
28+
2529
if (Elixir_FOUND)
2630
add_subdirectory(elixir)
2731
else()
28-
message("Unable to find elixirc -- skipping Elixir examples")
32+
message(WARNING "-- elixirc not found, skipping Elixir examples")
33+
endif()
34+
if (Gleam_FOUND)
35+
add_subdirectory(gleam)
36+
else()
37+
message(WARNING "-- gleam not found, skipping Gleam examples")
2938
endif()

examples/gleam/CMakeLists.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#
2+
# This file is part of AtomVM.
3+
#
4+
# Copyright 2025 Paul Guyot <pguyot@kallisys.net>
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
# SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
19+
#
20+
21+
project(examples_gleam)
22+
23+
add_subdirectory(hello_atomvm)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#
2+
# This file is part of AtomVM.
3+
#
4+
# Copyright 2025 Paul Guyot <pguyot@kallisys.net>
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
# SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
19+
#
20+
21+
project(hello_atomvm)
22+
23+
include(BuildGleam)
24+
25+
pack_gleam_runnable(hello_atomvm hello_atomvm estdlib gleam_avm)

0 commit comments

Comments
 (0)