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

fixes a lot #125

Merged
merged 7 commits into from
Aug 17, 2024
Merged
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
15 changes: 5 additions & 10 deletions docker/android/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@ ARG DEBIAN_FRONTEND=noninteractive

ENV PROJ_TARGET="android"

ENV ANDROID_NDK_VERSION="r21d"
ENV ANDROID_COMPILE_SDK="30"
ENV ANDROID_BUILD_TOOLS="30.0.2"
ENV ANDROID_SDK_TOOLS_REV="4333796"
ENV ANDROID_CMAKE_REV="3.6.4111459"
ENV ANDROID_CMAKE_REV_3_10="3.10.2.4988404"
ENV ANDROID_NDK_VERSION="r25c"
ENV ANDROID_HOME="/opt/android-sdk-linux"
ENV ANDROID_NDK_HOME="/opt/android-ndk-linux"

ENV GRADLE_VERSION="6.1.1"
ENV GRADLE_HOME="/opt/gradle-6.1.1"
ENV GRADLE_VERSION="8.10"
ENV GRADLE_HOME="/opt/gradle-8.10"

ENV JAVA_VERSION="8"
ENV JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/"
ENV JAVA_VERSION="17"
ENV JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64/"

ENV PYTHONIOENCODING="utf8"
ENV LC_ALL=C.UTF-8
Expand Down
4 changes: 4 additions & 0 deletions docs/BUILD_ANDROID.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ Now you can execute any command with pattern:
If you are in a macOS with arm64 processors (M*), build with command:

```docker build --platform linux/amd64 -t pdfium-android -f docker/android/Dockerfile docker/android```

and

```docker run --platform linux/amd64 -v ${PWD}:/app -it pdfium-android echo "test"```
4 changes: 4 additions & 0 deletions docs/BUILD_WASM.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ If you are in a macOS with arm64 processors (M*), build with command:

```docker build --platform linux/amd64 -t pdfium-wasm -f docker/wasm/Dockerfile docker/wasm```

and

```docker run --platform linux/amd64 -v ${PWD}:/app -it pdfium-wasm echo "test"```

## Run on browser

You can test the sample using commands:
Expand Down
40 changes: 13 additions & 27 deletions modules/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from pygemstones.system import runner as r
from pygemstones.util import log as l

import modules.common as cm
import modules.config as c
import modules.patch as patch
import modules.pdfium as p


Expand All @@ -21,17 +23,12 @@ def run_task_patch():
source_dir = os.path.join("build", "android", "pdfium")

# shared lib
source_file = os.path.join(source_dir, "BUILD.gn")
if c.shared_lib_android:
patch.apply_shared_library("android")

original_content = 'component("pdfium") {'
has_content = f.file_has_content(source_file, original_content)

if has_content:
new_content = 'shared_library("pdfium") {'
f.replace_in_file(source_file, original_content, new_content)
l.bullet("Applied: shared lib", l.GREEN)
else:
l.bullet("Skipped: shared lib", l.PURPLE)
# public headers
if c.shared_lib_android:
patch.apply_public_headers("android")

# build config
source_file = os.path.join(
Expand Down Expand Up @@ -90,23 +87,12 @@ def run_task_build():
l.YELLOW,
)

arg_is_debug = "true" if config == "debug" else "false"

args = []
args.append('target_os="{0}"'.format(target["pdfium_os"]))
args.append('target_cpu="{0}"'.format(target["target_cpu"]))
args.append("use_goma=false")
args.append("is_debug={0}".format(arg_is_debug))
args.append("treat_warnings_as_errors=false")
args.append("pdf_use_skia=false")
args.append("pdf_enable_xfa=false")
args.append("pdf_enable_v8=false")
args.append("is_component_build=false")
args.append("pdf_is_standalone=true")
args.append("pdf_bundle_freetype=true")

if config == "release":
args.append("symbol_level=0")
args = cm.get_build_args(
config,
c.shared_lib_android,
target["pdfium_os"],
target["target_cpu"],
)

args_str = " ".join(args)

Expand Down
88 changes: 88 additions & 0 deletions modules/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,91 @@ def run_task_format():
r.run(command)

l.ok()


# -----------------------------------------------------------------------------
def get_build_args(
config,
shared,
target_os,
target_cpu,
target_environment=None,
libc=None,
enable_v8=False,
):
args = []

arg_is_debug = "true" if config == "debug" else "false"

args.append(f"is_debug={arg_is_debug}")
args.append("pdf_use_partition_alloc=false")
args.append(f'target_cpu="{target_cpu}"')
args.append(f'target_os="{target_os}"')
args.append(f"pdf_enable_v8={str(enable_v8).lower()}")
args.append(f"pdf_enable_xfa={str(enable_v8).lower()}")
args.append("treat_warnings_as_errors=false")
args.append("is_component_build=false")

if enable_v8:
args.append("v8_use_external_startup_data=false")
args.append("v8_enable_i18n_support=false")

if target_os == "android":
args.append("clang_use_chrome_plugins=false")
args.append("default_min_sdk_version=21")
args.append("pdf_is_standalone=true")
args.append("pdf_bundle_freetype=true")
elif target_os == "ios":
args.append("ios_enable_code_signing=false")
args.append("use_blink=true")
args.append("pdf_is_standalone=false")
args.append("use_custom_libcxx=false")
args.append('target_environment="{0}"'.format(target_environment))

if enable_v8 and target_cpu == "arm64":
args.append('arm_control_flow_integrity="none"')
args.append("clang_use_chrome_plugins=false")

# static lib
if not shared:
args.append("pdf_is_complete_lib=true")
elif target_os == "linux":
args.append("clang_use_chrome_plugins=false")
args.append("pdf_is_standalone=true")
elif target_os.startswith("mac"):
args.append('mac_deployment_target="10.13.0"')
args.append("clang_use_chrome_plugins=false")
args.append("pdf_is_standalone=true")
args.append("use_custom_libcxx=false")
args.append("use_sysroot=false")
args.append("use_allocator_shim=false")

# static lib
if not shared:
args.append("pdf_is_complete_lib=true")
elif target_os.startswith("wasm"):
args.append("pdf_is_complete_lib=true")
args.append("is_clang=false")
args.append("use_custom_libcxx=false")
args.append("use_sysroot=false")

if libc == "musl":
args.append("is_musl=true")
args.append("is_clang=false")
args.append("use_custom_libcxx=false")

if enable_v8:
if target_cpu == "arm":
args.append(
'v8_snapshot_toolchain="//build/toolchain/linux:clang_x86_v8_arm"'
)
elif target_cpu == "arm64":
args.append(
'v8_snapshot_toolchain="//build/toolchain/linux:clang_x64_v8_arm64"'
)
else:
args.append(
f'v8_snapshot_toolchain="//build/toolchain/linux:{target_cpu}"'
)

return args
4 changes: 4 additions & 0 deletions modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@

# macos
configurations_macos = ["release"]
shared_lib_macos = False
targets_macos = [
{"target_os": "macos", "target_cpu": "x64", "pdfium_os": "mac"},
{"target_os": "macos", "target_cpu": "arm64", "pdfium_os": "mac"},
]

# ios
configurations_ios = ["release"]
shared_lib_ios = False
targets_ios = [
{
"target_os": "ios",
Expand All @@ -44,6 +46,7 @@

# android
configurations_android = ["release"]
shared_lib_android = True
targets_android = [
{
"target_os": "android",
Expand Down Expand Up @@ -73,6 +76,7 @@

# wasm
configurations_wasm = ["release"]
shared_lib_wasm = False
targets_wasm = [
{"target_os": "wasm32", "target_cpu": "wasm", "pdfium_os": "wasm"},
]
45 changes: 17 additions & 28 deletions modules/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from pygemstones.system import runner as r
from pygemstones.util import log as l

import modules.common as cm
import modules.config as c
import modules.patch as patch
import modules.pdfium as p


Expand All @@ -21,6 +23,14 @@ def run_task_patch():

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

# shared lib
if c.shared_lib_ios:
patch.apply_shared_library("ios")

# public headers
if c.shared_lib_ios:
patch.apply_public_headers("ios")

# rules - test
source_file = os.path.join(source_dir, "build", "config", "ios", "rules.gni")

Expand Down Expand Up @@ -115,34 +125,13 @@ def run_task_build():
l.YELLOW,
)

arg_is_debug = "true" if config == "debug" else "false"

args = []
args.append('target_os="{0}"'.format(target["pdfium_os"]))
args.append('target_cpu="{0}"'.format(target["target_cpu"]))
args.append('target_environment="{0}"'.format(target["target_environment"]))
args.append("use_goma=false")
args.append("is_debug={0}".format(arg_is_debug))
args.append("treat_warnings_as_errors=false")
args.append("pdf_use_skia=false")
args.append("pdf_enable_xfa=false")
args.append("pdf_enable_v8=false")
args.append("is_component_build=false")
args.append("clang_use_chrome_plugins=false")
args.append("pdf_is_standalone=false")
args.append('ios_deployment_target="11.0"')
args.append("ios_enable_code_signing=false")
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")
args.append("use_blink=true")

if target["target_cpu"] == "arm64":
args.append("enable_ios_bitcode=true")

if config == "release":
args.append("symbol_level=0")
args = cm.get_build_args(
config,
c.shared_lib_ios,
target["pdfium_os"],
target["target_cpu"],
target["target_environment"],
)

args_str = " ".join(args)

Expand Down
40 changes: 15 additions & 25 deletions modules/macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from pygemstones.system import runner as r
from pygemstones.util import log as l

import modules.common as cm
import modules.config as c
import modules.patch as patch
import modules.pdfium as p


Expand All @@ -19,7 +21,13 @@ def run_task_build_pdfium():
def run_task_patch():
l.colored("Patching files...", l.YELLOW)

# none
# shared lib
if c.shared_lib_macos:
patch.apply_shared_library("macos")

# public headers
if c.shared_lib_macos:
patch.apply_public_headers("macos")

l.ok()

Expand Down Expand Up @@ -60,30 +68,12 @@ def run_task_build():
l.YELLOW,
)

arg_is_debug = "true" if config == "debug" else "false"

args = []
args.append('target_os="{0}"'.format(target["pdfium_os"]))
args.append('target_cpu="{0}"'.format(target["target_cpu"]))
args.append("use_goma=false")
args.append("is_debug={0}".format(arg_is_debug))
args.append("treat_warnings_as_errors=false")
args.append("pdf_use_skia=false")
args.append("pdf_enable_xfa=false")
args.append("pdf_enable_v8=false")
args.append("is_component_build=false")
args.append("clang_use_chrome_plugins=false")
args.append("pdf_is_standalone=true")
args.append("use_xcode_clang=false")
args.append("pdf_is_complete_lib=true")
args.append("use_custom_libcxx=false")
args.append("use_sysroot=false")
args.append('mac_deployment_target="11.0.0"')
args.append("pdf_use_partition_alloc=false")
args.append("use_allocator_shim=false")

if config == "release":
args.append("symbol_level=0")
args = cm.get_build_args(
config,
c.shared_lib_macos,
target["pdfium_os"],
target["target_cpu"],
)

args_str = " ".join(args)

Expand Down
Loading
Loading