Skip to content

Commit

Permalink
Introduce erlang distribution
Browse files Browse the repository at this point in the history
- Add support for handshake from OTP nodes
- Add support for monitoring processes and sending messages to registered
processes from OTP nodes

Signed-off-by: Paul Guyot <[email protected]>
  • Loading branch information
pguyot committed Jan 12, 2025
1 parent b73c9ae commit aaf2a6b
Show file tree
Hide file tree
Showing 25 changed files with 2,241 additions and 23 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,14 @@ jobs:
with:
submodules: 'recursive'

- name: "APT update"
run: sudo apt update -y

- name: "Install deps"
run: |
sudo apt install -y ${{ matrix.compiler_pkgs}} cmake gperf zlib1g-dev doxygen valgrind libmbedtls-dev
sudo apt remove -y erlang
- uses: erlef/setup-beam@v1
with:
otp-version: ${{ matrix.otp }}
Expand All @@ -313,12 +321,6 @@ jobs:
if: matrix.arch == 'i386'
run: sudo dpkg --add-architecture i386

- name: "APT update"
run: sudo apt update -y

- name: "Install deps"
run: sudo apt install -y ${{ matrix.compiler_pkgs}} cmake gperf zlib1g-dev doxygen valgrind libmbedtls-dev

# Builder info
- name: "System info"
run: |
Expand Down
1 change: 1 addition & 0 deletions examples/erlang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ pack_runnable(mqtt_client mqtt_client estdlib eavmlib)
pack_runnable(network_console network_console estdlib eavmlib alisp)
pack_runnable(logging_example logging_example estdlib eavmlib)
pack_runnable(http_client http_client estdlib eavmlib)
pack_runnable(disterl disterl estdlib)
41 changes: 41 additions & 0 deletions examples/erlang/disterl.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
%
% This file is part of AtomVM.
%
% Copyright 2024 Paul Guyot <[email protected]>
%
% 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
%

-module(disterl).

-export([start/0]).

start() ->
{ok, _KernelPid} = kernel:start(normal, []),
{ok, _NetKernelPid} = net_kernel:start('[email protected]', #{name_domain => longnames}),
io:format("Distribution was started\n"),
io:format("Node is ~p\n", [node()]),
net_kernel:set_cookie(<<"AtomVM">>),
io:format("Cookie is ~s\n", [net_kernel:get_cookie()]),
register(disterl, self()),
io:format(
"This AtomVM node is waiting for 'quit' message, and this process is registered as 'disterl'\n"
),
io:format("On an OTP node with long names distribution, run:\n"),
io:format("erlang:set_cookie('[email protected]', 'AtomVM').\n"),
io:format("{disterl, '[email protected]'} ! quit.\n"),
receive
quit -> ok
end.
7 changes: 7 additions & 0 deletions libs/estdlib/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ project(estdlib)
include(BuildErlang)

set(ERLANG_MODULES
application
base64
binary
calendar
code
crypto
dist_util
erl_epmd
erts_debug
ets
Expand All @@ -41,6 +43,9 @@ set(ERLANG_MODULES
gen_tcp_inet
gen_tcp_socket
supervisor
kernel
net_kernel
net_kernel_sup
inet
io_lib
io
Expand All @@ -54,6 +59,8 @@ set(ERLANG_MODULES
queue
sets
socket
socket_dist
socket_dist_controller
ssl
string
timer
Expand Down
37 changes: 37 additions & 0 deletions libs/estdlib/src/application.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
%
% This file is part of AtomVM.
%
% Copyright 2025 Paul Guyot <[email protected]>
%
% 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
%

-module(application).
-export([get_env/3]).
-export_type([start_type/0]).

-type start_type() :: normal | {takeover, Node :: node()} | {failover, Node :: node()}.

%%-----------------------------------------------------------------------------
%% @param Application application to get the parameter value of
%% @param Parameter parameter to get the value of
%% @param Default default value if parameter is not found
%% @returns default value
%% @doc Retrieve the value of the configuration parameter `Parameter' for
%% application `Application' or `Default' if not found.
%% @end
%%-----------------------------------------------------------------------------
-spec get_env(Application :: atom(), Parameter :: atom(), Default :: any()) -> any().
get_env(_Application, _Parameter, Default) -> Default.
Loading

0 comments on commit aaf2a6b

Please sign in to comment.