diff --git a/emscriptenbuild/build.sh b/emscriptenbuild/build.sh index 4a90fd2b..ca1b2cb3 100755 --- a/emscriptenbuild/build.sh +++ b/emscriptenbuild/build.sh @@ -28,8 +28,12 @@ elif [ "$1" == "Debug-async" ]; then POST_JS="--post-js $(pwd)/post-async.js" fi -# Before building, remove any ../libgit2/src/transports/emscriptenhttp.c left from running setup.sh +# 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 -s \"EXTRA_EXPORTED_RUNTIME_METHODS=['FS','callMain']\" -lnodefs.js -lidbfs.js -s INVOKE_RUN=0 -s ALLOW_MEMORY_GROWTH=1 -s STACK_SIZE=131072" -DREGEX_BACKEND=regcomp -DSONAME=OFF -DUSE_HTTPS=OFF -DBUILD_SHARED_LIBS=OFF -DTHREADSAFE=OFF -DUSE_SSH=OFF -DBUILD_CLAR=OFF -DBUILD_EXAMPLES=ON ../libgit2 +# To enable debugging & disable extra optimizations/inlines: -g -sINLINING_LIMIT -O0 +# also Chrome extenion and devtools option +# see https://developer.chrome.com/blog/wasm-debugging-2020/ +emcmake cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_C_FLAGS="$EXTRA_CMAKE_C_FLAGS \ + -g -sINLINING_LIMIT -O0 --pre-js $(pwd)/pre.js $POST_JS -sEXPORTED_FUNCTIONS=['_my_sqrt','_main','_malloc','_git_repository_open_ext','_git_repository_init','_git_libgit2_init'] -s \"EXTRA_EXPORTED_RUNTIME_METHODS=['FS','callMain','ccall','cwrap']\" -lnodefs.js -lidbfs.js -s INVOKE_RUN=0 -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_MEMORY=512MB -s STACK_SIZE=131072" -DREGEX_BACKEND=regcomp -DSONAME=OFF -DUSE_HTTPS=OFF -DBUILD_SHARED_LIBS=OFF -DTHREADSAFE=OFF -DUSE_SSH=OFF -DBUILD_CLAR=OFF -DBUILD_EXAMPLES=ON ../libgit2 emmake make lg2 diff --git a/examples/example_webworker_init.js b/examples/example_webworker_init.js new file mode 100644 index 00000000..6b42e0f8 --- /dev/null +++ b/examples/example_webworker_init.js @@ -0,0 +1,22 @@ +importScripts('lg2.js'); + +Module.onRuntimeInitialized = () => { + + FS.mkdir('/working'); + FS.mount(MEMFS, { }, '/working'); + + FS.writeFile('/home/web_user/.gitconfig', '[user]\n' + + 'name = Test User\n' + + 'email = test@example.com'); + + // Allocate memory of 8 bytes for pointer (probably 4 would be enough) + let repoPointer = Module._malloc(8); + + // int git_repository_init(git_repository **out, const char *path, unsigned int is_bare); + let git_repository_init = Module.cwrap('git_repository_init', 'number', ['number','string','number']) + + debugger + let r1 = git_repository_init(repoPointer, ".", 0) + console.log(`r1 ${r1}`); + +}; \ No newline at end of file diff --git a/examples/index.html b/examples/index.html index 3b5b6ac3..2da52f71 100644 --- a/examples/index.html +++ b/examples/index.html @@ -6,7 +6,7 @@ Open the webconsole to see the output of the example_webworker.js script \ No newline at end of file diff --git a/wasm-git b/wasm-git new file mode 120000 index 00000000..08ed019a --- /dev/null +++ b/wasm-git @@ -0,0 +1 @@ +wasm-git \ No newline at end of file