Repository navigation
build(go): make bash build.sh work on macOS arm64 (Homebrew) - #15009
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughCross-platform build improvements add portable PCRE2 discovery in CMake, architecture-specific macOS linking in cgo and build scripts, and explicit C++ includes/overload fix for libc++ compatibility. ChangesCross-Platform Build and Library Portability
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
|
@Zzappy24 Since previous PR includes a binary file which is very big. So, I reset the head of main branch. Would you please re-submit the commit from current HEAD of main branch? Thank you very much. |
|
of course no problem, thank you for you response, I will re-submit as soon as possible |
3263135 to
b6d01aa
Compare
|
Re-submitted: rebased onto the current |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
build.sh (1)
36-41:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winAlign
check_cpp_depspcre2 check with the updatedbuild_gologic for macOS.The
check_cpp_depsfunction still only checks Linux paths and prints anapt-getwarning. macOS users running./build.sh --cppwill see misleading instructions, even though CMake (via the Homebrew detection you added inCMakeLists.txt) may successfully locate pcre2.For consistency and better UX, consider updating
check_cpp_depsto match thebuild_goapproach:Suggested alignment
# Check for pcre2 library - if [ -f "/usr/lib/x86_64-linux-gnu/libpcre2-8.a" ] || [ -f "/usr/local/lib/libpcre2-8.a" ]; then + if [ -f "/usr/lib/x86_64-linux-gnu/libpcre2-8.a" ] \ + || [ -f "/usr/local/lib/libpcre2-8.a" ] \ + || [ -f "/opt/homebrew/lib/libpcre2-8.a" ]; then echo "✓ pcre2 library found" else + if [ "$(uname)" = "Darwin" ]; then + echo -e "${YELLOW}Warning: libpcre2-8.a not found. Install with: brew install pcre2${NC}" + else echo -e "${YELLOW}Warning: libpcre2-8.a not found. You may need to install libpcre2-dev:${NC}" echo " sudo apt-get install libpcre2-dev" + fi 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 36 - 41, The check_cpp_deps function currently only checks Linux library paths and prints an apt-get instruction; update it to detect macOS/Homebrew like the build_go logic/CMakeLists.txt does by checking for Homebrew-installed pcre2 locations (e.g., /usr/local/opt/pcre2/lib or $(brew --prefix)/opt/pcre2/lib) or using brew --prefix when available, and change the warning text to show platform-appropriate install commands (apt-get for Linux, brew install pcre2 for macOS) so macOS users running ./build.sh --cpp receive correct instructions and the check aligns with CMakeLists.txt behavior.
🧹 Nitpick comments (2)
internal/cpp/CMakeLists.txt (2)
24-27: 💤 Low valueClarify the comment about the previous linking approach.
The comment states "upstream used the literal token
${PCRE2_LIB}" but according to the AI summary and the change description, the old code used the literal string"libpcre2-8.a", not a variable. The phrasing is confusing.Consider revising to:
-# Resolve libpcre2-8 portably — upstream used the literal token `${PCRE2_LIB}` +# Resolve libpcre2-8 portably — upstream used the literal library name 'libpcre2-8.a' # which only works on systems whose default linker search path already # contains it. find_library picks it up from either /usr/local/lib (Linux) # or /opt/homebrew/lib (macOS).🤖 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 `@internal/cpp/CMakeLists.txt` around lines 24 - 27, The comment about resolving libpcre2-8 should be clarified: replace the inaccurate phrase referencing the literal token `${PCRE2_LIB}` with the actual prior approach (the literal string "libpcre2-8.a") and explain that find_library is used instead to portably locate the library (e.g., in /usr/local/lib or /opt/homebrew/lib); update the comment near the PCRE2_LIB mention to reference "libpcre2-8.a" and state that find_library is used to avoid relying on hard-coded filenames.
10-22: ⚡ Quick winConsider adding HINTS parameter to
find_libraryfor more robust Homebrew path resolution.The
link_directories()call on line 20 affects only the linker, notfind_library's search paths per CMake documentation. While the current code successfully builds on macOS arm64 with Homebrew (verified in commit b6d01aa), adding an explicit HINTS parameter makes the dependency resolution more robust and reduces reliance on platform-specific CMake heuristics:Suggested change
find_library(PCRE2_LIB NAMES pcre2-8 HINTS "${HOMEBREW_PREFIX}/lib" REQUIRED)This ensures
find_librarychecks the Homebrew location first on all platforms, improving clarity and maintainability.🤖 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 `@internal/cpp/CMakeLists.txt` around lines 10 - 22, The CMake snippet sets HOMEBREW_PREFIX and calls include_directories() and link_directories(), but find_library isn't being guided to Homebrew's lib path; update the PCRE2 (and other relevant) find_library calls to include HINTS "${HOMEBREW_PREFIX}/lib" so CMake searches Homebrew first (e.g., modify the find_library call that defines PCRE2_LIB to add HINTS "${HOMEBREW_PREFIX}/lib"), keeping the existing include_directories(HOMEBREW_PREFIX/include) and link_directories intact.
🤖 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.
Outside diff comments:
In `@build.sh`:
- Around line 36-41: The check_cpp_deps function currently only checks Linux
library paths and prints an apt-get instruction; update it to detect
macOS/Homebrew like the build_go logic/CMakeLists.txt does by checking for
Homebrew-installed pcre2 locations (e.g., /usr/local/opt/pcre2/lib or $(brew
--prefix)/opt/pcre2/lib) or using brew --prefix when available, and change the
warning text to show platform-appropriate install commands (apt-get for Linux,
brew install pcre2 for macOS) so macOS users running ./build.sh --cpp receive
correct instructions and the check aligns with CMakeLists.txt behavior.
---
Nitpick comments:
In `@internal/cpp/CMakeLists.txt`:
- Around line 24-27: The comment about resolving libpcre2-8 should be clarified:
replace the inaccurate phrase referencing the literal token `${PCRE2_LIB}` with
the actual prior approach (the literal string "libpcre2-8.a") and explain that
find_library is used instead to portably locate the library (e.g., in
/usr/local/lib or /opt/homebrew/lib); update the comment near the PCRE2_LIB
mention to reference "libpcre2-8.a" and state that find_library is used to avoid
relying on hard-coded filenames.
- Around line 10-22: The CMake snippet sets HOMEBREW_PREFIX and calls
include_directories() and link_directories(), but find_library isn't being
guided to Homebrew's lib path; update the PCRE2 (and other relevant)
find_library calls to include HINTS "${HOMEBREW_PREFIX}/lib" so CMake searches
Homebrew first (e.g., modify the find_library call that defines PCRE2_LIB to add
HINTS "${HOMEBREW_PREFIX}/lib"), keeping the existing
include_directories(HOMEBREW_PREFIX/include) and link_directories intact.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5df6118d-9676-4591-925a-5a7071513e5d
📒 Files selected for processing (5)
build.shinternal/binding/rag_analyzer.gointernal/cpp/CMakeLists.txtinternal/cpp/rag_analyzer.cppinternal/cpp/wordnet_lemmatizer.cpp
Upstream's Go server build pipeline (build.sh + CMake + CGO) was tested on
Ubuntu 22.04 only. On macOS arm64 with Homebrew it fails in five places,
none of which require any platform-specific code path — the same builds
now succeed on both Linux and Darwin. Each fix is small and targeted.
These patches are upstream-friendly and the intent is to PR them back to
infiniflow/ragflow so we don't have to carry the diff at each merge.
Changes
-------
1. internal/cpp/CMakeLists.txt — find Homebrew + libpcre2-8 portably.
- Detect Apple platforms via if(APPLE), call `brew --prefix` once,
add ${HOMEBREW_PREFIX}/include and ${HOMEBREW_PREFIX}/lib to the
project's include/link paths. No effect on Linux.
- Replace the literal `libpcre2-8.a` token (only found by the linker
on Linux's default /usr/local/lib search path) with the result of
`find_library(PCRE2_LIB NAMES pcre2-8 REQUIRED)`. Works on both
/opt/homebrew/lib (Apple Silicon), /usr/local/lib (Intel Mac and
legacy Linux) and /usr/lib/x86_64-linux-gnu (Debian/Ubuntu).
2. internal/cpp/wordnet_lemmatizer.cpp + internal/cpp/rag_analyzer.cpp —
add explicit `#include <sstream>` next to the existing `<fstream>`
include. libstdc++ (Linux) pulls in <sstream> transitively, libc++
(Apple Clang) doesn't, so `std::istringstream` / `std::ostringstream`
are unknown types on macOS without the include. Both files use these
types directly.
3. internal/cpp/rag_analyzer.cpp — `Join(...)` template overload fix.
Line 146 called `Join(tokens, start, tokens.size(), delim)` which
passes `size_t` to an `int` parameter. C++23 strict mode in Apple
Clang refuses the implicit narrowing and reports the 4-arg overload
as a substitution failure, leaving the call ambiguous between the
3-arg and 4-arg templates. Fix: explicit `static_cast<int>(...)`.
Behaviour identical on libstdc++ — narrowing was always intentional.
4. internal/binding/rag_analyzer.go — split `darwin` CGO LDFLAGS into
`darwin,arm64` and `darwin,amd64` build constraints. The previous
`#cgo darwin LDFLAGS: ... /usr/local/lib/libpcre2-8.a` only worked on
Intel Macs where Homebrew installs to /usr/local; Apple Silicon
Homebrew installs to /opt/homebrew. Both constraints now resolve.
5. build.sh — pcre2 sanity-check accepts /opt/homebrew/lib in addition
to the two existing Linux paths. On macOS without pcre2 installed it
now fails cleanly with the right brew command instead of attempting
`sudo apt -y install libpcre2-dev`.
Adopted from upstream main (post-2026-05-15 merge)
--------------------------------------------------
6. conf/models/zhipu-ai.json — invalid JSON (missing comma after
"image2text") fixed upstream in a later commit. Adopting that
version now so the Go binary can boot locally; the next merge
upstream will be a no-op on this file.
Verified
--------
- `bash build.sh` completes on macOS arm64 (Apple Silicon, brew 4.x,
cmake 4.x, Apple Clang 17, Go 1.25.0, pcre2 10.x, simde 0.8.x).
- Produced binaries: bin/server_main, bin/admin_server, bin/ragflow_cli.
- `bin/server_main` boots, connects MySQL, runs migrations, loads the
64 model provider configs, fails only on `dial tcp [::1]:1200`
because we run Infinity (port 23817) not Elasticsearch — orthogonal
to this patchset; the build itself is now reproducible on Mac.
Not done in this commit
-----------------------
- Go server runtime on Infinity is blocked by upstream's own
`internal/engine/README.md`: "Infinity implementation is a placeholder
waiting for the official Infinity Go SDK. Only Elasticsearch is fully
functional at this time." Our Cyllene stack runs on Infinity by
design, so the Go façade migration plan (RBAC middleware + 128 route
mappings already committed in d721502) is paused at Etape 3 until
upstream ships the Infinity Go SDK. The build patches above are
pre-requisite groundwork — they unblock local development on Mac for
whichever team wants to contribute the SDK.
b6d01aa to
c59a809
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15009 +/- ##
=======================================
Coverage 93.12% 93.12%
=======================================
Files 10 10
Lines 713 713
Branches 116 116
=======================================
Hits 664 664
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
## Problem
The Go server build pipeline (`build.sh` + CMake + CGO bindings) was
tested on Ubuntu only. On macOS arm64 with Homebrew it fails in five
orthogonal places. None of these require platform-specific code paths —
the same source builds on both Linux and Darwin after these fixes.
## Reproduction (before)
```
$ uname -a
Darwin … 25.4.0 arm64
$ brew install cmake pcre2 simde
$ bash build.sh
…
error: 'simde/x86/sse4.1.h' file not found
error: implicit instantiation of undefined template 'std::basic_istringstream<char>'
error: no matching function for call to 'Join'
…
clang: error: no such file or directory: '/usr/local/lib/libpcre2-8.a'
```
## Fix (5 small, orthogonal changes)
### 1. `internal/cpp/CMakeLists.txt` — find Homebrew + libpcre2-8
portably
- Detect Apple platforms via `if(APPLE)`, call `brew --prefix` once, add
`${HOMEBREW_PREFIX}/include` and `${HOMEBREW_PREFIX}/lib`. No effect on
Linux.
- Replace the literal `libpcre2-8.a` link token (which only the Linux
linker finds in `/usr/local/lib` by default) with
`find_library(PCRE2_LIB NAMES pcre2-8 REQUIRED)`. Works on
`/usr/lib/x86_64-linux-gnu` (Debian/Ubuntu), `/usr/local/lib` (Intel Mac
& legacy Linux), `/opt/homebrew/lib` (Apple Silicon).
### 2. `internal/cpp/wordnet_lemmatizer.cpp` +
`internal/cpp/rag_analyzer.cpp` — explicit `#include <sstream>`
libstdc++ (Linux) pulls `<sstream>` in transitively via `<fstream>`;
libc++ (Apple Clang) doesn't, so the existing `std::istringstream` /
`std::ostringstream` uses fail to compile on macOS. One-line include in
each file.
### 3. `internal/cpp/rag_analyzer.cpp` — `Join` template overload fix
`Join(tokens, start, tokens.size(), delim)` at line 146 passes `size_t`
to an `int` parameter. C++23 strict mode in Apple Clang refuses the
implicit narrowing and reports the 4-arg overload as a substitution
failure, leaving the call ambiguous between the 3-arg and 4-arg
templates. Fix: explicit `static_cast<int>(tokens.size())`. Behaviour
identical on libstdc++ — the narrowing was always intentional.
### 4. `internal/binding/rag_analyzer.go` — split darwin CGO LDFLAGS
The existing `#cgo darwin LDFLAGS: ... /usr/local/lib/libpcre2-8.a` only
matches Intel Macs. Apple Silicon Homebrew installs to `/opt/homebrew`.
Split into `darwin,arm64` and `darwin,amd64` build constraints with the
right absolute path on each.
### 5. `build.sh` — accept Homebrew path in the pcre2 sanity check
The sanity check looked at two Linux paths only and then fell through to
`sudo apt -y install libpcre2-dev` on failure. Added
`/opt/homebrew/lib/libpcre2-8.a`, and on Darwin failure now exits
cleanly with the right `brew install pcre2` hint instead of trying
`apt`.
## Verified
- `bash build.sh` now completes on macOS arm64 (Apple Silicon, brew 4.x,
cmake 4.x, Apple Clang 17, Go 1.25, pcre2 10.x, simde 0.8.x).
- Produced binaries: `bin/server_main`, `bin/admin_server`,
`bin/ragflow_cli`.
- `bin/server_main` boots, connects MySQL, runs migrations, loads the 64
model provider configs cleanly.
- Still builds on Linux — the CMake additions are inside an `if(APPLE)`
guard, the `find_library` call matches Linux paths too, the build.sh
check still tries `apt` when not on Darwin.
## Out of scope
The Go server itself currently fails at runtime when not pointing at
Elasticsearch (`Failed to initialize doc engine: failed to ping
Elasticsearch`), but that's the placeholder Infinity engine documented
in `internal/engine/README.md` — unrelated to this build patchset.
---
Happy to split this into smaller PRs if you'd prefer (one per file). The
five changes are independent.
Problem
The Go server build pipeline (
build.sh+ CMake + CGO bindings) was tested on Ubuntu only. On macOS arm64 with Homebrew it fails in five orthogonal places. None of these require platform-specific code paths — the same source builds on both Linux and Darwin after these fixes.Reproduction (before)
Fix (5 small, orthogonal changes)
1.
internal/cpp/CMakeLists.txt— find Homebrew + libpcre2-8 portablyif(APPLE), callbrew --prefixonce, add${HOMEBREW_PREFIX}/includeand${HOMEBREW_PREFIX}/lib. No effect on Linux.libpcre2-8.alink token (which only the Linux linker finds in/usr/local/libby default) withfind_library(PCRE2_LIB NAMES pcre2-8 REQUIRED). Works on/usr/lib/x86_64-linux-gnu(Debian/Ubuntu),/usr/local/lib(Intel Mac & legacy Linux),/opt/homebrew/lib(Apple Silicon).2.
internal/cpp/wordnet_lemmatizer.cpp+internal/cpp/rag_analyzer.cpp— explicit#include <sstream>libstdc++ (Linux) pulls
<sstream>in transitively via<fstream>; libc++ (Apple Clang) doesn't, so the existingstd::istringstream/std::ostringstreamuses fail to compile on macOS. One-line include in each file.3.
internal/cpp/rag_analyzer.cpp—Jointemplate overload fixJoin(tokens, start, tokens.size(), delim)at line 146 passessize_tto anintparameter. C++23 strict mode in Apple Clang refuses the implicit narrowing and reports the 4-arg overload as a substitution failure, leaving the call ambiguous between the 3-arg and 4-arg templates. Fix: explicitstatic_cast<int>(tokens.size()). Behaviour identical on libstdc++ — the narrowing was always intentional.4.
internal/binding/rag_analyzer.go— split darwin CGO LDFLAGSThe existing
#cgo darwin LDFLAGS: ... /usr/local/lib/libpcre2-8.aonly matches Intel Macs. Apple Silicon Homebrew installs to/opt/homebrew. Split intodarwin,arm64anddarwin,amd64build constraints with the right absolute path on each.5.
build.sh— accept Homebrew path in the pcre2 sanity checkThe sanity check looked at two Linux paths only and then fell through to
sudo apt -y install libpcre2-devon failure. Added/opt/homebrew/lib/libpcre2-8.a, and on Darwin failure now exits cleanly with the rightbrew install pcre2hint instead of tryingapt.Verified
bash build.shnow completes on macOS arm64 (Apple Silicon, brew 4.x, cmake 4.x, Apple Clang 17, Go 1.25, pcre2 10.x, simde 0.8.x).bin/server_main,bin/admin_server,bin/ragflow_cli.bin/server_mainboots, connects MySQL, runs migrations, loads the 64 model provider configs cleanly.if(APPLE)guard, thefind_librarycall matches Linux paths too, the build.sh check still triesaptwhen not on Darwin.Out of scope
The Go server itself currently fails at runtime when not pointing at Elasticsearch (
Failed to initialize doc engine: failed to ping Elasticsearch), but that's the placeholder Infinity engine documented ininternal/engine/README.md— unrelated to this build patchset.Happy to split this into smaller PRs if you'd prefer (one per file). The five changes are independent.