Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multithreading #97

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
37 changes: 27 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project(monero-javascript-wasm)
# build with exception whitelist from file
file(STRINGS wasm_exception_whitelist.txt WASM_EXCEPTION_WHITELIST)
string(REPLACE ";" "," WASM_EXCEPTION_WHITELIST "${WASM_EXCEPTION_WHITELIST}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Oz -s EXCEPTION_CATCHING_ALLOWED='[${WASM_EXCEPTION_WHITELIST}]'")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pthread -Oz -s EXCEPTION_CATCHING_ALLOWED='[${WASM_EXCEPTION_WHITELIST}]'")
add_definitions(-DAUTO_INITIALIZE_EASYLOGGINGPP -DNO_AES)

set(BUILD_MONERO_WALLET_FULL_WASM ON)
Expand Down Expand Up @@ -65,6 +65,13 @@ include_directories("${MONERO_PROJECT}/contrib/epee/include/net")
include_directories("${MONERO_PROJECT}/build/release/translations")
include_directories("${MONERO_PROJECT}/build/release/generated_include")

#############
# Unbound
#############

include_directories("/usr/include") # linux
include_directories("/usr/local/opt/unbound/include") # mac

#############
# OpenSSL
#############
Expand All @@ -76,11 +83,11 @@ set(OPENSSL ${CMAKE_SOURCE_DIR}/build/openssl)
include_directories("${OPENSSL}")
include_directories("${OPENSSL}/include") # must exist already - run bin/build-openssl-emscripten.sh

add_library(openssl_crypto STATIC IMPORTED)
set_target_properties(
openssl_crypto PROPERTIES IMPORTED_LOCATION
${OPENSSL}/lib/libcrypto.a
)
#add_library(openssl_crypto STATIC IMPORTED)
#set_target_properties(
#openssl_crypto PROPERTIES IMPORTED_LOCATION
#${OPENSSL}/lib/libcrypto.a
#)

add_library(openssl_ssl STATIC IMPORTED)
set_target_properties(
Expand Down Expand Up @@ -255,22 +262,27 @@ set(
####################

#-s USE_PTHREADS=1 \
#-s PTHREAD_POOL_SIZE=2 \

#-s PROXY_TO_PTHREAD \
#-s DISABLE_EXCEPTION_CATCHING=0 \
#-s ASYNCIFY=1 \
#-s 'ASYNCIFY_IMPORTS=[\"js_send_json_request\",\"js_send_binary_request\",\"emscripten_sleep\"]' \
#-s ALLOW_MEMORY_GROWTH=0 \
#-s INITIAL_MEMORY=1536MB \
#-s USE_PTHREADS=1 \

#-s ENVIRONMENT=worker \


set (
EMCC_LINKER_FLAGS_BASE

# unsure if the -I...boost..include is necessary here due to include above
# TODO? does EXPORT_NAME need to be the same for both targets? (or should it be set per-target with …_WASM, …_ASMJS?)

"-Wall -Werror -Wl,--allow-undefined -std=c++11 -Oz \
--bind -s MODULARIZE=1 \
"-Wall -Werror -Wl,--allow-undefined -std=c++14 -pthread -Oz \
--bind \
-s MODULARIZE=1 \
-s 'EXPORT_NAME=\"monero_javascript\"' \
-s ERROR_ON_UNDEFINED_SYMBOLS=0 \
-s ASSERTIONS=0 \
Expand All @@ -283,7 +295,12 @@ EMCC_LINKER_FLAGS_BASE
-s RESERVED_FUNCTION_POINTERS=5 \
-s EXPORTED_RUNTIME_METHODS='[\"UTF8ToString\",\"stringToUTF8\",\"lengthBytesUTF8\",\"intArrayToString\",\"getTempRet0\",\"addFunction\"]' \
-s WASM=1 \
-s ALLOW_MEMORY_GROWTH=1 \
-s USE_PTHREADS=1 \
-s PROXY_TO_PTHREAD=0 \
-s ALLOW_MEMORY_GROWTH=0 \
-s INITIAL_MEMORY=1536MB \
-s PTHREAD_POOL_SIZE=16 \
-s ASSERTIONS=1 \
"
# • Disabling exception catching does not introduce silent failures
# • Probably don't need PRECISE_F32 but wouldn't want to not use it
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Monero JavaScript Library

A JavaScript library for creating Monero applications using RPC and WebAssembly bindings to [monero v0.18.0.0 'Flourine Fermie'](https://github.com/monero-project/monero/tree/v0.18.0.0).
A JavaScript library for creating Monero applications using RPC and WebAssembly bindings to [monero v0.18.1.0 'Flourine Fermie'](https://github.com/monero-project/monero/tree/v0.18.1.0).

* Supports browser and Node.js applications using WebAssembly.
* Supports wallet and daemon RPC clients.
Expand Down Expand Up @@ -122,7 +122,7 @@ await walletFull.close(true);
## Using monero-javascript in your project

1. `cd your_project` or `mkdir your_project && cd your_project && npm init`
2. `npm install [email protected].2`
2. `npm install [email protected].3`
3. Add `require("monero-javascript")` to your application code.
4. If building a browser application, copy assets from ./dist to your web app's build directory as needed.

Expand All @@ -146,7 +146,8 @@ Compiled WebAssembly binaries are committed to ./dist for convenience, but these
3. `cd monero-javascript`
4. `./bin/update_submodules.sh`
5. Modify ./external/monero-cpp/external/monero-project/src/crypto/wallet/CMakeLists.txt from `set(MONERO_WALLET_CRYPTO_LIBRARY "auto" ...` to `set(MONERO_WALLET_CRYPTO_LIBRARY "cn" ...`.
6. `./bin/build_all.sh` (install [monero-project dependencies](https://github.com/monero-project/monero#dependencies) as needed for your system)
6. Build [unbound](https://unbound.docs.nlnetlabs.nl/en/latest/getting-started/installation.html) for your system.
7. `./bin/build_all.sh` (install [monero-project dependencies](https://github.com/monero-project/monero#dependencies) as needed for your system)

## Running tests

Expand Down
1 change: 1 addition & 0 deletions bin/build_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

# build monero-project translations directory
cd ./external/monero-cpp/external/monero-project || exit 1
git submodule update --init --force || exit 1
HOST_NCORES=$(nproc 2>/dev/null || shell nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 1)
make release-static -j$HOST_NCORES # don't exit because this will build translations directory even if build fails
cd ../../../../ || exit 1
Expand Down
8 changes: 4 additions & 4 deletions bin/build_boost_emscripten.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

. $(dirname $0)/emsdk_inc.sh
. $(dirname $0)/download_deps.sh
[ -f $(dirname $0)/colors.sh ] && . $(dirname $0)/colors.sh

PLATFORM="emscripten"
Expand Down Expand Up @@ -87,7 +87,7 @@ export NO_BZIP2=1 #bc it's supplied by emscripten but b2 will fail to find it


./bootstrap.sh \
--with-libraries=system,thread,chrono,serialization,regex \
--with-libraries=system,thread,chrono,serialization,regex,atomic \
2>&1

if [ $? != 0 ]; then
Expand All @@ -107,11 +107,11 @@ HOST_NCORES=$(nproc 2>/dev/null|| shell nproc 2>/dev/null || sysctl -n hw.ncpu 2

./b2 -q -a -j $HOST_NCORES \
toolset=clang-emscripten \
threading=single \
threading=multi \
link=static \
optimization=space \
variant=release \
cxxflags=-no-pthread \
cxxflags=-pthread \
stage \
--stagedir="$INSTALL_PATH" \
2>&1
Expand Down
4 changes: 2 additions & 2 deletions bin/build_openssl_emscripten.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

. $(dirname $0)/emsdk_inc.sh
. $(dirname $0)/download_deps.sh
[ -f $(dirname $0)/colors.sh ] && . $(dirname $0)/colors.sh

PLATFORM="emscripten"
Expand Down Expand Up @@ -67,7 +67,7 @@ cd "$SRC_PATH"

perl ./Configure \
linux-generic32 \
-no-asm no-ssl2 no-ssl3 no-comp no-engine no-deprecated no-tests no-dso no-shared no-threads disable-shared \
-no-asm no-ssl2 no-ssl3 no-comp no-engine no-deprecated no-tests no-dso no-shared disable-shared \
--prefix="$INSTALL_PATH" \
--openssldir="$INSTALL_PATH" \
2>&1
Expand Down
10 changes: 10 additions & 0 deletions bin/build_wasm_emscripten.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ mkdir -p ./dist || exit 1
&& {
mv ./build/monero_wallet_keys.wasm ./dist/
}

[ -f ./build/monero_wallet_keys.worker.js ] \
&& {
mv ./build/monero_wallet_keys.worker.js ./dist/
}

[ -f ./build/monero_wallet_full.js ] \
&& {
Expand All @@ -39,4 +44,9 @@ mkdir -p ./dist || exit 1
[ -f ./build/monero_wallet_full.wasm ] \
&& {
mv ./build/monero_wallet_full.wasm ./dist/
}

[ -f ./build/monero_wallet_full.worker.js ] \
&& {
mv ./build/monero_wallet_full.worker.js ./dist/
}
4 changes: 2 additions & 2 deletions bin/emsdk_inc.sh → bin/download_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ get_openssl_source() {
[ -d ${SDK_PATH} ] || { echo "get_openssl_source: Missing directory: ${SDK_PATH}"; return 1; }

local DL_URL="https://github.com/openssl/openssl/archive"
local DL_FILE="OpenSSL_1_1_1m.tar.gz"
local DL_FILE="OpenSSL_1_1_1q.tar.gz"

check_archive "${SDK_PATH}/${DL_FILE}" \
&& {
Expand All @@ -190,7 +190,7 @@ get_openssl_source() {
}

mkdir ${SDK_PATH}/openssl-sdk
tar -C ${SDK_PATH}/openssl-sdk --strip-components=1 -xvf ${SDK_PATH}/OpenSSL_1_1_1m.tar.gz || return 1
tar -C ${SDK_PATH}/openssl-sdk --strip-components=1 -xvf ${SDK_PATH}/OpenSSL_1_1_1q.tar.gz || return 1

return 0
}
4 changes: 2 additions & 2 deletions configs/emscripten.jam
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ local EMSCRIPTEN = [ os.environ EMSCRIPTEN ] ;

using clang : emscripten
:
emcc -v -s USE_ZLIB=1 -s USE_PTHREADS=0
emcc -v -pthread -s USE_ZLIB=1 -s USE_PTHREADS=1
:
<root>$(EMSCRIPTEN)
<archiver>$(EMSCRIPTEN)/emar
<ranlib>$(EMSCRIPTEN)/emranlib
<linker>$(EMSCRIPTEN)/emlink
<cxxflags>-std=c++11
<cxxflags>-std=c++14
;


Expand Down
2 changes: 1 addition & 1 deletion external/monero-cpp
Loading