Skip to content

Commit f033a40

Browse files
authored
Build nimbus evmc shared library and fix issue to enable loading (#3050)
1 parent 67b8dd7 commit f033a40

File tree

3 files changed

+31
-27
lines changed

3 files changed

+31
-27
lines changed

Makefile

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018-2024 Status Research & Development GmbH. Licensed under
1+
# Copyright (c) 2018-2025 Status Research & Development GmbH. Licensed under
22
# either of:
33
# - Apache License, version 2.0
44
# - MIT license
@@ -83,14 +83,14 @@ FLUFFY_TOOLS_DIRS := \
8383
FLUFFY_TOOLS_CSV := $(subst $(SPACE),$(COMMA),$(FLUFFY_TOOLS))
8484

8585
# Namespaced variables to avoid conflicts with other makefiles
86-
VERIF_PROXY_OS = $(shell $(CC) -dumpmachine)
87-
ifneq (, $(findstring darwin, $(VERIF_PROXY_OS)))
88-
VERIF_PROXY_SHAREDLIBEXT = dylib
86+
OS_PLATFORM = $(shell $(CC) -dumpmachine)
87+
ifneq (, $(findstring darwin, $(OS_PLATFORM)))
88+
SHAREDLIBEXT = dylib
8989
else
90-
ifneq (, $(findstring mingw, $(VERIF_PROXY_OS))$(findstring cygwin, $(VERIF_PROXY_OS))$(findstring msys, $(VERIF_PROXY_OS)))
91-
VERIF_PROXY_SHAREDLIBEXT = dll
90+
ifneq (, $(findstring mingw, $(OS_PLATFORM))$(findstring cygwin, $(OS_PLATFORM))$(findstring msys, $(OS_PLATFORM)))
91+
SHAREDLIBEXT = dll
9292
else
93-
VERIF_PROXY_SHAREDLIBEXT = so
93+
SHAREDLIBEXT = so
9494
endif
9595
endif
9696

@@ -333,7 +333,7 @@ nimbus-verified-proxy-test: | build deps rocksdb
333333
libverifproxy: | build deps rocksdb
334334
+ echo -e $(BUILD_MSG) "build/$@" && \
335335
$(ENV_SCRIPT) nim --version && \
336-
$(ENV_SCRIPT) nim c --app:lib -d:"libp2p_pki_schemes=secp256k1" --noMain:on --threads:on --nimcache:nimcache/libverifproxy -o:$(VERIF_PROXY_OUT_PATH)/$@.$(VERIF_PROXY_SHAREDLIBEXT) $(NIM_PARAMS) nimbus_verified_proxy/libverifproxy/verifproxy.nim
336+
$(ENV_SCRIPT) nim c --app:lib -d:"libp2p_pki_schemes=secp256k1" --noMain:on --threads:on --nimcache:nimcache/libverifproxy -o:$(VERIF_PROXY_OUT_PATH)/$@.$(SHAREDLIBEXT) $(NIM_PARAMS) nimbus_verified_proxy/libverifproxy/verifproxy.nim
337337
cp nimbus_verified_proxy/libverifproxy/verifproxy.h $(VERIF_PROXY_OUT_PATH)/
338338
echo -e $(BUILD_END_MSG) "build/$@"
339339

@@ -357,6 +357,10 @@ evmstate_test: | build deps evmstate
357357
txparse: | build deps
358358
$(ENV_SCRIPT) nim c $(NIM_PARAMS) "tools/txparse/$@.nim"
359359

360+
# builds the nimbus evmc shared library
361+
libnimbusevm: | build deps
362+
$(ENV_SCRIPT) nim c $(NIM_PARAMS) -d:evmc_enabled --app:lib --noMain -o:build/libnimbusevm/$@.$(SHAREDLIBEXT) nimbus/transaction/evmc_vm_glue.nim
363+
360364
# usual cleaning
361365
clean: | clean-common
362366
rm -rf build/{nimbus,nimbus_execution_client,fluffy,libverifproxy,nimbus_verified_proxy,$(TOOLS_CSV),$(FLUFFY_TOOLS_CSV),all_tests,test_kvstore_rocksdb,test_rpc,all_fluffy_tests,all_history_network_custom_chain_tests,test_portal_testnet,utp_test_app,utp_test,*.dSYM}

nimbus/transaction/evmc_dynamic_loader.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Nimbus - Dynamic loader for EVM modules as shared libraries / DLLs
22
#
3-
# Copyright (c) 2019-2024 Status Research & Development GmbH
3+
# Copyright (c) 2019-2025 Status Research & Development GmbH
44
# Licensed under either of
55
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
66
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
@@ -14,9 +14,9 @@ import
1414
evmc/evmc, ../config
1515

1616
# The built-in Nimbus EVM, via imported C function.
17-
proc evmc_create_nimbus_evm(): ptr evmc_vm {.cdecl, importc, raises: [], gcsafe.}
17+
proc evmc_create_nimbusevm(): ptr evmc_vm {.cdecl, importc, raises: [], gcsafe.}
1818

19-
# Import this module to link in the definition of `evmc_create_nimbus_evm`.
19+
# Import this module to link in the definition of `evmc_create_nimbusevm`.
2020
# Nim thinks the module is unused because the function is only called via
2121
# `.exportc` -> `.importc`.
2222
{.warning[UnusedImport]: off.}:
@@ -36,7 +36,7 @@ proc evmcLoadVMGetCreateFn(): (evmc_create_vm_name_fn, string) =
3636

3737
# Use built-in EVM if no other is specified.
3838
if path.len == 0:
39-
return (evmc_create_nimbus_evm, "built-in")
39+
return (evmc_create_nimbusevm, "built-in")
4040

4141
# The steps below match the EVMC Loader documentation, copied here:
4242
#

nimbus/transaction/evmc_vm_glue.nim

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Nimbus - Binary compatibility on the VM side of the EVMC API interface
22
#
3-
# Copyright (c) 2019-2024 Status Research & Development GmbH
3+
# Copyright (c) 2019-2025 Status Research & Development GmbH
44
# Licensed under either of
55
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
66
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
@@ -82,24 +82,24 @@ proc evmcSetOption(vm: ptr evmc_vm, name, value: cstring): evmc_set_option_resul
8282
return EVMC_SET_OPTION_INVALID_NAME
8383

8484
proc evmcDestroy(vm: ptr evmc_vm) {.cdecl.} =
85-
GC_unref(cast[ref evmc_vm](vm))
85+
dealloc(vm)
8686

87-
proc evmc_create_nimbus_evm(): ptr evmc_vm {.cdecl, exportc.} =
87+
proc evmc_create_nimbusevm*(): ptr evmc_vm {.cdecl, exportc, dynlib.} =
8888
## Entry point to the Nimbus EVM, using an EVMC compatible interface.
8989
## This is an exported C function. EVMC specifies the function must
9090
## have this name format when exported from a shared library.
91-
let vm = (ref evmc_vm)(
92-
abi_version: EVMC_ABI_VERSION,
93-
name: evmcName,
94-
version: evmcVersion,
95-
destroy: evmcDestroy,
96-
execute: evmcExecute,
97-
get_capabilities: evmcGetCapabilities,
98-
set_option: evmcSetOption
99-
)
100-
# Keep an extra reference on this, until `evmcDestroy` is called.
101-
GC_ref(vm)
102-
return cast[ptr evmc_vm](vm)
91+
92+
let vm = cast[ptr evmc_vm](alloc(sizeof(evmc_vm)))
93+
94+
vm.abi_version = EVMC_ABI_VERSION
95+
vm.name = evmcName
96+
vm.version = evmcVersion
97+
vm.destroy = evmcDestroy
98+
vm.execute = evmcExecute
99+
vm.get_capabilities = evmcGetCapabilities
100+
vm.set_option = evmcSetOption
101+
102+
return vm
103103
104104
# This code assumes fields, methods and types of ABI version 12, and must be
105105
# checked for compatibility if the `import evmc/evmc` major version is updated.

0 commit comments

Comments
 (0)