From f66a31c88a486cee230f81ba78b88b4aae4f377b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPaulo?= Date: Fri, 16 Aug 2024 18:06:27 -0300 Subject: [PATCH 1/7] fixes a lot --- docker/android/Dockerfile | 15 ++++------ docs/BUILD_ANDROID.md | 4 +++ docs/BUILD_WASM.md | 4 +++ modules/android.py | 35 +++++------------------ modules/common.py | 60 +++++++++++++++++++++++++++++++++++++++ modules/config.py | 4 +++ modules/ios.py | 39 +++++++------------------ modules/macos.py | 35 ++++++----------------- modules/patch.py | 50 ++++++++++++++++++++++++++++++++ modules/wasm.py | 34 +++++++--------------- 10 files changed, 163 insertions(+), 117 deletions(-) create mode 100644 modules/patch.py diff --git a/docker/android/Dockerfile b/docker/android/Dockerfile index c5f8ad0..3870610 100644 --- a/docker/android/Dockerfile +++ b/docker/android/Dockerfile @@ -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 diff --git a/docs/BUILD_ANDROID.md b/docs/BUILD_ANDROID.md index 0ab845f..b0a4936 100644 --- a/docs/BUILD_ANDROID.md +++ b/docs/BUILD_ANDROID.md @@ -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"``` diff --git a/docs/BUILD_WASM.md b/docs/BUILD_WASM.md index bfa8794..0db5108 100644 --- a/docs/BUILD_WASM.md +++ b/docs/BUILD_WASM.md @@ -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: diff --git a/modules/android.py b/modules/android.py index d02e9db..b6a61ed 100644 --- a/modules/android.py +++ b/modules/android.py @@ -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 @@ -21,17 +23,11 @@ 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 + patch.apply_public_headers("android") # build config source_file = os.path.join( @@ -90,24 +86,7 @@ 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, target["pdfium_os"], target["target_cpu"]) args_str = " ".join(args) command = [ diff --git a/modules/common.py b/modules/common.py index c8b73cb..78cc79a 100644 --- a/modules/common.py +++ b/modules/common.py @@ -102,3 +102,63 @@ def run_task_format(): r.run(command) l.ok() + + +# ----------------------------------------------------------------------------- +def get_build_args(config, target_os, target_cpu, 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_is_standalone=true") + 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") + elif target_os == "ios": + args.append("ios_enable_code_signing=false") + args.append("use_blink=true") + if enable_v8 and target_cpu == "arm64": + args.append('arm_control_flow_integrity="none"') + args.append("clang_use_chrome_plugins=false") + elif target_os == "linux": + args.append("clang_use_chrome_plugins=false") + elif target_os == "mac": + args.append('mac_deployment_target="10.13.0"') + args.append("clang_use_chrome_plugins=false") + elif target_os == "wasm": + args.append("pdf_is_complete_lib=true") + args.append("is_clang=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 diff --git a/modules/config.py b/modules/config.py index 97be6bc..9774105 100644 --- a/modules/config.py +++ b/modules/config.py @@ -14,6 +14,7 @@ # 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"}, @@ -21,6 +22,7 @@ # ios configurations_ios = ["release"] +shared_lib_ios = False targets_ios = [ { "target_os": "ios", @@ -44,6 +46,7 @@ # android configurations_android = ["release"] +shared_lib_android = True targets_android = [ { "target_os": "android", @@ -73,6 +76,7 @@ # wasm configurations_wasm = ["release"] +shared_lib_wasm = False targets_wasm = [ {"target_os": "wasm32", "target_cpu": "wasm", "pdfium_os": "wasm"}, ] diff --git a/modules/ios.py b/modules/ios.py index 1c7dafd..ab96a17 100644 --- a/modules/ios.py +++ b/modules/ios.py @@ -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 @@ -21,6 +23,13 @@ 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 + patch.apply_public_headers("ios") + # rules - test source_file = os.path.join(source_dir, "build", "config", "ios", "rules.gni") @@ -115,35 +124,7 @@ 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, target["pdfium_os"], target["target_cpu"]) args_str = " ".join(args) command = [ diff --git a/modules/macos.py b/modules/macos.py index 46d9fd6..f071d70 100644 --- a/modules/macos.py +++ b/modules/macos.py @@ -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 @@ -19,7 +21,12 @@ 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 + patch.apply_public_headers("macos") l.ok() @@ -60,31 +67,7 @@ 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, target["pdfium_os"], target["target_cpu"]) args_str = " ".join(args) command = [ diff --git a/modules/patch.py b/modules/patch.py new file mode 100644 index 0000000..9f1b230 --- /dev/null +++ b/modules/patch.py @@ -0,0 +1,50 @@ +import os + +from pygemstones.io import file as f +from pygemstones.util import log as l + + +# ----------------------------------------------------------------------------- +def apply_shared_library(target): + source_dir = os.path.join("build", target, "pdfium") + source_file = os.path.join(source_dir, "BUILD.gn") + + 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 library", l.GREEN) + else: + l.bullet("Skipped: shared library", l.PURPLE) + + +# ----------------------------------------------------------------------------- +def apply_public_headers(target): + source_dir = os.path.join("build", target, "pdfium") + public_dir = os.path.join(source_dir, "public") + + # file: public/fpdfview.h (p1) + source_file = os.path.join(public_dir, "fpdfview.h") + + original_content = "#if defined(COMPONENT_BUILD)\n// FPDF_EXPORT should be consistent with |export| in the pdfium_fuzzer\n// template in testing/fuzzers/BUILD.gn." + has_content = f.file_has_content(source_file, original_content) + + if has_content: + f.replace_in_file(source_file, original_content, "") + l.bullet("Applied: public headers (p1)", l.GREEN) + else: + l.bullet("Skipped: public headers (p1)", l.PURPLE) + + # file: public/fpdfview.h (p2) + source_file = os.path.join(public_dir, "fpdfview.h") + + original_content = "#else\n#define FPDF_EXPORT\n#endif // defined(COMPONENT_BUILD)" + has_content = f.file_has_content(source_file, original_content) + + if has_content: + f.replace_in_file(source_file, original_content, "") + l.bullet("Applied: public headers (p2)", l.GREEN) + else: + l.bullet("Skipped: public headers (p2)", l.PURPLE) diff --git a/modules/wasm.py b/modules/wasm.py index 1547b32..0ca9d19 100644 --- a/modules/wasm.py +++ b/modules/wasm.py @@ -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 @@ -21,6 +23,13 @@ def run_task_patch(): source_dir = os.path.join("build", "wasm32", "pdfium") + # shared lib + if c.shared_lib_wasm: + patch.apply_shared_library("wasm32") + + # public headers + patch.apply_public_headers("wasm32") + # build target source_file = os.path.join( source_dir, @@ -318,30 +327,7 @@ 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_debug_fission=false") - args.append("use_custom_libcxx=false") - args.append("use_sysroot=false") - args.append("pdf_is_complete_lib=true") - args.append("pdf_use_partition_alloc=false") - args.append("is_clang=false") - - if config == "release": - args.append("symbol_level=0") - + args = cm.get_build_args(config, target["pdfium_os"], target["target_cpu"]) args_str = " ".join(args) command = [ From 25dfa576fcd6a9d3a4f01d21b015b362dd5306ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPaulo?= Date: Fri, 16 Aug 2024 18:40:34 -0300 Subject: [PATCH 2/7] fixes a lot --- modules/android.py | 3 ++- modules/ios.py | 3 ++- modules/macos.py | 3 ++- modules/wasm.py | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/android.py b/modules/android.py index b6a61ed..979fe14 100644 --- a/modules/android.py +++ b/modules/android.py @@ -27,7 +27,8 @@ def run_task_patch(): patch.apply_shared_library("android") # public headers - patch.apply_public_headers("android") + if c.shared_lib_android: + patch.apply_public_headers("android") # build config source_file = os.path.join( diff --git a/modules/ios.py b/modules/ios.py index ab96a17..f73c3ab 100644 --- a/modules/ios.py +++ b/modules/ios.py @@ -28,7 +28,8 @@ def run_task_patch(): patch.apply_shared_library("ios") # public headers - patch.apply_public_headers("ios") + if c.shared_lib_ios: + patch.apply_public_headers("ios") # rules - test source_file = os.path.join(source_dir, "build", "config", "ios", "rules.gni") diff --git a/modules/macos.py b/modules/macos.py index f071d70..392b10e 100644 --- a/modules/macos.py +++ b/modules/macos.py @@ -26,7 +26,8 @@ def run_task_patch(): patch.apply_shared_library("macos") # public headers - patch.apply_public_headers("macos") + if c.shared_lib_macos: + patch.apply_public_headers("macos") l.ok() diff --git a/modules/wasm.py b/modules/wasm.py index 0ca9d19..6419a91 100644 --- a/modules/wasm.py +++ b/modules/wasm.py @@ -28,7 +28,8 @@ def run_task_patch(): patch.apply_shared_library("wasm32") # public headers - patch.apply_public_headers("wasm32") + if c.shared_lib_wasm: + patch.apply_public_headers("wasm32") # build target source_file = os.path.join( From b7eea739f15dd2c58d3096a3cebd4acc16aff79e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPaulo?= Date: Sat, 17 Aug 2024 00:52:48 -0300 Subject: [PATCH 3/7] fixes a lot --- modules/common.py | 7 +++++-- modules/config.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/common.py b/modules/common.py index 78cc79a..863edb6 100644 --- a/modules/common.py +++ b/modules/common.py @@ -130,15 +130,18 @@ def get_build_args(config, target_os, target_cpu, libc=None, enable_v8=False): elif target_os == "ios": args.append("ios_enable_code_signing=false") args.append("use_blink=true") + args.append("pdf_is_complete_lib=true") + if enable_v8 and target_cpu == "arm64": args.append('arm_control_flow_integrity="none"') args.append("clang_use_chrome_plugins=false") elif target_os == "linux": args.append("clang_use_chrome_plugins=false") - elif target_os == "mac": + elif target_os.startswith("mac"): args.append('mac_deployment_target="10.13.0"') args.append("clang_use_chrome_plugins=false") - elif target_os == "wasm": + args.append("pdf_is_complete_lib=true") + elif target_os.startswith("wasm"): args.append("pdf_is_complete_lib=true") args.append("is_clang=false") diff --git a/modules/config.py b/modules/config.py index 9774105..7729893 100644 --- a/modules/config.py +++ b/modules/config.py @@ -14,7 +14,7 @@ # macos configurations_macos = ["release"] -shared_lib_macos = False +shared_lib_macos = True targets_macos = [ {"target_os": "macos", "target_cpu": "x64", "pdfium_os": "mac"}, {"target_os": "macos", "target_cpu": "arm64", "pdfium_os": "mac"}, From e0f1f1cbaf1ab856dd53985bc60915994a6337d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPaulo?= Date: Sat, 17 Aug 2024 00:55:38 -0300 Subject: [PATCH 4/7] fixes a lot --- modules/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/config.py b/modules/config.py index 7729893..9774105 100644 --- a/modules/config.py +++ b/modules/config.py @@ -14,7 +14,7 @@ # macos configurations_macos = ["release"] -shared_lib_macos = True +shared_lib_macos = False targets_macos = [ {"target_os": "macos", "target_cpu": "x64", "pdfium_os": "mac"}, {"target_os": "macos", "target_cpu": "arm64", "pdfium_os": "mac"}, From b180ecf62598472ef5f6d7abb8760987348cb716 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPaulo?= Date: Sat, 17 Aug 2024 01:11:23 -0300 Subject: [PATCH 5/7] fixes a lot --- modules/common.py | 5 +++-- modules/config.py | 4 ++-- modules/ios.py | 12 +++++++----- modules/macos.py | 9 ++++----- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/modules/common.py b/modules/common.py index 863edb6..de0b7ef 100644 --- a/modules/common.py +++ b/modules/common.py @@ -120,6 +120,9 @@ def get_build_args(config, target_os, target_cpu, libc=None, enable_v8=False): args.append("treat_warnings_as_errors=false") args.append("is_component_build=false") + # static lib + # args.append("pdf_is_complete_lib=true") + if enable_v8: args.append("v8_use_external_startup_data=false") args.append("v8_enable_i18n_support=false") @@ -130,7 +133,6 @@ def get_build_args(config, target_os, target_cpu, libc=None, enable_v8=False): elif target_os == "ios": args.append("ios_enable_code_signing=false") args.append("use_blink=true") - args.append("pdf_is_complete_lib=true") if enable_v8 and target_cpu == "arm64": args.append('arm_control_flow_integrity="none"') @@ -140,7 +142,6 @@ def get_build_args(config, target_os, target_cpu, libc=None, enable_v8=False): elif target_os.startswith("mac"): args.append('mac_deployment_target="10.13.0"') args.append("clang_use_chrome_plugins=false") - args.append("pdf_is_complete_lib=true") elif target_os.startswith("wasm"): args.append("pdf_is_complete_lib=true") args.append("is_clang=false") diff --git a/modules/config.py b/modules/config.py index 9774105..f1e4aa8 100644 --- a/modules/config.py +++ b/modules/config.py @@ -14,7 +14,7 @@ # macos configurations_macos = ["release"] -shared_lib_macos = False +shared_lib_macos = True targets_macos = [ {"target_os": "macos", "target_cpu": "x64", "pdfium_os": "mac"}, {"target_os": "macos", "target_cpu": "arm64", "pdfium_os": "mac"}, @@ -22,7 +22,7 @@ # ios configurations_ios = ["release"] -shared_lib_ios = False +shared_lib_ios = True targets_ios = [ { "target_os": "ios", diff --git a/modules/ios.py b/modules/ios.py index f73c3ab..69f4d7b 100644 --- a/modules/ios.py +++ b/modules/ios.py @@ -191,7 +191,7 @@ def run_task_install(): config, ), "obj", - "libpdfium.a", + "libpdfium.dylib", ) target_lib_path = os.path.join( @@ -199,7 +199,7 @@ def run_task_install(): target["target_os"], config, "lib", - "libpdfium_{0}-{1}.a".format( + "libpdfium_{0}-{1}.dylib".format( target["target_cpu"], target["target_environment"] ), ) @@ -222,12 +222,14 @@ def run_task_install(): # universal universal_libs = [] for env in ["simulator", "device"]: - folder = os.path.join("build", "ios", config, "lib", "*-{0}.a".format(env)) + folder = os.path.join( + "build", "ios", config, "lib", "*-{0}.dylib".format(env) + ) files = glob.glob(folder) files_str = " ".join(files) f.create_dir(os.path.join("build", "ios", config, "lib", env)) lib_file_out = os.path.join( - "build", "ios", config, "lib", env, "libpdfium.a" + "build", "ios", config, "lib", env, "libpdfium.dylib" ) l.colored("Merging {0} libraries (lipo)...".format(env), l.YELLOW) @@ -281,7 +283,7 @@ def run_task_test(): for config in c.configurations_ios: for env in ["simulator", "device"]: lib_dir = os.path.join("build", "ios", config, "lib", env) - command = ["file", os.path.join(lib_dir, "libpdfium.a")] + command = ["file", os.path.join(lib_dir, "libpdfium.dylib")] r.run(command) framework_dir = os.path.join("build", "ios", config, "pdfium.xcframework") diff --git a/modules/macos.py b/modules/macos.py index 392b10e..5d25866 100644 --- a/modules/macos.py +++ b/modules/macos.py @@ -122,8 +122,7 @@ def run_task_install(): "pdfium", "out", "{0}-{1}-{2}".format(target["target_os"], target["target_cpu"], config), - "obj", - "libpdfium.a", + "libpdfium.dylib", ) target_lib_path = os.path.join( @@ -131,7 +130,7 @@ def run_task_install(): target["target_os"], config, "lib", - "libpdfium_{0}.a".format(target["target_cpu"]), + "libpdfium_{0}.dylib".format(target["target_cpu"]), ) f.copy_file(source_lib_path, target_lib_path) @@ -150,10 +149,10 @@ def run_task_install(): f.replace_in_file(header, '#include "public/', '#include "../') # universal - folder = os.path.join("build", "macos", config, "lib", "*.a") + folder = os.path.join("build", "macos", config, "lib", "*.dylib") files = glob.glob(folder) files_str = " ".join(files) - lib_file_out = os.path.join("build", "macos", config, "lib", "libpdfium.a") + lib_file_out = os.path.join("build", "macos", config, "lib", "libpdfium.dylib") l.colored("Merging libraries (lipo)...", l.YELLOW) command = ["lipo", "-create", files_str, "-o", lib_file_out] From 85a1c3ee3b2f2f32d5274617f73b5a6c4e2878ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPaulo?= Date: Sat, 17 Aug 2024 01:25:40 -0300 Subject: [PATCH 6/7] fixes a lot --- modules/ios.py | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/ios.py b/modules/ios.py index 69f4d7b..1e10d9a 100644 --- a/modules/ios.py +++ b/modules/ios.py @@ -190,7 +190,6 @@ def run_task_install(): target["target_environment"], config, ), - "obj", "libpdfium.dylib", ) From 1df32bf679bef5b6c8f4702979285d585653410e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPaulo?= Date: Sat, 17 Aug 2024 02:40:14 -0300 Subject: [PATCH 7/7] fixes a lot --- modules/android.py | 8 +++++++- modules/common.py | 34 +++++++++++++++++++++++++++++----- modules/config.py | 4 ++-- modules/ios.py | 22 ++++++++++++++-------- modules/macos.py | 17 ++++++++++++----- modules/wasm.py | 8 +++++++- 6 files changed, 71 insertions(+), 22 deletions(-) diff --git a/modules/android.py b/modules/android.py index 979fe14..96bcf19 100644 --- a/modules/android.py +++ b/modules/android.py @@ -87,7 +87,13 @@ def run_task_build(): l.YELLOW, ) - args = cm.get_build_args(config, target["pdfium_os"], target["target_cpu"]) + args = cm.get_build_args( + config, + c.shared_lib_android, + target["pdfium_os"], + target["target_cpu"], + ) + args_str = " ".join(args) command = [ diff --git a/modules/common.py b/modules/common.py index de0b7ef..1faa9ca 100644 --- a/modules/common.py +++ b/modules/common.py @@ -105,13 +105,20 @@ def run_task_format(): # ----------------------------------------------------------------------------- -def get_build_args(config, target_os, target_cpu, libc=None, enable_v8=False): +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_is_standalone=true") args.append("pdf_use_partition_alloc=false") args.append(f'target_cpu="{target_cpu}"') args.append(f'target_os="{target_os}"') @@ -120,9 +127,6 @@ def get_build_args(config, target_os, target_cpu, libc=None, enable_v8=False): args.append("treat_warnings_as_errors=false") args.append("is_component_build=false") - # static lib - # args.append("pdf_is_complete_lib=true") - if enable_v8: args.append("v8_use_external_startup_data=false") args.append("v8_enable_i18n_support=false") @@ -130,21 +134,41 @@ def get_build_args(config, target_os, target_cpu, libc=None, enable_v8=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") diff --git a/modules/config.py b/modules/config.py index f1e4aa8..9774105 100644 --- a/modules/config.py +++ b/modules/config.py @@ -14,7 +14,7 @@ # macos configurations_macos = ["release"] -shared_lib_macos = True +shared_lib_macos = False targets_macos = [ {"target_os": "macos", "target_cpu": "x64", "pdfium_os": "mac"}, {"target_os": "macos", "target_cpu": "arm64", "pdfium_os": "mac"}, @@ -22,7 +22,7 @@ # ios configurations_ios = ["release"] -shared_lib_ios = True +shared_lib_ios = False targets_ios = [ { "target_os": "ios", diff --git a/modules/ios.py b/modules/ios.py index 1e10d9a..e0637e6 100644 --- a/modules/ios.py +++ b/modules/ios.py @@ -125,7 +125,14 @@ def run_task_build(): l.YELLOW, ) - args = cm.get_build_args(config, target["pdfium_os"], target["target_cpu"]) + args = cm.get_build_args( + config, + c.shared_lib_ios, + target["pdfium_os"], + target["target_cpu"], + target["target_environment"], + ) + args_str = " ".join(args) command = [ @@ -190,7 +197,8 @@ def run_task_install(): target["target_environment"], config, ), - "libpdfium.dylib", + "obj", + "libpdfium.a", ) target_lib_path = os.path.join( @@ -198,7 +206,7 @@ def run_task_install(): target["target_os"], config, "lib", - "libpdfium_{0}-{1}.dylib".format( + "libpdfium_{0}-{1}.a".format( target["target_cpu"], target["target_environment"] ), ) @@ -221,14 +229,12 @@ def run_task_install(): # universal universal_libs = [] for env in ["simulator", "device"]: - folder = os.path.join( - "build", "ios", config, "lib", "*-{0}.dylib".format(env) - ) + folder = os.path.join("build", "ios", config, "lib", "*-{0}.a".format(env)) files = glob.glob(folder) files_str = " ".join(files) f.create_dir(os.path.join("build", "ios", config, "lib", env)) lib_file_out = os.path.join( - "build", "ios", config, "lib", env, "libpdfium.dylib" + "build", "ios", config, "lib", env, "libpdfium.a" ) l.colored("Merging {0} libraries (lipo)...".format(env), l.YELLOW) @@ -282,7 +288,7 @@ def run_task_test(): for config in c.configurations_ios: for env in ["simulator", "device"]: lib_dir = os.path.join("build", "ios", config, "lib", env) - command = ["file", os.path.join(lib_dir, "libpdfium.dylib")] + command = ["file", os.path.join(lib_dir, "libpdfium.a")] r.run(command) framework_dir = os.path.join("build", "ios", config, "pdfium.xcframework") diff --git a/modules/macos.py b/modules/macos.py index 5d25866..24b23ef 100644 --- a/modules/macos.py +++ b/modules/macos.py @@ -68,7 +68,13 @@ def run_task_build(): l.YELLOW, ) - args = cm.get_build_args(config, target["pdfium_os"], target["target_cpu"]) + args = cm.get_build_args( + config, + c.shared_lib_macos, + target["pdfium_os"], + target["target_cpu"], + ) + args_str = " ".join(args) command = [ @@ -122,7 +128,8 @@ def run_task_install(): "pdfium", "out", "{0}-{1}-{2}".format(target["target_os"], target["target_cpu"], config), - "libpdfium.dylib", + "obj", + "libpdfium.a", ) target_lib_path = os.path.join( @@ -130,7 +137,7 @@ def run_task_install(): target["target_os"], config, "lib", - "libpdfium_{0}.dylib".format(target["target_cpu"]), + "libpdfium_{0}.a".format(target["target_cpu"]), ) f.copy_file(source_lib_path, target_lib_path) @@ -149,10 +156,10 @@ def run_task_install(): f.replace_in_file(header, '#include "public/', '#include "../') # universal - folder = os.path.join("build", "macos", config, "lib", "*.dylib") + folder = os.path.join("build", "macos", config, "lib", "*.a") files = glob.glob(folder) files_str = " ".join(files) - lib_file_out = os.path.join("build", "macos", config, "lib", "libpdfium.dylib") + lib_file_out = os.path.join("build", "macos", config, "lib", "libpdfium.a") l.colored("Merging libraries (lipo)...", l.YELLOW) command = ["lipo", "-create", files_str, "-o", lib_file_out] diff --git a/modules/wasm.py b/modules/wasm.py index 6419a91..3f0d664 100644 --- a/modules/wasm.py +++ b/modules/wasm.py @@ -328,7 +328,13 @@ def run_task_build(): l.YELLOW, ) - args = cm.get_build_args(config, target["pdfium_os"], target["target_cpu"]) + args = cm.get_build_args( + config, + c.shared_lib_wasm, + target["pdfium_os"], + target["target_cpu"], + ) + args_str = " ".join(args) command = [