Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for windows #88

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:
matrix:
config:
- { name: "Ubuntu", os: "ubuntu-20.04", target: "android" }
python-version: [3.7]
python-version: [3.9]

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -35,8 +35,10 @@ jobs:
- name: Display PIP version
run: python3 -m pip --version

- name: Python requirements
run: python3 -m pip install -r requirements.txt --user
- name: Python Requirements
run: |
python3 -m pip install -r requirements.txt --user
echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Remove trash
run: |
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ jobs:
matrix:
config:
- { name: "macOS", os: "macos-latest", target: "ios" }
python-version: [3.7]
python-version: [3.9]

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

Expand Down Expand Up @@ -81,8 +81,10 @@ jobs:
)
endif()

- name: Python requirements
run: python3 -m pip install -r requirements.txt --user
- name: Python Requirements
run: |
python3 -m pip install -r requirements.txt --user
echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Depot tools
run: python3 make.py build-depot-tools
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ jobs:
matrix:
config:
- { name: "macOS", os: "macos-latest", target: "macos" }
python-version: [3.7]
python-version: [3.9]

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

Expand Down Expand Up @@ -81,8 +81,10 @@ jobs:
)
endif()

- name: Python requirements
run: python3 -m pip install -r requirements.txt --user
- name: Python Requirements
run: |
python3 -m pip install -r requirements.txt --user
echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Depot tools
run: python3 make.py build-depot-tools
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:
matrix:
config:
- { name: "Ubuntu", os: "ubuntu-20.04", target: "wasm" }
python-version: [3.7]
python-version: [3.9]

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -35,8 +35,10 @@ jobs:
- name: Display PIP version
run: python3 -m pip --version

- name: Python requirements
run: python3 -m pip install -r requirements.txt --user
- name: Python Requirements
run: |
python3 -m pip install -r requirements.txt --user
echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Docker build
run: docker build -t pdfium-wasm -f docker/wasm/Dockerfile docker/wasm
Expand Down
150 changes: 150 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
name: Windows

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

env:
CMAKE_VERSION: "3.24.0"
NINJA_VERSION: "1.10.0"

jobs:
build:
name: ${{ matrix.config.name }}
runs-on: ${{ matrix.config.os }}
strategy:
fail-fast: false
matrix:
config:
- { name: "Windows", os: "windows-latest", target: "windows" }
python-version: [3.9]

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Upgrade PIP
run: python3 -m pip install --upgrade pip setuptools wheel

- name: Display Python version
run: python3 --version

- name: Display PIP version
run: python3 -m pip --version

- name: Install Ninja and CMake
id: cmake_and_ninja
shell: cmake -P {0}
run: |
set(cmake_version $ENV{CMAKE_VERSION})
set(ninja_version $ENV{NINJA_VERSION})

message(STATUS "Using host CMake version: ${CMAKE_VERSION}")

if ("${{ runner.os }}" STREQUAL "Windows")
set(ninja_suffix "win.zip")
set(cmake_suffix "win64-x64.zip")
set(cmake_dir "cmake-${cmake_version}-win64-x64/bin")
elseif ("${{ runner.os }}" STREQUAL "Linux")
set(ninja_suffix "linux.zip")
set(cmake_suffix "Linux-x86_64.tar.gz")
set(cmake_dir "cmake-${cmake_version}-Linux-x86_64/bin")
elseif ("${{ runner.os }}" STREQUAL "macOS")
set(ninja_suffix "mac.zip")
set(cmake_suffix "Darwin-x86_64.tar.gz")
set(cmake_dir "cmake-${cmake_version}-Darwin-x86_64/CMake.app/Contents/bin")
endif()

set(ninja_url "https://github.com/ninja-build/ninja/releases/download/v${ninja_version}/ninja-${ninja_suffix}")
file(DOWNLOAD "${ninja_url}" ./ninja.zip SHOW_PROGRESS)
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xvf ./ninja.zip)

set(cmake_url "https://github.com/Kitware/CMake/releases/download/v${cmake_version}/cmake-${cmake_version}-${cmake_suffix}")
file(DOWNLOAD "${cmake_url}" ./cmake.zip SHOW_PROGRESS)
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xvf ./cmake.zip)

# Save the path for other steps
file(TO_CMAKE_PATH "$ENV{GITHUB_WORKSPACE}/${cmake_dir}" cmake_dir)
message("::set-output name=cmake_dir::${cmake_dir}")

if (NOT "${{ runner.os }}" STREQUAL "Windows")
execute_process(
COMMAND chmod +x ninja
COMMAND chmod +x ${cmake_dir}/cmake
)
endif()

- name: Python Requirements
run: |
python3 -m pip install -r requirements.txt --user
echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Depot tools
run: python3 make.py build-depot-tools

- name: Environment
run: |
echo "${PWD}/build/depot-tools" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
echo "DEPOT_TOOLS_WIN_TOOLCHAIN=0" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append

- name: PDFium
run: python3 make.py build-pdfium-${{ matrix.config.target }}

- name: Patch
run: |
python3 -m pip install -r requirements.txt --user
python3 make.py patch-${{ matrix.config.target }}

- name: Patch - Check
run: python3 make.py patch-${{ matrix.config.target }}

- name: Build
run: python3 make.py build-${{ matrix.config.target }}

- name: Install
run: python3 make.py install-${{ matrix.config.target }}

- name: Test
run: python3 make.py test-${{ matrix.config.target }}

- name: Archive
run: python3 make.py archive-${{ matrix.config.target }}

- name: Save
uses: actions/upload-artifact@v2
with:
name: artifact-${{ matrix.config.target }}
path: ${{ matrix.config.target }}.tgz

deploy:
name: Deploy
runs-on: ubuntu-latest
needs: [build]
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Load
uses: actions/download-artifact@v2
with:
name: artifact-windows
- name: Get release
id: get_release
uses: bruceadams/[email protected]
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Upload release asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.get_release.outputs.upload_url }}
asset_path: windows.tgz
asset_name: windows.tgz
asset_content_type: application/tar+gzip
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ Thumbs.db
__pycache__/
*.py[cod]
*$py.class
.ruff_cache
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
<a href="https://github.com/paulocoutinhox/pdfium-lib/actions/workflows/macos.yml"><img src="https://github.com/paulocoutinhox/pdfium-lib/actions/workflows/macos.yml/badge.svg" alt="PDFium - macOS"></a>
<a href="https://github.com/paulocoutinhox/pdfium-lib/actions/workflows/android.yml"><img src="https://github.com/paulocoutinhox/pdfium-lib/actions/workflows/android.yml/badge.svg" alt="PDFium - Android"></a>
<a href="https://github.com/paulocoutinhox/pdfium-lib/actions/workflows/wasm.yml"><img src="https://github.com/paulocoutinhox/pdfium-lib/actions/workflows/wasm.yml/badge.svg" alt="PDFium - WASM"></a>
<a href="https://github.com/paulocoutinhox/pdfium-lib/actions/workflows/windows.yml"><img src="https://github.com/paulocoutinhox/pdfium-lib/actions/workflows/windows.yml/badge.svg" alt="PDFium - Windows"></a>
</p>

<p align="center">
Project to compile PDFium library to multiple platforms.
Project to compile cross-platform PDFium library from locally reproducible scripts.
</p>

<br>
Expand All @@ -28,11 +29,11 @@ This project currently compiles to these platforms:
- [X] Android (armv7, armv8, x86, x86_64)
- [x] macOS (x86_64, arm64)
- [x] WASM (Web Assembly)
- [x] Windows

Platforms in roadmap:

- Linux
- Windows

Obs: PDFium project is from Google and i only patch it to compile to all platforms above. Check all oficial details and PDFium license here:

Expand Down
30 changes: 30 additions & 0 deletions docs/BUILD_WINDOWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Build for Windows

1. Execute all **general** steps

2. Export some environment variables:
```
set DEPOT_TOOLS_WIN_TOOLCHAIN=0
```

3. Get PDFium:
```python3 make.py build-pdfium-windows```

4. Patch:
```python3 make.py patch-windows```

5. Compile:
```python3 make.py build-windows```

6. Install libraries:
```python3 make.py install-windows```

7. Test:
```python3 make.py test-windows```

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

# Sample

The sample project is here: `sample`.
36 changes: 36 additions & 0 deletions make.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@
- publish-wasm
- publish-to-web-wasm
- archive-wasm

- build-pdfium-windows
- patch-windows
- build-windows
- install-windows
- test-windows
- archive-windows
"""

from docopt import docopt
Expand All @@ -65,6 +72,7 @@
import modules.ios as ios
import modules.macos as macos
import modules.wasm as wasm
import modules.windows as windows


def main(options):
Expand Down Expand Up @@ -227,6 +235,34 @@ def main(options):
elif task == "archive-wasm":
wasm.run_task_archive()

#######################
# Windows
#######################

# build pdfium - windows
elif task == "build-pdfium-windows":
windows.run_task_build_pdfium()

# patch - windows
elif task == "patch-windows":
windows.run_task_patch()

# build - windows
elif task == "build-windows":
windows.run_task_build()

# install - windows
elif task == "install-windows":
windows.run_task_install()

# test - windows
elif task == "test-windows":
windows.run_task_test()

# archive - windows
elif task == "archive-windows":
windows.run_task_archive()

#######################
# Invalid
#######################
Expand Down
3 changes: 3 additions & 0 deletions modules/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ def run_task_build_depot_tools():
r.run(command, cwd=cwd)

l.colored("Execute on your terminal:", l.PURPLE)

l.m("export PATH=$PATH:$PWD/build/depot-tools")
l.colored("Or on Windows:", l.PURPLE)
l.m("set PATH=%PATH%;{0}".format(os.path.abspath(tools_dir)))

l.ok()

Expand Down
Loading