Skip to content

Commit e175046

Browse files
committed
Fix build to load fonts into memory, not tmp files
1 parent e4a27c4 commit e175046

File tree

6 files changed

+75
-17
lines changed

6 files changed

+75
-17
lines changed

build/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ embuilder build freetype
5252

5353
# Make the cmake target for Emscripten
5454
# Use -g instead of -O2 to get debug symbols.
55-
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"
55+
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"
5656

5757
# Make xpdf
58-
make
58+
emmake make
5959

6060
# Copy the built wasm binary to the root of the project
6161
cp xpdf/*.wasm ../../../wasm

build/emscripten.patch

Lines changed: 73 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/system/lib/standalone/standalone.c b/system/lib/standalone/standalone.c
2-
index 200002dce..bbaf32d7d 100644
2+
index 200002dce..5624c926f 100644
33
--- a/system/lib/standalone/standalone.c
44
+++ b/system/lib/standalone/standalone.c
55
@@ -6,6 +6,7 @@
@@ -38,7 +38,7 @@ index 200002dce..bbaf32d7d 100644
3838
void abort() {
3939
_Exit(1);
4040
}
41-
@@ -85,41 +100,809 @@ __attribute__((__weak__)) int _munmap_js(
41+
@@ -85,41 +100,867 @@ __attribute__((__weak__)) int _munmap_js(
4242
return -ENOSYS;
4343
}
4444

@@ -520,31 +520,89 @@ index 200002dce..bbaf32d7d 100644
520520
+}
521521
+
522522
+__attribute__((__weak__)) int __syscall_rmdir(intptr_t path) {
523-
+ return -ENOSYS;
524-
+}
525-
+
523+
return -ENOSYS;
524+
}
525+
526+
-// There is no good source of entropy without an import. Make this weak so that
527+
-// it can be replaced with a pRNG or a proper import.
526528
+__attribute__((__weak__)) int __syscall_unlinkat(int dirfd, intptr_t path, int flags) {
527-
+ return -ENOSYS;
529+
+ const char* resolved_path = (const char*)path;
530+
+
531+
+ // Resolve path if fd is AT_FDCWD.
532+
+ if (dirfd == AT_FDCWD) {
533+
+ char *relative_path;
534+
+ dirfd = find_relpath(resolved_path, &relative_path);
535+
+
536+
+ // If we can't find a preopen for it, fail as if we can't find the path.
537+
+ if (dirfd == -1) {
538+
+ errno = ENOENT;
539+
+ return -1;
540+
+ }
541+
+
542+
+ resolved_path = relative_path;
543+
+ }
544+
+
545+
+ __wasi_errno_t error = __wasi_path_unlink_file(dirfd, resolved_path, strlen(resolved_path));
546+
+ if (error != 0) {
547+
+ errno = error;
548+
+ return -1;
549+
+ }
550+
+ return 0;
528551
+}
529552
+
530553
+__attribute__((__weak__)) int __syscall_pipe(intptr_t fd) {
531554
+ return -ENOSYS;
532555
+}
533556
+
534557
+__attribute__((__weak__)) int __syscall_renameat(int olddirfd, intptr_t oldpath, int newdirfd, intptr_t newpath) {
535-
+ return -ENOSYS;
558+
+ const char* oldpathresolved_path = (const char*)oldpath;
559+
+
560+
+ // Resolve path if fd is AT_FDCWD.
561+
+ if (olddirfd == AT_FDCWD) {
562+
+ char *oldpathrelative_path;
563+
+ olddirfd = find_relpath(oldpathresolved_path, &oldpathrelative_path);
564+
+
565+
+ // If we can't find a preopen for it, fail as if we can't find the path.
566+
+ if (olddirfd == -1) {
567+
+ errno = ENOENT;
568+
+ return -1;
569+
+ }
570+
+
571+
+ oldpathresolved_path = oldpathrelative_path;
572+
+ }
573+
+
574+
+ const char* newpathresolved_path = (const char*)newpath;
575+
+
576+
+ // Resolve path if fd is AT_FDCWD.
577+
+ if (newdirfd == AT_FDCWD) {
578+
+ char *newpathrelative_path;
579+
+ newdirfd = find_relpath(newpathresolved_path, &newpathrelative_path);
580+
+
581+
+ // If we can't find a preopen for it, fail as if we can't find the path.
582+
+ if (newdirfd == -1) {
583+
+ errno = ENOENT;
584+
+ return -1;
585+
+ }
586+
+
587+
+ newpathresolved_path = newpathrelative_path;
588+
+ }
589+
+
590+
+ __wasi_errno_t error = __wasi_path_rename(olddirfd, oldpathresolved_path, strlen(oldpathresolved_path), newdirfd, newpathresolved_path, strlen(newpathresolved_path));
591+
+ if (error != 0) {
592+
+ errno = error;
593+
+ return -1;
594+
+ }
595+
+ return 0;
536596
+}
537597
+
538598
+__attribute__((__weak__)) int __syscall_dup(int fd) {
539599
+ return -ENOSYS;
540600
+}
541601
+
542602
+__attribute__((__weak__)) int __syscall_dup3(int fd, int suggestfd, int flags) {
543-
return -ENOSYS;
544-
}
545-
546-
-// There is no good source of entropy without an import. Make this weak so that
547-
-// it can be replaced with a pRNG or a proper import.
603+
+ return -ENOSYS;
604+
+}
605+
+
548606
+__attribute__((__weak__)) int __syscall_faccessat(int dirfd, intptr_t path, int amode, int flags) {
549607
+ return -ENOSYS;
550608
+}
@@ -859,7 +917,7 @@ index 200002dce..bbaf32d7d 100644
859917
}
860918

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

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

890948
__attribute__((__weak__))
891949
void __cxa_throw(void* ptr, void* type, void* destructor) {
@@ -898,7 +956,7 @@ index 200002dce..bbaf32d7d 100644
898956
abort();
899957
}
900958

901-
@@ -228,3 +1019,14 @@ void _emscripten_err(const char* text) { wasi_writeln(2, text); }
959+
@@ -228,3 +1077,14 @@ void _emscripten_err(const char* text) { wasi_writeln(2, text); }
902960
void __call_sighandler(sighandler_t handler, int sig) {
903961
handler(sig);
904962
}

wasm/pdftohtml.wasm

-1.53 KB
Binary file not shown.

wasm/pdftopng.wasm

-1.51 KB
Binary file not shown.

wasm/pdftoppm.wasm

-1.53 KB
Binary file not shown.

wasm/pdftops.wasm

-1.22 KB
Binary file not shown.

0 commit comments

Comments
 (0)