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

[cmake] add FindWasm.cmake and binaryen code into the repo #1412

Merged
merged 23 commits into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6fd5d62
[cmake] FindBinaryen
asiniscalchi Feb 17, 2018
630b108
[cmake] add FindWasm.cmake
asiniscalchi Feb 17, 2018
6f835a3
[travis] fix cmake defines
asiniscalchi Feb 17, 2018
deeb424
[cmake] WAST_TOOLCHAIN -> WAST_TOOLCHAIN_FOUND
asiniscalchi Feb 17, 2018
54c7615
[cmake] move TODO
asiniscalchi Feb 17, 2018
96533a5
fix bootstrap script
asiniscalchi Feb 17, 2018
2ecf14c
Merge branch 'master' into dev_cmake_using_finds
asiniscalchi Feb 21, 2018
bd6529f
[cmake] FindBinaryen search for include dir and libraries
asiniscalchi Feb 23, 2018
ff86b55
[cmake] removed space
asiniscalchi Feb 23, 2018
3b99d30
[cmake] WASM_TOOLCHAIN found by cmake tools
asiniscalchi Feb 23, 2018
b00680b
Merge branch 'master' into dev_cmake_using_finds
asiniscalchi Feb 23, 2018
403222d
[cmake] removed unusefull part of FindBinaryen.cmake
asiniscalchi Feb 24, 2018
87df018
added binaryen into the source code
asiniscalchi Feb 24, 2018
91e5133
compile binaryen
asiniscalchi Feb 24, 2018
c2305ef
Merge branch 'dev_binaryen_into_source' into dev_cmake_using_finds
asiniscalchi Feb 24, 2018
22e8563
using binaryen submodule
asiniscalchi Feb 24, 2018
6fcd58f
[cmake] make WASM_TOOLCHAIN mandatory (for a while)
asiniscalchi Feb 24, 2018
7d65a18
merging master @ f66d188c to resolve conflicts
b1bart Feb 26, 2018
1b74d35
Change binaryen submodule to point to EOSIOs fork with the changes fo…
b1bart Feb 26, 2018
c701f0c
using WASM_ROOT in Docker
asiniscalchi Feb 27, 2018
22ad4a8
update doc
asiniscalchi Feb 27, 2018
502c569
Merge branch 'master' into dev_cmake_using_finds
asiniscalchi Feb 27, 2018
d1201ca
remove stale submodule files
b1bart Feb 27, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@
path = contracts/libc++/upstream
url = https://github.com/EOSIO/libcxx.git
branch = eosio
[submodule "external/binaryen"]
path = external/binaryen
url = https://github.com/EOSIO/binaryen.git
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,10 @@ if(ENABLE_COVERAGE_TESTING)
find_program( GENHTML_PATH NAMES genhtml)
endif()

add_subdirectory(external)

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)

63 changes: 6 additions & 57 deletions CMakeModules/wasm.cmake
Original file line number Diff line number Diff line change
@@ -1,61 +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()

if( NOT ("${WASM_CLANG}" STREQUAL "" OR "${WASM_LLC}" STREQUAL "" OR "${WASM_LLVM_LINK}" STREQUAL "") )
if( NOT "${BINARYEN_ROOT}" STREQUAL "" )

if(EXISTS "${BINARYEN_ROOT}/bin/s2wasm")

set(BINARYEN_BIN ${BINARYEN_ROOT}/bin)

endif()

else()

message(STATUS "BINARYEN_BIN not defined looking in PATH")
find_path(BINARYEN_BIN
NAMES s2wasm
ENV PATH )
if (BINARYEN_BIN AND NOT EXISTS ${BINARYEN_ROOT}/s2wasm)

unset(BINARYEN_BIN)

endif()

endif()

message(STATUS "BINARYEN_BIN => " ${BINARYEN_BIN})

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 "" OR NOT BINARYEN_BIN) )
set(WASM_TOOLCHAIN TRUE)
if (NOT WASM_TOOLCHAIN_FOUND)
return()
endif()

macro(compile_wast)
Expand Down Expand Up @@ -199,7 +148,7 @@ macro(add_wast_executable)

add_custom_command(OUTPUT ${DESTINATION_FOLDER}/${target}.wast
DEPENDS ${target}.s
COMMAND ${BINARYEN_BIN}/s2wasm -o ${DESTINATION_FOLDER}/${target}.wast -s 4096 ${MAX_MEMORY_PARAM} ${target}.s
COMMAND "$<TARGET_FILE:s2wasm>" -o ${DESTINATION_FOLDER}/${target}.wast -s 4096 ${MAX_MEMORY_PARAM} ${target}.s
COMMENT "Generating WAST ${target}.wast"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
VERBATIM
Expand Down
10 changes: 4 additions & 6 deletions eosio_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@
esac

export BOOST_ROOT=${HOME}/opt/boost_1_66_0
export BINARYEN_BIN=${HOME}/opt/binaryen/bin
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 @@ -93,8 +92,7 @@
if [ $ARCH == "Darwin" ]; then
OPENSSL_ROOT_DIR=/usr/local/opt/openssl
OPENSSL_LIBRARIES=/usr/local/opt/openssl/lib
BINARYEN_BIN=/usr/local/binaryen/bin/
WASM_LLVM_CONFIG=/usr/local/wasm/bin/llvm-config
WASM_ROOT=/usr/local/wasm
CXX_COMPILER=clang++
C_COMPILER=clang

Expand All @@ -121,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} \
-DBINARYEN_BIN=${BINARYEN_BIN} -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
1 change: 1 addition & 0 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(binaryen)
1 change: 1 addition & 0 deletions external/binaryen
Submodule binaryen added at b21be8
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, there is no "successful" cmake run where WASM_TOOLCHAIN_FOUND would be false. Most of these conditionals can be removed in favor of running the side of the branch that corresponds with success.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. I was trying to mimic the master branch behavior

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