Skip to content

Commit

Permalink
Merge pull request #79 from paulocoutinhox/wasm-modularize
Browse files Browse the repository at this point in the history
wasm modularize and sample for ios and mac
  • Loading branch information
paulocoutinhox authored Nov 8, 2022
2 parents 2f6b4e5 + 6e6db22 commit 37f7aa0
Show file tree
Hide file tree
Showing 42 changed files with 2,366 additions and 41 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/android.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: Android

on: [push]
on:
push:
paths-ignore:
- '**.md'
- 'docs/**'
- 'extras/images/**'

jobs:
build:
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/ios.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: iOS

on: [push]
on:
push:
paths-ignore:
- '**.md'
- 'docs/**'
- 'extras/images/**'

env:
CMAKE_VERSION: "3.24.0"
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: macOS

on: [push]
on:
push:
paths-ignore:
- '**.md'
- 'docs/**'
- 'extras/images/**'

env:
CMAKE_VERSION: "3.24.0"
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: WASM

on: [push]
on:
push:
paths-ignore:
- '**.md'
- 'docs/**'
- 'extras/images/**'

jobs:
build:
Expand Down
30 changes: 18 additions & 12 deletions docs/BUILD_IOS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,26 @@

1. Execute all **general** steps

2. Get PDFium:
```python3 make.py build-pdfium-ios```
2. Get PDFium:
```python3 make.py build-pdfium-ios```

3. Patch:
```python3 make.py patch-ios```
3. Patch:
```python3 make.py patch-ios```

4. Compile:
```python3 make.py build-ios```

5. Install libraries:
```python3 make.py install-ios```
4. Compile:
```python3 make.py build-ios```

6. Test:
```python3 make.py test-ios```
5. Install libraries:
```python3 make.py install-ios```

6. Test:
```python3 make.py test-ios```

Obs:
- The file **make.py** need be executed with python version 3.
- The file **make.py** need be executed with python version 3.

# Sample

The sample project is here: `sample-apple/Sample.xcodeproj`.

Copy the `pdfium.xcframework` to folder `sample-apple/Sample/Vendor`.
30 changes: 18 additions & 12 deletions docs/BUILD_MACOS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,26 @@

1. Execute all **general** steps

2. Get PDFium:
```python3 make.py build-pdfium-macos```
2. Get PDFium:
```python3 make.py build-pdfium-macos```

3. Patch:
```python3 make.py patch-macos```
3. Patch:
```python3 make.py patch-macos```

4. Compile:
```python3 make.py build-macos```

5. Install libraries:
```python3 make.py install-macos```
4. Compile:
```python3 make.py build-macos```

6. Test:
```python3 make.py test-macos```
5. Install libraries:
```python3 make.py install-macos```

6. Test:
```python3 make.py test-macos```

Obs:
- The file **make.py** need be executed with python version 3.
- The file **make.py** need be executed with python version 3.

# Sample

The sample project is here: `sample-apple/Sample.xcodeproj`.

Copy the `include` and `lib` dirs to folder `sample-apple/SampleMac/Vendor`.
7 changes: 5 additions & 2 deletions extras/wasm/template/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
let autoOpenMode = true;
let doc;
let FPDF = {};
let Module = null;

// pdfium initialization
Object.assign(FPDF, {
Expand Down Expand Up @@ -279,15 +280,17 @@
}

// runtime initialized
Module.onRuntimeInitialized = async _ => {
PDFiumModule().then(function (pdfiumModule) {
Module = pdfiumModule;

moduleLoaded = true;

if (pageLoaded) {
console.log('The module was loaded!');
}

checkIfEverythingWasLoaded();
};
});

// functions
async function loadFile() {
Expand Down
2 changes: 1 addition & 1 deletion modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@
# wasm
configurations_wasm = ["release"]
targets_wasm = [
{"target_os": "wasm", "target_cpu": "wasm", "pdfium_os": "wasm"},
{"target_os": "wasm32", "target_cpu": "wasm", "pdfium_os": "wasm"},
]
1 change: 1 addition & 0 deletions modules/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def run_task_build():
args.append("use_xcode_clang=true")
args.append("pdf_is_complete_lib=true")
args.append("use_custom_libcxx=false")
args.append("pdf_use_partition_alloc=false")

if target["target_cpu"] == "arm64":
args.append("enable_ios_bitcode=true")
Expand Down
22 changes: 12 additions & 10 deletions modules/wasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

# -----------------------------------------------------------------------------
def run_task_build_pdfium():
p.get_pdfium_by_target("wasm")
p.get_pdfium_by_target("wasm32")


# -----------------------------------------------------------------------------
def run_task_patch():
l.colored("Patching files...", l.YELLOW)

source_dir = os.path.join("build", "wasm", "pdfium")
source_dir = os.path.join("build", "wasm32", "pdfium")

# build target
source_file = os.path.join(
Expand Down Expand Up @@ -450,7 +450,7 @@ def run_task_install():
# headers
l.colored("Copying header files...", l.YELLOW)

include_dir = os.path.join("build", "wasm", "pdfium", "public")
include_dir = os.path.join("build", "wasm32", "pdfium", "public")
include_cpp_dir = os.path.join(include_dir, "cpp")
target_include_dir = os.path.join(
"build", target["target_os"], target["target_cpu"], config, "include"
Expand Down Expand Up @@ -620,16 +620,16 @@ def run_task_generate():

f.recreate_dir(gen_out_dir)

html_file = os.path.join(
output_file = os.path.join(
gen_out_dir,
"pdfium.html",
"pdfium.js",
)

command = [
"em++",
"{0}".format("-g" if config == "debug" else "-O3"),
"-o",
html_file,
output_file,
"-s",
'EXPORTED_FUNCTIONS="$(node function-names ../xml/index.xml)"',
"-s",
Expand All @@ -649,6 +649,8 @@ def run_task_generate():
"ASSERTIONS=1",
"-s",
"ALLOW_MEMORY_GROWTH=1",
"-sMODULARIZE",
"-sEXPORT_NAME=PDFiumModule",
"-std=c++11",
"-Wall",
"--no-entry",
Expand Down Expand Up @@ -700,8 +702,8 @@ def run_task_publish():
l.colored("Publishing...", l.YELLOW)

current_dir = f.current_dir()
publish_dir = os.path.join(current_dir, "build", "wasm", "publish")
node_dir = os.path.join(current_dir, "build", "wasm", "wasm", "release", "node")
publish_dir = os.path.join(current_dir, "build", "wasm32", "publish")
node_dir = os.path.join(current_dir, "build", "wasm32", "wasm", "release", "node")
template_dir = os.path.join(current_dir, "extras", "wasm", "template")

# copy generated files
Expand All @@ -723,8 +725,8 @@ def run_task_publish_to_web():
l.colored("Publishing...", l.YELLOW)

current_dir = os.getcwd()
publish_dir = os.path.join(current_dir, "build", "wasm", "publish")
node_dir = os.path.join(current_dir, "build", "wasm", "wasm", "release", "node")
publish_dir = os.path.join(current_dir, "build", "wasm32", "publish")
node_dir = os.path.join(current_dir, "build", "wasm32", "wasm", "release", "node")
template_dir = os.path.join(current_dir, "extras", "wasm", "template")

# copy generated files
Expand Down
33 changes: 33 additions & 0 deletions sample-apple/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# trash
.DS_Store
Thumbs.db

# xcode
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate

# intelliJ
.idea
*.iml

# misc
/Fastlane/*.xml
/Fastlane/*.md
/Carthage
/Pods
Podfile.lock
Gemfile.lock
Loading

0 comments on commit 37f7aa0

Please sign in to comment.