Skip to content

Commit

Permalink
Fix build to load fonts into memory, not tmp files
Browse files Browse the repository at this point in the history
  • Loading branch information
jerbob92 committed Apr 19, 2023
1 parent e4a27c4 commit e175046
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 17 deletions.
4 changes: 2 additions & 2 deletions build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ embuilder build freetype

# Make the cmake target for Emscripten
# Use -g instead of -O2 to get debug symbols.
emcmake cmake .. -DCMAKE_TOOLCHAIN_FILE=$EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CXX_FLAGS="-std=c++14 -O2" -DCMAKE_EXE_LINKER_FLAGS="-static -sERROR_ON_UNDEFINED_SYMBOLS=0 -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s STANDALONE_WASM=1 -s USE_FREETYPE=1 -s USE_ZLIB=1 -s USE_LIBPNG=1 -s USE_LIBJPEG=1"
emcmake cmake .. -DCMAKE_TOOLCHAIN_FILE=$EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CXX_FLAGS="-std=c++14 -O2 -DLOAD_FONTS_FROM_MEM=1" -DCMAKE_EXE_LINKER_FLAGS="-static -sERROR_ON_UNDEFINED_SYMBOLS=0 -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s STANDALONE_WASM=1 -s USE_FREETYPE=1 -s USE_ZLIB=1 -s USE_LIBPNG=1 -s USE_LIBJPEG=1"

# Make xpdf
make
emmake make

# Copy the built wasm binary to the root of the project
cp xpdf/*.wasm ../../../wasm
Expand Down
88 changes: 73 additions & 15 deletions build/emscripten.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/system/lib/standalone/standalone.c b/system/lib/standalone/standalone.c
index 200002dce..bbaf32d7d 100644
index 200002dce..5624c926f 100644
--- a/system/lib/standalone/standalone.c
+++ b/system/lib/standalone/standalone.c
@@ -6,6 +6,7 @@
Expand Down Expand Up @@ -38,7 +38,7 @@ index 200002dce..bbaf32d7d 100644
void abort() {
_Exit(1);
}
@@ -85,41 +100,809 @@ __attribute__((__weak__)) int _munmap_js(
@@ -85,41 +100,867 @@ __attribute__((__weak__)) int _munmap_js(
return -ENOSYS;
}

Expand Down Expand Up @@ -520,31 +520,89 @@ index 200002dce..bbaf32d7d 100644
+}
+
+__attribute__((__weak__)) int __syscall_rmdir(intptr_t path) {
+ return -ENOSYS;
+}
+
return -ENOSYS;
}

-// There is no good source of entropy without an import. Make this weak so that
-// it can be replaced with a pRNG or a proper import.
+__attribute__((__weak__)) int __syscall_unlinkat(int dirfd, intptr_t path, int flags) {
+ return -ENOSYS;
+ const char* resolved_path = (const char*)path;
+
+ // Resolve path if fd is AT_FDCWD.
+ if (dirfd == AT_FDCWD) {
+ char *relative_path;
+ dirfd = find_relpath(resolved_path, &relative_path);
+
+ // If we can't find a preopen for it, fail as if we can't find the path.
+ if (dirfd == -1) {
+ errno = ENOENT;
+ return -1;
+ }
+
+ resolved_path = relative_path;
+ }
+
+ __wasi_errno_t error = __wasi_path_unlink_file(dirfd, resolved_path, strlen(resolved_path));
+ if (error != 0) {
+ errno = error;
+ return -1;
+ }
+ return 0;
+}
+
+__attribute__((__weak__)) int __syscall_pipe(intptr_t fd) {
+ return -ENOSYS;
+}
+
+__attribute__((__weak__)) int __syscall_renameat(int olddirfd, intptr_t oldpath, int newdirfd, intptr_t newpath) {
+ return -ENOSYS;
+ const char* oldpathresolved_path = (const char*)oldpath;
+
+ // Resolve path if fd is AT_FDCWD.
+ if (olddirfd == AT_FDCWD) {
+ char *oldpathrelative_path;
+ olddirfd = find_relpath(oldpathresolved_path, &oldpathrelative_path);
+
+ // If we can't find a preopen for it, fail as if we can't find the path.
+ if (olddirfd == -1) {
+ errno = ENOENT;
+ return -1;
+ }
+
+ oldpathresolved_path = oldpathrelative_path;
+ }
+
+ const char* newpathresolved_path = (const char*)newpath;
+
+ // Resolve path if fd is AT_FDCWD.
+ if (newdirfd == AT_FDCWD) {
+ char *newpathrelative_path;
+ newdirfd = find_relpath(newpathresolved_path, &newpathrelative_path);
+
+ // If we can't find a preopen for it, fail as if we can't find the path.
+ if (newdirfd == -1) {
+ errno = ENOENT;
+ return -1;
+ }
+
+ newpathresolved_path = newpathrelative_path;
+ }
+
+ __wasi_errno_t error = __wasi_path_rename(olddirfd, oldpathresolved_path, strlen(oldpathresolved_path), newdirfd, newpathresolved_path, strlen(newpathresolved_path));
+ if (error != 0) {
+ errno = error;
+ return -1;
+ }
+ return 0;
+}
+
+__attribute__((__weak__)) int __syscall_dup(int fd) {
+ return -ENOSYS;
+}
+
+__attribute__((__weak__)) int __syscall_dup3(int fd, int suggestfd, int flags) {
return -ENOSYS;
}

-// There is no good source of entropy without an import. Make this weak so that
-// it can be replaced with a pRNG or a proper import.
+ return -ENOSYS;
+}
+
+__attribute__((__weak__)) int __syscall_faccessat(int dirfd, intptr_t path, int amode, int flags) {
+ return -ENOSYS;
+}
Expand Down Expand Up @@ -859,7 +917,7 @@ index 200002dce..bbaf32d7d 100644
}

// Emscripten additions
@@ -155,12 +938,24 @@ double emscripten_get_now(void) {
@@ -155,12 +996,24 @@ double emscripten_get_now(void) {
return (1000 * clock()) / (double)CLOCKS_PER_SEC;
}

Expand All @@ -885,7 +943,7 @@ index 200002dce..bbaf32d7d 100644
//
// Define these symbols as weak so that when we build with exceptions
// enabled (using wasm-eh) we get the real versions of these functions
@@ -168,11 +963,7 @@ double emscripten_get_now(void) {
@@ -168,11 +1021,7 @@ double emscripten_get_now(void) {

__attribute__((__weak__))
void __cxa_throw(void* ptr, void* type, void* destructor) {
Expand All @@ -898,7 +956,7 @@ index 200002dce..bbaf32d7d 100644
abort();
}

@@ -228,3 +1019,14 @@ void _emscripten_err(const char* text) { wasi_writeln(2, text); }
@@ -228,3 +1077,14 @@ void _emscripten_err(const char* text) { wasi_writeln(2, text); }
void __call_sighandler(sighandler_t handler, int sig) {
handler(sig);
}
Expand Down
Binary file modified wasm/pdftohtml.wasm
Binary file not shown.
Binary file modified wasm/pdftopng.wasm
Binary file not shown.
Binary file modified wasm/pdftoppm.wasm
Binary file not shown.
Binary file modified wasm/pdftops.wasm
Binary file not shown.

0 comments on commit e175046

Please sign in to comment.