diff --git a/CMakeLists.txt b/CMakeLists.txt index ab2b989..75e01d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,13 +21,7 @@ include(HunterGate) include(GNUInstallDirs) include(defaults/HunterCacheServers) -# Setup Hunter. -# Hunter is going to be initialized only if building with tests, -# where it is needed to get dependencies. -HunterGate( - URL "https://github.com/ruslo/hunter/archive/v0.20.37.tar.gz" - SHA1 "51886d10428c924cc21756abc17623bcf4986386" -) +include(HunterConfig) project(evmc) set(PROJECT_VERSION "0.1.0.dev0") diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..67e98d4 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,29 @@ +version: "{build}" +branches: + only: + - master + - appveyor + - hunter +configuration: + - Release +environment: + matrix: + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + GENERATOR: "Visual Studio 15 2017 Win64" + + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + GENERATOR: "Visual Studio 14 2015 Win64" +cache: + - C:\.hunter\_Base\Cache -> cmake\HunterConfig.cmake + +before_build: | + if not exist build mkdir build + cd build + cmake -G "%GENERATOR%" .. -DBUILD_SHARED_LIBS=ON -DEVMC_EXAMPLES=ON -DEVMC_TESTING=ON -DCMAKE_INSTALL_PREFIX=C:\install + +build_script: | + cmake --build . --config %CONFIGURATION% --target install + +after_build: | + C:\projects\evmc\build\test\Release\evmc-test.exe + C:\install\bin\evmc-vmtester.exe C:\install\bin\evmc-examplevm.dll diff --git a/cmake/HunterConfig.cmake b/cmake/HunterConfig.cmake new file mode 100644 index 0000000..36d5712 --- /dev/null +++ b/cmake/HunterConfig.cmake @@ -0,0 +1,11 @@ +# EVMC: Ethereum Client-VM Connector API. +# Copyright 2018 Pawel Bylica. +# Licensed under the MIT License. See the LICENSE file. + +# Setup Hunter. +# Hunter is going to be initialized only if building with tests, +# where it is needed to get dependencies. +HunterGate( + URL "https://github.com/ruslo/hunter/archive/v0.20.37.tar.gz" + SHA1 "51886d10428c924cc21756abc17623bcf4986386" +) diff --git a/examples/capi.c b/examples/capi.c index bee81ff..6ffa402 100644 --- a/examples/capi.c +++ b/examples/capi.c @@ -10,12 +10,15 @@ struct evmc_uint256be balance(struct evmc_context* context, const struct evmc_address* address) { + (void)context; + (void)address; struct evmc_uint256be ret = {.bytes = {1, 2, 3, 4}}; return ret; } struct evmc_address address(struct evmc_context* context) { + (void)context; struct evmc_address ret = {.bytes = {1, 2, 3, 4}}; return ret; } @@ -29,6 +32,7 @@ static void print_address(const struct evmc_address* address) static int account_exists(struct evmc_context* context, const struct evmc_address* address) { + (void)context; printf("EVM-C: EXISTS @"); print_address(address); printf("\n"); @@ -40,6 +44,9 @@ static void get_storage(struct evmc_uint256be* result, const struct evmc_address* address, const struct evmc_uint256be* key) { + (void)result; + (void)context; + (void)key; printf("EVM-C: SLOAD @"); print_address(address); printf("\n"); @@ -50,6 +57,9 @@ static void set_storage(struct evmc_context* context, const struct evmc_uint256be* key, const struct evmc_uint256be* value) { + (void)context; + (void)key; + (void)value; printf("EVM-C: SSTORE @"); print_address(address); printf("\n"); @@ -67,6 +77,7 @@ static void get_balance(struct evmc_uint256be* result, static size_t get_code_size(struct evmc_context* context, const struct evmc_address* address) { + (void)context; printf("EVM-C: CODESIZE @"); print_address(address); printf("\n"); @@ -79,6 +90,10 @@ static size_t copy_code(struct evmc_context* context, uint8_t* buffer_data, size_t buffer_size) { + (void)context; + (void)code_offset; + (void)buffer_data; + (void)buffer_size; printf("EVM-C: COPYCODE @"); print_address(address); printf("\n"); @@ -89,6 +104,7 @@ static void selfdestruct(struct evmc_context* context, const struct evmc_address* address, const struct evmc_address* beneficiary) { + (void)context; printf("EVM-C: SELFDESTRUCT "); print_address(address); printf(" -> "); @@ -100,16 +116,25 @@ static void call(struct evmc_result* result, struct evmc_context* context, const struct evmc_message* msg) { + (void)context; printf("EVM-C: CALL (depth: %d)\n", msg->depth); result->status_code = EVMC_FAILURE; } -static void get_tx_context(struct evmc_tx_context* result, struct evmc_context* context) {} +static void get_tx_context(struct evmc_tx_context* result, struct evmc_context* context) +{ + (void)result; + (void)context; +} static void get_block_hash(struct evmc_uint256be* result, struct evmc_context* context, int64_t number) -{} +{ + (void)result; + (void)context; + (void)number; +} /// EVM log callback. /// @@ -121,6 +146,11 @@ static void evm_log(struct evmc_context* context, const struct evmc_uint256be topics[], size_t topics_count) { + (void)context; + (void)address; + (void)data; + (void)data_size; + (void)topics; printf("EVM-C: LOG%d\n", (int)topics_count); } @@ -130,23 +160,31 @@ static const struct evmc_context_fn_table ctx_fn_table = { }; /// Example how the API is supposed to be used. -int main(int argc, char* argv[]) +int main() { struct evmc_instance* jit = evmc_create_examplevm(); if (jit->abi_version != EVMC_ABI_VERSION) return 1; // Incompatible ABI version. - uint8_t const code[] = "Place some EVM bytecode here"; + const uint8_t code[] = "Place some EVM bytecode here"; const size_t code_size = sizeof(code); - struct evmc_uint256be code_hash = {.bytes = {1, 2, 3}}; - uint8_t const input[] = "Hello World!"; - struct evmc_uint256be value = {{1, 0}}; - struct evmc_address addr = {{0, 1, 2}}; - int64_t gas = 200000; + const struct evmc_uint256be code_hash = {.bytes = {1, 2, 3}}; + const uint8_t input[] = "Hello World!"; + const struct evmc_uint256be value = {{1, 0}}; + const struct evmc_address addr = {{0, 1, 2}}; + const int64_t gas = 200000; struct evmc_context ctx = {&ctx_fn_table}; - struct evmc_message msg = {addr, addr, value, input, sizeof(input), code_hash, gas, 0}; + struct evmc_message msg; + msg.sender = addr; + msg.destination = addr; + msg.value = value; + msg.input_data = input; + msg.input_size = sizeof(input); + msg.code_hash = code_hash; + msg.gas = gas; + msg.depth = 0; struct evmc_result result = jit->execute(jit, &ctx, EVMC_HOMESTEAD, &msg, code, code_size); diff --git a/examples/examplevm/examplevm.h b/examples/examplevm/examplevm.h index f1ebf98..37261ef 100644 --- a/examples/examplevm/examplevm.h +++ b/examples/examplevm/examplevm.h @@ -6,8 +6,9 @@ #pragma once #include +#include /** * Creates EVMC Example VM. */ -struct evmc_instance* evmc_create_examplevm(void); +EVMC_EXPORT struct evmc_instance* evmc_create_examplevm(void); diff --git a/include/evmc/instructions.h b/include/evmc/instructions.h index 4492427..1dc50b9 100644 --- a/include/evmc/instructions.h +++ b/include/evmc/instructions.h @@ -6,6 +6,7 @@ #pragma once #include +#include #include @@ -191,7 +192,7 @@ struct evmc_instruction_metrics * @return The pointer to the array of 256 instruction metrics. Null pointer in case * an invalid EVM revision provided. */ -const struct evmc_instruction_metrics* evmc_get_instruction_metrics_table( +EVMC_EXPORT const struct evmc_instruction_metrics* evmc_get_instruction_metrics_table( enum evmc_revision revision); /** @@ -203,7 +204,7 @@ const struct evmc_instruction_metrics* evmc_get_instruction_metrics_table( * @return The pointer to the array of 256 instruction names. Null pointer in case * an invalid EVM revision provided. */ -const char* const* evmc_get_instruction_names_table(enum evmc_revision revision); +EVMC_EXPORT const char* const* evmc_get_instruction_names_table(enum evmc_revision revision); #if __cplusplus } diff --git a/include/evmc/utils.h b/include/evmc/utils.h new file mode 100644 index 0000000..c527c61 --- /dev/null +++ b/include/evmc/utils.h @@ -0,0 +1,12 @@ +/* EVMC: Ethereum Client-VM Connector API. + * Copyright 2018 Pawel Bylica. + * Licensed under the MIT License. See the LICENSE file. + */ + +#pragma once + +#ifdef _MSC_VER +#define EVMC_EXPORT __declspec(dllexport) +#else +#define EVMC_EXPORT __attribute__ ((visibility ("default"))) +#endif diff --git a/lib/instructions/CMakeLists.txt b/lib/instructions/CMakeLists.txt index 10cbca1..a9b0d3e 100644 --- a/lib/instructions/CMakeLists.txt +++ b/lib/instructions/CMakeLists.txt @@ -3,7 +3,7 @@ # Licensed under the MIT License. See the LICENSE file. add_library( - instructions + instructions STATIC ${include_dir}/evmc/instructions.h instruction_metrics.c instruction_names.c diff --git a/test/vmtester/tests.cpp b/test/vmtester/tests.cpp index 7d3e2c9..a284412 100644 --- a/test/vmtester/tests.cpp +++ b/test/vmtester/tests.cpp @@ -10,7 +10,7 @@ static_assert(sizeof(evmc_uint256be) == 32, "evmc_uint256be is too big"); static_assert(sizeof(evmc_address) == 20, "evmc_address is too big"); -static_assert(sizeof(evmc_result) == 64, "evmc_result does not fit cache line"); +static_assert(sizeof(evmc_result) <= 64, "evmc_result does not fit cache line"); static_assert(sizeof(evmc_instance) <= 64, "evmc_instance does not fit cache line"); static_assert(sizeof(evmc_message) <= 18 * 8, "evmc_message not optimally packed"); static_assert(offsetof(evmc_message, code_hash) % 8 == 0, "evmc_message.code_hash not aligned");