From 3b0cd82205352388fe9a67ee91985a77087e3ea1 Mon Sep 17 00:00:00 2001 From: Ilya Kantor Date: Sun, 5 Feb 2023 16:02:28 +0100 Subject: [PATCH] failing init --- emscriptenbuild/build.sh | 5 +++-- examples/example_webworker_init.js | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 examples/example_webworker_init.js diff --git a/emscriptenbuild/build.sh b/emscriptenbuild/build.sh index 4a90fd2b..577c30a7 100755 --- a/emscriptenbuild/build.sh +++ b/emscriptenbuild/build.sh @@ -28,8 +28,9 @@ 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 +emcmake cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_C_FLAGS="$EXTRA_CMAKE_C_FLAGS \ + --pre-js $(pwd)/pre.js $POST_JS -sEXPORTED_FUNCTIONS=['_my_sqrt','_main','_malloc','_git_repository_open_ext','_git_repository_init'] -s \"EXTRA_EXPORTED_RUNTIME_METHODS=['FS','callMain','ccall','cwrap']\" -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 emmake make lg2 diff --git a/examples/example_webworker_init.js b/examples/example_webworker_init.js new file mode 100644 index 00000000..0de00ad9 --- /dev/null +++ b/examples/example_webworker_init.js @@ -0,0 +1,21 @@ +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']) + + let r1 = git_repository_init(repoPointer, "/working", 0) + console.log(`r1 ${r1}`); + +}; \ No newline at end of file