forked from samcamwilliams/HyperBEAM
-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathMakefile
More file actions
180 lines (160 loc) · 5.72 KB
/
Copy pathMakefile
File metadata and controls
180 lines (160 loc) · 5.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
.PHONY: compile buildinfo clean-generated preloaded-store
compile:
rebar3 compile
WAMR_VERSION = 2.2.0
WAMR_DIR = _build/wamr
BUILD_SOURCE = $(shell git rev-parse HEAD)
BUILD_SOURCE_SHORT = $(shell git rev-parse --short HEAD)
GENESIS_WASM_BRANCH = feat/hb-unit
GENESIS_WASM_REPO = https://github.com/permaweb/ao.git
GENESIS_WASM_SERVER_DIR = _build/genesis_wasm/genesis-wasm-server
HYPERBUDDY_UI_REPO = https://github.com/permaweb/hb-explorer
HYPERBUDDY_UI_PACKAGE_JSON = https://raw.githubusercontent.com/permaweb/hb-explorer/main/package.json
HYPERBUDDY_UI_TARGET = src/html/hyperbuddy@1.0/bundle.js
ARWEAVE_GATEWAY = https://arweave.net
PRELOADED_INPUTS = \
scripts/build-preloaded-store.escript \
rebar.config \
rebar.lock \
include \
src/preloaded \
src/forge \
src/core/device \
src/core/include
CLEAN_GENERATED = \
priv \
$(WAMR_DIR) \
_build/genesis_wasm \
_build/preloaded-store \
_build/device-test-store \
_build/device-implementations \
_build/hb_buildinfo.hrl \
_build/hb_buildinfo.hrl.* \
_build/hb_preloaded_index.hrl \
_build/hb_preloaded_index.hrl.* \
native/hb_beamr/*.o \
native/hb_beamr/*.d \
native/hb_keccak/*.o \
native/hb_keccak/*.d
ifdef HB_DEBUG
WAMR_FLAGS = -DWAMR_ENABLE_LOG=1 -DWAMR_BUILD_DUMP_CALL_STACK=1 -DCMAKE_BUILD_TYPE=Debug
else
WAMR_FLAGS = -DCMAKE_BUILD_TYPE=Release
endif
UNAME_S := $(shell uname -s)
UNAME_M := $(shell uname -m)
ifeq ($(UNAME_S),Darwin)
WAMR_BUILD_PLATFORM = darwin
ifeq ($(UNAME_M),arm64)
WAMR_BUILD_TARGET = AARCH64
else
WAMR_BUILD_TARGET = X86_64
endif
else
WAMR_BUILD_PLATFORM = linux
WAMR_BUILD_TARGET = X86_64
endif
wamr: $(WAMR_DIR)/lib/libvmlib.a
buildinfo:
@mkdir -p priv
@tmp=$$(mktemp priv/hb_buildinfo.XXXXXX) && \
printf '%s\n' \
'#{' \
' <<"source">> => <<"$(BUILD_SOURCE)">>,' \
' <<"source-short">> => <<"$(BUILD_SOURCE_SHORT)">>,' \
' <<"build-time">> => '$$(date +%s) \
'}.' \
> "$$tmp" && \
mv "$$tmp" priv/hb_buildinfo
preloaded-store:
@if [ ! -f _build/preloaded-store/data.mdb ] || \
[ -n "$$(find $(PRELOADED_INPUTS) -type f -newer _build/preloaded-store/data.mdb -print -quit)" ] || \
{ key=$${HB_KEY:-hyperbeam-key.json}; [ ! -f "$$key" ] || [ "$$key" -nt _build/preloaded-store/data.mdb ]; }; then \
scripts/build-preloaded-store.escript; \
fi
clean-generated:
rm -rf $(CLEAN_GENERATED)
debug: debug-clean $(WAMR_DIR)
HB_DEBUG=1 make $(WAMR_DIR)/lib/libvmlib.a
CFLAGS="-DHB_DEBUG=1" rebar3 compile
debug-clean:
rm -rf priv $(WAMR_DIR)
# Clone the WAMR repository at our target release
$(WAMR_DIR):
git clone \
https://github.com/bytecodealliance/wasm-micro-runtime.git \
$(WAMR_DIR) \
-b WAMR-$(WAMR_VERSION) \
--single-branch
$(WAMR_DIR)/lib/libvmlib.a: $(WAMR_DIR)
@if ! grep -Fq 'tbl_inst->is_table64 = 1;' ./_build/wamr/core/iwasm/aot/aot_runtime.c; then \
awk 'NR == 742 { print; print "tbl_inst->is_table64 = 1;"; next } { print }' \
./_build/wamr/core/iwasm/aot/aot_runtime.c > ./_build/wamr/core/iwasm/aot/aot_runtime.c.tmp && \
mv ./_build/wamr/core/iwasm/aot/aot_runtime.c.tmp ./_build/wamr/core/iwasm/aot/aot_runtime.c; \
fi; \
cmake \
$(WAMR_FLAGS) \
-S $(WAMR_DIR) \
-B $(WAMR_DIR)/lib \
-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
-DWAMR_BUILD_TARGET=$(WAMR_BUILD_TARGET) \
-DWAMR_BUILD_PLATFORM=$(WAMR_BUILD_PLATFORM) \
-DWAMR_BUILD_MEMORY64=1 \
-DWAMR_DISABLE_HW_BOUND_CHECK=1 \
-DWAMR_BUILD_EXCE_HANDLING=1 \
-DWAMR_BUILD_SHARED_MEMORY=0 \
-DWAMR_BUILD_AOT=1 \
-DWAMR_BUILD_LIBC_WASI=0 \
-DWAMR_BUILD_FAST_INTERP=0 \
-DWAMR_BUILD_INTERP=1 \
-DWAMR_BUILD_JIT=0 \
-DWAMR_BUILD_FAST_JIT=0 \
-DWAMR_BUILD_DEBUG_AOT=1 \
-DWAMR_BUILD_TAIL_CALL=1 \
-DWAMR_BUILD_AOT_STACK_FRAME=1 \
-DWAMR_BUILD_MEMORY_PROFILING=1 \
-DWAMR_BUILD_DUMP_CALL_STACK=1
make -C $(WAMR_DIR)/lib -j8
clean:
rebar3 clean
# Add a new target to print the library path
print-lib-path:
@echo $(CURDIR)/lib/libvmlib.a
$(GENESIS_WASM_SERVER_DIR):
mkdir -p $(GENESIS_WASM_SERVER_DIR)
@echo "Cloning genesis-wasm repository..." && \
tmp_dir=$$(mktemp -d) && \
git clone --depth=1 -b $(GENESIS_WASM_BRANCH) $(GENESIS_WASM_REPO) $$tmp_dir && \
mkdir -p $(GENESIS_WASM_SERVER_DIR) && \
cp -r $$tmp_dir/servers/cu/* $(GENESIS_WASM_SERVER_DIR) && \
rm -rf $$tmp_dir && \
echo "Extracted servers/genesis-wasm to $(GENESIS_WASM_SERVER_DIR)"
# Set up genesis-wasm@1.0 environment
setup-genesis-wasm: $(GENESIS_WASM_SERVER_DIR)
@cp native/genesis-wasm/launch-monitored.sh $(GENESIS_WASM_SERVER_DIR) && \
if ! command -v node > /dev/null; then \
echo "Error: Node.js is not installed. Please install Node.js before continuing."; \
echo "For Ubuntu/Debian, you can install it with:"; \
echo " curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash - && \\"; \
echo " apt-get install -y nodejs=22.16.0-1nodesource1 --allow-downgrades && \\"; \
echo " node -v && npm -v"; \
exit 1; \
fi
@cd $(GENESIS_WASM_SERVER_DIR) && npm install > /dev/null 2>&1 && \
echo "Installed genesis-wasm@1.0 server."
# Update hyperbuddy-ui from remote bundle
update-hyperbuddy-ui:
@echo "Fetching package.json from $(HYPERBUDDY_UI_REPO)..." && \
TX_ID=$$(curl -s "$(HYPERBUDDY_UI_PACKAGE_JSON)" | grep -o '"bundle"[[:space:]]*:[[:space:]]*"[^"]*"' | cut -d'"' -f4) && \
if [ -z "$$TX_ID" ]; then \
echo "Error: Could not find 'bundle' field in package.json"; \
exit 1; \
fi && \
echo "Found transaction ID: $$TX_ID" && \
if [ -f "$(HYPERBUDDY_UI_TARGET)" ]; then \
rm "$(HYPERBUDDY_UI_TARGET)" && \
echo "Removed existing bundle.js"; \
fi && \
echo "Downloading source code from Arweave..." && \
curl -sL "$(ARWEAVE_GATEWAY)/$$TX_ID" -o "$(HYPERBUDDY_UI_TARGET)" && \
echo "Successfully updated $(HYPERBUDDY_UI_TARGET)"