好奇的探索者,理性的思考者,踏实的行动者。
Table of Contents:
为了编写自己的wasm智能合约的工具,于是参考了维基链的wasm_cdt,而维基链的代码是参考eos的。
https://github.com/WaykiChain/wicc-wasm-cdt
注意事项:
* 1.配置最低4核8G
* 2.若是虚拟机的话不要共享目录中安装
* 3.不要用自带的build.sh
来安装,因为build.sh
会检查机器的硬件和软件环境,不符合的话会报错
可以直接用cmake直接安装
mkdir build
cmake ..
make
make install
编译好之后需要进行安装,安装的路径为/usr/local/wasm.cdt
内容包括:
1.头文件 /usr/local/wasm.cdt/include
2.静态库 /usr/local/wasm.cdt/lib
3.二进制程序 /usr/local/wasm.cdt/lib
4.cmake编译时用到的文件 /usr/local/lib/cmake/wasm.cdt
master的最新代码
CMakeLists.txt中的include(modules/LibrariesExternalProject.txt)
编译的内容为libraries
目录下的内容,包括boost、libc、libc++、wasmlib
Scanning dependencies of target WasmLibraries
[ 70%] Creating directories for 'WasmLibraries'
[ 74%] No download step for 'WasmLibraries'
[ 77%] No patch step for 'WasmLibraries'
[ 81%] No update step for 'WasmLibraries'
[ 85%] Performing configure step for 'WasmLibraries'
编译libraries
中的文件需要wasm编译工具链:wasm-cc wasm-cpp wasm-ld等,
但是cmake并没有找到工具链的位置,而是用gcc的工具链去编,导致编译无法进行
把wasm.cdt的代码版本切换到v1.0的稳定版本后编译通过
可以参考eos官方文档
https://developers.eos.io/manuals/eosio.cdt/latest/how-to-guides/compile/compile-a-contract-via-cli
wasm-cpp -abigen ../src/hello.cpp -o hello.wasm -I ../include/
$ cd examples/hello
$ mkdir build
$ cd build
$ cmake ..
$ make
CMake Warning at CMakeLists.txt:4 (find_package):
By not providing "Findeosio.cdt.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"wasm.cdt", but CMake did not find one.
Could not find a package configuration file provided by "wasm.cdt" with
any of the following names:
wasm.cdtConfig.cmake
wasm.cdt-config.cmake
Add the installation prefix of "wasm.cdt" to CMAKE_PREFIX_PATH or set
"wasm.cdt_DIR" to a directory containing one of the above files. If
"wasm.cdt" provides a separate development package or SDK, be sure it has
been installed.
project(hello)
cmake_minimum_required(VERSION 3.5)
include(ExternalProject)
# if no cdt root is given use default path
if(WASM_CDT_ROOT STREQUAL "" OR NOT WASM_CDT_ROOT)
find_package(wasm.cdt)
endif()
ExternalProject_Add(
hello_project
SOURCE_DIR ${CMAKE_SOURCE_DIR}/src
BINARY_DIR ${CMAKE_BINARY_DIR}/hello
CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${WASM_CDT_ROOT}/lib/cmake/wasm.cdt/WasmWasmToolchain.cmake
UPDATE_COMMAND ""
PATCH_COMMAND ""
TEST_COMMAND ""
INSTALL_COMMAND ""
BUILD_ALWAYS 1
)
project(hello)
cmake_minimum_required(VERSION 3.5)
set(WASM_WASM_OLD_BEHAVIOR "Off")
find_package(wasm.cdt)
add_contract( hello hello hello.cpp )
target_include_directories( hello PUBLIC ${CMAKE_SOURCE_DIR}/../include )
target_ricardian_directory( hello ${CMAKE_SOURCE_DIR}/../ricardian )
根目录下的find_package可以找到,src目录下的find_package确找不到包
在src目录中的cmake文件增加如下代码,让find_package可以找到wasm.cdt的cmake配置的路径
set(wasm.cdt_DIR /usr/local/lib/cmake/wasm.cdt)