Skip to content

Fix: use .a to replace .so for pdfium/pdf_oxide/office_oxide - #16496

Merged
yingfeng merged 11 commits into
infiniflow:mainfrom
xugangqiang:feat/use-static-linkage
Jul 1, 2026
Merged

yingfeng merged 11 commits into
infiniflow:mainfrom
xugangqiang:feat/use-static-linkage

Conversation

@xugangqiang

Copy link
Copy Markdown
Contributor

Summary

Use .a to replace .so for pdfium/pdf_oxide/office_oxide

@xugangqiang xugangqiang added the ci Continue Integration label Jun 30, 2026
@xugangqiang
xugangqiang marked this pull request as ready for review June 30, 2026 09:06
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 30, 2026
@coderabbitai

coderabbitai Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

build.sh now installs and links static native .a libraries for office_oxide, pdfium, and pdf_oxide. CGO settings, pdfium linker flags, development instructions, and Go test package filters were updated to match the static workflow.

Changes

Static Native Library Migration

Layer / File(s) Summary
Dependency config and static installers
build.sh
Updates static-build prefixes and versions, changes the office_oxide check to require liboffice_oxide.a, and rewrites the pdfium and pdf_oxide dependency checks to download and verify static archives.
Static CGO linking and build flow
build.sh
Rewrites setup_cgo_env for static-only CGO_LDFLAGS, removes runtime loader setup, updates build_go and run_go_tests to use the new flow, and removes the redundant setup call from run().
Pdfium binding and development docs
internal/deepdoc/parser/pdf/pdfium/pdfium.go, internal/development.md
Updates the pdfium Go binding header and linker flags for static linking, revises the development instructions for the static native-library workflow, and adjusts the CLI login example prompt formatting.
Go test package filtering
.github/workflows/tests.yml
Removes the deepdoc PDF parser exclusions from the Go unit test package lists in both workflow jobs, leaving the handler exclusion in place.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested labels

🧪 test

Poem

🐇 I hop through archives, tidy and neat,
Static .a libs make the build complete.
No rpath trails or shared-library dreams,
Just cozy linker flags and compile-time beams.
Hooray for snug little builds! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: switching pdfium, pdf_oxide, and office_oxide from .so to .a.
Description check ✅ Passed The description matches the required Summary section and states the core purpose of the PR.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@xugangqiang
xugangqiang marked this pull request as draft June 30, 2026 09:12
@xugangqiang
xugangqiang marked this pull request as ready for review June 30, 2026 09:12

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@build.sh`:
- Around line 188-230: The check_pdfium_deps function currently reports success
once libpdfium.a exists, but on Linux setup_cgo_env also requires libc++.a and
libc++abi.a, so a partial extraction can slip through and fail later. Update
check_pdfium_deps to validate the Linux-specific archive set before returning
success by checking the extra required libraries after _download_and_extract and
only printing the installed message when all expected files are present; use the
existing check_pdfium_deps and setup_cgo_env symbols to keep the behavior
aligned across the install and link paths.

In `@internal/deepdoc/parser/pdf/pdfium/pdfium.go`:
- Around line 7-8: The CGO linker flags in pdfium.go are applied
unconditionally, which causes unsupported flags like -ldl to be used on Darwin
builds. Update the cgo directives near the package header to make the LDFLAGS
OS-specific, separating the Linux and macOS cases so each platform only receives
compatible linker flags.

In `@internal/development.md`:
- Line 30: The guidance in the development docs incorrectly tells new users to
start with build.sh --go, but that path still fails when
build/librag_tokenizer_c_api.a has not been generated yet. Update the note near
the run/debug instructions to direct fresh checkouts to run a build that creates
the native library first, such as build.sh --cpp or build.sh --all, and only
then use build.sh --go for Go-based run/debug workflows.
- Around line 33-43: The CGO linker example in the development docs mixes
Linux-only flags with macOS PLATFORM values, so update the setup around the
CGO_LDFLAGS example to be OS-specific. Split the manual export snippet into
separate Linux and darwin variants, and align the listed libraries/flags with
what setup_cgo_env() uses for each target so the example matches the correct
linker line for linux_amd64, linux_arm64, darwin_amd64, and darwin_arm64.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b1776b48-ffb3-4303-a099-a995a913efe4

📥 Commits

Reviewing files that changed from the base of the PR and between b3af9fc and db53616.

📒 Files selected for processing (3)
  • build.sh
  • internal/deepdoc/parser/pdf/pdfium/pdfium.go
  • internal/development.md

Comment thread build.sh Resolved
Comment thread internal/development.md Resolved
Comment thread internal/development.md Resolved
xugangqiang and others added 3 commits June 30, 2026 22:00
GNU ld 2.42 cannot merge .eh_frame sections produced by Chromium's
Clang toolchain, causing linker errors for all kognitos/pdfium-static
archives (libpdfium.a, libc++.a, libc++abi.a).

Use -fuse-ld=lld to invoke LLVM's linker which handles these sections
correctly. This requires lld to be installed (apt install lld).

Co-Authored-By: Claude <[email protected]>
Both pdf_oxide and office_oxide are Rust staticlibs that embed the Rust
runtime (rust_eh_personality). When statically linked together into the
same binary, ld reports duplicate symbol errors.

Co-Authored-By: Claude <[email protected]>
@xugangqiang
xugangqiang force-pushed the feat/use-static-linkage branch from a8baadc to cf3712f Compare June 30, 2026 14:03
These tests were excluded by PR infiniflow#16505 because the old .so-based build
required system-native libraries at test-compile time. With the switch
to static linking (.a + -fuse-ld=lld), these packages compile and pass
correctly.

Co-Authored-By: Claude <[email protected]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
build.sh (2)

157-172: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Add an unsupported-OS branch before building the office_oxide URL.

If uname -s is neither Linux nor Darwin, asset_name is never assigned before Line 174, producing an invalid release URL or an unbound-variable failure.

Proposed fix
     case "$(uname -s)" in
         Linux)
             case "$(uname -m)" in
                 x86_64)  asset_name="native-linux-x86_64" ;;
                 aarch64|arm64) asset_name="native-linux-aarch64" ;;
                 *) echo -e "${RED}Unsupported arch: $(uname -m)${NC}"; exit 1 ;;
             esac
             ;;
         Darwin)
             case "$(uname -m)" in
                 x86_64)  asset_name="native-macos-x86_64" ;;
                 aarch64|arm64) asset_name="native-macos-aarch64" ;;
                 *) echo -e "${RED}Unsupported arch: $(uname -m)${NC}"; exit 1 ;;
             esac
             ;;
+        *) echo -e "${RED}Unsupported OS: $(uname -s)${NC}"; exit 1 ;;
     esac
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@build.sh` around lines 157 - 172, The OS selection logic in the shell script
only handles Linux and Darwin, so `asset_name` can remain unset before the
office_oxide download URL is built. Update the `uname -s` switch in `build.sh`
to include an explicit unsupported-OS branch alongside the existing `asset_name`
assignments, and fail fast with a clear error before any URL construction
happens. Use the same pattern as the current architecture checks so the
`asset_name` variable is always defined or the script exits cleanly.

179-183: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Re-validate the office_oxide header after extraction.

The first check requires both the static archive and office_oxide.h, but the install path reports success when only liboffice_oxide.a exists. A partial extract can fail later at CGO compile time.

Proposed fix
-    if [ ! -f "$lib_path" ]; then
-        echo -e "${RED}Error: Failed to install office_oxide native library (missing ${lib_path})${NC}"
+    if [ ! -f "$lib_path" ] || [ ! -f "$header_path" ]; then
+        echo -e "${RED}Error: Failed to install office_oxide native library (missing ${lib_path} or ${header_path})${NC}"
         echo "  Try: curl -fsSL ${release_url} | tar xzf - -C ${OFFICE_OXIDE_PREFIX}"
         exit 1
     fi
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@build.sh` around lines 179 - 183, The office_oxide install check only
verifies the static archive after extraction, so update the install flow to also
re-validate that office_oxide.h exists before reporting success. In the build.sh
extraction path around the lib_path check, add a second presence check for the
header alongside the existing archive validation, and fail with the same
error/exit behavior if either artifact is missing so partial extracts are caught
before CGO compilation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@build.sh`:
- Around line 410-414: The Linux linker flags in build.sh are always adding
-fuse-ld=lld, which breaks builds on hosts without LLVM’s linker. Update the
Linux branch that exports CGO_LDFLAGS to first check for ld.lld with command -v
before appending the lld-specific flag, and keep the rest of the PDFium linker
flags unchanged. Use the existing uname -s Linux guard and the CGO_LDFLAGS
export block to place this check.

---

Outside diff comments:
In `@build.sh`:
- Around line 157-172: The OS selection logic in the shell script only handles
Linux and Darwin, so `asset_name` can remain unset before the office_oxide
download URL is built. Update the `uname -s` switch in `build.sh` to include an
explicit unsupported-OS branch alongside the existing `asset_name` assignments,
and fail fast with a clear error before any URL construction happens. Use the
same pattern as the current architecture checks so the `asset_name` variable is
always defined or the script exits cleanly.
- Around line 179-183: The office_oxide install check only verifies the static
archive after extraction, so update the install flow to also re-validate that
office_oxide.h exists before reporting success. In the build.sh extraction path
around the lib_path check, add a second presence check for the header alongside
the existing archive validation, and fail with the same error/exit behavior if
either artifact is missing so partial extracts are caught before CGO
compilation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e4776399-eed1-42a9-a1aa-1c8d37d452e2

📥 Commits

Reviewing files that changed from the base of the PR and between a8baadc and cf3712f.

📒 Files selected for processing (3)
  • build.sh
  • internal/deepdoc/parser/pdf/pdfium/pdfium.go
  • internal/development.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/deepdoc/parser/pdf/pdfium/pdfium.go
  • internal/development.md

Comment thread build.sh Resolved
xugangqiang and others added 7 commits July 1, 2026 11:26
Add _seed_from_system() to copy pre-installed native static libs from
/opt/ragflow-deps/ to ~/ragflow-deps/ before attempting download. CI
runner images that pre-bake these files will skip network access.

Co-Authored-By: Claude <[email protected]>
build.sh now only checks /opt/ragflow-deps/ (system) and
~/ragflow-deps/ (local cache). If libraries are missing, it
prints a clear error pointing to download_deps.py.

Download is handled by download_deps.py (CI images) or manually.

Co-Authored-By: Claude <[email protected]>
@xugangqiang
xugangqiang marked this pull request as draft July 1, 2026 08:40
@xugangqiang
xugangqiang marked this pull request as ready for review July 1, 2026 08:40
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (3633d08) to head (d73d059).
⚠️ Report is 28 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16496   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yingfeng
yingfeng merged commit 42a0faa into infiniflow:main Jul 1, 2026
6 of 12 checks passed
@xugangqiang
xugangqiang deleted the feat/use-static-linkage branch August 7, 2026 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants