diff --git a/circle.yml b/circle.yml index c686e55..a778dfd 100644 --- a/circle.yml +++ b/circle.yml @@ -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 diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 4fd7657..eb0c309 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -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) diff --git a/examples/example.c b/examples/example.c index 6888979..37516ab 100644 --- a/examples/example.c +++ b/examples/example.c @@ -4,18 +4,37 @@ */ #include "example_host.h" +#ifdef STATICALLY_LINKED_EXAMPLE #include "example_vm/example_vm.h" +#endif #include +#include #include #include -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";