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

Consider options for offering automated building of Pdfium as part of pdfium-render. #53

Open
ajrcarey opened this issue Oct 1, 2022 · 8 comments
Assignees

Comments

@ajrcarey
Copy link
Owner

ajrcarey commented Oct 1, 2022

Follow-on from #12, #51. Look into options for offering automated building of Pdfium as part of pdfium-render, and in the meantime document the process for building Pdfium manually based on a sample build script provided by Victor-N-Suadicani as part of #51.

@ajrcarey
Copy link
Owner Author

ajrcarey commented Oct 1, 2022

A sample build script that creates a libpdfium.a suitable for static linking on Linux:

#!/usr/bin/env bash
mkdir -p pdfium
cd pdfium

# Clone depot tools, standard tools used for building Chromium and associated projects.
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH="$PATH:$(cd depot_tools; pwd)"

# Clone the pdfium source.
gclient config --unmanaged https://pdfium.googlesource.com/pdfium.git
gclient sync --no-history

# Create default build configuration...
cd pdfium
./build/install-build-deps.sh --no-prompt
rm out/Default/args.gn
gn gen out/Default

# ... and now customise it as needed.
echo "use_goma = false" >> out/Default/args.gn
echo "clang_use_chrome_plugins = false" >> out/Default/args.gn
echo "is_component_build = false" >> out/Default/args.gn
echo "pdf_is_standalone = true" >> out/Default/args.gn
echo "pdf_is_complete_lib = true" >> out/Default/args.gn
echo "pdf_enable_v8 = true" >> out/Default/args.gn
echo "pdf_enable_xfa = true" >> out/Default/args.gn
echo "pdf_use_skia = false" >> out/Default/args.gn
echo "pdf_use_skia_paths = false" >> out/Default/args.gn
echo "is_clang = true" >> out/Default/args.gn
echo "use_custom_libcxx = false" >> out/Default/args.gn
#echo "treat_warnings_as_errors = false" >> out/Default/args.gn
#echo "target_cpu = \"x64\"" >> out/Default/args.gn
#echo "target_os = \"linux\"" >> out/Default/args.gn
#echo "is_debug = false" >> out/Default/args.gn

# Run the build.
ninja -C out/Default pdfium

Building Pdfium is only officially supported on certain Ubuntu and Debian distros, but in practice it probably will work on other distros as well; the build works fine on Arch, for instance.

@ajrcarey
Copy link
Owner Author

ajrcarey commented Oct 1, 2022

Some notes on the configuration flags that can be set in the build script:

  • use_goma: sets whether or not Google's distributed goma compiler should be used. Should be false for everyone outside Google.
  • clang_use_chrome_plugins: sets an internal flag used when compiling Pdfium into the Chromium browser. Should be false for everyone not compiling Chromium :)
  • is_component_build: based on https://groups.google.com/g/pdfium/c/b3ZbohOzTyo, appears to be another Chromium-specific setting. Should therefore be false for everyone not compiling Chromium.
  • pdf_is_standalone: set to true to create a static library (libpdfium.a), set to false to create a dynamic library (libpdfium.so).
  • pdf_is_complete_lib: based on https://stackoverflow.com/a/66071317, appears to control whether all dependencies are compiled into Pdfium at build time. true is recommended to avoid linker problems.
  • pdf_enable_v8: set to true to enable bindings to Chromium's V8 Javascript engine. There's probably no reason to do this if not compiling Pdfium as part of Chromium.
  • pdf_enable_xfa: set to true to include PDF XFA support. If true, appears to require pdf_enable_v8 to also be true.
  • pdf_use_skia: set to true to enable experimental use of SKIA as a rendering engine.
  • pdf_use_skia_paths: set to true to enable experimental use of SKIA as a rendering engine just for path objects.
  • is_clang: presumably controls which compiler is used, but in my tests, there was no appreciable difference between having this flag set to true or false. Presumably if it's false, gcc is used?
  • use_custom_libcxx: Google includes a vendored C++ standard library as part of Pdfium, presumably for reasons of compatibility. It can make it harder to link Pdfium at compile time, though (see Can't get static compilation to work #51). Set to false to use the build system's C++ standard library instead.
  • treat_warnings_as_errors: set to true to tighten compiler settings during build.
  • target_cpu: presumably for cross-compilation. Based on https://github.com/bblanchon/pdfium-binaries/blob/master/build.sh, valid values appear to be arm, arm64, x64, x86, warm.
  • target_os: presumably for cross-compilation. Based on https://github.com/bblanchon/pdfium-binaries/blob/master/build.sh, valid values appear to be android, ios, linux, mac, wasm, win.

@ajrcarey
Copy link
Owner Author

ajrcarey commented Oct 1, 2022

It would be nice for pdfium-render to eventually offer a cargo subcommand to build Pdfium; something like:

cargo build-pdfium --use_goma=false --is_component_build=false --pdf_is_standalone=true ...

If the build could be dockerised, even better.

@ajrcarey ajrcarey self-assigned this Oct 25, 2022
@ajrcarey
Copy link
Owner Author

ajrcarey commented Dec 5, 2022

@mara004
Copy link

mara004 commented Mar 21, 2023

Possibly, pypdfium2's build script might interest you?

Also note that you can list all GN arguments (including defaults, possible values and help) by running gn args $COMPILE_DIR --list, where $COMPILE_DIR would commonly be out/Default/ in the pdfium sourcetree.

@ajrcarey
Copy link
Owner Author

Thanks for the suggestion @mara004 , that's very helpful! I'll take a look at that build script.

@mara004
Copy link

mara004 commented Mar 21, 2023

PS on #53 (comment) (script) and #53 (comment) (build config):

  • I don't think you need ./build/install-build-deps.sh. pdfium-binaries doesn't do this, and I believe said script contains a lot of stuff for the tooling that is not required if you just want to build pdfium (update: see post by pdfium dev Lei Zhang and surrounding messages)
  • Not overly relevant, but pdf_use_skia_paths was removed at some point (see post by pdfium dev K. Moon)

@ajrcarey
Copy link
Owner Author

ajrcarey commented Dec 3, 2023

@SzelamC noted in #126 that it may be necessary on macOS to also link to the CoreGraphics framework like so:

cargo:rustc-link-lib=framework=CoreGraphics

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants