-
Notifications
You must be signed in to change notification settings - Fork 71
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
[feature] Make it easier to use monero-javascript for front end development #83
Comments
I support this and would also like to see typescript implemented. I'm looking for help on both. Thanks. |
I was looking to use this thing in sveltekit, but that seems to be blocked by the vite tooling. vitejs/vite#5075 links to a bunch of issues describing the problem. It's not really a Edit: Maybe this Using WASM in SvelteKit can bring me closer. |
I've been messing around with this off and on. Here's a workaround to get something going with create-react-app:
|
I'm hoping svelte-emscripten is up for the task. The required emscripten linker flags got me worried, as I can't find those. What do you think @woodser ? ✔️ How to UseWhen you compile your program in Emscripten, use the output filetype *.js and use the linker flags below. These are required to adapt your program into component form:
Then, use the component in your Svelte app: import { default as Emscripten } from 'svelte-emscripten';
import { default as module } from './module.js';
<Emscripten
module={module}
canvas={true}
console={false}
verticalOrientation={false}
options={
{
autorun: true,
wasmPath: 'path/to/module.wasm'
}
}
/> |
I'm not getting far enough to start tweaking linker flags. Trying to build standard on -- Configuring done
-- Generating done
-- Build files have been written to: /path/to/build-monero-javascript/github-monero-javascript/build
make: cmake --build . -j4
Unknown argument -j4
Usage: cmake --build <dir> [options] [-- [native-options]]
Options:
<dir> = Project binary directory to be built.
--target <tgt> = Build <tgt> instead of default targets.
--config <cfg> = For multi-configuration tools, choose <cfg>.
--clean-first = Build target 'clean' first, then build.
(To clean only, use --target 'clean'.)
--use-stderr = Ignored. Behavior is default in CMake >= 3.0.
-- = Pass remaining options to the native tool.
emmake: error: 'cmake --build . -j4' failed (returned 1) |
The build script: #!/bin/bash
BASE=$(dirname "$(realpath "$0")")
cd "${BASE}" || exit 1
if [ ! -d "${BASE}/emsdk" ]; then
git clone https://github.com/emscripten-core/emsdk.git
fi
cd "${BASE}/emsdk" || exit 1
git pull \
&& ./emsdk install latest-upstream \
&& ./emsdk activate latest-upstream \
&& source ./emsdk_env.sh
export EMSCRIPTEN="${BASE}/emsdk/upstream/emscripten"
export EMSDK="${BASE}/emsdk"
export EM_CONFIG="${BASE}/emsdk/.emscripten"
export EMSDK_NODE="${BASE}/emsdk/node/14.18.2_64bit/bin/node"
cd "${BASE}/github-monero-javascript" || exit 1
./bin/update_submodules.sh || exit 1
PATCH_FILE="${BASE}/github-monero-javascript/external/monero-cpp/external/monero-project/src/crypto/wallet/CMakeLists.txt"
sed -i 's/set(MONERO_WALLET_CRYPTO_LIBRARY "auto"/set(MONERO_WALLET_CRYPTO_LIBRARY "cn"/g' "${PATCH_FILE}"
HEADER_FILE="${BASE}/../build-monero-pool/staging-area/monero/monero-build/translations/translation_files.h"
HEADER_DEST="${BASE}/github-monero-javascript/external/monero-cpp/external/monero-project/build/release/translations/"
if [ ! -f "${HEADER_DEST}/$(basename "${HEADER_FILE}")" ]; then
echo "*${WHITE} copy 'translation_files.h' ${RESTORE}"
sleep 3
cp "${HEADER_FILE}" "${HEADER_DEST}"
fi
./bin/build_all.sh || exit 1 Edit 1: Forgot to patch |
Removing Next error is:
That file does not exist in Isn't it supposed to be generated by: |
I'd try building the monero-project submodule directly to ensure it succeeds, and build twice since some files are not built the first time, e.g.:
Then the translations directory should exist. |
Building monero in Maybe setting |
Nope, no cake. BOOST_ROOT=$(realpath "/path/to/github-monero-javascript/build/boost") \
BOOST_LIBRARYDIR="${BOOST_ROOT}/lib/" \
make release-static -j4 results in: CMake Error at /usr/share/cmake-3.5/Modules/FindBoost.cmake:1657 (message):
Unable to find the requested Boost libraries.
Boost version: 1.59.0
Boost include path: /usr/include |
Building
Building in
Changing ./bootstrap.sh \
- --with-libraries=system,thread,chrono,serialization,regex \
+ --with-libraries=system,thread,chrono,serialization,regex,filesystem,date_time,program_options,locale \
2>&1 Results in:
|
The updated build script: #!/bin/bash
BASE=$(dirname "$(realpath "$0")")
cd "${BASE}" || exit 1
if [ ! -d "${BASE}/emsdk" ]; then
git clone https://github.com/emscripten-core/emsdk.git
fi
cd "${BASE}/emsdk" || exit 1
git pull \
&& ./emsdk install latest-upstream \
&& ./emsdk activate latest-upstream \
&& source ./emsdk_env.sh
export EMSCRIPTEN="${BASE}/emsdk/upstream/emscripten"
export EMSDK="${BASE}/emsdk"
export EM_CONFIG="${BASE}/emsdk/.emscripten"
export EMSDK_NODE="${BASE}/emsdk/node/14.18.2_64bit/bin/node"
cd "${BASE}/github-monero-javascript" || exit 1
./bin/update_submodules.sh || exit 1
echo "${WHITE}* Patching ${YELLOW}build_boost_emscripten.sh${RESTORE}"
PATCH_FILE="${BASE}/monero-javascript/bin/build_boost_emscripten.sh"
PATCH_FROM='--with-libraries=system,thread,chrono,serialization,regex \\'
PATCH_TO='--with-libraries=system,thread,chrono,serialization,regex,locale,filesystem,date_time,program_options \\'
sed -i "s/${PATCH_FROM}/${PATCH_TO}/g" "${PATCH_FILE}" || exit 1
./bin/build_boost_emscripten.sh || exit 1
PATCH_FILE="${BASE}/github-monero-javascript/external/monero-cpp/external/monero-project/src/crypto/wallet/CMakeLists.txt"
sed -i 's/set(MONERO_WALLET_CRYPTO_LIBRARY "auto"/set(MONERO_WALLET_CRYPTO_LIBRARY "cn"/g' "${PATCH_FILE}"
MONERO_BUILD="${BASE}/github-monero-javascript/external/monero-cpp/external/monero-project/build"
if [ ! -d "${MONERO_BUILD}" ]; then
mkdir "${MONERO_BUILD}" || exit 1
fi
cd "${MONERO_BUILD}" || exit 1
export BOOST_ROOT="${BASE}/github-monero-javascript/build/boost"
export BOOST_LIBRARYDIR="${BOOST_ROOT}/lib"
cmake .. || exit 1
make release-static -j2 || exit 1
make release-static -j2 || exit 1
#HEADER_FILE="${BASE}/../build-monero-pool/staging-area/monero/monero-build/translations/translation_files.h"
#HEADER_DEST="${BASE}/github-monero-javascript/external/monero-cpp/external/monero-project/build/release/translations/"
#if [ ! -f "${HEADER_DEST}/$(basename "${HEADER_FILE}")" ]; then
# echo "*${WHITE} copy 'translation_files.h' ${RESTORE}"
# sleep 3
# cp "${HEADER_FILE}" "${HEADER_DEST}"
#fi
cd "${BASE}/github-monero-javascript/" || exit 1
./bin/build_all.sh || exit 1 Edit 1: submodules before boost :) |
Okay, this is beyond me. I can't get that |
It shouldn't be necessary to modify the boost libraries in You still get boost errors without that modification? And have you installed boost with |
I'm on Slackware 14.2 (x64). Slackware does not include static libraries at all. |
What would need to change in order to remove the need to copy files out of |
This is a bit out of my wheelhouse, but I did a little searching on npm and found a couple examples where they're providing their wasm as browser-importable js modules: Would be great if there was just one minified / tree-shakable js file that just works on browser or node. We're definitely almost there. Searching for libraries on npm with 'browser and node.js' might give some good examples of what might need to be done. Axios is one that's usable on node and browser without any user-involvement beside installing, and it just works. |
I think you're right, the solution involves bundling plus a package.json that points to the right files (xxhash for example). I think automating the emscripten part of the process to the point where all one needs to do after a fresh
Having laid out everything like this I don't think it's a ton of work (automating all the wasm stuff would probably be the hardest part), but it's possible I've missed something. |
@woodser @DangerOnTheRanger |
@CryptoGrampy I made the change from the PR and created single .js files. However, the .js file for the full wallet is 11.2 mbs, whereas the combined size of the old .js and .wasm is 6.7 mbs. Additionally, monero_web_worker.js punches out to 11.6 mbs, instead of the old 2.2 mbs. I need to find a way to optimize these. |
Hopefully this issue is resolved with the latest v0.9.2 release (and project rename to monero-ts). |
A lot of progress has been made since this issue was opened. Yes, polyfills are still required to use functionality from Node.js in the browser, and I don't see how that can be easily changed. However, numerous other fixes have been made to make this library more friendly with various app frameworks. First, as requested, we've updated the deprecated networking libraries to Axios, thanks to @mainnet-pat in #230. Second, as requested, we've combined the dist assets into singular *.js files, completely removing the separate .wasm files, again thanks to @mainnet-pat in #250. Additionally, the dist assets no longer need to be copied manually to "public" (though the web worker must be copied or imported with a special line). Third, we now support a variety of browser frameworks with sample applications to get up and running quickly, with the help of @mainnet-pat: What's not supported from the wishlist:
But with the networking libraries updated, the dist assets combined, and the sample apps supported, I'm going to go ahead and close this issue. Please if you encounter any sticking points, open a new issue for us to work through that specifically. Thanks, and hope to see you guys around! :) |
For such a comprehensive and easy to use library for node, it's not possible to simply npm i monero-javascript and use it for front end/browser apps (yes, this is documented), and it's quite painful to integrate it with even basic create-react-app or vuejs boilerplate code. I think this is a big problem and is likely a bottleneck for a lot of would-be front end development.
I would really like to be able to simply install and use this library with no fussing with webpack and build configs if such a thing is possible.... i.e. I should be able to run create-react-app, or npm init vue@latest, run npm i monero-javascript, and be ready to roll.
Example of what needs to be done to use the library with Vue (see the fallbacks and additional packages necessary in package.json): https://github.com/xmrdotgift/wallet/blob/master/webpack.config.js
The text was updated successfully, but these errors were encountered: