Skip to content

Commit 4355d35

Browse files
committed
Move files to mimic rustler's skeleton
1 parent 5d5313a commit 4355d35

File tree

8 files changed

+14
-16
lines changed

8 files changed

+14
-16
lines changed

Makefile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,26 @@
33
BREW_PREFIX := $(shell brew --prefix)
44
ERLANG_INCLUDES = $(BREW_PREFIX)/Cellar/erlang/26.0.2/lib/erlang/usr/include/
55

6-
GO_SOURCES = libp2p/main.go
6+
LIBP2P_DIR = native/libp2p_nif
7+
OUTPUT_DIR = priv/native
8+
9+
GO_SOURCES = $(LIBP2P_DIR)/main.go
710
GO_ARCHIVES := $(patsubst %.go,%.a,$(GO_SOURCES))
811
GO_HEADERS := $(patsubst %.go,%.h,$(GO_SOURCES))
912

1013

11-
libp2p/%.a libp2p/%.h: libp2p/%.go
12-
cd libp2p; go build -buildmode=c-archive $*.go
14+
$(LIBP2P_DIR)/%.a $(LIBP2P_DIR)/%.h: $(LIBP2P_DIR)/%.go
15+
cd $(LIBP2P_DIR); go build -buildmode=c-archive $*.go
1316

14-
libp2p.so: $(GO_ARCHIVES) $(GO_HEADERS) libp2p/libp2p.c libp2p/utils.c
15-
gcc -Wall -Werror -dynamiclib -undefined dynamic_lookup -I $(ERLANG_INCLUDES) -o libp2p.so \
16-
libp2p/libp2p.c libp2p/utils.c $(GO_ARCHIVES)
17+
$(OUTPUT_DIR)/libp2p_nif.so: $(GO_ARCHIVES) $(GO_HEADERS) $(LIBP2P_DIR)/libp2p.c $(LIBP2P_DIR)/utils.c
18+
gcc -Wall -Werror -dynamiclib -undefined dynamic_lookup -I $(ERLANG_INCLUDES) -o $(OUTPUT_DIR)/libp2p_nif.so \
19+
$(LIBP2P_DIR)/libp2p.c $(LIBP2P_DIR)/utils.c $(GO_ARCHIVES)
1720

1821
clean:
19-
-rm $(GO_ARCHIVES) $(GO_HEADERS) libp2p.so
22+
-rm $(GO_ARCHIVES) $(GO_HEADERS) $(OUTPUT_DIR)/*
2023

2124
# Compile C and Go artifacts.
22-
compile-native: libp2p.so
25+
compile-native: $(OUTPUT_DIR)/libp2p_nif.so
2326

2427
# Run an interactive terminal with the main supervisor setup.
2528
iex:

lib/libp2p.ex renamed to lib/lambda_ethereum_consensus/libp2p.ex

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ defmodule Libp2p do
66
@on_load :load_nifs
77

88
def load_nifs do
9-
:erlang.load_nif(~c"./libp2p", 0)
9+
dir = :code.priv_dir(:lambda_ethereum_consensus)
10+
:erlang.load_nif(dir ++ ~c"/native/libp2p_nif", 0)
1011
end
1112

1213
@typedoc """
@@ -55,14 +56,8 @@ defmodule Libp2p do
5556
@spec ttl_permanent_addr :: integer
5657
def ttl_permanent_addr, do: 2 ** 63 - 1
5758

58-
@doc """
59-
Creates a new Host.
60-
"""
61-
@spec host_new :: {:ok, host} | error
62-
def host_new(), do: host_new([])
63-
6459
@spec host_new(list(option)) :: {:ok, host} | error
65-
def host_new(_option_list),
60+
def host_new(_option_list \\ []),
6661
do: :erlang.nif_error(:not_implemented)
6762

6863
@doc """
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)