Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit 5fde2c5

Browse files
committed
Figured out a way to override the MEMFS object through --js-library linking, and wrapped the Emscripten module in a function that can take arguments
1 parent 1a1e44c commit 5fde2c5

File tree

6 files changed

+337
-37
lines changed

6 files changed

+337
-37
lines changed

README.md

Lines changed: 275 additions & 0 deletions
Large diffs are not rendered by default.

emscripten/build.sh

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,16 @@ emcc \
2828
-O2 \
2929
--bind \
3030
--memory-init-file 0 \
31-
--pre-js ./prejs.js \
31+
--pre-js ./pre.js \
32+
--post-js ./post.js \
33+
--js-library ./library_virtualfs.js \
3234
-s "EXTRA_EXPORTED_RUNTIME_METHODS=['FS']" \
33-
-s FORCE_FILESYSTEM=1 \
3435
-s PRECISE_I64_MATH=1 \
3536
-s PRECISE_F32=1 \
3637
-s ASSERTIONS=2 \
37-
libgit2_wrapper.bc \
38-
libgit2.bc \
39-
-o libgit2.js
38+
./libgit2_wrapper.bc \
39+
./libgit2.bc \
40+
-o ./libgit2.js
4041

41-
# require libgit2.js into VirtualGit.js module
42-
# expose a JS wrapper around functions and JS semantics
43-
# moduralize and export name may not actually work
44-
# the --memory-init-file=0 makes sure not to have a separate memory file
45-
# since this is not designed for browser usage, or well it's geared towards system usage anyway
46-
# libgit2.js would eventually be required by VirtualGit.js and then a proper cjs module and es6 module exposed here, which has to allow the insertion of the VirtualFS as a parameter from the outside
42+
// if the resulting js uses es6 modules
43+
// you need to use babel and rollup to use it

emscripten/library_virtualfs.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// suppose this a thing to be linked over the MEMFS
2+
// so it overrides the MEMFS implementation
3+
// OH I GET IT
4+
// the resulting system evals this
5+
// modules.js EVALS this code
6+
// the mergeInto function is evaluated at compile time
7+
// this is evaluated at compile time
8+
// we can pass in JS code to be evaluated at program load time
9+
// or in this case LibGit call time
10+
// this will set the correct item?
11+
// but if staticInit is called first, then you have a problem, since that will try to initialise the fs with no memfs available?
12+
// ok this won't work cause the staticInit is called first before the $MEMFS__postset
13+
// so we cannot acquire the Module.libgit.virtualfs here
14+
15+
mergeInto(LibraryManager.library, {
16+
$MEMFS__deps: ['$FS'],
17+
$MEMFS__postset: 'console.log("MEMFS POSTSET");',
18+
$MEMFS: null
19+
});

emscripten/post.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
return Module;
2+
3+
} // LibGit function footer
4+
5+
module.exports = LibGit;
6+
7+
// use this once we have babel + rollup working
8+
// exports default LibGit;

emscripten/pre.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// vfs: VirtualFS instance
2+
// there may be other parameters to add in the future
3+
// like socket implementation (to deal with different underlying engine)
4+
function LibGit (vfs) { // LibGit function header
5+
6+
// this prevents explicit cjs exporting at shell.js
7+
let module = undefined;
8+
9+
// we'll use a libgit namespace to avoid conflicts
10+
var Module = {
11+
thisProgram: 'virtualgit',
12+
libgit: {
13+
virtualfs: vfs
14+
}
15+
};
16+
17+
// things that change according to environment:
18+
// so if we set environment to shell, which is the most generic environment
19+
// these methods will need to be set
20+
// print, printErr
21+
// read
22+
// readBinary
23+
// arguments
24+
// load
25+
// readAsync
26+
// thisProgram
27+
// inspect

emscripten/prejs.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)