From cdbaf067c7311070e577c56b5a799549895f3d3e Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Thu, 28 Nov 2019 20:41:28 +0100 Subject: [PATCH] Internal emscripten build cleanup --- cmake/EthCompilerSettings.cmake | 3 + scripts/travis-emscripten/emscripten.jam | 195 ++++++++++++++++++++++ scripts/travis-emscripten/install_deps.sh | 5 +- 3 files changed, 201 insertions(+), 2 deletions(-) create mode 100644 scripts/travis-emscripten/emscripten.jam diff --git a/cmake/EthCompilerSettings.cmake b/cmake/EthCompilerSettings.cmake index eb55feef1..4d24668e6 100644 --- a/cmake/EthCompilerSettings.cmake +++ b/cmake/EthCompilerSettings.cmake @@ -113,6 +113,9 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s EXTRA_EXPORTED_RUNTIME_METHODS=['cwrap','addFunction','removeFunction','Pointer_stringify','lengthBytesUTF8','_malloc','stringToUTF8','setValue']") # Do not build as a WebAssembly target - we need an asm.js output. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s WASM=0") + + # Disable warnings about not being pure asm.js due to memory growth. + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-almost-asm") endif() endif() diff --git a/scripts/travis-emscripten/emscripten.jam b/scripts/travis-emscripten/emscripten.jam new file mode 100644 index 000000000..cff1977c5 --- /dev/null +++ b/scripts/travis-emscripten/emscripten.jam @@ -0,0 +1,195 @@ +# This is a copy of emscripten.jam from https://github.com/tee3/boost-build-emscripten +# which is released under the following license: +# +# Boost Software License - Version 1.0 - August 17th, 2003 +# +# Permission is hereby granted, free of charge, to any person or organization +# obtaining a copy of the software and accompanying documentation covered by +# this license (the "Software") to use, reproduce, display, distribute, +# execute, and transmit the Software, and to prepare derivative works of the +# Software, and to permit third-parties to whom the Software is furnished to +# do so, all subject to the following: +# +# The copyright notices in the Software and this entire statement, including +# the above license grant, this restriction and the following disclaimer, +# must be included in all copies of the Software, in whole or in part, and +# all derivative works of the Software, unless such copies or derivative +# works are solely in the form of machine-executable object code generated by +# a source language processor. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +# SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +# FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# +# Boost.Build support for Emscipten. +# +# @todo add support for dynamic linking +# @todo add support for --js-library, --pre-js, and --post-js options + +import generators ; +import type ; +import toolset ; +import feature ; +import common ; +import errors ; + +if [ MATCH (--debug-configuration) : [ modules.peek : ARGV ] ] +{ + .debug-configuration = true ; +} + +# add an emscripten toolset +feature.extend toolset : emscripten ; + +# extend the target-os list to include emscripten +feature.extend target-os : emscripten ; +# make emscripten the default target-os when compiling with the emscripten toolset +feature.set-default target-os : emscripten ; + +# initialize the emscripten toolset +rule init ( version ? : command * : options * ) +{ + command = [ common.get-invocation-command emscripten : em++ : $(command) ] ; + + root = ; + if $(command) + { + root = [ common.get-absolute-tool-path $(command[-1]) ] ; + root = $(root:P) ; + + version ?= [ MATCH "^([0-9.]+)" : [ SHELL \""$(command)\" --version" ] ] ; + if $(version) + { + local actual_version = [ MATCH "^([0-9.]+)" : [ SHELL \""$(command)\" --version" ] ] ; + if $(actual_version) != $(version) + { + errors.user-error "emscripten: detected version $(actual_version) does not match desired $(version)" ; + } + } + } + else + { + errors.user-error "emscripten: em++ not found" ; + } + + local condition = [ common.check-init-parameters emscripten : version $(version) ] ; + + common.handle-options emscripten : $(condition) : $(command) : $(options) ; + + # @todo this seems to be the right way, but this is a list somehow + toolset.add-requirements emscripten:node ; + + if $(.debug-configuration) + { + ECHO "emscripten: using compiler" $(version) "at" $(root) ; + } + + toolset.flags emscripten.compile STDHDRS $(condition) : $(root)/libexec/system/include ; + toolset.flags emscripten.link STDLIBPATH $(condition) : $(root)/libexec/system/lib ; + toolset.flags emscripten AR $(condition) : $(root)/bin/emar ; + toolset.flags emscripten RANLIB $(condition) : $(root)/bin/emranlib ; +} + +type.set-generated-target-suffix EXE : emscripten : js ; +#type.set-generated-target-suffix STATIC_LIB : emscripten : bc ; +#type.set-generated-target-suffix SHARED_LIB : emscripten : bc ; +#type.set-generated-target-suffix OBJ : emscripten : bc ; + +generators.register-linker emscripten.link : OBJ STATIC_LIB : EXE : emscripten ; + +generators.register-archiver emscripten.archive : OBJ : STATIC_LIB : emscripten ; + +generators.register-c-compiler emscripten.compile.c++.preprocess : CPP : PREPROCESSED_CPP : emscripten ; +generators.register-c-compiler emscripten.compile.c.preprocess : C : PREPROCESSED_C : emscripten ; +generators.register-c-compiler emscripten.compile.c++ : CPP : OBJ : emscripten ; +generators.register-c-compiler emscripten.compile.c : C : OBJ : emscripten ; + +# Declare flags + +toolset.flags emscripten.compile OPTIONS off : -O0 ; +toolset.flags emscripten.compile OPTIONS speed : -O3 ; +toolset.flags emscripten.compile OPTIONS space : -Os ; + +toolset.flags emscripten.compile OPTIONS off : -fno-inline ; +toolset.flags emscripten.compile OPTIONS on : -Wno-inline ; +toolset.flags emscripten.compile OPTIONS full : -finline-functions -Wno-inline ; + +toolset.flags emscripten.compile OPTIONS off : -w ; +toolset.flags emscripten.compile OPTIONS on : -Wall ; +toolset.flags emscripten.compile OPTIONS all : -Wall -pedantic ; +toolset.flags emscripten.compile OPTIONS on : -Werror ; + +toolset.flags emscripten.compile OPTIONS on : -g ; +toolset.flags emscripten.compile OPTIONS on : -pg ; + +toolset.flags emscripten.compile.c++ OPTIONS off : -fno-rtti ; +toolset.flags emscripten.compile.c++ OPTIONS off : -fno-exceptions ; + +toolset.flags emscripten.compile USER_OPTIONS ; +toolset.flags emscripten.compile.c++ USER_OPTIONS ; +toolset.flags emscripten.compile DEFINES ; +toolset.flags emscripten.compile INCLUDES ; +toolset.flags emscripten.compile.c++ TEMPLATE_DEPTH ; +toolset.flags emscripten.compile.fortran USER_OPTIONS ; + +toolset.flags emscripten.link DEFAULTS : -Wno-warn-absolute-paths ; + +toolset.flags emscripten.link LIBRARY_PATH ; +toolset.flags emscripten.link FINDLIBS_ST ; +toolset.flags emscripten.link FINDLIBS_SA ; +toolset.flags emscripten.link LIBRARIES ; + +toolset.flags emscripten.link OPTIONS ; + +toolset.flags emscripten.archive AROPTIONS ; + +rule compile.c++ ( targets * : sources * : properties * ) +{ + # Some extensions are compiled as C++ by default. For others, we need to + # pass -x c++. We could always pass -x c++ but distcc does not work with it. + if ! $(>:S) in .cc .cp .cxx .cpp .c++ .C + { + LANG on $(<) = "-x c++" ; + } +} + +rule compile.c ( targets * : sources * : properties * ) +{ + LANG on $(<) = "-x c" ; +} + +actions compile.c++ +{ + "$(CONFIG_COMMAND)" $(LANG) $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<:W)" "$(>:W)" +} + +actions compile.c +{ + "$(CONFIG_COMMAND)" $(LANG) $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)" +} + +actions compile.c++.preprocess +{ + "$(CONFIG_COMMAND)" $(LANG) $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" "$(>:W)" -E >"$(<:W)" +} + +actions compile.c.preprocess +{ + "$(CONFIG_COMMAND)" $(LANG) $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" "$(>)" -E >$(<) +} + +actions link +{ + "$(CONFIG_COMMAND)" $(DEFAULTS) $(OPTIONS) -L"$(LIBRARY_PATH:W)" -L"$(STDLIBPATH:W)" -o "$(<:W)" "$(>:W)" -l"$(LIBRARIES:W)" -l"$(STDLIBRARIES:W)" +} + +RM = [ common.rm-command ] ; +actions piecemeal archive +{ + $(RM) "$(<)" + $(AR) $(AROPTIONS) rc "$(<:W)" "$(>:W)" +} diff --git a/scripts/travis-emscripten/install_deps.sh b/scripts/travis-emscripten/install_deps.sh index fc81851c2..7544da4e2 100755 --- a/scripts/travis-emscripten/install_deps.sh +++ b/scripts/travis-emscripten/install_deps.sh @@ -29,6 +29,8 @@ set -ev +SCRIPT_DIR="$(realpath $(dirname $0))" + echo -en 'travis_fold:start:installing_dependencies\\r' test -e boost_1_70_0_install/include/boost/version.hpp || ( rm -rf boost_1_70_0 @@ -40,8 +42,7 @@ tar -xzf boost.tar.gz rm boost.tar.gz cd boost_1_70_0 ./bootstrap.sh -wget -q 'https://raw.githubusercontent.com/tee3/boost-build-emscripten/master/emscripten.jam' -test "$(shasum emscripten.jam)" = "a7e13fc2c1e53b0e079ef440622f879aa6da3049 emscripten.jam" +cp "${SCRIPT_DIR}/emscripten.jam" . echo "using emscripten : : em++ ;" >> project-config.jam ) cd ..