提交 86d89491 编写于 作者: D Daniel Larimer 提交者: GitHub

Merge pull request #83 from elmato/cmake-clang-wasm

Use cmake custom target to generate wast files
......@@ -159,7 +159,18 @@ if(ENABLE_COVERAGE_TESTING)
SET(CMAKE_CXX_FLAGS "--coverage ${CMAKE_CXX_FLAGS}")
endif()
add_subdirectory( contracts )
include(wasm)
if(WASM_TOOLCHAIN)
message(STATUS "Using WASM clang => " ${WASM_CLANG})
message(STATUS "Using WASM llc => " ${WASM_LLC})
message(STATUS "Using WASM llvm-link => " ${WASM_LLVM_LINK})
add_subdirectory(contracts)
else()
message(STATUS "-------------------------------------------------------------------")
message(STATUS "No WASM compiler could be found ... (skiping building of contracts)")
message(STATUS "-------------------------------------------------------------------")
endif()
add_subdirectory( libraries )
add_subdirectory( programs )
add_subdirectory( plugins )
......
set(WASM_TOOLCHAIN FALSE)
if( NOT "$ENV{WASM_LLVM_CONFIG}" STREQUAL "" )
execute_process(
COMMAND $ENV{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()
# 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)
endif()
macro(add_wast_target target SOURCE_FILES INCLUDE_FOLDERS DESTINATION_FOLDER)
# add_definitions( -DDebug )
# get_directory_property( DirDefs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS )
set(outfiles "")
foreach(srcfile ${SOURCE_FILES})
get_filename_component(outfile ${srcfile} NAME)
get_filename_component(infile ${srcfile} ABSOLUTE)
add_custom_command(OUTPUT ${outfile}.bc
DEPENDS ${infile}
COMMAND ${WASM_CLANG} -emit-llvm -O3 --std=c++14 --target=wasm32 -I ${INCLUDE_FOLDERS} -fno-threadsafe-statics -fno-rtti -fno-exceptions -c ${infile} -o ${outfile}.bc
IMPLICIT_DEPENDS CXX ${infile}
COMMENT "Building LLVM bitcode ${outfile}.bc"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
VERBATIM
)
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${outfile}.bc)
list(APPEND outfiles ${outfile}.bc)
endforeach(srcfile)
add_custom_command(OUTPUT ${target}.bc
DEPENDS ${outfiles}
COMMAND ${WASM_LLVM_LINK} -o ${target}.bc ${outfiles}
COMMENT "Linking LLVM bitcode ${target}.bc"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
VERBATIM
)
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${target}.bc)
add_custom_command(OUTPUT ${target}.s
DEPENDS ${target}.bc
COMMAND ${WASM_LLC} -asm-verbose=false -o ${target}.s ${target}.bc
COMMENT "Generating textual assembly ${target}.s"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
VERBATIM
)
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${target}.s)
add_custom_command(OUTPUT ${DESTINATION_FOLDER}/${target}.wast
DEPENDS ${target}.s
COMMAND s2wasm -o ${DESTINATION_FOLDER}/${target}.wast -s 1024 ${target}.s
COMMENT "Generating WAST ${target}.wast"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
VERBATIM
)
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${target}.wast)
add_custom_command(OUTPUT ${DESTINATION_FOLDER}/${target}.wast.hpp
DEPENDS ${DESTINATION_FOLDER}/${target}.wast
COMMAND echo "const char* currency_wast = R\"=====(" > ${DESTINATION_FOLDER}/${target}.wast.hpp
COMMAND cat ${DESTINATION_FOLDER}/${target}.wast >> ${DESTINATION_FOLDER}/${target}.wast.hpp
COMMAND echo ")=====\";" >> ${DESTINATION_FOLDER}/${target}.wast.hpp
COMMENT "Generating ${target}.wast.hpp"
VERBATIM
)
add_custom_target(${target} ALL DEPENDS ${DESTINATION_FOLDER}/${target}.wast.hpp)
endmacro(add_wast_target)
add_subdirectory(currency)
add_subdirectory(exchange)
#add_subdirectory(social)
\ No newline at end of file
file(GLOB SOURCE_FILES "*.cpp")
add_wast_target(currency "${SOURCE_FILES}" "${CMAKE_SOURCE_DIR}/contracts" ${CMAKE_CURRENT_SOURCE_DIR})
\ No newline at end of file
currency.wast: currency.cpp Makefile ../eoslib/eos.hpp currency.hpp
/usr/local/Cellar/llvm/4.0.0_1/bin/clang-4.0 -emit-llvm -O3 --std=c++14 --target=wasm32 -c currency.cpp -I.. -fno-threadsafe-statics -fno-rtti -fno-exceptions -o .currency.bc
/Users/dlarimer/Downloads/llvm/build/bin/llc -asm-verbose=false .currency.bc
/Users/dlarimer/eos/libraries/binaryen/bin/s2wasm -s 1024 .currency.s > currency.wast
wc -l currency.wast
echo 'const char* currency_wast = R"=====(' > currency.wast.hpp
cat currency.wast >> currency.wast.hpp
echo ')=====";' >> currency.wast.hpp
# /usr/local/Cellar/llvm/4.0.0_1/bin/clang-4.0 -emit-llvm -O3 --std=c++14 --target=wasm32 -nostdinc -c currency.cpp -I.. -fno-threadsafe-statics -fno-rtti -fno-exceptions -o .currency.bc
# /usr/local/Cellar/llvm/4.0.0_1/bin/clang-4.0 -emit-llvm --std=c++14 --target=wasm32 -nostdinc -c currency.cpp -I.. -fno-threadsafe-statics -fno-rtti -fno-exceptions -o .currency.bc
test.wast: test.cpp Makefile ../eoslib/eos.hpp
/usr/local/Cellar/llvm/4.0.0_1/bin/clang-4.0 -emit-llvm --std=c++14 --target=wasm32 -c test.cpp -I.. -fno-threadsafe-statics -fno-rtti -fno-exceptions -o .test.bc
/Users/dlarimer/Downloads/llvm/build/bin/llc -asm-verbose=false .test.bc
/Users/dlarimer/eos/libraries/binaryen/bin/s2wasm -s 1024 .test.s > test.wast
wc -l test.wast
echo '#pragma once ' > test.wast.hpp
echo 'const char* test_wast = R"=====(' >> test.wast.hpp
cat test.wast >> test.wast.hpp
echo ')=====";' >> test.wast.hpp
file(GLOB SOURCE_FILES "*.cpp")
add_wast_target(exchange "${SOURCE_FILES}" "${CMAKE_SOURCE_DIR}/contracts" ${CMAKE_CURRENT_SOURCE_DIR})
\ No newline at end of file
exchange.wast: exchange.cpp Makefile ../eoslib/* exchange.hpp
/usr/local/Cellar/llvm/4.0.0_1/bin/clang-4.0 -emit-llvm -O3 --std=c++14 --target=wasm32 -c exchange.cpp -I.. -fno-threadsafe-statics -fno-rtti -fno-exceptions -o .exchange.bc -I /usr/local/Cellar/llvm/4.0.0_1/include/c++/v1/
/Users/dlarimer/Downloads/llvm/build/bin/llc -asm-verbose=false .exchange.bc
/Users/dlarimer/eos/libraries/binaryen/bin/s2wasm -s 1024 .exchange.s > exchange.wast
wc -l exchange.wast
echo 'const char* exchange_wast = R"=====(' > exchange.wast.hpp
cat exchange.wast >> exchange.wast.hpp
echo ')=====";' >> exchange.wast.hpp
# /usr/local/Cellar/llvm/4.0.0_1/bin/clang-4.0 -emit-llvm -O3 --std=c++14 --target=wasm32 -nostdinc -c currency.cpp -I.. -fno-threadsafe-statics -fno-rtti -fno-exceptions -o .currency.bc
# /usr/local/Cellar/llvm/4.0.0_1/bin/clang-4.0 -emit-llvm --std=c++14 --target=wasm32 -nostdinc -c currency.cpp -I.. -fno-threadsafe-statics -fno-rtti -fno-exceptions -o .currency.bc
test.wast: test.cpp Makefile eos.hpp
/usr/local/Cellar/llvm/4.0.0_1/bin/clang-4.0 -emit-llvm -O3 --std=c++14 --target=wasm32 -nostdinc -c test.cpp -I.. -fno-threadsafe-statics -fno-rtti -fno-exceptions
/Users/dlarimer/Downloads/llvm/build/bin/llc -asm-verbose=false test.bc
/Users/dlarimer/eos/libraries/binaryen/bin/s2wasm test.s -s 1024 > test.wast
cat test.wast
file(GLOB SOURCE_FILES "*.cpp")
add_wast_target(social "${SOURCE_FILES}" "${CMAKE_SOURCE_DIR}/contracts" ${CMAKE_CURRENT_SOURCE_DIR})
\ No newline at end of file
add_subdirectory( fc )
add_subdirectory( chainbase )
add_subdirectory( wasm-jit )
#add_subdirectory( binaryen )
if(WASM_TOOLCHAIN)
add_subdirectory( binaryen )
endif()
add_subdirectory( types )
add_subdirectory( chain )
add_subdirectory( egenesis )
......
......@@ -10,7 +10,10 @@ file(GLOB UNIT_TESTS "tests/*.cpp")
add_executable( chain_test ${UNIT_TESTS} ${COMMON_SOURCES} )
target_link_libraries( chain_test eos_native_contract eos_chain chainbase eos_utilities eos_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} )
file(GLOB SLOW_TESTS "slow_tests/*.cpp")
add_executable( slow_test ${SLOW_TESTS} ${COMMON_SOURCES} )
target_link_libraries( slow_test eos_native_contract eos_chain chainbase eos_utilities eos_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} )
target_include_directories( slow_test PUBLIC ${CMAKE_SOURCE_DIR}/contracts )
if(WASM_TOOLCHAIN)
file(GLOB SLOW_TESTS "slow_tests/*.cpp")
add_executable( slow_test ${SLOW_TESTS} ${COMMON_SOURCES} )
target_link_libraries( slow_test eos_native_contract eos_chain chainbase eos_utilities eos_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} )
target_include_directories( slow_test PUBLIC ${CMAKE_SOURCE_DIR}/contracts )
add_dependencies(slow_test currency)
endif()
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册