diff --git a/crates/pdf_viewer/src/pdfium.rs b/crates/pdf_viewer/src/pdfium.rs index f222ce1064..9c23a1d81f 100644 --- a/crates/pdf_viewer/src/pdfium.rs +++ b/crates/pdf_viewer/src/pdfium.rs @@ -174,6 +174,13 @@ impl PdfiumEngine { PathBuf::from("/usr/local/lib/libpdfium.dylib"), ]); + // macOS app bundles ship libpdfium.dylib in Contents/Frameworks. + if let Ok(executable_path) = std::env::current_exe() { + if let Some(executable_dir) = executable_path.parent() { + common_paths.push(executable_dir.join("../Frameworks/libpdfium.dylib")); + } + } + for path in &common_paths { if path.exists() { if let Ok(bindings) = Pdfium::bind_to_library(path) { diff --git a/script/bundle-mac b/script/bundle-mac index 14d600ae4f..32429a1e93 100755 --- a/script/bundle-mac +++ b/script/bundle-mac @@ -146,6 +146,7 @@ fi GIT_VERSION="v2.43.3" GIT_VERSION_SHA="fa29823" +PDFIUM_TAG="chromium/8066" function download_and_unpack() { local url=$1 @@ -192,6 +193,42 @@ function download_git() { rm -rf "$tmp_dir" } +function download_pdfium() { + local architecture=$1 + local target_path=$2 + + case "$architecture" in + aarch64-apple-darwin) + pdfium_flavor="mac-arm64" + pdfium_sha256="336219e80580b93c6523f44db7dc1de59cc497b13a7390ddac84223f68ca162b" + ;; + x86_64-apple-darwin) + pdfium_flavor="mac-x64" + pdfium_sha256="841ecac278cdd46288dd065873522cf72f3996560d8978f473d336f01d59942c" + ;; + *) + echo "Unsupported architecture for pdfium: $architecture" + exit 1 + ;; + esac + + # sha256sum is not present on stock macOS, so checksums go through shasum. + pdfium_tgz="${target_dir}/pdfium-${pdfium_flavor}.tgz" + if ! echo "${pdfium_sha256} ${pdfium_tgz}" | shasum -a 256 -c >/dev/null 2>&1; then + mkdir -p "${target_dir}" + curl --silent --fail --location --output "${pdfium_tgz}" \ + "https://github.com/bblanchon/pdfium-binaries/releases/download/${PDFIUM_TAG}/pdfium-${pdfium_flavor}.tgz" + echo "${pdfium_sha256} ${pdfium_tgz}" | shasum -a 256 -c + fi + + pdfium_tmp=$(mktemp -d) + tar -xzf "${pdfium_tgz}" -C "${pdfium_tmp}" "lib/libpdfium.dylib" "LICENSE" "licenses" + cp "${pdfium_tmp}/lib/libpdfium.dylib" "${target_path}" + mkdir -p "${app_path}/Contents/Resources/pdfium-licenses" + cp "${pdfium_tmp}/LICENSE" "${pdfium_tmp}/licenses/"* "${app_path}/Contents/Resources/pdfium-licenses/" + rm -rf "${pdfium_tmp}" +} + function sign_app_binaries() { rm -rf "${app_path}/Contents/Frameworks" mkdir -p "${app_path}/Contents/Frameworks" @@ -199,6 +236,10 @@ function sign_app_binaries() { echo "Downloading git binary" download_git "${target_triple}" "${app_path}/Contents/MacOS/git" + # PDFium is dlopen'd at runtime by the bundled pdf_viewer for native PDF viewing. + echo "Downloading pdfium library" + download_pdfium "${target_triple}" "${app_path}/Contents/Frameworks/libpdfium.dylib" + # Note: The app identifier for our development builds is the same as the app identifier for nightly. cp crates/zed/contents/$channel/embedded.provisionprofile "${app_path}/Contents/"