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

provide working example (with webpack too?) #16

Open
tsnobip opened this issue Oct 9, 2020 · 2 comments
Open

provide working example (with webpack too?) #16

tsnobip opened this issue Oct 9, 2020 · 2 comments

Comments

@tsnobip
Copy link

tsnobip commented Oct 9, 2020

Hi,
I'd be really interested in seeing a working example of your lib in a website, is the source of https://wasm-git.petersalomonsen.com/ available for example?

I couldn't make the example provided in the repo work in my browser, I tried multiple integrations with webpack without success so far, so I'm a bit frustrated. ^^

I have no experience with WASM and emscripten so that probably explains why too.

Any pointer would be welcome.

Thanks!

@petersalomonsen
Copy link
Owner

Hi,

Sorry it seems like I missed this. You can see the sources of https://wasm-git.petersalomonsen.com here: https://github.com/petersalomonsen/githttpserver

Also I use it in this project here: https://github.com/petersalomonsen/javascriptmusic and a live showcase where a git repository is cloned can be seen here: https://petersalomonsen.com/webassemblymusic/livecodev2/?gitrepo=test

Regarding use with a webpack project, I would not try to bundle in the wasm-git library, but rather load it at runtime (from a webworker), like you can see in the example project.

Hope this helps :-)

/Peter

@leookun
Copy link

leookun commented Nov 2, 2024

Add the -s ENVIRONMENT=web parameter to emscriptenbuild/build.sh, and the built lg2_async.js will not bundle node-related modules.
I did this. It works normally in webpack and other tools.

https://www.npmjs.com/package/wasm-git-browser

#!/bin/bash

BUILD_TYPE=Debug
ASYNCIFY_FLAGS=" -s ASYNCIFY -s 'ASYNCIFY_IMPORTS=[\"emscriptenhttp_do_get\", \"emscriptenhttp_do_read\", \"emscriptenhttp_do_post\"]' "
POST_JS="--post-js $(pwd)/post.js"

# Reset in case we've done an '-async' build
cp ../libgit2patchedfiles/src/transports/emscriptenhttp.c ../libgit2/src/libgit2/transports/emscriptenhttp.c

export LG2_OUTPUT_NAME=lg2

BUILD_TYPE=Release
cp ../libgit2patchedfiles/src/transports/emscriptenhttp-async.c ../libgit2/src/libgit2/transports/emscriptenhttp.c

EXTRA_CMAKE_C_FLAGS="-O3 $ASYNCIFY_FLAGS"

export LG2_OUTPUT_NAME=lg2_async
# Before building, remove any ../libgit2/src/ transports/emscriptenhttp.c left from running setup.sh 
[ -f "../libgit2/src/libgit2/transports/emscriptenhttp-async.c" ] && rm ../libgit2/src/libgit2/transports/emscriptenhttp-async.c

emcmake cmake \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCMAKE_C_FLAGS="$EXTRA_CMAKE_C_FLAGS --pre-js $(pwd)/pre.js --post-js $(pwd)/post-async.js -s \"EXPORTED_RUNTIME_METHODS=['FS','MEMFS','IDBFS','callMain']\" -sFORCE_FILESYSTEM -s EXPORT_ES6=1 -s INVOKE_RUN=0 -s ENVIRONMENT=web  -s DEMANGLE_SUPPORT=1 -s ALLOW_MEMORY_GROWTH=1 -s STACK_SIZE=131072 -lidbfs.js" \
-DREGEX_BACKEND=regcomp \
-DSONAME=OFF \
-DUSE_HTTPS=OFF \
-DBUILD_SHARED_LIBS=OFF \
-DTHREADSAFE=OFF \
-DUSE_SSH=OFF \
-DBUILD_CLAR=OFF \
-DBUILD_EXAMPLES=ON \
..
emmake make lg2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants