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

[DRAFT] Tried to add direct calls example, but init fails #64

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions emscriptenbuild/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 22 additions & 0 deletions examples/example_webworker_init.js
Original file line number Diff line number Diff line change
@@ -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 = [email protected]');

// 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}`);

};
2 changes: 1 addition & 1 deletion examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<body>
Open the webconsole to see the output of the <a href="example_webworker.js" target="_blank">example_webworker.js</a> script
<script>
new Worker('example_webworker.js');
new Worker('example_webworker_init.js');
</script>
</body>
</html>
1 change: 1 addition & 0 deletions wasm-git