Skip to content

CI: Add Elixir pack_test #1625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 20, 2025
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
61 changes: 61 additions & 0 deletions CMakeModules/BuildElixir.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,64 @@ macro(pack_runnable avm_name main)
add_dependencies(${avm_name} ${avm_name}_main ${ARCHIVE_TARGETS} PackBEAM)

endmacro()


macro(pack_test avm_name main)
find_package(Elixir REQUIRED)

# Compile the main module
add_custom_command(
OUTPUT Elixir.${main}.beam
COMMAND elixirc ${CMAKE_CURRENT_SOURCE_DIR}/${main}.ex
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${main}.ex
COMMENT "Compiling ${main}.ex"
VERBATIM
)

add_custom_target(
${avm_name}_main
DEPENDS Elixir.${main}.beam
)

# Compile test modules
foreach(module_name ${ARGN})
add_custom_command(
OUTPUT Elixir.${module_name}.beam
COMMAND elixirc ${CMAKE_CURRENT_SOURCE_DIR}/${module_name}.ex
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${module_name}.ex
COMMENT "Compiling ${module_name}.ex"
VERBATIM
)
set(TEST_BEAMS ${TEST_BEAMS} Elixir.${module_name}.beam)
endforeach()

add_custom_target(
${avm_name}_tests
DEPENDS ${TEST_BEAMS}
)

if(AVM_RELEASE)
set(INCLUDE_LINES "")
else()
set(INCLUDE_LINES "-i")
endif()

# Set up standard libraries
set(ARCHIVE_TARGETS estdlib eavmlib exavmlib etest)
foreach(archive_name ${ARCHIVE_TARGETS})
if(${archive_name} STREQUAL "exavmlib")
set(ARCHIVES ${ARCHIVES} ${CMAKE_BINARY_DIR}/libs/${archive_name}/lib/${archive_name}.avm)
else()
set(ARCHIVES ${ARCHIVES} ${CMAKE_BINARY_DIR}/libs/${archive_name}/src/${archive_name}.avm)
endif()
endforeach()

add_custom_target(
${avm_name} ALL
COMMAND ${CMAKE_BINARY_DIR}/tools/packbeam/PackBEAM ${INCLUDE_LINES} ${avm_name}.avm Elixir.${main}.beam ${TEST_BEAMS} ${ARCHIVES}
COMMENT "Packing test ${avm_name}.avm"
VERBATIM
)
add_dependencies(${avm_name} ${avm_name}_main ${avm_name}_tests ${ARCHIVE_TARGETS} PackBEAM)

endmacro()
6 changes: 5 additions & 1 deletion tests/libs/exavmlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ project(test_exavmlib)

include(BuildElixir)

pack_runnable(Tests Tests estdlib eavmlib exavmlib etest)
set(TEST_MODULES
Some.Submodule
)

pack_test(Tests Tests ${TEST_MODULES})
25 changes: 25 additions & 0 deletions tests/libs/exavmlib/Some.Submodule.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# This file is part of AtomVM.
#
# Copyright 2024 Davide Bettio <davide@uninstall.it>
#
# 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
#

defmodule Some.Submodule do
def start do
:ok
end
end
1 change: 1 addition & 0 deletions tests/libs/exavmlib/Tests.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ defmodule Tests do

def start() do
:ok = IO.puts("Running Elixir tests")
:ok = Some.Submodule.start()
:ok = test_enum()
:ok = test_exception()
:ok = test_chars_protocol()
Expand Down
Loading