108 lines
4.6 KiB
Bash
108 lines
4.6 KiB
Bash
#!/usr/bin/env bash
|
|
# Build PDFium from source (Linux / macOS) into third_party/pdfium/install/.
|
|
#
|
|
# depot_tools, the PDFium checkout, and the GN/Ninja build all happen under a
|
|
# BUILD ROOT. depot_tools, GN and Ninja do NOT support spaces anywhere in their
|
|
# own path. If this repo lives under a path containing a space, you MUST point
|
|
# the build root somewhere space-free:
|
|
#
|
|
# PDFIUM_BUILD_ROOT=/tmp/pdfium-build ./third_party/pdfium/build_pdfium.sh
|
|
#
|
|
# The finished static lib + public headers are always installed into
|
|
# third_party/pdfium/install/ (git-ignored) regardless of the build root, so
|
|
# cmake/pdfium.cmake finds them in the same place either way.
|
|
#
|
|
# One-time and slow: a multi-GB gclient sync plus a long compile. See README.md.
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
INSTALL_DIR="${SCRIPT_DIR}/install"
|
|
PINNED_FILE="${SCRIPT_DIR}/pdfium.pinned"
|
|
|
|
# Build root: depot_tools + the checkout live here. Defaults to this directory
|
|
# (fine for repos on a space-free path), but MUST be overridden otherwise.
|
|
BUILD_ROOT="${PDFIUM_BUILD_ROOT:-${SCRIPT_DIR}}"
|
|
case "${BUILD_ROOT}" in
|
|
*' '*)
|
|
echo "ERROR: PDFium build root contains a space: ${BUILD_ROOT}" >&2
|
|
echo "depot_tools, GN and Ninja cannot build under a path with spaces." >&2
|
|
echo "Re-run with a space-free build root, e.g.:" >&2
|
|
echo " PDFIUM_BUILD_ROOT=/tmp/pdfium-build $0" >&2
|
|
exit 1 ;;
|
|
esac
|
|
DEPOT_TOOLS_DIR="${BUILD_ROOT}/depot_tools"
|
|
CHECKOUT_DIR="${BUILD_ROOT}/checkout"
|
|
echo ">> Build root: ${BUILD_ROOT}"
|
|
|
|
# --- 1. Read and validate the pinned revision -------------------------------
|
|
PDFIUM_REPO="$(grep -E '^PDFIUM_REPO=' "${PINNED_FILE}" | cut -d= -f2- | tr -d '\r')"
|
|
PDFIUM_COMMIT="$(grep -E '^PDFIUM_COMMIT=' "${PINNED_FILE}" | cut -d= -f2- | tr -d '\r')"
|
|
if [[ -z "${PDFIUM_COMMIT}" || "${PDFIUM_COMMIT}" == "REPLACE_WITH_PINNED_COMMIT_SHA" ]]; then
|
|
echo "ERROR: PDFium revision is not pinned. Edit pdfium.pinned first (see README.md)." >&2
|
|
exit 1
|
|
fi
|
|
echo ">> PDFium pinned at ${PDFIUM_COMMIT}"
|
|
|
|
# --- 2. depot_tools ---------------------------------------------------------
|
|
mkdir -p "${BUILD_ROOT}"
|
|
if ! command -v gclient &> /dev/null; then
|
|
if [[ ! -d "${DEPOT_TOOLS_DIR}/.git" ]]; then
|
|
echo ">> Cloning depot_tools"
|
|
git clone --depth 1 https://chromium.googlesource.com/chromium/tools/depot_tools.git \
|
|
"${DEPOT_TOOLS_DIR}"
|
|
fi
|
|
export PATH="${DEPOT_TOOLS_DIR}:${PATH}"
|
|
fi
|
|
# Do NOT set DEPOT_TOOLS_UPDATE=0 — depot_tools is designed to self-manage, and
|
|
# on first use it must bootstrap. Reproducibility comes from the pinned PDFium
|
|
# revision below, not from freezing depot_tools.
|
|
|
|
# Git settings injected per-process via GIT_CONFIG_* so the user's global git
|
|
# config is never touched. core.autocrlf=false avoids gclient seeing dependency
|
|
# checkouts as "uncommitted changes" on platforms where autocrlf is enabled.
|
|
export GIT_CONFIG_COUNT=4
|
|
export GIT_CONFIG_KEY_0=core.autocrlf GIT_CONFIG_VALUE_0=false
|
|
export GIT_CONFIG_KEY_1=core.filemode GIT_CONFIG_VALUE_1=false
|
|
export GIT_CONFIG_KEY_2=http.postBuffer GIT_CONFIG_VALUE_2=1048576000
|
|
export GIT_CONFIG_KEY_3=core.compression GIT_CONFIG_VALUE_3=0
|
|
|
|
# --- 3. Fetch / sync the PDFium tree ----------------------------------------
|
|
mkdir -p "${CHECKOUT_DIR}"
|
|
cd "${CHECKOUT_DIR}"
|
|
if [[ ! -d "${CHECKOUT_DIR}/pdfium" ]]; then
|
|
echo ">> gclient config (unmanaged)"
|
|
gclient config --unmanaged "${PDFIUM_REPO}"
|
|
fi
|
|
echo ">> gclient sync (pulls several GB; slow)"
|
|
gclient sync --no-history --shallow --reset --force
|
|
|
|
# --- 4. Pin to the exact commit + sync its DEPS -----------------------------
|
|
cd "${CHECKOUT_DIR}/pdfium"
|
|
git fetch origin "${PDFIUM_COMMIT}"
|
|
git checkout --detach "${PDFIUM_COMMIT}"
|
|
gclient sync --no-history --shallow --reset --force -D
|
|
|
|
# --- 5. GN args: static, standalone, monolithic, embed-friendly -------------
|
|
mkdir -p out/Release
|
|
cp "${SCRIPT_DIR}/args.gn" out/Release/args.gn
|
|
|
|
# --- 6. Generate + build ----------------------------------------------------
|
|
echo ">> gn gen + ninja"
|
|
gn gen out/Release
|
|
ninja -C out/Release pdfium
|
|
|
|
# --- 7. Install: public headers + static lib --------------------------------
|
|
echo ">> Installing into ${INSTALL_DIR}"
|
|
rm -rf "${INSTALL_DIR}"
|
|
mkdir -p "${INSTALL_DIR}/include" "${INSTALL_DIR}/lib"
|
|
cp public/*.h "${INSTALL_DIR}/include/"
|
|
cp -r public/cpp "${INSTALL_DIR}/include/" 2>/dev/null || true
|
|
if [[ -f out/Release/obj/libpdfium.a ]]; then
|
|
cp out/Release/obj/libpdfium.a "${INSTALL_DIR}/lib/"
|
|
else
|
|
# Fallback: some configurations emit the lib at the out-dir root.
|
|
cp out/Release/libpdfium.a "${INSTALL_DIR}/lib/"
|
|
fi
|
|
|
|
echo ">> Done. Configure the engine with -DPDFENGINE_WITH_PDFIUM=ON"
|