Skip to content

Commit

Permalink
implement pdfium wasm compling
Browse files Browse the repository at this point in the history
  • Loading branch information
jichang committed May 16, 2024
1 parent 5b06d08 commit 9a9edd8
Show file tree
Hide file tree
Showing 24 changed files with 37,065 additions and 11,902 deletions.
45,727 changes: 36,938 additions & 8,789 deletions package-lock.json

Large diffs are not rendered by default.

27 changes: 19 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,31 @@
"private": false,
"version": "0.24.0",
"workspaces": [
"packages/pdfium",
"packages/models",
"packages/engines",
"packages/react"
],
"devDependencies": {
"@parcel/packager-ts": "^2.10.3",
"@parcel/transformer-typescript-types": "^2.10.3",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"@parcel/packager-ts": "^2.12.0",
"@parcel/transformer-typescript-types": "^2.12.0",
"@typescript-eslint/eslint-plugin": "^7.9.0",
"@typescript-eslint/parser": "^7.9.0",
"buffer": "^6.0.3",
"crypto-browserify": "^3.12.0",
"eslint": "^8.56.0",
"husky": "^8.0.3",
"prettier": "^3.1.0",
"typedoc": "^0.25.4",
"typescript": "^5.3.3"
"events": "^3.3.0",
"husky": "^9.0.11",
"path-browserify": "^1.0.1",
"prettier": "^3.2.5",
"process": "^0.11.10",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"stream-browserify": "^3.0.0",
"string_decoder": "^1.3.0",
"typedoc": "^0.25.13",
"typescript": "^5.4.5",
"vm-browserify": "^1.1.2"
},
"scripts": {
"doc": "typedoc",
Expand Down
11 changes: 4 additions & 7 deletions packages/engines/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,18 @@
},
"homepage": "https://github.com/jichang/unionpdf#readme",
"devDependencies": {
"@parcel/packager-ts": "^2.10.3",
"@parcel/transformer-typescript-types": "^2.10.3",
"@parcel/watcher": "^2.3.0",
"@types/jest": "^29.5.10",
"@types/jest": "^29.5.12",
"cpy-cli": "^5.0.0",
"crypto-browserify": "^3.12.0",
"del-cli": "^5.1.0",
"events": "^3.3.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"parcel": "^2.10.3",
"parcel": "^2.12.0",
"path-browserify": "^1.0.1",
"stream-browserify": "^3.0.0",
"ts-jest": "^29.1.1",
"typescript": "~5.3.2"
"ts-jest": "^29.1.2",
"typescript": "^5.4.5"
},
"dependencies": {
"@unionpdf/models": "^0.24.0",
Expand Down
20 changes: 8 additions & 12 deletions packages/engines/src/webworker/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@ export type PdfEngineMethodReturnType<P extends PdfEngineMethodName> = Readonly<
*
* @public
*/
export type TaskResolveValueType<T> = T extends Task<infer R, infer U>
? R
: never;
export type TaskResolveValueType<T> =
T extends Task<infer R, infer U> ? R : never;
/**
* Type of task rejected error
*
* @public
*/
export type TaskRejectErrorType<T> = T extends Task<infer R, infer U>
? U
: never;
export type TaskRejectErrorType<T> =
T extends Task<infer R, infer U> ? U : never;

/**
* Request body that represent method calls of PdfEngine, it contains the
Expand All @@ -59,12 +57,10 @@ export type PdfEngineMethodRequestBody = {
/**
* Type that represent the result of executing task
*/
export type TaskResultType<T extends Task<any, any>> = T extends Task<
infer R,
infer E
>
? { type: 'resolve'; result: R } | { type: 'reject'; error: E }
: never;
export type TaskResultType<T extends Task<any, any>> =
T extends Task<infer R, infer E>
? { type: 'resolve'; result: R } | { type: 'reject'; error: E }
: never;
/**
* Response body that represent return value of PdfEngine
*/
Expand Down
14 changes: 7 additions & 7 deletions packages/models/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@
},
"homepage": "https://github.com/jichang/unionpdf#readme",
"devDependencies": {
"@parcel/packager-ts": "^2.10.3",
"@parcel/transformer-typescript-types": "^2.10.3",
"@parcel/watcher": "^2.3.0",
"@types/jest": "^29.5.10",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.12",
"cpy-cli": "^5.0.0",
"del-cli": "^5.1.0",
"jest": "^29.7.0",
"jest-canvas-mock": "^2.5.2",
"jest-environment-jsdom": "^29.7.0",
"parcel": "^2.10.3",
"ts-jest": "^29.1.1",
"typescript": "~5.3.2"
"parcel": "^2.12.0",
"ts-jest": "^29.1.2",
"typescript": "^5.4.5"
},
"overrides": {
"lmdb": "2.6.0"
Expand Down
3 changes: 2 additions & 1 deletion packages/models/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */,
"types": ["node", "jest"]
},
"include": ["src/**/*", "demo/**/*"],
"exclude": ["dist/**/*"]
Expand Down
3 changes: 2 additions & 1 deletion packages/pdfium/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
docker
docker
dist
10 changes: 7 additions & 3 deletions packages/pdfium/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ RUN bash -x ./pdfium/build/install-build-deps.sh

FROM pdfium-src AS pdfium-patch
COPY build/patch/BUILD.gn /build/pdfium/BUILD.gn
COPY build/patch/build/compiler/BUILD.gn /build/pdfium/build/compiler/BUILD.gn
COPY build/patch/build/config/wasm/BUILD.gn /build/pdfium/build/config/wasm/BUILD.gn
COPY build/patch/build/config/BUILDCONFIG.gn /build/pdfium/build/config/BUILDCONFIG.gn
COPY build/patch/build/toolchain/wasm/BUILD.gn /build/pdfium/build/toolchain/wasm/BUILD.gn
COPY build/patch/core/fxge/BUILD.gn /build/pdfium/core/fxge/BUILD.gn
Expand All @@ -42,4 +40,10 @@ WORKDIR /build/pdfium
RUN gn gen out/prod --args='use_goma=false is_debug=false treat_warnings_as_errors=false pdf_use_skia=false pdf_enable_xfa=false pdf_enable_v8=false is_component_build=false clang_use_chrome_plugins=false pdf_is_standalone=true use_debug_fission=false use_custom_libcxx=false use_sysroot=false pdf_is_complete_lib=true pdf_use_partition_alloc=false is_clang=false symbol_level=0'
RUN echo 'target_os="wasm"' >> out/prod/args.gn
RUN echo 'target_cpu="wasm"' >> out/prod/args.gn
RUN ninja -C out/prod pdfium
RUN ninja -C out/prod pdfium -v

FROM pdfium-compile AS pdfium-wasm
RUN mkdir /build/out
COPY build/code/cpp/wasm.cpp /build/out
WORKDIR /build/out
RUN em++ wasm.cpp /build/pdfium/out/prod/obj/libpdfium.a -O2 -sEXPORT_ES6=1 -sENVIRONMENT=worker -sWASM_BIGINT -sMODULARIZE=1 -sWASM=1 -sALLOW_MEMORY_GROWTH=1 -sEXPORT_NAME=createPdfium -sUSE_ZLIB=1 -sUSE_LIBJPEG=1 -sASSERTIONS=1 -I/build/pdfium/public -L/build/pdfium/out/prod/obj -std=c++11 -Wall --no-entry -o ./pdfium.js
2 changes: 1 addition & 1 deletion packages/pdfium/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ clean:
.PHONY: build
build:
make clean
docker buildx build -o ./docker .
docker buildx build -o docker .
27 changes: 27 additions & 0 deletions packages/pdfium/build/code/cpp/wasm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "fpdfview.h"
#include <emscripten.h>

#ifdef __cplusplus
extern "C"
{
#endif

EMSCRIPTEN_KEEPALIVE void PDFium_Init();

#ifdef __cplusplus
}
#endif

void PDFium_Init()
{
// https://source.chromium.org/chromium/chromium/src/+/master:third_party/pdfium/samples/pdfium_test.cc;l=1172

FPDF_LIBRARY_CONFIG config;
config.version = 3;
config.m_pUserFontPaths = nullptr;
config.m_pIsolate = nullptr;
config.m_v8EmbedderSlot = 0;
config.m_pPlatform = nullptr;

FPDF_InitLibraryWithConfig(&config);
}
10 changes: 0 additions & 10 deletions packages/pdfium/build/js/export-runtime.js

This file was deleted.

3 changes: 0 additions & 3 deletions packages/pdfium/build/js/export.js

This file was deleted.

Empty file removed packages/pdfium/build/js/pre.js
Empty file.
Loading

0 comments on commit 9a9edd8

Please sign in to comment.