Skip to content
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

Build nimbus evmc shared library and fix issue to enable loading #3050

Merged
merged 3 commits into from
Feb 10, 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
20 changes: 12 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2018-2024 Status Research & Development GmbH. Licensed under
# Copyright (c) 2018-2025 Status Research & Development GmbH. Licensed under
# either of:
# - Apache License, version 2.0
# - MIT license
Expand Down Expand Up @@ -83,14 +83,14 @@ FLUFFY_TOOLS_DIRS := \
FLUFFY_TOOLS_CSV := $(subst $(SPACE),$(COMMA),$(FLUFFY_TOOLS))

# Namespaced variables to avoid conflicts with other makefiles
VERIF_PROXY_OS = $(shell $(CC) -dumpmachine)
ifneq (, $(findstring darwin, $(VERIF_PROXY_OS)))
VERIF_PROXY_SHAREDLIBEXT = dylib
OS_PLATFORM = $(shell $(CC) -dumpmachine)
ifneq (, $(findstring darwin, $(OS_PLATFORM)))
SHAREDLIBEXT = dylib
else
ifneq (, $(findstring mingw, $(VERIF_PROXY_OS))$(findstring cygwin, $(VERIF_PROXY_OS))$(findstring msys, $(VERIF_PROXY_OS)))
VERIF_PROXY_SHAREDLIBEXT = dll
ifneq (, $(findstring mingw, $(OS_PLATFORM))$(findstring cygwin, $(OS_PLATFORM))$(findstring msys, $(OS_PLATFORM)))
SHAREDLIBEXT = dll
else
VERIF_PROXY_SHAREDLIBEXT = so
SHAREDLIBEXT = so
endif
endif

Expand Down Expand Up @@ -333,7 +333,7 @@ nimbus-verified-proxy-test: | build deps rocksdb
libverifproxy: | build deps rocksdb
+ echo -e $(BUILD_MSG) "build/$@" && \
$(ENV_SCRIPT) nim --version && \
$(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
$(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
cp nimbus_verified_proxy/libverifproxy/verifproxy.h $(VERIF_PROXY_OUT_PATH)/
echo -e $(BUILD_END_MSG) "build/$@"

Expand All @@ -357,6 +357,10 @@ evmstate_test: | build deps evmstate
txparse: | build deps
$(ENV_SCRIPT) nim c $(NIM_PARAMS) "tools/txparse/[email protected]"

# builds the nimbus evmc shared library
libnimbusevm: | build deps
$(ENV_SCRIPT) nim c $(NIM_PARAMS) -d:evmc_enabled --app:lib --noMain -o:build/libnimbusevm/$@.$(SHAREDLIBEXT) nimbus/transaction/evmc_vm_glue.nim

# usual cleaning
clean: | clean-common
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}
Expand Down
8 changes: 4 additions & 4 deletions nimbus/transaction/evmc_dynamic_loader.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Nimbus - Dynamic loader for EVM modules as shared libraries / DLLs
#
# Copyright (c) 2019-2024 Status Research & Development GmbH
# Copyright (c) 2019-2025 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
Expand All @@ -14,9 +14,9 @@ import
evmc/evmc, ../config

# The built-in Nimbus EVM, via imported C function.
proc evmc_create_nimbus_evm(): ptr evmc_vm {.cdecl, importc, raises: [], gcsafe.}
proc evmc_create_nimbusevm(): ptr evmc_vm {.cdecl, importc, raises: [], gcsafe.}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to enabled loading by the evmc-vmtester tool.


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

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

# The steps below match the EVMC Loader documentation, copied here:
#
Expand Down
30 changes: 15 additions & 15 deletions nimbus/transaction/evmc_vm_glue.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Nimbus - Binary compatibility on the VM side of the EVMC API interface
#
# Copyright (c) 2019-2024 Status Research & Development GmbH
# Copyright (c) 2019-2025 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
Expand Down Expand Up @@ -82,24 +82,24 @@ proc evmcSetOption(vm: ptr evmc_vm, name, value: cstring): evmc_set_option_resul
return EVMC_SET_OPTION_INVALID_NAME

proc evmcDestroy(vm: ptr evmc_vm) {.cdecl.} =
GC_unref(cast[ref evmc_vm](vm))
dealloc(vm)

proc evmc_create_nimbus_evm(): ptr evmc_vm {.cdecl, exportc.} =
proc evmc_create_nimbusevm*(): ptr evmc_vm {.cdecl, exportc, dynlib.} =
## Entry point to the Nimbus EVM, using an EVMC compatible interface.
## This is an exported C function. EVMC specifies the function must
## have this name format when exported from a shared library.
let vm = (ref evmc_vm)(
abi_version: EVMC_ABI_VERSION,
name: evmcName,
version: evmcVersion,
destroy: evmcDestroy,
execute: evmcExecute,
get_capabilities: evmcGetCapabilities,
set_option: evmcSetOption
)
# Keep an extra reference on this, until `evmcDestroy` is called.
GC_ref(vm)
return cast[ptr evmc_vm](vm)

let vm = cast[ptr evmc_vm](alloc(sizeof(evmc_vm)))

vm.abi_version = EVMC_ABI_VERSION
vm.name = evmcName
vm.version = evmcVersion
vm.destroy = evmcDestroy
vm.execute = evmcExecute
vm.get_capabilities = evmcGetCapabilities
vm.set_option = evmcSetOption

return vm

# This code assumes fields, methods and types of ABI version 12, and must be
# checked for compatibility if the `import evmc/evmc` major version is updated.
Expand Down
Loading