Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1412 from asiniscalchi/dev_cmake_using_finds
Browse files Browse the repository at this point in the history
[cmake] add FindWasm.cmake and binaryen code into the repo
  • Loading branch information
b1bart authored Feb 27, 2018
2 parents 96e6c21 + d1201ca commit 4773369
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 71 deletions.
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
[submodule "externals/binaryen"]
path = externals/binaryen
url = https://github.com/EOSIO/binaryen

2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ endif()
add_subdirectory( externals )

include(wasm)
if(WASM_TOOLCHAIN)
if(WASM_TOOLCHAIN_FOUND)
message(STATUS "Using WASM clang => " ${WASM_CLANG})
message(STATUS "Using WASM llc => " ${WASM_LLC})
message(STATUS "Using WASM llvm-link => " ${WASM_LLVM_LINK})
Expand Down
17 changes: 17 additions & 0 deletions CMakeModules/FindWasm.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# - Try to find WASM
# Once done this will define
# WASM_FOUND - System has WASM

# TODO: Check if compiler is able to generate wasm32

find_file(WASM_LLVM_CONFIG llvm-config HINTS ${WASM_ROOT}/bin)
find_program(WASM_CLANG clang HINTS ${WASM_ROOT}/bin)
find_program(WASM_LLC llc HINTS ${WASM_ROOT}/bin)
find_program(WASM_LLVM_LINK llvm-link HINTS ${WASM_ROOT}/bin)

include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set EOS_FOUND to TRUE
# if all listed variables are TRUE

find_package_handle_standard_args(WASM DEFAULT_MSG WASM_LLVM_CONFIG WASM_CLANG WASM_LLC WASM_LLVM_LINK)

34 changes: 5 additions & 29 deletions CMakeModules/wasm.cmake
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
set(WASM_TOOLCHAIN FALSE)
find_package(Wasm)

if(NOT DEFINED WASM_LLVM_CONFIG)
if(NOT "$ENV{WASM_LLVM_CONFIG}" STREQUAL "")
set(WASM_LLVM_CONFIG "$ENV{WASM_LLVM_CONFIG}" CACHE FILEPATH "Location of llvm-config compiled with WASM support.")
endif()
endif()

if(WASM_LLVM_CONFIG)
execute_process(
COMMAND ${WASM_LLVM_CONFIG} --bindir
RESULT_VARIABLE WASM_LLVM_CONFIG_OK
OUTPUT_VARIABLE WASM_LLVM_BIN
)

if("${WASM_LLVM_CONFIG_OK}" STREQUAL "0")
string(STRIP "${WASM_LLVM_BIN}" WASM_LLVM_BIN)
set(WASM_CLANG ${WASM_LLVM_BIN}/clang)
set(WASM_LLC ${WASM_LLVM_BIN}/llc)
set(WASM_LLVM_LINK ${WASM_LLVM_BIN}/llvm-link)
endif()

else()
set(WASM_CLANG $ENV{WASM_CLANG})
set(WASM_LLC $ENV{WASM_LLC})
set(WASM_LLVM_LINK $ENV{WASM_LLVM_LINK})
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(WASM_TOOLCHAIN DEFAULT_MSG WASM_FOUND)

# TODO: Check if compiler is able to generate wasm32
if( NOT ("${WASM_CLANG}" STREQUAL "" OR "${WASM_LLC}" STREQUAL "" OR "${WASM_LLVM_LINK}" STREQUAL "") )
set(WASM_TOOLCHAIN TRUE)
if (NOT WASM_TOOLCHAIN_FOUND)
return()
endif()

macro(compile_wast)
Expand Down
2 changes: 1 addition & 1 deletion Docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ RUN git clone --depth 1 -b releases/stable git://github.com/mongodb/mongo-cxx-dr

RUN git clone -b master --depth 1 https://github.com/EOSIO/eos.git --recursive \
&& cd eos \
&& cmake -H. -B"/tmp/build" -GNinja -DCMAKE_BUILD_TYPE=Release -DWASM_LLVM_CONFIG=/opt/wasm/bin/llvm-config -DCMAKE_CXX_COMPILER=clang++ \
&& cmake -H. -B"/tmp/build" -GNinja -DCMAKE_BUILD_TYPE=Release -DWASM_ROOT=/opt/wasm -DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_C_COMPILER=clang -DCMAKE_INSTALL_PREFIX=/opt/eos -DSecp256k1_ROOT_DIR=/usr/local \
&& cmake --build /tmp/build --target install

Expand Down
33 changes: 1 addition & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,11 @@ git submodule update --init --recursive
<a name="build"></a>
### Building from source code

The *WASM_LLVM_CONFIG* environment variable is used to find our recently built WASM compiler.
This is needed to compile the example contracts inside `eos/contracts` folder and their respective tests.

```bash
cd ~
git clone https://github.com/eosio/eos --recursive
mkdir -p ~/eos/build && cd ~/eos/build
cmake -DBINARYEN_BIN=~/binaryen/bin -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib ..
cmake -DBINARYEN_BIN=~/binaryen/bin -DWASM_ROOT=~/wasm-compiler/llvm -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib ..
make -j$( nproc )
```

Expand Down Expand Up @@ -643,13 +640,6 @@ make -j$( nproc )
make install
```

Add `WASM_LLVM_CONFIG` and `LLVM_DIR` to your `.bash_profile`:

```bash
echo "export WASM_LLVM_CONFIG=~/wasm-compiler/llvm/bin/llvm-config" >> ~/.bash_profile
echo "export LLVM_DIR=~/wasm-compiler/lib/cmake/llvm" >> ~/.bash_profile
source ~/.bash_profile
```
Your environment is set up. Now you can <a href="#runanode">build EOS and run a node</a>.

<a name="manualdepfedora"></a>
Expand Down Expand Up @@ -724,13 +714,6 @@ cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=.. -DLLVM_TARGETS_TO_BUILD= -DL
make -j$( nproc ) install
```

Add `WASM_LLVM_CONFIG` and `LLVM_DIR` to your `.bash_profile`:

```bash
echo "export WASM_LLVM_CONFIG=~/wasm-compiler/llvm/bin/llvm-config" >> ~/.bash_profile
echo "export LLVM_DIR=~/wasm-compiler/lib/cmake/llvm" >> ~/.bash_profile
source ~/.bash_profile
```
Your environment is set up. Now you can <a href="#runanode">build EOS and run a node</a>.

<a name="manualdepubuntu"></a>
Expand Down Expand Up @@ -806,13 +789,6 @@ cd build
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=.. -DLLVM_TARGETS_TO_BUILD= -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly -DCMAKE_BUILD_TYPE=Release ../
make -j4 install
```
Add `WASM_LLVM_CONFIG` and `LLVM_DIR` to your `.bash_profile`:

```bash
echo "export WASM_LLVM_CONFIG=~/wasm-compiler/llvm/bin/llvm-config" >> ~/.bash_profile
echo "export LLVM_DIR=/usr/local/Cellar/llvm/4.0.1/lib/cmake/llvm" >> ~/.bash_profile
source ~/.bash_profile
```

Your environment is set up. Now you can <a href="#runanode">build EOS and run a node</a>.

Expand Down Expand Up @@ -889,11 +865,4 @@ make -j$( sysctl -in machdep.cpu.core_count )
make install
```

Add `WASM_LLVM_CONFIG` and `LLVM_DIR` to your `.bash_profile`:

```bash
echo "export WASM_LLVM_CONFIG=~/wasm-compiler/llvm/bin/llvm-config" >> ~/.bash_profile
echo "export LLVM_DIR=/usr/local/Cellar/llvm@4/4.0.1/lib/cmake/llvm/" >> ~/.bash_profile
source ~/.bash_profile
```
Your environment is set up. Now you can <a href="#runanode">build EOS and run a node</a>.
8 changes: 4 additions & 4 deletions eosio_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
export BOOST_ROOT=${HOME}/opt/boost_1_66_0
export OPENSSL_ROOT_DIR=/usr/include/openssl
export OPENSSL_LIBRARIES=/usr/include/openssl
export WASM_LLVM_CONFIG=${HOME}/opt/wasm/bin/llvm-config
export WASM_ROOT=${HOME}/opt/wasm

. $FILE

Expand All @@ -92,7 +92,7 @@
if [ $ARCH == "Darwin" ]; then
OPENSSL_ROOT_DIR=/usr/local/opt/openssl
OPENSSL_LIBRARIES=/usr/local/opt/openssl/lib
WASM_LLVM_CONFIG=/usr/local/wasm/bin/llvm-config
WASM_ROOT=/usr/local/wasm
CXX_COMPILER=clang++
C_COMPILER=clang

Expand All @@ -119,8 +119,8 @@

# Build EOS
$CMAKE -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_CXX_COMPILER=${CXX_COMPILER} \
-DCMAKE_C_COMPILER=${C_COMPILER} -DWASM_LLVM_CONFIG=${WASM_LLVM_CONFIG} \
-DOPENSSL_ROOT_DIR=${OPENSSL_ROOT_DIR} \
-DCMAKE_C_COMPILER=${C_COMPILER} -DWASM_ROOT=${WASM_ROOT} \
-DOPENSSL_ROOT_DIR=${OPENSSL_ROOT_DIR} \
-DOPENSSL_LIBRARIES=${OPENSSL_LIBRARIES} ..
if [ $? -ne 0 ]; then
printf "\n\t>>>>>>>>>>>>>>>>>>>> CMAKE building EOSIO has exited with the above error.\n\n"
Expand Down
2 changes: 1 addition & 1 deletion plugins/txn_test_gen_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if(WASM_TOOLCHAIN)
if(WASM_TOOLCHAIN_FOUND)
file(GLOB HEADERS "include/eosio/txn_test_gen_plugin/*.hpp")
add_library( txn_test_gen_plugin
txn_test_gen_plugin.cpp
Expand Down
6 changes: 3 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ include_directories("${CMAKE_SOURCE_DIR}/contracts")

file(GLOB UNIT_TESTS "chain_tests/*.cpp" "api_tests/*.cpp" "tests/abi_tests.cpp" "tests/database_tests.cpp" "tests/misc_tests.cpp")

if(WASM_TOOLCHAIN)
if(WASM_TOOLCHAIN_FOUND)
file(GLOB WASM_UNIT_TESTS "wasm_tests/*.cpp")
endif()

add_executable( chain_test ${UNIT_TESTS} ${WASM_UNIT_TESTS} common/main.cpp )
target_link_libraries( chain_test eosio_testing eosio_chain chainbase eos_utilities eos_egenesis_none chain_plugin abi_generator fc ${PLATFORM_SPECIFIC_LIBS} )

if(WASM_TOOLCHAIN)
if(WASM_TOOLCHAIN_FOUND)
target_include_directories( chain_test PUBLIC ${CMAKE_BINARY_DIR}/contracts ${CMAKE_CURRENT_BINARY_DIR}/tests/contracts )
target_include_directories( chain_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/wasm_tests )
add_dependencies(chain_test asserter test_api currency proxy identity identity_test stltest infinite)
endif()


# WASM only tests
#if(WASM_TOOLCHAIN)
#if(WASM_TOOLCHAIN_FOUND)
# file(GLOB SLOW_TESTS "slow_tests/*.cpp")
# add_executable( slow_test ${SLOW_TESTS} ${COMMON_SOURCES} )
# target_link_libraries( slow_test eos_native_contract eosio_chain chainbase eos_utilities eos_egenesis_none chain_plugin producer_plugin fc ${PLATFORM_SPECIFIC_LIBS} )
Expand Down

0 comments on commit 4773369

Please sign in to comment.