Add libarchive, switch to WASMFS, use pack file (base.pack) for fsroot
parent
b38c5ec421
commit
ba415e7e8c
|
@ -10,7 +10,8 @@ RUN \
|
|||
build-essential \
|
||||
cmake \
|
||||
tclsh \
|
||||
zip
|
||||
zip \
|
||||
zstd
|
||||
|
||||
COPY . /minetest-wasm
|
||||
|
||||
|
|
|
@ -6,3 +6,5 @@ cd "$EMSDK_ROOT"
|
|||
|
||||
patch -p1 < "$BASE_DIR/emsdk_emcc.patch"
|
||||
patch -p1 < "$BASE_DIR/emsdk_file_packager.patch"
|
||||
patch -p1 < "$BASE_DIR/emsdk_dirperms.patch"
|
||||
patch -p1 < "$BASE_DIR/emsdk_setlk.patch"
|
||||
|
|
|
@ -19,6 +19,7 @@ emcc --clear-cache --clear-ports
|
|||
./build_libvorbis.sh # uses ogg
|
||||
./build_freetype.sh # uses zlib, libpng
|
||||
./build_zstd.sh
|
||||
./build_libarchive.sh # uses zstd
|
||||
./build_sqlite3.sh
|
||||
./build_webshims.sh
|
||||
./build_openssl.sh
|
||||
|
|
|
@ -42,3 +42,15 @@ done
|
|||
|
||||
# Copy the irrlicht shaders
|
||||
cp -r "$IRRLICHT_REPO/media/Shaders" client/shaders/Irrlicht
|
||||
|
||||
popd
|
||||
|
||||
# Make fsroot.tar
|
||||
rm -f fsroot.tar
|
||||
pushd fsroot
|
||||
tar cf ../fsroot.tar .
|
||||
popd
|
||||
|
||||
# Compress with ZSTD
|
||||
rm -f fsroot.tar.zst
|
||||
zstd --ultra -22 fsroot.tar
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
#!/bin/bash -eux
|
||||
|
||||
source common.sh
|
||||
|
||||
unpack_source libarchive
|
||||
|
||||
pushd "$BUILD_DIR/libarchive"
|
||||
|
||||
export CPPFLAGS="-I${INSTALL_DIR}/include"
|
||||
export LDFLAGS="-L${INSTALL_DIR}/lib"
|
||||
emconfigure ./configure \
|
||||
--enable-static \
|
||||
--disable-shared \
|
||||
--disable-bsdtar \
|
||||
--disable-bsdcat \
|
||||
--disable-bsdcpio \
|
||||
--enable-posix-regex-lib=libc \
|
||||
--disable-xattr --disable-acl --without-nettle --without-lzo2 \
|
||||
--without-cng --without-lz4 \
|
||||
--without-xml2 --without-expat \
|
||||
--with-zstd \
|
||||
--prefix="$INSTALL_DIR"
|
||||
|
||||
emmake make
|
||||
emmake make install
|
||||
|
||||
echo "libarchive OK"
|
|
@ -14,11 +14,8 @@ pushd minetest
|
|||
export EMSDK_EXTRA="-sUSE_SDL=2"
|
||||
export CFLAGS="$CFLAGS $EMSDK_EXTRA"
|
||||
export CXXFLAGS="$CXXFLAGS $EMSDK_EXTRA"
|
||||
export LDFLAGS="$LDFLAGS $EMSDK_EXTRA -sPTHREAD_POOL_SIZE=20 -s EXPORTED_RUNTIME_METHODS=ccall,cwrap -s INITIAL_MEMORY=2013265920 -sMIN_WEBGL_VERSION=2 -sUSE_WEBGL2"
|
||||
export LDFLAGS="$LDFLAGS -L$INSTALL_DIR/lib -lssl -lcrypto -lemsocket -lwebsocket.js"
|
||||
|
||||
# Used by CMakeFiles.txt in the webport
|
||||
export FSROOT_DIR="$BUILD_DIR/fsroot"
|
||||
export LDFLAGS="$LDFLAGS $EMSDK_EXTRA -sPTHREAD_POOL_SIZE=20 -s EXPORTED_RUNTIME_METHODS=ccall,cwrap -s INITIAL_MEMORY=2013265920 -sMIN_WEBGL_VERSION=2 -sUSE_WEBGL2 -sWASMFS=1"
|
||||
export LDFLAGS="$LDFLAGS -L$INSTALL_DIR/lib -larchive -lssl -lcrypto -lemsocket -lwebsocket.js"
|
||||
|
||||
# Create a dummy .o file to use as a substitute for the OpenGLES2 / EGL libraries,
|
||||
# since Emscripten doesn't actually provide those. (the symbols are resolved through
|
||||
|
@ -64,17 +61,13 @@ if ! $INCREMENTAL; then
|
|||
"$BASE_DIR/minetest"
|
||||
fi
|
||||
|
||||
if $INCREMENTAL; then
|
||||
emmake make -j1
|
||||
else
|
||||
emmake make -j4
|
||||
fi
|
||||
emmake make -j4
|
||||
|
||||
echo "Installing into www/"
|
||||
rm -rf "$WWW_DIR"
|
||||
mkdir "$WWW_DIR"
|
||||
|
||||
FILES="minetest.data minetest.js minetest.wasm minetest.worker.js"
|
||||
FILES="minetest.js minetest.wasm minetest.worker.js"
|
||||
|
||||
for I in $FILES; do
|
||||
cp src/"$I" "$WWW_DIR"
|
||||
|
@ -87,6 +80,8 @@ fi
|
|||
cp "$BASE_DIR/static/index.html" "$WWW_DIR"
|
||||
cp "$BASE_DIR/static/.htaccess" "$WWW_DIR"
|
||||
|
||||
cp "$BUILD_DIR/fsroot.tar.zst" "$WWW_DIR/base.pack"
|
||||
|
||||
echo "DONE"
|
||||
|
||||
popd
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
Binary files emsdk-orig/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libwasmfs-mt.a and emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libwasmfs-mt.a differ
|
||||
diff -urN emsdk-orig/upstream/emscripten/system/lib/wasmfs/wasmfs.cpp emsdk/upstream/emscripten/system/lib/wasmfs/wasmfs.cpp
|
||||
--- emsdk-orig/upstream/emscripten/system/lib/wasmfs/wasmfs.cpp 2022-07-29 17:22:28.000000000 +0000
|
||||
+++ emsdk/upstream/emscripten/system/lib/wasmfs/wasmfs.cpp 2022-08-06 02:07:24.098196400 +0000
|
||||
@@ -141,7 +141,7 @@
|
||||
}
|
||||
|
||||
auto inserted =
|
||||
- lockedParentDir.insertDirectory(childName, S_IRUGO | S_IXUGO);
|
||||
+ lockedParentDir.insertDirectory(childName, S_IRUGO | S_IWUGO | S_IXUGO);
|
||||
assert(inserted && "TODO: handle preload insertion errors");
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
--- emsdk-orig/upstream/emscripten/system/lib/wasmfs/syscalls.cpp 2022-07-29 17:22:28.000000000 +0000
|
||||
+++ emsdk/upstream/emscripten/system/lib/wasmfs/syscalls.cpp 2022-08-06 05:05:17.014502697 +0000
|
||||
@@ -1419,7 +1419,7 @@
|
||||
static_assert(F_SETLK == F_SETLK64);
|
||||
static_assert(F_SETLKW == F_SETLKW64);
|
||||
// Always error for now, until we implement byte-range locks.
|
||||
- return -EACCES;
|
||||
+ return 0; //-EACCES;
|
||||
}
|
||||
case F_GETOWN_EX:
|
||||
case F_SETOWN:
|
|
@ -17,6 +17,7 @@ getsource "https://www.sqlite.org/src/tarball/698edb77/SQLite-698edb77.tar.gz" b
|
|||
getsource "https://www.openssl.org/source/openssl-1.1.1n.tar.gz" 40dceb51a4f6a5275bde0e6bf20ef4b91bfc32ed57c0552e2e8e15463372b17a
|
||||
getsource "https://curl.se/download/curl-7.82.0.tar.bz2" 46d9a0400a33408fd992770b04a44a7434b3036f2e8089ac28b57573d59d371f
|
||||
getsource "https://github.com/minetest/minetest/releases/download/5.5.1/minetest-5.5.1-win64.zip" 9be48fb4126312b0d8fd048d1ab06d59b3109f6fe037fcd5ab65b99507e68a5f
|
||||
getsource "https://www.libarchive.org/downloads/libarchive-3.6.1.tar.xz" 5a411aceb978f43e626f0c2d1812ddd8807b645ed892453acabd532376c148e6
|
||||
|
||||
# These are never checked into the repo, since they are separate git repos.
|
||||
# Be sure to add new entries here to .gitignore
|
||||
|
|
Binary file not shown.
|
@ -135,13 +135,32 @@
|
|||
var consoleDirty = false;
|
||||
var wasmReady = false;
|
||||
var invokedMain = false;
|
||||
var packsReady = false;
|
||||
var packs = [];
|
||||
|
||||
// Called by the MainLoop when main() is ready to be called
|
||||
// Called by MainLoop when the wasm module is ready
|
||||
function emloop_ready() {
|
||||
wasmReady = true;
|
||||
emloop_invoke_main = cwrap("emloop_invoke_main", null, ["number", "number"]);
|
||||
irrlicht_want_pointerlock = cwrap("irrlicht_want_pointerlock", "number");
|
||||
emloop_install_pack = cwrap("emloop_install_pack", null, ["number", "number", "number"]);
|
||||
irrlicht_want_pointerlock = cwrap("irrlicht_want_pointerlock", "number");
|
||||
irrlicht_resize = cwrap("irrlicht_resize", null, ["number", "number"]);
|
||||
maybeStart();
|
||||
}
|
||||
|
||||
function all_packs_ready() {
|
||||
packsReady = true;
|
||||
maybeStart();
|
||||
}
|
||||
|
||||
function maybeStart() {
|
||||
if (!wasmReady || !packsReady) return;
|
||||
if (packs.length > 0) {
|
||||
for (const [name, data] of packs) {
|
||||
installPack(name, data);
|
||||
}
|
||||
packs = [];
|
||||
}
|
||||
showLaunchButton();
|
||||
}
|
||||
|
||||
|
@ -167,6 +186,67 @@
|
|||
return [i, argv];
|
||||
}
|
||||
|
||||
function fetchPacks() {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
fetchPack('base');
|
||||
if (params.has('gameid')) {
|
||||
const gameid = params.get('gameid');
|
||||
if (gameid != 'minetest_game' && gameid != 'devtest') {
|
||||
fetchPack(params.get('gameid'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var pendingPacks = 0;
|
||||
function fetchPack(name) {
|
||||
pendingPacks += 1;
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', name + '.pack', true);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.onprogress = (event) => {
|
||||
console.log(`Fetched ${event.loaded} of ${event.total}`);
|
||||
};
|
||||
xhr.onload = (event) => {
|
||||
if (xhr.status == 200 || xhr.status == 304 || xhr.status == 206 || (xhr.status == 0 && xhr.response)) {
|
||||
packs.push([name, xhr.response]);
|
||||
pendingPacks -= 1;
|
||||
if (pendingPacks == 0) {
|
||||
all_packs_ready();
|
||||
}
|
||||
} else {
|
||||
throw new Error(xhr.statusText + " : " + xhr.responseURL);
|
||||
}
|
||||
};
|
||||
xhr.send(null);
|
||||
}
|
||||
|
||||
function installPack(name, arrayBuffer) {
|
||||
const arr = new Uint8Array(arrayBuffer);
|
||||
const data = _malloc(arr.length * arr.BYTES_PER_ELEMENT);
|
||||
HEAP8.set(arr, data);
|
||||
emloop_install_pack(allocateUTF8(name), data, arr.length);
|
||||
_free(data);
|
||||
}
|
||||
|
||||
function parseQueryArgs() {
|
||||
const args = ['./minetest'];
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const keyList0 = ['go', 'server'];
|
||||
const keyList1 = ['name', 'gameid', 'address', 'address', 'port'];
|
||||
for (const key of keyList0) {
|
||||
if (params.has(key)) {
|
||||
args.push('--' + key);
|
||||
}
|
||||
}
|
||||
for (const key of keyList1) {
|
||||
if (params.has(key)) {
|
||||
args.push('--' + key);
|
||||
args.push(params.get(key));
|
||||
}
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
function doLaunch() {
|
||||
if (launchButton) {
|
||||
launchButton.remove();
|
||||
|
@ -175,7 +255,7 @@
|
|||
|
||||
if (!invokedMain && wasmReady) {
|
||||
invokedMain = true;
|
||||
const args = ['./minetest'];
|
||||
const args = parseQueryArgs();
|
||||
const [argc, argv] = makeArgv(args);
|
||||
emloop_invoke_main(argc, argv);
|
||||
// irrlicht initialization resets the width/height
|
||||
|
@ -398,6 +478,7 @@
|
|||
}
|
||||
}
|
||||
});
|
||||
fetchPacks();
|
||||
</script>
|
||||
<script async type="text/javascript" src="minetest.js"></script>
|
||||
</body>
|
||||
|
|
Loading…
Reference in New Issue