Merge pull request #37 from ethereum/appveyor

Windows support and CI
This commit is contained in:
Paweł Bylica 2018-06-26 09:44:38 +02:00 committed by GitHub
commit 81ac4b62ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 108 additions and 22 deletions

View File

@ -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")

29
appveyor.yml Normal file
View File

@ -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

11
cmake/HunterConfig.cmake Normal file
View File

@ -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"
)

View File

@ -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);

View File

@ -6,8 +6,9 @@
#pragma once
#include <evmc/evmc.h>
#include <evmc/utils.h>
/**
* Creates EVMC Example VM.
*/
struct evmc_instance* evmc_create_examplevm(void);
EVMC_EXPORT struct evmc_instance* evmc_create_examplevm(void);

View File

@ -6,6 +6,7 @@
#pragma once
#include <evmc/evmc.h>
#include <evmc/utils.h>
#include <stdint.h>
@ -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
}

12
include/evmc/utils.h Normal file
View File

@ -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

View File

@ -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

View File

@ -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");