diff --git a/.cicd/platforms/ubuntu18.Dockerfile b/.cicd/platforms/ubuntu18.Dockerfile index a3a2c07896..04df4f9c72 100644 --- a/.cicd/platforms/ubuntu18.Dockerfile +++ b/.cicd/platforms/ubuntu18.Dockerfile @@ -3,6 +3,7 @@ FROM ubuntu:bionic RUN apt-get update && apt-get upgrade -y && \ DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential \ cmake \ + g++-8 \ curl \ ninja-build \ software-properties-common \ @@ -15,4 +16,7 @@ RUN curl -L https://www.python.org/ftp/python/3.10.6/Python-3.10.6.tgz | tar zx ./configure --enable-optimizations --prefix=/usr && \ make -j$(nproc) install && \ cd .. && \ - rm -rf Python* \ No newline at end of file + rm -rf Python* + +ENV CC=gcc-8 +ENV CXX=g++-8 \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index ac62b95d85..42f9caaedb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "libraries/native/softfloat"] path = libraries/native/softfloat url = https://github.com/AntelopeIO/berkeley-softfloat-3 +[submodule "tools/external/eos-vm"] + path = tools/external/eos-vm + url = https://github.com/AntelopeIO/eos-vm diff --git a/libraries/eosiolib/CMakeLists.txt b/libraries/eosiolib/CMakeLists.txt index 32a5ebc204..ed7ca73d9b 100644 --- a/libraries/eosiolib/CMakeLists.txt +++ b/libraries/eosiolib/CMakeLists.txt @@ -1,50 +1,74 @@ +set(PARENT_PROJECT_NAME ${PROJECT_NAME}) + file(GLOB HEADERS "*.hpp" "*.h") -add_library(eosio - eosiolib.cpp - crypto.cpp - ${HEADERS}) - -add_library(eosio_malloc - malloc.cpp - ${HEADERS}) - -add_library(eosio_dsm - simple_malloc.cpp - ${HEADERS}) - -add_library(eosio_cmem - memory.cpp - ${HEADERS}) - - -set_target_properties(eosio_malloc PROPERTIES LINKER_LANGUAGE C) - -target_include_directories(eosio PUBLIC - ${CMAKE_SOURCE_DIR}/libc/cdt-musl/include - ${CMAKE_SOURCE_DIR}/libc/cdt-musl/src/internal - ${CMAKE_SOURCE_DIR}/libc/cdt-musl/src/crypt - ${CMAKE_SOURCE_DIR}/libc/cdt-musl/arch/eos - ${CMAKE_SOURCE_DIR}/libc++/cdt-libcxx/include - ${CMAKE_SOURCE_DIR} - ${CMAKE_SOURCE_DIR}/boost/include) - -target_link_libraries( eosio c c++ ) -add_custom_command( TARGET eosio POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ ${BASE_BINARY_DIR}/lib ) -add_custom_command( TARGET eosio_malloc POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ ${BASE_BINARY_DIR}/lib ) -add_custom_command( TARGET eosio_dsm POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ ${BASE_BINARY_DIR}/lib ) -add_custom_command( TARGET eosio_cmem POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ ${BASE_BINARY_DIR}/lib ) - -if (ENABLE_NATIVE_COMPILER) - add_native_library(native_eosio - eosiolib.cpp - crypto.cpp - malloc.cpp - ${HEADERS}) - - add_dependencies( native_eosio eosio ) - add_custom_command( TARGET native_eosio POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ ${BASE_BINARY_DIR}/lib ) -endif() - -file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../eosiolib DESTINATION ${BASE_BINARY_DIR}/include FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp") +if (${PARENT_PROJECT_NAME} STREQUAL "cdt_tools") + project(native_eosio) + add_library( ${PROJECT_NAME} + eosiolib.cpp + crypto.cpp + malloc.cpp + ${HEADERS} ) + target_compile_definitions(${PROJECT_NAME} PUBLIC EOSIO_NATIVE EOSIOLIB_DISABLE_MALLOC) + target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_SOURCE_DIR}/../libraries/eosiolib/core + ${CMAKE_SOURCE_DIR}/../libraries/boost/include + ${CMAKE_SOURCE_DIR}/../libraries/meta_refl/include) + target_compile_options(${PROJECT_NAME} PUBLIC -fPIC -fexceptions -fno-rtti) + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "12.0") + target_compile_options(${PROJECT_NAME} PUBLIC -Wno-attributes) + else() + target_compile_options(${PROJECT_NAME} PUBLIC -Wno-attributes=gnu::eosio_wasm_import) + target_compile_options(${PROJECT_NAME} PUBLIC -Wno-attributes=eosio::ignore) + endif() + endif() +else() + add_library(eosio + eosiolib.cpp + crypto.cpp + ${HEADERS}) + + add_library(eosio_malloc + malloc.cpp + ${HEADERS}) + + add_library(eosio_dsm + simple_malloc.cpp + ${HEADERS}) + + add_library(eosio_cmem + memory.cpp + ${HEADERS}) + + + set_target_properties(eosio_malloc PROPERTIES LINKER_LANGUAGE C) + + target_include_directories(eosio PUBLIC + ${CMAKE_SOURCE_DIR}/libc/cdt-musl/include + ${CMAKE_SOURCE_DIR}/libc/cdt-musl/src/internal + ${CMAKE_SOURCE_DIR}/libc/cdt-musl/src/crypt + ${CMAKE_SOURCE_DIR}/libc/cdt-musl/arch/eos + ${CMAKE_SOURCE_DIR}/libc++/cdt-libcxx/include + ${CMAKE_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/boost/include) + + target_link_libraries( eosio c c++ ) + add_custom_command( TARGET eosio POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ ${BASE_BINARY_DIR}/lib ) + add_custom_command( TARGET eosio_malloc POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ ${BASE_BINARY_DIR}/lib ) + add_custom_command( TARGET eosio_dsm POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ ${BASE_BINARY_DIR}/lib ) + add_custom_command( TARGET eosio_cmem POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ ${BASE_BINARY_DIR}/lib ) + + if (ENABLE_NATIVE_COMPILER) + add_native_library(native_eosio + eosiolib.cpp + crypto.cpp + malloc.cpp + ${HEADERS}) + + add_dependencies( native_eosio eosio ) + add_custom_command( TARGET native_eosio POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ ${BASE_BINARY_DIR}/lib ) + endif() + + file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../eosiolib DESTINATION ${BASE_BINARY_DIR}/include FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp") +endif() \ No newline at end of file diff --git a/libraries/eosiolib/capi/eosio/db.h b/libraries/eosiolib/capi/eosio/db.h index e21f20caf7..ae58579b46 100644 --- a/libraries/eosiolib/capi/eosio/db.h +++ b/libraries/eosiolib/capi/eosio/db.h @@ -6,6 +6,8 @@ #pragma once #include "types.h" +#include "eosio/types.hpp" + #ifdef __cplusplus extern "C" { #endif diff --git a/libraries/eosiolib/capi/eosio/types.h b/libraries/eosiolib/capi/eosio/types.h index 9350b9b4d1..b3f54915b9 100644 --- a/libraries/eosiolib/capi/eosio/types.h +++ b/libraries/eosiolib/capi/eosio/types.h @@ -32,7 +32,12 @@ typedef uint64_t capi_name; /** * EOSIO Public Key. K1 and R1 keys are 34 bytes. Newer keys can be variable-sized */ -struct __attribute__((deprecated("newer public key types cannot be represented as a fixed size structure", "char[]"))) +struct +#ifdef __GNUC__ +__attribute__((deprecated("newer public key types cannot be represented as a fixed size structure, use char[] instead"))) +#else +__attribute__((deprecated("newer public key types cannot be represented as a fixed size structure", "char[]"))) +#endif capi_public_key { char data[34]; }; @@ -40,7 +45,12 @@ capi_public_key { /** * EOSIO Signature. K1 and R1 signatures are 66 bytes. Newer signatures can be variable-sized */ -struct __attribute__((deprecated("newer signature types cannot be represented as a fixed size structure", "char[]"))) +struct +#ifdef __GNUC__ +__attribute__((deprecated("newer public key types cannot be represented as a fixed size structure, use char[] instead"))) +#else +__attribute__((deprecated("newer public key types cannot be represented as a fixed size structure", "char[]"))) +#endif capi_signature { uint8_t data[66]; }; diff --git a/libraries/eosiolib/contracts/eosio/action.hpp b/libraries/eosiolib/contracts/eosio/action.hpp index 195c85f842..2ec2163013 100644 --- a/libraries/eosiolib/contracts/eosio/action.hpp +++ b/libraries/eosiolib/contracts/eosio/action.hpp @@ -268,12 +268,12 @@ namespace eosio { /** * Name of the account the action is intended for */ - name account; + eosio::name account; /** * Name of the action */ - name name; + eosio::name name; /** * List of permissions that authorize this action diff --git a/libraries/eosiolib/core/eosio/datastream.hpp b/libraries/eosiolib/core/eosio/datastream.hpp index 8fd97c3c79..2f5bd88251 100644 --- a/libraries/eosiolib/core/eosio/datastream.hpp +++ b/libraries/eosiolib/core/eosio/datastream.hpp @@ -16,6 +16,8 @@ #include #include +#include + #include #include #include diff --git a/libraries/eosiolib/core/eosio/fixed_bytes.hpp b/libraries/eosiolib/core/eosio/fixed_bytes.hpp index 97cbf40bb8..812117b4d6 100644 --- a/libraries/eosiolib/core/eosio/fixed_bytes.hpp +++ b/libraries/eosiolib/core/eosio/fixed_bytes.hpp @@ -4,6 +4,7 @@ */ #pragma once #include "datastream.hpp" +#include "types.hpp" #include #include diff --git a/libraries/eosiolib/core/eosio/print.hpp b/libraries/eosiolib/core/eosio/print.hpp index c2ee216fdc..de8db22ae6 100644 --- a/libraries/eosiolib/core/eosio/print.hpp +++ b/libraries/eosiolib/core/eosio/print.hpp @@ -5,7 +5,7 @@ #pragma once #include #include - +#include "types.hpp" namespace eosio { diff --git a/libraries/eosiolib/core/eosio/reflect.hpp b/libraries/eosiolib/core/eosio/reflect.hpp index 683342638b..bd74557254 100644 --- a/libraries/eosiolib/core/eosio/reflect.hpp +++ b/libraries/eosiolib/core/eosio/reflect.hpp @@ -3,4 +3,4 @@ #include #define CDT_REFLECT(...) \ - BLUEGRASS_META_REFL(__VA_ARGS__); \ + BLUEGRASS_META_REFL(__VA_ARGS__); diff --git a/libraries/eosiolib/core/eosio/types.hpp b/libraries/eosiolib/core/eosio/types.hpp new file mode 100644 index 0000000000..af5c5d7075 --- /dev/null +++ b/libraries/eosiolib/core/eosio/types.hpp @@ -0,0 +1,10 @@ +/** + * @file + * @copyright defined in eos/LICENSE + */ +#pragma once + +#ifdef __GNUC__ +typedef __int128 int128_t; +typedef unsigned __int128 uint128_t; +#endif \ No newline at end of file diff --git a/libraries/eosiolib/malloc.cpp b/libraries/eosiolib/malloc.cpp index 2f3585baa9..9f936b2933 100644 --- a/libraries/eosiolib/malloc.cpp +++ b/libraries/eosiolib/malloc.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "core/eosio/check.hpp" #include "core/eosio/print.hpp" @@ -525,6 +526,8 @@ namespace eosio { } /// namespace eosio extern "C" { +#ifndef EOSIOLIB_DISABLE_MALLOC + void* malloc(size_t size) { return eosio::memory_heap.malloc(size); } @@ -542,5 +545,6 @@ void* realloc(void* ptr, size_t size) { void free(void* ptr) { return eosio::memory_heap.free(ptr); } +#endif } diff --git a/libraries/meta_refl/include/bluegrass/meta/function_traits.hpp b/libraries/meta_refl/include/bluegrass/meta/function_traits.hpp index a3d4abbb72..3940c2d8f3 100644 --- a/libraries/meta_refl/include/bluegrass/meta/function_traits.hpp +++ b/libraries/meta_refl/include/bluegrass/meta/function_traits.hpp @@ -34,7 +34,7 @@ #define BLUEGRASS_HAS_TEMPLATE_MEMBER(ARG, NAME) \ bluegrass::meta::overloaded { \ - [&](auto&& f, std::enable_if_t> && \ + [](auto&& f, std::enable_if_t> && \ bluegrass::meta::detail::pass_type< \ decltype(&std::decay_t::type::template NAME)>(), int> = 0) constexpr { \ return true; \ diff --git a/libraries/native/CMakeLists.txt b/libraries/native/CMakeLists.txt index 68ed5238ab..d9858069e2 100644 --- a/libraries/native/CMakeLists.txt +++ b/libraries/native/CMakeLists.txt @@ -1,3 +1,5 @@ +set(PARENT_PROJECT_NAME ${PROJECT_NAME}) + project(native LANGUAGES CXX ASM) if (NOT __APPLE) @@ -6,8 +8,10 @@ else() set(CRT_ASM macho_crt.s) endif() -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-everything -allow-sse") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-everything -allow-sse") +if (NOT ${PARENT_PROJECT_NAME} MATCHES "cdt_tools") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-everything -allow-sse") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-everything -allow-sse") +endif() file(GLOB HEADERS "*.hpp" "*.h") @@ -332,15 +336,30 @@ list( APPEND softfloat_sources ${softfloat_headers} ) add_library ( sf STATIC ${softfloat_sources} ) target_include_directories( sf PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/softfloat/source/include" "${CMAKE_CURRENT_SOURCE_DIR}/softfloat/source/8086-SSE" "${CMAKE_CURRENT_SOURCE_DIR}/softfloat/build/Linux-x86_64-GCC" ${CMAKE_SOURCE_DIR}) -add_native_library ( native STATIC ${softfloat_sources} intrinsics.cpp crt.cpp ${CRT_ASM} ) +if (${PARENT_PROJECT_NAME} STREQUAL "cdt_tools") + add_library(${PROJECT_NAME} STATIC ${softfloat_sources} intrinsics.cpp crt_lib.cpp) + + target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_SOURCE_DIR}/../libraries/eosiolib/core + ${CMAKE_SOURCE_DIR}/../libraries/eosiolib/contracts + ${CMAKE_SOURCE_DIR}/../libraries/eosiolib/capi + ${CMAKE_SOURCE_DIR}/../libraries/boost/include + ${CMAKE_SOURCE_DIR}/../libraries/meta_refl/include) + # suppress executable stack warning. this is due to absence of .note.GNU-stack + target_link_libraries(${PROJECT_NAME} PUBLIC "-Wl,-z,noexecstack") +else() + add_native_library ( native STATIC ${softfloat_sources} intrinsics.cpp crt.cpp ${CRT_ASM}) +endif() + target_include_directories( native PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/softfloat/source/include" "${CMAKE_CURRENT_SOURCE_DIR}/softfloat/source/8086-SSE" "${CMAKE_CURRENT_SOURCE_DIR}/softfloat/build/Linux-x86_64-GCC" ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/eosiolib/capi ${CMAKE_SOURCE_DIR}/eosiolib/contracts ${CMAKE_SOURCE_DIR}/eosiolib/core) add_dependencies(native native_eosio) -add_custom_command( TARGET native POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ ${BASE_BINARY_DIR}/lib ) +if (NOT ${PARENT_PROJECT_NAME} MATCHES "cdt_tools") + add_custom_command( TARGET native POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ ${BASE_BINARY_DIR}/lib ) -add_custom_command( TARGET sf POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ ${BASE_BINARY_DIR}/lib ) + add_custom_command( TARGET sf POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ ${BASE_BINARY_DIR}/lib ) -file(COPY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION ${BASE_BINARY_DIR}/include/eosio FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp" PATTERN "softfloat" EXCLUDE) + file(COPY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION ${BASE_BINARY_DIR}/include/eosio FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp" PATTERN "softfloat" EXCLUDE) -file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/native DESTINATION ${BASE_BINARY_DIR}/include/eosiolib FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp" PATTERN "softfloat" EXCLUDE) + file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/native DESTINATION ${BASE_BINARY_DIR}/include/eosiolib FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp" PATTERN "softfloat" EXCLUDE) +endif() \ No newline at end of file diff --git a/libraries/native/crt.cpp b/libraries/native/crt.cpp index 112820eda0..d75c6c44f6 100644 --- a/libraries/native/crt.cpp +++ b/libraries/native/crt.cpp @@ -64,6 +64,9 @@ extern "C" { } } + jmp_buf* __get_jmp_buf() { + return ___env_ptr; + } void __set_env_test() { ___env_ptr = &test_env; } diff --git a/libraries/native/crt_lib.cpp b/libraries/native/crt_lib.cpp new file mode 100644 index 0000000000..1f5021b257 --- /dev/null +++ b/libraries/native/crt_lib.cpp @@ -0,0 +1,45 @@ +#include "native/eosio/crt.hpp" + +#include + +eosio::cdt::output_stream std_out; +eosio::cdt::output_stream std_err; + +bool ___disable_output = false; +bool ___has_failed = false; +bool ___earlier_unit_test_has_failed = false; +static jmp_buf env; +static jmp_buf test_env; +jmp_buf* ___env_ptr = &env; + +jmp_buf* __get_jmp_buf() { + return ___env_ptr; +} +void __set_env_test() { + ___env_ptr = &test_env; +} +void __reset_env() { + ___env_ptr = &env; +} + +void _prints_l(const char* cstr, uint32_t len, uint8_t which) { + for (int i=0; i < len; i++) { + if (which == eosio::cdt::output_stream_kind::std_out) + std_out.push(cstr[i]); + else if (which == eosio::cdt::output_stream_kind::std_err) + std_err.push(cstr[i]); + if (!___disable_output) { + std::putc(cstr[i], which == eosio::cdt::output_stream_kind::std_out ? stdout : stderr); + } + } +} +void _prints(const char* cstr, uint8_t which) { + for (int i=0; cstr[i] != '\0'; i++) { + if (which == eosio::cdt::output_stream_kind::std_out) + std_out.push(cstr[i]); + else if (which == eosio::cdt::output_stream_kind::std_err) + std_err.push(cstr[i]); + if (!___disable_output) + std::putc(cstr[i], which == eosio::cdt::output_stream_kind::std_out ? stdout : stderr); + } +} \ No newline at end of file diff --git a/libraries/native/native/eosio/crt.hpp b/libraries/native/native/eosio/crt.hpp index 5d81a60015..9e9d23e3fb 100644 --- a/libraries/native/native/eosio/crt.hpp +++ b/libraries/native/native/eosio/crt.hpp @@ -4,6 +4,7 @@ #include namespace eosio { namespace cdt { + enum output_stream_kind { std_out, std_err, @@ -25,10 +26,15 @@ namespace eosio { namespace cdt { extern eosio::cdt::output_stream std_out; extern eosio::cdt::output_stream std_err; -extern "C" jmp_buf* ___env_ptr; -extern "C" char* ___heap_ptr; extern "C" { + extern jmp_buf* ___env_ptr; + extern char* ___heap_ptr; + extern bool ___disable_output; + extern bool ___has_failed; + extern bool ___earlier_unit_test_has_failed; + + jmp_buf* __get_jmp_buf(); void __set_env_test(); void __reset_env(); void _prints_l(const char* cstr, uint32_t len, uint8_t which); diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 141ae16197..f788de2263 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,4 +1,5 @@ cmake_minimum_required(VERSION 3.5) +project(cdt_tools) find_package(LLVM REQUIRED CONFIG) message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") @@ -23,7 +24,9 @@ include_directories(${LLVM_BINDIR}/include) link_directories(${LLVM_LIBRARY_DIRS}) add_definitions(${LLVM_DEFINITIONS}) +set(CMAKE_CXX_STANDARD 17) set(EOSIO_STACK_SIZE 8192) +set(ENABLE_NATIVE_COMPILER TRUE) macro (add_tool name) set(LLVM_LINK_COMPONENTS support) @@ -71,10 +74,13 @@ macro (add_tool name) add_custom_command( TARGET ${name} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_BINARY_DIR}/bin/ ) endmacro() +add_subdirectory(../libraries/eosiolib ${CMAKE_BINARY_DIR}/eosiolib) +add_subdirectory(../libraries/native ${CMAKE_BINARY_DIR}/native) add_subdirectory(abidiff) add_subdirectory(cc) add_subdirectory(ld) add_subdirectory(init) add_subdirectory(external) +add_subdirectory(antler-run) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/compiler_options.hpp.in ${CMAKE_BINARY_DIR}/compiler_options.hpp) diff --git a/tools/antler-run/CMakeLists.txt b/tools/antler-run/CMakeLists.txt new file mode 100644 index 0000000000..f0dbe5ca7b --- /dev/null +++ b/tools/antler-run/CMakeLists.txt @@ -0,0 +1,23 @@ +project(antler-run) + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/antler-run.cpp ${CMAKE_BINARY_DIR}/antler-run.cpp) +find_package(eos-vm) + +set(TOOLS_DIR ${CMAKE_SOURCE_DIR}) +set(LIB_DIR ${CMAKE_SOURCE_DIR}/../libraries) +set(CDT_NO_START TRUE) + +include_directories(${LIB_DIR}) + +add_tool(antler-run) +target_compile_options(${PROJECT_NAME} PUBLIC -ldl) +set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-Wl,-rpath,\"\\$ORIGIN/../lib\"") +target_include_directories(${PROJECT_NAME} PUBLIC ${TOOLS_DIR}/external/eos-vm/include + ${LIB_DIR}/eosiolib/contracts + ${LIB_DIR}/eosiolib/core + ${LIB_DIR}/eosiolib/capi + ${LIB_DIR}/eosiolib/native + ${LIB_DIR}/native + ${LIB_DIR}/meta_refl/include + ${LIB_DIR}/boost/include) +target_link_libraries(${PROJECT_NAME} native_eosio native) \ No newline at end of file diff --git a/tools/antler-run/antler-run.cpp b/tools/antler-run/antler-run.cpp new file mode 100644 index 0000000000..521f7617f8 --- /dev/null +++ b/tools/antler-run/antler-run.cpp @@ -0,0 +1,50 @@ +#include "options.hpp" +#include "file-utils.hpp" + +#include +#include +#include + +#include +#include + +#include +#include + +#include "llvm/Support/CommandLine.h" + +using namespace eosio; +using namespace eosio::cdt; +using namespace eosio::native; +using namespace eosio::vm; +using namespace llvm; + +int main(int argc, const char **argv) { + + cl::SetVersionPrinter([](llvm::raw_ostream& os) { + os << "Antler-run version ${VERSION_FULL}" << "\n"; + }); + + cl::ParseCommandLineOptions(argc, argv); + + const auto& contract_path = contract_path_opt.getValue(); + + if (test_so_opt) { + auto contract_type = utils::get_file_type(contract_path.c_str()); + if ( contract_type != utils::file_type::elf_shared_object ) { + fprintf(stderr, "not a shared object file: %s\n", file_type_str(contract_type).c_str()); + } + // TODO: add check for neccesary exports + // TODO: add unit test that generates shared object and executes runner with this flag + return 0; + } + + const auto& node_url = nodeos_url_opt.getValue(); + const auto& node_port = nodeos_port_opt.getValue(); + const auto& action = action_name_opt.getValue(); + const auto& account = register_opt.getValue(); + + //TODO add runner implementation here + + return 0; +} \ No newline at end of file diff --git a/tools/antler-run/file-utils.hpp b/tools/antler-run/file-utils.hpp new file mode 100644 index 0000000000..b54f8924c9 --- /dev/null +++ b/tools/antler-run/file-utils.hpp @@ -0,0 +1,78 @@ +#pragma once + +#include + +#include +#include +#include +#include +#include + +namespace eosio { namespace utils { + +enum class file_type { + uninitialized, + non_elf_other, + elf_object, + elf_executable, + elf_shared_object, + elf_core_dump, + wasm +}; + +inline file_type get_file_type(const char* path) { + std::fstream file; + file.open(path, std::fstream::in | std::fstream::binary); + assert(file.is_open()); + + std::vector buf(17); + file.read(buf.data(), buf.size()); + + if (buf[0] == 0x7F && + buf[1] == 'E' && + buf[2] == 'L' && + buf[3] == 'F') { + //ELF binary + switch (buf[16]) { + case 1: + return file_type::elf_object; + case 2: + return file_type::elf_executable; + case 3: + return file_type::elf_shared_object; + case 4: + return file_type::elf_core_dump; + } + } else { + uint32_t wasm_magic; + memcpy(&wasm_magic, buf.data(), sizeof(wasm_magic)); + if (wasm_magic == eosio::vm::magic) + return file_type::wasm; + + return file_type::non_elf_other; + } + + return file_type::uninitialized; +} + +inline std::string file_type_str(file_type t) { + switch (t) { + case file_type::non_elf_other: + return "non elf"; + case file_type::elf_object: + return "object"; + case file_type::elf_executable: + return "executable"; + case file_type::elf_shared_object: + return "shared object"; + case file_type::elf_core_dump: + return "core dump"; + case file_type::wasm: + return "wasm"; + case file_type::uninitialized: + default: + return "uninitialized"; + } +} + +}} // eosio::utils \ No newline at end of file diff --git a/tools/antler-run/options.hpp b/tools/antler-run/options.hpp new file mode 100644 index 0000000000..3f65f18041 --- /dev/null +++ b/tools/antler-run/options.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include "llvm/Support/CommandLine.h" + +#include + +static llvm::cl::OptionCategory AntlerRunOptions("Runner options"); + +llvm::cl::opt contract_path_opt ( "contract", + llvm::cl::desc("Smart contract path to debug. It could be either wasm or native shared object"), + llvm::cl::cat(AntlerRunOptions), + llvm::cl::Required ); +llvm::cl::opt test_so_opt ( "test", + llvm::cl::desc("Test that shared object is loadable and has neccesary exports"), + llvm::cl::cat(AntlerRunOptions), + llvm::cl::ZeroOrMore ); +llvm::cl::opt nodeos_url_opt ( "nodeos-url", + llvm::cl::desc("`nodeos` URL"), + llvm::cl::cat(AntlerRunOptions), + llvm::cl::ZeroOrMore ); +llvm::cl::opt nodeos_port_opt ( "nodeos-port", + llvm::cl::desc("`nodeos` port"), + llvm::cl::cat(AntlerRunOptions), + llvm::cl::ZeroOrMore ); +llvm::cl::opt action_name_opt ( "call-action", + llvm::cl::desc("Action that will be called"), + llvm::cl::cat(AntlerRunOptions), + llvm::cl::ZeroOrMore ); +llvm::cl::opt register_opt ( "register", + llvm::cl::desc("Register an account name to be debuggable through `nodeos`"), + llvm::cl::cat(AntlerRunOptions), + llvm::cl::ZeroOrMore ); diff --git a/tools/external/CMakeLists.txt b/tools/external/CMakeLists.txt index eae7583dca..19ca931b9e 100644 --- a/tools/external/CMakeLists.txt +++ b/tools/external/CMakeLists.txt @@ -1 +1,2 @@ add_subdirectory(wabt) +add_subdirectory(eos-vm) \ No newline at end of file diff --git a/tools/external/eos-vm b/tools/external/eos-vm new file mode 160000 index 0000000000..1592261e96 --- /dev/null +++ b/tools/external/eos-vm @@ -0,0 +1 @@ +Subproject commit 1592261e96a5ebb4a5f261d7167c0723ca941b9b