Skip to content

Commit 2f4745b

Browse files
jprendesjcbhmr
authored andcommitted
Add fsroot to fix linking issue
1 parent 5ee91bf commit 2f4745b

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

tools/fsroot.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* @license
3+
* Copyright 2013 The Emscripten Authors
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
7+
mergeInto(LibraryManager.library, {
8+
$FSROOT__deps: ["$FS"],
9+
$FSROOT__postset: "FSROOT.staticInit();",
10+
$FSROOT: {
11+
staticInit: () => {
12+
FS.root = null;
13+
14+
let opts = (Module.ROOT && Module.ROOT.opts) || {};
15+
let type = (Module.ROOT && Module.ROOT.type) || "MEMFS";
16+
if (typeof type === "string") {
17+
type = FS.filesystems[type] || eval(type);
18+
} else if (typeof type === "function") {
19+
type = type(Module);
20+
}
21+
FS.mount(type, opts, '/');
22+
23+
FSROOT.createDefaultMountPoints();
24+
25+
// We need to ignore errors in mkdir
26+
// since we are pre-creation mountpoints
27+
// for directories otherwise created by the
28+
// FS.create* functions
29+
const restore_mkdir = FSROOT.safeMkdir();
30+
31+
FS.createDefaultDirectories();
32+
FS.createDefaultDevices();
33+
FS.createSpecialDirectories();
34+
35+
restore_mkdir();
36+
},
37+
createDefaultMountPoints: () => {
38+
// Mount a new MEMFS for /dev
39+
FS.mkdirTree("/dev");
40+
FS.mount(MEMFS, {}, "/dev");
41+
42+
// Mount a new MEMFS for /proc/self
43+
FS.mkdirTree('/proc/self');
44+
FS.mount(MEMFS, {}, '/proc/self');
45+
},
46+
safeMkdir: () => {
47+
const mkdir = FS.mkdir;
48+
FS.mkdir = (path, mode) => {
49+
try {
50+
return mkdir(path, mode);
51+
} catch {
52+
// ignore errors
53+
return FS.lookupPath(path, { follow: true }).node;
54+
}
55+
};
56+
return () => {
57+
FS.mkdir = mkdir;
58+
};
59+
},
60+
},
61+
});
62+
63+
DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.push('$FSROOT');

0 commit comments

Comments
 (0)