mirror of
https://github.com/status-im/evmc.git
synced 2025-02-23 16:38:06 +00:00
Merge pull request #383 from ethereum/example-dynamic
examples: extend example to support dynamic loading
This commit is contained in:
commit
a63b536664
@ -30,7 +30,10 @@ commands:
|
||||
name: "Test"
|
||||
command: |
|
||||
cmake --build ~/build --target test -- ARGS="-j4 --schedule-random --output-on-failure"
|
||||
~/build/examples/evmc-example
|
||||
# Test statically linked end-to-end example
|
||||
~/build/examples/evmc-example-static
|
||||
# Test dynamically loaded end-to-end example
|
||||
~/build/examples/evmc-example ~/build/examples/example_vm/libevmc-example-vm.so
|
||||
- run:
|
||||
name: "Install"
|
||||
command: cmake --build ~/build --target install
|
||||
|
@ -16,5 +16,9 @@ add_subdirectory(example_precompiles_vm)
|
||||
add_library(evmc-example-host STATIC example_host.cpp)
|
||||
target_link_libraries(evmc-example-host PRIVATE evmc)
|
||||
|
||||
add_executable(evmc-example-static example.c)
|
||||
target_link_libraries(evmc-example-static PRIVATE evmc-example-host evmc-example-vm-static evmc)
|
||||
target_compile_definitions(evmc-example-static PRIVATE STATICALLY_LINKED_EXAMPLE)
|
||||
|
||||
add_executable(evmc-example example.c)
|
||||
target_link_libraries(evmc-example PRIVATE evmc-example-host evmc-example-vm-static evmc)
|
||||
target_link_libraries(evmc-example PRIVATE evmc-example-host evmc evmc::loader)
|
||||
|
@ -4,18 +4,37 @@
|
||||
*/
|
||||
|
||||
#include "example_host.h"
|
||||
#ifdef STATICALLY_LINKED_EXAMPLE
|
||||
#include "example_vm/example_vm.h"
|
||||
#endif
|
||||
|
||||
#include <evmc/helpers.h>
|
||||
#include <evmc/loader.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
#ifdef STATICALLY_LINKED_EXAMPLE
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
struct evmc_instance* vm = evmc_create_example_vm();
|
||||
if (!vm)
|
||||
return EVMC_LOADER_INSTANCE_CREATION_FAILURE;
|
||||
if (!evmc_is_abi_compatible(vm))
|
||||
return -1;
|
||||
return EVMC_LOADER_ABI_VERSION_MISMATCH;
|
||||
#else
|
||||
const char* config_string = (argc > 1) ? argv[1] : "example-vm.so";
|
||||
enum evmc_loader_error_code error_code;
|
||||
struct evmc_instance* vm = evmc_load_and_configure(config_string, &error_code);
|
||||
if (!vm)
|
||||
{
|
||||
printf("Loading error: %d\n", error_code);
|
||||
// NOTE: the values are small enough for casting
|
||||
return (int)error_code;
|
||||
}
|
||||
#endif
|
||||
|
||||
// EVM bytecode goes here. This is one of the examples.
|
||||
const uint8_t code[] = "\x30\x60\x00\x52\x59\x60\x00\xf3";
|
||||
|
Loading…
x
Reference in New Issue
Block a user