From 9d94ab5e1d45ef947d1decac4176b5ce26ff05b9 Mon Sep 17 00:00:00 2001 From: hesphoros Date: Thu, 17 Sep 2026 00:32:19 +0800 Subject: [PATCH 1/3] Document Debug CMake build on Apple Silicon --- .gitignore | 1 + docs/cn/getting_started.md | 35 +++++++++++++++++++++++++++++++++++ docs/en/getting_started.md | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/.gitignore b/.gitignore index c7b21b9350..894f032e9e 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ CTestTestfile.cmake /CPackSourceConfig.cmake /CPackConfig.cmake /cmake-build-debug/ +/build-debug/ /googletest-download/ /googletest-src/ /test/rpc_data/ diff --git a/docs/cn/getting_started.md b/docs/cn/getting_started.md index 51e9b9759e..7a6ca11852 100644 --- a/docs/cn/getting_started.md +++ b/docs/cn/getting_started.md @@ -283,6 +283,41 @@ Monterey中openssl的安装位置可能不再位于`/usr/local/opt/openssl`, * 先运行`brew link openssl --force`看看`/usr/local/opt/openssl`是否出现了 * 没有的话可以自行设置软链:`sudo ln -s /opt/homebrew/Cellar/openssl@3/3.0.3 /usr/local/opt/openssl`。请注意此命令中openssl的目录可能随环境变化而变化,可通过`brew info openssl`查看。 +### 使用cmake编译Debug版brpc + +Apple Silicon 可以使用 Homebrew 安装的依赖编译 Debug 版本: + +```shell +cmake -S . -B build-debug \ + -DCMAKE_BUILD_TYPE=Debug \ + -DDEBUG=ON \ + -DCMAKE_OSX_ARCHITECTURES=arm64 \ + -DCMAKE_OSX_SYSROOT="$(xcrun --sdk macosx --show-sdk-path)" \ + -DCMAKE_PREFIX_PATH="$(brew --prefix)" \ + -DOPENSSL_ROOT_DIR="$(brew --prefix openssl@3)" +cmake --build build-debug --parallel +``` + +`CMAKE_BUILD_TYPE=Debug`启用cmake的Debug构建配置,`DEBUG=ON`启用brpc的 +调试日志并保留断言。构建产物位于`build-debug/output/`。 + +如需为 clangd 等工具生成编译数据库,请在配置命令中添加以下可选项: + +```shell +-DCMAKE_EXPORT_COMPILE_COMMANDS=ON +``` + +生成的编译数据库位于 `build-debug/compile_commands.json`。 + +如果 CMake 报错 `tapi error: malformed file`,请确认 Command Line Tools 与 Xcode +版本一致,并选择当前安装的 Xcode: + +```shell +sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer +``` + +如果问题仍然存在,请检查`xcrun --sdk macosx --show-sdk-path`返回的SDK路径是否有效。 + ### 使用config_brpc.sh编译brpc git克隆brpc,进入到项目目录然后运行: ```shell diff --git a/docs/en/getting_started.md b/docs/en/getting_started.md index 9acadc75e0..f98bf325a6 100644 --- a/docs/en/getting_started.md +++ b/docs/en/getting_started.md @@ -291,6 +291,44 @@ openssl installed in Monterey may not be found at `/usr/local/opt/openssl`, inst * Run `brew link openssl --force` first and check if `/usr/local/opt/openssl` appears. * If above command does not work, consider making a soft link using `sudo ln -s /opt/homebrew/Cellar/openssl@3/3.0.3 /usr/local/opt/openssl`. Note that the installed openssl in above command may be put in different places in different environments, which could be revealed by running `brew info openssl`. +### Compile a Debug build with cmake + +Apple Silicon can build the Debug configuration against dependencies installed by Homebrew: + +```shell +cmake -S . -B build-debug \ + -DCMAKE_BUILD_TYPE=Debug \ + -DDEBUG=ON \ + -DCMAKE_OSX_ARCHITECTURES=arm64 \ + -DCMAKE_OSX_SYSROOT="$(xcrun --sdk macosx --show-sdk-path)" \ + -DCMAKE_PREFIX_PATH="$(brew --prefix)" \ + -DOPENSSL_ROOT_DIR="$(brew --prefix openssl@3)" +cmake --build build-debug --parallel +``` + +`CMAKE_BUILD_TYPE=Debug` selects cmake's Debug configuration, while `DEBUG=ON` +enables brpc's debug logs and keeps assertions enabled. Build artifacts are +written to `build-debug/output/`. + +To generate a compilation database for tools such as clangd, add the following +optional argument to the configuration command: + +```shell +-DCMAKE_EXPORT_COMPILE_COMMANDS=ON +``` + +The compilation database is generated at `build-debug/compile_commands.json`. + +If cmake reports `tapi error: malformed file`, make sure the Command Line Tools +and Xcode versions match, then select the installed Xcode: + +```shell +sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer +``` + +If the problem persists, verify that `xcrun --sdk macosx --show-sdk-path` returns +a valid SDK path. + ### Compile brpc with config_brpc.sh git clone brpc, cd into the repo and run ```shell From 166a338130577a5ced4bfbeb8a7c3bcbdcba6f0e Mon Sep 17 00:00:00 2001 From: hesphoros Date: Thu, 17 Sep 2026 01:22:58 +0800 Subject: [PATCH 2/3] Fix formatting and clarify CMake usage for brpc Update instructions for using CMake to compile Debug version of brpc on Apple Silicon. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- docs/cn/getting_started.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/cn/getting_started.md b/docs/cn/getting_started.md index 7a6ca11852..8b90d900cd 100644 --- a/docs/cn/getting_started.md +++ b/docs/cn/getting_started.md @@ -283,7 +283,7 @@ Monterey中openssl的安装位置可能不再位于`/usr/local/opt/openssl`, * 先运行`brew link openssl --force`看看`/usr/local/opt/openssl`是否出现了 * 没有的话可以自行设置软链:`sudo ln -s /opt/homebrew/Cellar/openssl@3/3.0.3 /usr/local/opt/openssl`。请注意此命令中openssl的目录可能随环境变化而变化,可通过`brew info openssl`查看。 -### 使用cmake编译Debug版brpc +### 使用 CMake 编译 Debug 版 brpc Apple Silicon 可以使用 Homebrew 安装的依赖编译 Debug 版本: From ce7439524d0770178cc13fde4ee04a84d8c03195 Mon Sep 17 00:00:00 2001 From: hesphoros Date: Thu, 17 Sep 2026 01:32:06 +0800 Subject: [PATCH 3/3] Address CMake documentation review --- docs/cn/getting_started.md | 7 ++++--- docs/en/getting_started.md | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/cn/getting_started.md b/docs/cn/getting_started.md index 8b90d900cd..80d8cb5214 100644 --- a/docs/cn/getting_started.md +++ b/docs/cn/getting_started.md @@ -288,7 +288,7 @@ Monterey中openssl的安装位置可能不再位于`/usr/local/opt/openssl`, Apple Silicon 可以使用 Homebrew 安装的依赖编译 Debug 版本: ```shell -cmake -S . -B build-debug \ +cmake -S . -B build-debug -G "Unix Makefiles" \ -DCMAKE_BUILD_TYPE=Debug \ -DDEBUG=ON \ -DCMAKE_OSX_ARCHITECTURES=arm64 \ @@ -298,8 +298,9 @@ cmake -S . -B build-debug \ cmake --build build-debug --parallel ``` -`CMAKE_BUILD_TYPE=Debug`启用cmake的Debug构建配置,`DEBUG=ON`启用brpc的 -调试日志并保留断言。构建产物位于`build-debug/output/`。 +该命令使用单配置的Unix Makefiles生成器,因此`CMAKE_BUILD_TYPE=Debug`会选择 +CMake的Debug构建配置。`DEBUG=ON`启用brpc的调试日志并保留断言。构建产物位于 +`build-debug/output/`。 如需为 clangd 等工具生成编译数据库,请在配置命令中添加以下可选项: diff --git a/docs/en/getting_started.md b/docs/en/getting_started.md index f98bf325a6..19957751e9 100644 --- a/docs/en/getting_started.md +++ b/docs/en/getting_started.md @@ -291,12 +291,12 @@ openssl installed in Monterey may not be found at `/usr/local/opt/openssl`, inst * Run `brew link openssl --force` first and check if `/usr/local/opt/openssl` appears. * If above command does not work, consider making a soft link using `sudo ln -s /opt/homebrew/Cellar/openssl@3/3.0.3 /usr/local/opt/openssl`. Note that the installed openssl in above command may be put in different places in different environments, which could be revealed by running `brew info openssl`. -### Compile a Debug build with cmake +### Compile a Debug build with CMake Apple Silicon can build the Debug configuration against dependencies installed by Homebrew: ```shell -cmake -S . -B build-debug \ +cmake -S . -B build-debug -G "Unix Makefiles" \ -DCMAKE_BUILD_TYPE=Debug \ -DDEBUG=ON \ -DCMAKE_OSX_ARCHITECTURES=arm64 \ @@ -306,7 +306,8 @@ cmake -S . -B build-debug \ cmake --build build-debug --parallel ``` -`CMAKE_BUILD_TYPE=Debug` selects cmake's Debug configuration, while `DEBUG=ON` +The command uses the single-config Unix Makefiles generator, so +`CMAKE_BUILD_TYPE=Debug` selects CMake's Debug configuration. `DEBUG=ON` enables brpc's debug logs and keeps assertions enabled. Build artifacts are written to `build-debug/output/`. @@ -319,7 +320,7 @@ optional argument to the configuration command: The compilation database is generated at `build-debug/compile_commands.json`. -If cmake reports `tapi error: malformed file`, make sure the Command Line Tools +If CMake reports `tapi error: malformed file`, make sure the Command Line Tools and Xcode versions match, then select the installed Xcode: ```shell