Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty antler-run with eos-vm and eosiolib linked #94

Merged
merged 14 commits into from
Feb 13, 2023
Merged
6 changes: 5 additions & 1 deletion .cicd/platforms/ubuntu18.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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*
rm -rf Python*

ENV CC=gcc-8
ENV CXX=g++-8
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
118 changes: 71 additions & 47 deletions libraries/eosiolib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 $<TARGET_FILE:eosio> ${BASE_BINARY_DIR}/lib )
add_custom_command( TARGET eosio_malloc POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:eosio_malloc> ${BASE_BINARY_DIR}/lib )
add_custom_command( TARGET eosio_dsm POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:eosio_dsm> ${BASE_BINARY_DIR}/lib )
add_custom_command( TARGET eosio_cmem POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:eosio_cmem> ${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 $<TARGET_FILE:native_eosio> ${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 $<TARGET_FILE:eosio> ${BASE_BINARY_DIR}/lib )
add_custom_command( TARGET eosio_malloc POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:eosio_malloc> ${BASE_BINARY_DIR}/lib )
add_custom_command( TARGET eosio_dsm POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:eosio_dsm> ${BASE_BINARY_DIR}/lib )
add_custom_command( TARGET eosio_cmem POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:eosio_cmem> ${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 $<TARGET_FILE:native_eosio> ${BASE_BINARY_DIR}/lib )
endif()

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../eosiolib DESTINATION ${BASE_BINARY_DIR}/include FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
endif()
2 changes: 2 additions & 0 deletions libraries/eosiolib/capi/eosio/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#pragma once

#include "types.h"
#include "eosio/types.hpp"

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
14 changes: 12 additions & 2 deletions libraries/eosiolib/capi/eosio/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,25 @@ 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")))
ScottBailey marked this conversation as resolved.
Show resolved Hide resolved
#else
__attribute__((deprecated("newer public key types cannot be represented as a fixed size structure", "char[]")))
#endif
capi_public_key {
char data[34];
};

/**
* 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];
};
Expand Down
4 changes: 2 additions & 2 deletions libraries/eosiolib/contracts/eosio/action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions libraries/eosiolib/core/eosio/datastream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <optional>
#include <variant>

#include <cstring>

#include <boost/fusion/algorithm/iteration/for_each.hpp>
#include <boost/fusion/include/for_each.hpp>
#include <boost/fusion/adapted/std_tuple.hpp>
Expand Down
1 change: 1 addition & 0 deletions libraries/eosiolib/core/eosio/fixed_bytes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
#pragma once
#include "datastream.hpp"
#include "types.hpp"

#include <array>
#include <algorithm>
Expand Down
2 changes: 1 addition & 1 deletion libraries/eosiolib/core/eosio/print.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#pragma once
#include <utility>
#include <string>

#include "types.hpp"


namespace eosio {
Expand Down
2 changes: 1 addition & 1 deletion libraries/eosiolib/core/eosio/reflect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
#include <bluegrass/meta/refl.hpp>

#define CDT_REFLECT(...) \
BLUEGRASS_META_REFL(__VA_ARGS__); \
BLUEGRASS_META_REFL(__VA_ARGS__);
10 changes: 10 additions & 0 deletions libraries/eosiolib/core/eosio/types.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* @file
* @copyright defined in eos/LICENSE
*/
#pragma once

#ifdef __GNUC__
typedef __int128 int128_t;
typedef unsigned __int128 uint128_t;
#endif
4 changes: 4 additions & 0 deletions libraries/eosiolib/malloc.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <cstdlib>
#include <alloca.h>
#include <string.h>
#include "core/eosio/check.hpp"
#include "core/eosio/print.hpp"

Expand Down Expand Up @@ -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);
}
Expand All @@ -542,5 +545,6 @@ void* realloc(void* ptr, size_t size) {
void free(void* ptr) {
return eosio::memory_heap.free(ptr);
}
#endif
}

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

#define BLUEGRASS_HAS_TEMPLATE_MEMBER(ARG, NAME) \
bluegrass::meta::overloaded { \
[&](auto&& f, std::enable_if_t<std::is_class_v<std::decay_t<decltype(f)>> && \
[](auto&& f, std::enable_if_t<std::is_class_v<std::decay_t<decltype(f)>> && \
bluegrass::meta::detail::pass_type< \
decltype(&std::decay_t<decltype(f)>::type::template NAME)>(), int> = 0) constexpr { \
return true; \
Expand Down
33 changes: 26 additions & 7 deletions libraries/native/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
set(PARENT_PROJECT_NAME ${PROJECT_NAME})

project(native LANGUAGES CXX ASM)

if (NOT __APPLE)
Expand All @@ -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")
Expand Down Expand Up @@ -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 $<TARGET_FILE:native> ${BASE_BINARY_DIR}/lib )
if (NOT ${PARENT_PROJECT_NAME} MATCHES "cdt_tools")
add_custom_command( TARGET native POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:native> ${BASE_BINARY_DIR}/lib )

add_custom_command( TARGET sf POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:sf> ${BASE_BINARY_DIR}/lib )
add_custom_command( TARGET sf POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:sf> ${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()
3 changes: 3 additions & 0 deletions libraries/native/crt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ extern "C" {
}
}

jmp_buf* __get_jmp_buf() {
return ___env_ptr;
}
void __set_env_test() {
___env_ptr = &test_env;
}
Expand Down
45 changes: 45 additions & 0 deletions libraries/native/crt_lib.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "native/eosio/crt.hpp"

#include <cstdio>

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);
}
}
Loading