You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by "wasphin (via GitHub)" <gi...@apache.org> on 2026/10/10 15:36:56 UTC

[PR] Add optional standalone CMake component libraries (brpc)

wasphin opened a new pull request, #3596:
URL: https://github.com/apache/brpc/pull/3596

   ### What problem does this PR solve?
   
   Issue Number: N/A
   
   Problem Summary:
   
   CMake currently packages the production modules into the brpc bundle. Applications
   that only need butil, bvar, bthread, json2pb or mcpack2pb cannot consume an installed
   component target independently, which also prevents packaging these modules for
   standalone use through vcpkg.
   
   ### What is changed and the side effects?
   
   Changed:
   
   The four commits separate directory ownership, target ownership, component
   packaging and mcpack IDL ownership so each stage can be reviewed independently:
   
   1. Move production source definitions into their module directories.
   2. Define module-owned object targets, scope feature/dependency handling to the
      owning modules and reuse those targets for the legacy bundles and tests.
   3. Add optional component libraries and exported CMake package targets.
   4. Make mcpack2pb own the IDL option schema, generated public header and symbols,
      updating CMake, Make and Bazel rules without changing public import names.
   
   - `BRPC_BUILD_COMPONENT_LIBS` is OFF by default. Enabling it builds all six
     components alongside the existing bundle; `BUILD_SHARED_LIBS` controls the
     standalone libraries' linkage.
   - Export `brpc::butil`, `brpc::bvar`, `brpc::bthread`, `brpc::json2pb`,
     `brpc::mcpack2pb` and `brpc::brpc` with their transitive dependencies.
     The RPC-only library is named `libbrpc-only` to avoid conflicting with the
     existing `libbrpc` bundle.
   - Install headers directly from module source/build directories and use target
     build/install interfaces instead of staging copies in `output/include`.
   - Keep generated IDL definitions in mcpack2pb and obtain them transitively from
     the RPC component. Preserve `import "idl_options.proto"` and
     `#include "idl_options.pb.h"`.
   - Do not distribute producer-side custom Find modules in the installed package.
   - Add six standalone consumer checks, including custom-option consumption and a
     complete RPC client/server exchange using an ephemeral server port.
   - Update both English and Chinese getting-started documentation, including an
     independent vcpkg consumer example. The documented `components` feature is
     provided by an overlay port, not the current registry port.
   
   Side effects:
   - Performance effects: Production objects are compiled once and reused by the
     bundle and standalone libraries. Enabling components adds library linking and
     packaging work; it does not duplicate production source compilation.
   
   - Breaking backward compatibility: Existing bundle names and linkage remain
     unchanged, and standalone components are opt-in. CMake builds no longer stage
     headers in `output/include`; users relying on that directory should run
     `cmake --install build --prefix build/output`. Do not link the bundle and
     standalone components into the same application because they share symbols.
   
   ---
   ### Check List:
   - [x] Please make sure your changes are compilable.
   - [x] When providing us with a new feature, it is best to add related tests.
   - [x] Please follow [Contributor Covenant Code of Conduct](https://github.com/apache/brpc/blob/master/CODE_OF_CONDUCT.md).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [PR] Add optional standalone CMake component libraries (brpc)

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #3596:
URL: https://github.com/apache/brpc/pull/3596#discussion_r4240235391


##########
src/mcpack2pb/CMakeLists.txt:
##########
@@ -0,0 +1,75 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set(MCPACK2PB_SOURCES
+    ${CMAKE_CURRENT_SOURCE_DIR}/field_type.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/mcpack2pb.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/parser.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/serializer.cpp)
+
+include(CompileProto)
+compile_proto(IDL_OPTIONS_HDRS IDL_OPTIONS_SRCS ${CMAKE_CURRENT_BINARY_DIR}
+    ${CMAKE_CURRENT_SOURCE_DIR}
+    "idl_options.proto")
+add_library(mcpack2pb_build_config INTERFACE)
+target_include_directories(mcpack2pb_build_config BEFORE INTERFACE
+    ${CMAKE_CURRENT_BINARY_DIR})
+target_link_libraries(mcpack2pb_build_config INTERFACE butil_build_config)
+add_library(IDL_OPTIONS_LIB OBJECT ${IDL_OPTIONS_SRCS} ${IDL_OPTIONS_HDRS})
+set_property(TARGET IDL_OPTIONS_LIB PROPERTY POSITION_INDEPENDENT_CODE 1)
+target_link_libraries(IDL_OPTIONS_LIB PRIVATE mcpack2pb_build_config)
+
+add_library(MCPACK2PB_LIB OBJECT ${MCPACK2PB_SOURCES})
+target_link_libraries(MCPACK2PB_LIB PRIVATE mcpack2pb_build_config)
+set_property(TARGET MCPACK2PB_LIB PROPERTY POSITION_INDEPENDENT_CODE 1)
+
+if(TARGET protobuf::libprotoc)
+    set(PROTOC_LIB protobuf::libprotoc)
+else()
+    find_library(PROTOC_LIB NAMES protoc)
+endif()
+if(NOT PROTOC_LIB)
+    message(FATAL_ERROR "Fail to find protoc lib")
+endif()
+
+# Legacy bundles/tests retain protoc linkage; the runtime component does not.
+set_property(TARGET MCPACK2PB_LIB PROPERTY BRPC_BUNDLE_LIBRARIES "${PROTOC_LIB}")
+set_property(TARGET MCPACK2PB_LIB PROPERTY BRPC_PRIVATE_LIBS "-lprotoc")
+
+add_executable(protoc-gen-mcpack generator.cpp)
+add_dependencies(protoc-gen-mcpack IDL_OPTIONS_LIB)
+set_target_properties(protoc-gen-mcpack PROPERTIES
+    RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/output/bin)
+target_link_libraries(protoc-gen-mcpack PRIVATE mcpack2pb_build_config)
+if(BUILD_SHARED_LIBS)
+    target_link_libraries(protoc-gen-mcpack PRIVATE brpc-shared brpc_bundle_dependencies)
+else()
+    target_link_libraries(protoc-gen-mcpack PRIVATE brpc-static brpc_bundle_dependencies)
+endif()
+
+if(BRPC_BUILD_COMPONENT_LIBS)
+    brpc_add_component(mcpack2pb MCPACK2PB_LIB ${IDL_OPTIONS_HDRS})

Review Comment:
   The build-tree export cannot expose `idl_options.proto`: `brpc_add_component()` only publishes this module's binary directory and the parent `src` directory, while the schema now lives in `src/mcpack2pb`. Installed consumers work because line 68 installs it at the include root, but a consumer using the generated build-tree `brpc-config.cmake` cannot resolve the preserved `import "idl_options.proto"`. Publish this source directory as a build-only include path (and add a build-tree consumer check).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [PR] Add optional standalone CMake component libraries (brpc)

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #3596:
URL: https://github.com/apache/brpc/pull/3596#discussion_r4240162822


##########
test/CMakeLists.txt:
##########
@@ -202,9 +205,29 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
     )
 endif()
 
+# Read module-owned sources from their targets, not parent-scope variables.
+get_target_property(BUTIL_SOURCES BUTIL_LIB SOURCES)
+# Source properties are directory-scoped; reuse production CRC32C settings.
+get_target_property(butil_crc32c_options BUTIL_LIB BRPC_CRC32C_COMPILE_OPTIONS)
+if(butil_crc32c_options)
+    set_property(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/../src/butil/crc32c.cc
+        APPEND PROPERTY COMPILE_OPTIONS ${butil_crc32c_options})
+endif()
+if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND
+   CMAKE_SYSTEM_PROCESSOR MATCHES "riscv64" AND WITH_RISCV_ZVBC)
+    set_property(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/../src/butil/third_party/modp_b64/modp_b64_rvv.cc
+        APPEND PROPERTY COMPILE_OPTIONS -march=rv64gcv_zbc_zvbc)

Review Comment:
   The debug-library copy of the RISC-V settings repeats the same partial flag assignment: only `modp_b64_rvv.cc` gets `-march`, while its caller and the IOBuf/StringPiece RVV sources are compiled as scalar code. Apply the Zvbc option consistently to all RVV-dependent entries in `BUTIL_SOURCES` so the debug build matches production and can exercise these paths.



##########
src/butil/CMakeLists.txt:
##########
@@ -0,0 +1,351 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set(WITH_GLOG_VAL "0")
+if(WITH_GLOG)
+    set(WITH_GLOG_VAL "1")
+    set(BRPC_WITH_GLOG 1)
+endif()
+
+set(WITH_CPU_FREQUENCY_VAL "0")
+if(WITH_CPU_FREQUENCY)
+    set(WITH_CPU_FREQUENCY_VAL "1")
+    set(BUTIL_USE_CPU_FREQUENCY 1)
+endif()
+
+set(BUTIL_DEFINITIONS
+    BRPC_WITH_GLOG=${WITH_GLOG_VAL}
+    BUTIL_USE_CPU_FREQUENCY=${WITH_CPU_FREQUENCY_VAL})
+if(WITH_MESALINK)
+    list(APPEND BUTIL_DEFINITIONS USE_MESALINK)
+endif()
+if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+    include(CheckFunctionExists)
+    CHECK_FUNCTION_EXISTS(clock_gettime HAVE_CLOCK_GETTIME)
+    if(NOT HAVE_CLOCK_GETTIME)
+        list(APPEND BUTIL_DEFINITIONS NO_CLOCK_GETTIME_IN_MAC)
+    endif()
+endif()
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
+    ${CMAKE_CURRENT_SOURCE_DIR}/config.h @ONLY)
+
+set(BUTIL_INCLUDE_DIRS ${GFLAGS_INCLUDE_PATH} ${PROTOBUF_INCLUDE_DIRS})
+if(WITH_GLOG)
+    find_path(GLOG_INCLUDE_PATH NAMES glog/logging.h)
+    find_library(GLOG_LIB NAMES glog)
+    if((NOT GLOG_INCLUDE_PATH) OR (NOT GLOG_LIB))
+        message(FATAL_ERROR "Fail to find glog")
+    endif()
+    list(APPEND BUTIL_INCLUDE_DIRS ${GLOG_INCLUDE_PATH})
+endif()
+
+if(WITH_MESALINK)
+    find_path(MESALINK_INCLUDE_PATH NAMES mesalink/openssl/ssl.h)
+    find_library(MESALINK_LIB NAMES mesalink)
+    if((NOT MESALINK_INCLUDE_PATH) OR (NOT MESALINK_LIB))
+        message(FATAL_ERROR "Fail to find MesaLink")
+    else()
+        message(STATUS "Found MesaLink: ${MESALINK_LIB}")
+    endif()
+    list(APPEND BUTIL_INCLUDE_DIRS ${MESALINK_INCLUDE_PATH})
+endif()
+
+if(WITH_BORINGSSL)
+    find_package(BoringSSL REQUIRED)
+    list(APPEND BUTIL_INCLUDE_DIRS ${BORINGSSL_INCLUDE_DIR})
+else()
+    if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT OPENSSL_ROOT_DIR)
+        set(OPENSSL_ROOT_DIR
+            "/usr/local/opt/openssl" # Homebrew installed OpenSSL
+        )
+    endif()
+
+    find_package(OpenSSL REQUIRED)
+    list(APPEND BUTIL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR})
+endif()
+
+add_library(butil_build_config INTERFACE)
+target_link_libraries(butil_build_config INTERFACE brpc_common_config)
+target_compile_definitions(butil_build_config INTERFACE ${BUTIL_DEFINITIONS})
+target_include_directories(butil_build_config INTERFACE ${BUTIL_INCLUDE_DIRS})
+
+set(butil_crc32c_options)
+if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+    if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
+        # Only CRC32C needs the SSE4.2 intrinsics and feature macro.
+        list(APPEND butil_crc32c_options -msse4.2)
+    elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "riscv64")
+        option(WITH_RISCV_ZBC "Enable RISC-V Zbc carry-less multiplication for CRC32C acceleration" OFF)
+        option(WITH_RISCV_ZVBC "Enable RISC-V Zvbc vector carry-less multiplication for CRC32C acceleration" OFF)
+        if(WITH_RISCV_ZVBC)
+            list(APPEND butil_crc32c_options -march=rv64gcv_zbc_zvbc)
+            # Preserve the existing RVV base64 implementation as well.
+            set_property(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/third_party/modp_b64/modp_b64_rvv.cc
+                APPEND PROPERTY COMPILE_OPTIONS -march=rv64gcv_zbc_zvbc)

Review Comment:
   With `WITH_RISCV_ZVBC=ON`, the new scoping applies the vector ISA only to CRC32C and `modp_b64_rvv.cc`. The callers in `modp_b64.cc`, `iobuf.cpp`, and `strings/string_piece.cc`, plus the `rvv_memcmp` implementation in `string_compare_rvv.cc`, are therefore compiled without `__riscv_vector`; the RVV paths are compiled out (and vector-enabled downstream `StringPiece` code can reference symbols the library did not emit). Apply this option to every RVV-dependent source, or retain the previous target-wide `-march` behavior, and mirror that setup for the debug objects in `test/CMakeLists.txt`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [PR] Add optional standalone CMake component libraries (brpc)

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #3596:
URL: https://github.com/apache/brpc/pull/3596#discussion_r4241793921


##########
src/brpc/CMakeLists.txt:
##########
@@ -0,0 +1,358 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set(WITH_RDMA_VAL "0")
+if(WITH_RDMA)
+    set(WITH_RDMA_VAL "1")
+endif()
+
+set(WITH_URMA_VAL "0")
+if(WITH_URMA)
+    set(WITH_URMA_VAL "1")
+endif()
+
+string(TOUPPER "${URMA_USE_MOCK}" URMA_USE_MOCK_MODE)
+if(NOT URMA_USE_MOCK_MODE STREQUAL "AUTO" AND
+   NOT URMA_USE_MOCK_MODE STREQUAL "ON" AND
+   NOT URMA_USE_MOCK_MODE STREQUAL "OFF")
+    message(FATAL_ERROR
+        "URMA_USE_MOCK must be AUTO, ON, or OFF, got: ${URMA_USE_MOCK}")
+endif()
+
+set(WITH_UBRING_VAL "0")
+if(WITH_UBRING)
+        set(WITH_UBRING_VAL "1")
+endif()
+
+set(BRPC_DEFINITIONS
+    BRPC_WITH_RDMA=${WITH_RDMA_VAL}
+    BRPC_WITH_URMA=${WITH_URMA_VAL}
+    BRPC_WITH_UBRING=${WITH_UBRING_VAL})
+set(BRPC_INCLUDE_DIRS)
+if(WITH_THRIFT)
+    list(APPEND BRPC_DEFINITIONS ENABLE_THRIFT_FRAMED_PROTOCOL)
+    find_library(THRIFT_LIB NAMES thrift)
+    if (NOT THRIFT_LIB)
+        message(FATAL_ERROR "Fail to find Thrift")
+    endif()
+endif()
+
+if(WITH_THRIFT)
+    find_path(THRIFT_INCLUDE_PATH NAMES thrift/Thrift.h)
+    if(NOT THRIFT_INCLUDE_PATH)
+        message(FATAL_ERROR "Fail to find Thrift headers")
+    endif()
+    list(APPEND BRPC_INCLUDE_DIRS ${THRIFT_INCLUDE_PATH})
+endif()
+find_package(ZLIB REQUIRED)
+list(APPEND BRPC_INCLUDE_DIRS ${ZLIB_INCLUDE_DIRS})
+
+find_path(LEVELDB_INCLUDE_PATH NAMES leveldb/db.h)
+find_library(LEVELDB_LIB NAMES leveldb)
+if ((NOT LEVELDB_INCLUDE_PATH) OR (NOT LEVELDB_LIB))
+    message(FATAL_ERROR "Fail to find leveldb")
+endif()
+
+if(WITH_SNAPPY)
+    find_path(SNAPPY_INCLUDE_PATH NAMES snappy.h)
+    find_library(SNAPPY_LIB NAMES snappy)
+    if ((NOT SNAPPY_INCLUDE_PATH) OR (NOT SNAPPY_LIB))
+        message(FATAL_ERROR "Fail to find snappy")
+    endif()
+    list(APPEND BRPC_INCLUDE_DIRS ${SNAPPY_INCLUDE_PATH})
+endif()
+
+if(WITH_RDMA)
+    message("brpc compile with rdma")
+    find_path(RDMA_INCLUDE_PATH NAMES infiniband/verbs.h)
+    find_library(RDMA_LIB NAMES ibverbs)
+    if((NOT RDMA_INCLUDE_PATH) OR (NOT RDMA_LIB))
+        message(FATAL_ERROR "Fail to find ibverbs")
+    endif()
+    list(APPEND BRPC_INCLUDE_DIRS ${RDMA_INCLUDE_PATH})
+endif()
+
+if(WITH_URMA)
+    # UrmaTransport and its link-time mock both compile against the upstream
+    # UMDK API. Prefer installed headers; otherwise fetch a pinned upstream
+    # commit, following Mooncake's URMA mock setup.
+    find_path(URMA_INCLUDE_PATH NAMES urma_api.h
+              HINTS ENV URMA_ROOT
+              PATHS /usr/include /usr/local/include
+              PATH_SUFFIXES ub/umdk/urma umdk/urma urma
+                            src/urma/lib/urma/core/include)
+    find_path(URMA_BOND_INCLUDE_PATH NAMES urma_ubagg.h
+              HINTS ENV URMA_ROOT
+              PATHS /usr/include /usr/local/include
+              PATH_SUFFIXES ub/umdk/urma umdk/urma urma
+                            src/urma/lib/urma/bond/include)
+    if(NOT URMA_INCLUDE_PATH AND DOWNLOAD_URMA_HEADERS)
+        include(FetchContent)
+        FetchContent_Declare(
+            urma_headers
+            GIT_REPOSITORY https://atomgit.com/openeuler/umdk.git
+            GIT_TAG 564ee727a55523d4351a8fb3c94292b388ebb924
+            # brpc only consumes UMDK headers; avoid cloning unrelated UMDK
+            # submodules such as CAM dependencies during configuration.
+            GIT_SUBMODULES ""
+            GIT_SHALLOW TRUE)
+        FetchContent_GetProperties(urma_headers)
+        if(NOT urma_headers_POPULATED)
+            FetchContent_Populate(urma_headers)
+        endif()
+        set(URMA_INCLUDE_PATH
+            "${urma_headers_SOURCE_DIR}/src/urma/lib/urma/core/include")
+        set(URMA_BOND_INCLUDE_PATH
+            "${urma_headers_SOURCE_DIR}/src/urma/lib/urma/bond/include")
+        message(STATUS "Using downloaded UMDK headers: ${URMA_INCLUDE_PATH}")
+    endif()
+    if(NOT URMA_INCLUDE_PATH)
+        message(FATAL_ERROR
+            "Fail to find urma_api.h. Install UMDK headers, set URMA_ROOT, "
+            "or enable DOWNLOAD_URMA_HEADERS.")
+    endif()
+
+    find_library(URMA_LIB NAMES urma
+                 HINTS ENV URMA_ROOT
+                 PATH_SUFFIXES lib lib64)
+    if(URMA_USE_MOCK_MODE STREQUAL "ON")
+        message(STATUS "URMA_USE_MOCK=ON; forcing the link-time URMA mock")
+        set(URMA_USE_MOCK_ENABLED 1)
+    elseif(URMA_USE_MOCK_MODE STREQUAL "OFF")
+        if(NOT URMA_LIB)
+            message(FATAL_ERROR
+                "URMA_USE_MOCK=OFF requires liburma; install it or use AUTO/ON.")
+        endif()
+        message(STATUS "URMA_USE_MOCK=OFF; using liburma")
+        set(URMA_USE_MOCK_ENABLED 0)
+    elseif(URMA_LIB)
+        message(STATUS "Found URMA library: ${URMA_LIB}")
+        set(URMA_USE_MOCK_ENABLED 0)
+    else()
+        message(STATUS
+            "liburma not found; building with the URMA link-time mock")
+        set(URMA_USE_MOCK_ENABLED 1)
+    endif()
+endif()
+
+if(WITH_URMA)
+    list(APPEND BRPC_INCLUDE_DIRS ${URMA_INCLUDE_PATH})
+    if(URMA_BOND_INCLUDE_PATH)
+        list(APPEND BRPC_INCLUDE_DIRS ${URMA_BOND_INCLUDE_PATH})
+    endif()
+    # The bundle/package need the selected mode and downloaded header paths.
+    set(URMA_USE_MOCK_ENABLED ${URMA_USE_MOCK_ENABLED} PARENT_SCOPE)
+    set(URMA_INCLUDE_PATH ${URMA_INCLUDE_PATH} PARENT_SCOPE)
+    set(URMA_BOND_INCLUDE_PATH ${URMA_BOND_INCLUDE_PATH} PARENT_SCOPE)
+endif()
+list(APPEND BRPC_INCLUDE_DIRS ${LEVELDB_INCLUDE_PATH})
+add_library(brpc_build_config INTERFACE)
+target_link_libraries(brpc_build_config INTERFACE
+    mcpack2pb_build_config bthread_build_config)
+target_include_directories(brpc_build_config BEFORE INTERFACE
+    ${CMAKE_CURRENT_BINARY_DIR})
+target_compile_definitions(brpc_build_config INTERFACE ${BRPC_DEFINITIONS})
+target_include_directories(brpc_build_config INTERFACE ${BRPC_INCLUDE_DIRS})
+
+function(check_thrift_version target_arg)
+    #use thrift command to get version
+    execute_process(
+        COMMAND thrift --version
+        OUTPUT_VARIABLE THRIFT_VERSION_OUTPUT
+        ERROR_QUIET
+        OUTPUT_STRIP_TRAILING_WHITESPACE
+    )
+
+    string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" THRIFT_VERSION ${THRIFT_VERSION_OUTPUT})
+    string(REGEX REPLACE "\\." ";" THRIFT_VERSION_LIST ${THRIFT_VERSION})
+
+    list(GET THRIFT_VERSION_LIST 0 THRIFT_MAJOR_VERSION)
+    list(GET THRIFT_VERSION_LIST 1 THRIFT_MINOR_VERSION)
+
+    if (THRIFT_MAJOR_VERSION EQUAL 0 AND THRIFT_MINOR_VERSION LESS 11)
+        message(STATUS "Thrift version is less than 0.11.0")
+        target_compile_definitions(${target_arg} INTERFACE _THRIFT_VERSION_LOWER_THAN_0_11_0_)
+    else()
+        message(STATUS "Thrift version is equal to or greater than 0.11.0")
+    endif()
+endfunction()
+
+if(WITH_THRIFT)
+    check_thrift_version(brpc_build_config)
+endif()
+
+file(GLOB_RECURSE BRPC_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
+file(GLOB_RECURSE THRIFT_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/thrift*.cpp")
+file(GLOB_RECURSE EXCLUDE_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/event_dispatcher_*.cpp")
+
+# When building with the real liburma, exclude the link-time mock so its urma_*
+# symbols do not clash with the library. When liburma is absent, keep it so CI
+# can build and test UrmaTransport without URMA hardware.
+if(WITH_URMA AND NOT URMA_USE_MOCK_ENABLED)
+    list(REMOVE_ITEM BRPC_SOURCES
+         "${CMAKE_CURRENT_SOURCE_DIR}/urma/mock_urma.cpp")
+endif()
+
+if(WITH_THRIFT)
+    message("brpc compile with thrift protocol")
+else()
+    # Remove thrift sources
+    foreach(v ${THRIFT_SOURCES})
+        list(REMOVE_ITEM BRPC_SOURCES ${v})
+    endforeach()
+    set(THRIFT_SOURCES "")
+endif()
+
+foreach(v ${EXCLUDE_SOURCES})
+    list(REMOVE_ITEM BRPC_SOURCES ${v})
+endforeach()
+
+include(CompileProto)
+set(PROTO_FILES brpc/builtin_service.proto
+                brpc/errno.proto
+                brpc/get_favicon.proto
+                brpc/get_js.proto
+                brpc/grpc_health_check.proto
+                brpc/nshead_meta.proto
+                brpc/options.proto
+                brpc/policy/baidu_rpc_meta.proto
+                brpc/policy/hulu_pbrpc_meta.proto
+                brpc/policy/mongo.proto
+                brpc/policy/public_pbrpc_meta.proto
+                brpc/policy/sofa_pbrpc_meta.proto
+                brpc/proto_base.proto
+                brpc/rdma/rdma_handshake.proto
+                brpc/rpc_dump.proto
+                brpc/rtmp.proto
+                brpc/span.proto
+                brpc/streaming_rpc_meta.proto
+                brpc/trackme.proto
+                brpc/urma/urma_handshake.proto)
+compile_proto(PROTO_HDRS PROTO_SRCS ${CMAKE_CURRENT_BINARY_DIR}
+                                    ${CMAKE_CURRENT_SOURCE_DIR}/..
+                                    "${PROTO_FILES}")
+add_library(PROTO_LIB OBJECT ${PROTO_SRCS} ${PROTO_HDRS})
+set_property(TARGET PROTO_LIB PROPERTY POSITION_INDEPENDENT_CODE 1)
+target_link_libraries(PROTO_LIB PRIVATE brpc_build_config)
+
+set(brpc_libraries ${LEVELDB_LIB} ZLIB::ZLIB)
+set(brpc_private_libs "-lleveldb -lz")
+if(WITH_THRIFT)
+    list(APPEND brpc_libraries ${THRIFT_LIB})
+endif()
+if(WITH_SNAPPY)
+    list(APPEND brpc_libraries ${SNAPPY_LIB})
+    string(APPEND brpc_private_libs " -lsnappy")
+endif()
+if(WITH_RDMA)
+    list(APPEND brpc_libraries ${RDMA_LIB})
+endif()
+if(WITH_URMA)
+    message(STATUS "brpc compile with URMA (mock=${URMA_USE_MOCK_ENABLED})")
+    if(NOT URMA_USE_MOCK_ENABLED)
+        list(APPEND brpc_libraries ${URMA_LIB})
+    endif()
+endif()
+if(WITH_UBRING)
+    message(STATUS "brpc compile with ubring")
+    list(APPEND brpc_libraries ${UB_LIB})
+endif()
+
+add_library(brpc_runtime_dependencies INTERFACE)
+target_link_libraries(brpc_runtime_dependencies INTERFACE ${brpc_libraries})
+
+add_library(BRPC_LIB OBJECT ${BRPC_SOURCES})
+target_link_libraries(BRPC_LIB PRIVATE brpc_build_config)
+set_property(TARGET BRPC_LIB PROPERTY POSITION_INDEPENDENT_CODE 1)
+set_property(TARGET BRPC_LIB PROPERTY BRPC_BUNDLE_LIBRARIES brpc_runtime_dependencies)
+set_property(TARGET BRPC_LIB PROPERTY BRPC_PRIVATE_LIBS "${brpc_private_libs}")
+add_dependencies(BRPC_LIB PROTO_LIB IDL_OPTIONS_LIB)
+
+if(BRPC_BUILD_COMPONENT_LIBS)
+    # Prefer the dependency's package metadata, including static-link dependencies
+    # and per-configuration locations. Retain support for system installations
+    # that do not provide a CMake package.
+    find_package(leveldb CONFIG QUIET)
+    if(TARGET leveldb::leveldb)
+        # Some LevelDB packages export a bare snappy library name rather than
+        # a target. Resolve it so non-system library prefixes also work.
+        get_target_property(leveldb_link_libraries leveldb::leveldb
+            INTERFACE_LINK_LIBRARIES)
+        if("snappy" IN_LIST leveldb_link_libraries AND NOT TARGET snappy)
+            find_library(LEVELDB_SNAPPY_LIB NAMES snappy)
+            if(NOT LEVELDB_SNAPPY_LIB)
+                message(FATAL_ERROR "LevelDB requires the Snappy development library")
+            endif()
+            add_library(snappy UNKNOWN IMPORTED)
+            set_property(TARGET snappy PROPERTY IMPORTED_LOCATION "${LEVELDB_SNAPPY_LIB}")
+        endif()
+        add_library(brpc::leveldb INTERFACE IMPORTED)
+        set_property(TARGET brpc::leveldb PROPERTY
+            INTERFACE_LINK_LIBRARIES leveldb::leveldb)
+    else()
+        add_library(brpc::leveldb UNKNOWN IMPORTED)
+        set_target_properties(brpc::leveldb PROPERTIES
+            IMPORTED_LOCATION "${LEVELDB_LIB}"
+            INTERFACE_INCLUDE_DIRECTORIES "${LEVELDB_INCLUDE_PATH}")
+    endif()
+
+    set(BRPC_COMPONENT_URMA_REAL OFF)
+    if(WITH_URMA AND NOT URMA_USE_MOCK_ENABLED)
+        set(BRPC_COMPONENT_URMA_REAL ON)
+    endif()
+    set(BRPC_COMPONENT_UB_NAME "")
+    if(WITH_UBRING AND UB_LIB)
+        get_filename_component(BRPC_COMPONENT_UB_NAME "${UB_LIB}" NAME_WE)
+        string(REGEX REPLACE "^lib|\\..*$" "" BRPC_COMPONENT_UB_NAME "${BRPC_COMPONENT_UB_NAME}")
+    endif()
+    foreach(dep THRIFT RDMA SNAPPY URMA UB)
+        if((dep STREQUAL "THRIFT" AND WITH_THRIFT) OR
+           (dep STREQUAL "RDMA" AND WITH_RDMA) OR
+           (dep STREQUAL "SNAPPY" AND WITH_SNAPPY) OR
+           (dep STREQUAL "URMA" AND BRPC_COMPONENT_URMA_REAL) OR

Review Comment:
   With `WITH_URMA=ON` and the link-time mock selected, this condition omits `brpc::urma` while `brpc::brpc` still exports `BRPC_WITH_URMA=1`. The public `brpc/urma/urma_endpoint.h` includes `urma_api.h`, but neither the build-tree target nor the installed package (`brpc-config.cmake.in` has the same real-library condition) supplies its include directory, so consumers of that API cannot compile without adding UMDK paths themselves. Export a header-only URMA dependency whenever URMA is enabled, and require/link liburma only in real-library mode, in both package paths.



##########
example/cmake/BrpcExample.cmake:
##########
@@ -29,7 +29,7 @@ endfunction()
 
 macro(brpc_example_find_common_deps out_libs)
     execute_process(
-        COMMAND bash -c "find ${PROJECT_SOURCE_DIR}/../.. -type d -regex \".*output/include$\" | head -n1 | xargs dirname | tr -d '\n'"
+        COMMAND bash -c "find ${CMAKE_CURRENT_SOURCE_DIR}/../.. -type d -regex \".*output/include$\" | head -n1 | xargs dirname | tr -d '\n'"

Review Comment:
   A fresh CMake build no longer creates `output/include`, so this lookup returns no build prefix even though `output/lib` contains the just-built bundle. The examples using this helper then cannot locate brpc through `find_path`/`find_library` unless brpc was installed elsewhere. The independent `example/ubring_performance/CMakeLists.txt` repeats the same lookup. Update both paths to use an explicit install prefix or the new build-tree headers and bundle location rather than the removed staging directory.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [PR] Add optional standalone CMake component libraries (brpc)

Posted by "wwbmmm (via GitHub)" <gi...@apache.org>.
wwbmmm commented on code in PR #3596:
URL: https://github.com/apache/brpc/pull/3596#discussion_r4244981551


##########
cmake/brpc-config.cmake.in:
##########
@@ -0,0 +1,239 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+@PACKAGE_INIT@
+set(brpc_FOUND TRUE)
+unset(brpc_NOT_FOUND_MESSAGE)
+
+# Build every library, but consumers need only their selected dependency closure.
+set(_brpc_components ${brpc_FIND_COMPONENTS})
+if(NOT _brpc_components)
+    set(_brpc_components butil bvar bthread json2pb mcpack2pb brpc)
+endif()
+if("brpc" IN_LIST _brpc_components)
+    list(APPEND _brpc_components bthread bvar json2pb mcpack2pb)
+endif()
+if("bthread" IN_LIST _brpc_components)
+    list(APPEND _brpc_components bvar)
+endif()
+list(APPEND _brpc_components butil)
+
+include(CMakeFindDependencyMacro)
+find_dependency(Threads)
+find_dependency(Protobuf)
+if(Protobuf_VERSION VERSION_GREATER 4.21 OR
+   (@WITH_BTHREAD_TRACER@ AND "bthread" IN_LIST _brpc_components))
+    find_dependency(absl CONFIG)
+endif()
+if(@WITH_BORINGSSL@)
+    find_path(_brpc_boringssl_include NAMES openssl/base.h
+        HINTS ${BORINGSSL_ROOT_DIR}/include)
+    find_library(_brpc_boringssl_ssl_library NAMES ssl
+        HINTS ${BORINGSSL_ROOT_DIR}/lib)
+    find_library(_brpc_boringssl_crypto_library NAMES crypto
+        HINTS ${BORINGSSL_ROOT_DIR}/lib)
+    if(NOT _brpc_boringssl_include OR NOT _brpc_boringssl_ssl_library OR
+       NOT _brpc_boringssl_crypto_library)
+        set(brpc_FOUND FALSE)
+        set(brpc_NOT_FOUND_MESSAGE "brpc requires BoringSSL")
+        return()
+    endif()
+    foreach(_brpc_lib SSL CRYPTO)
+        string(TOLOWER ${_brpc_lib} _brpc_lib_lower)
+        if(NOT TARGET brpc::boringssl_${_brpc_lib_lower})
+            add_library(brpc::boringssl_${_brpc_lib_lower} UNKNOWN IMPORTED)
+            set_target_properties(brpc::boringssl_${_brpc_lib_lower} PROPERTIES
+                IMPORTED_LOCATION "${_brpc_boringssl_${_brpc_lib_lower}_library}"
+                INTERFACE_INCLUDE_DIRECTORIES "${_brpc_boringssl_include}")
+        endif()
+    endforeach()
+else()
+    find_dependency(OpenSSL)
+endif()
+
+if(NOT TARGET brpc::gflags)
+    find_package(gflags CONFIG QUIET)
+    if(TARGET gflags::gflags OR TARGET gflags)
+        add_library(brpc::gflags INTERFACE IMPORTED)
+        if(TARGET gflags::gflags)
+            set_property(TARGET brpc::gflags PROPERTY
+                INTERFACE_LINK_LIBRARIES gflags::gflags)
+        else()
+            set_property(TARGET brpc::gflags PROPERTY
+                INTERFACE_LINK_LIBRARIES gflags)
+        endif()
+    else()
+        # Older system packages may provide only headers and libraries.
+        find_path(GFLAGS_INCLUDE_PATH NAMES gflags/gflags.h)
+        find_library(GFLAGS_LIBRARY NAMES gflags libgflags)
+        if(NOT GFLAGS_INCLUDE_PATH OR NOT GFLAGS_LIBRARY)
+            set(brpc_FOUND FALSE)
+            set(brpc_NOT_FOUND_MESSAGE "brpc requires gflags")
+            return()
+        endif()
+        add_library(brpc::gflags UNKNOWN IMPORTED)
+        set_target_properties(brpc::gflags PROPERTIES
+            IMPORTED_LOCATION "${GFLAGS_LIBRARY}"
+            INTERFACE_INCLUDE_DIRECTORIES "${GFLAGS_INCLUDE_PATH}")
+    endif()
+endif()
+
+if("brpc" IN_LIST _brpc_components)
+    find_dependency(ZLIB)
+    find_package(leveldb CONFIG QUIET)
+    if(NOT TARGET brpc::leveldb)
+        if(TARGET leveldb::leveldb)
+            get_target_property(_brpc_leveldb_link_libraries leveldb::leveldb
+                INTERFACE_LINK_LIBRARIES)
+            if("snappy" IN_LIST _brpc_leveldb_link_libraries AND NOT TARGET snappy)
+                find_library(_brpc_leveldb_snappy_library NAMES snappy)
+                if(NOT _brpc_leveldb_snappy_library)
+                    set(brpc_FOUND FALSE)
+                    set(brpc_NOT_FOUND_MESSAGE
+                        "LevelDB requires the Snappy development library")
+                    return()
+                endif()
+                add_library(snappy UNKNOWN IMPORTED)
+                set_property(TARGET snappy PROPERTY IMPORTED_LOCATION
+                    "${_brpc_leveldb_snappy_library}")
+            endif()
+            add_library(brpc::leveldb INTERFACE IMPORTED)
+            set_property(TARGET brpc::leveldb PROPERTY
+                INTERFACE_LINK_LIBRARIES leveldb::leveldb)
+        else()
+            find_library(_brpc_leveldb_library NAMES leveldb)
+            find_path(_brpc_leveldb_include NAMES leveldb/db.h)
+            if(NOT _brpc_leveldb_library OR NOT _brpc_leveldb_include)
+                set(brpc_FOUND FALSE)
+                set(brpc_NOT_FOUND_MESSAGE "brpc requires LevelDB")
+                return()
+            endif()
+            add_library(brpc::leveldb UNKNOWN IMPORTED)
+            set_target_properties(brpc::leveldb PROPERTIES
+                IMPORTED_LOCATION "${_brpc_leveldb_library}"
+                INTERFACE_INCLUDE_DIRECTORIES "${_brpc_leveldb_include}")
+        endif()
+    endif()
+endif()
+
+if("brpc" IN_LIST _brpc_components AND @WITH_URMA@ AND NOT TARGET brpc::urma)
+    find_path(_brpc_urma_include NAMES urma_api.h
+        HINTS ENV URMA_ROOT
+        PATH_SUFFIXES ub/umdk/urma umdk/urma urma
+                      src/urma/lib/urma/core/include)
+    if(NOT _brpc_urma_include)
+        set(brpc_FOUND FALSE)
+        set(brpc_NOT_FOUND_MESSAGE "brpc requires UMDK headers even in URMA mock mode")
+        return()
+    endif()
+    find_path(_brpc_urma_bond_include NAMES urma_ubagg.h
+        HINTS ENV URMA_ROOT
+        PATH_SUFFIXES ub/umdk/urma umdk/urma urma
+                      src/urma/lib/urma/bond/include)
+    if(@BRPC_COMPONENT_URMA_REAL@)
+        find_library(_brpc_urma_library NAMES urma
+            HINTS ENV URMA_ROOT PATH_SUFFIXES lib lib64)
+        if(NOT _brpc_urma_library)
+            set(brpc_FOUND FALSE)
+            set(brpc_NOT_FOUND_MESSAGE "brpc requires liburma")
+            return()
+        endif()
+    endif()
+    add_library(brpc::urma INTERFACE IMPORTED)
+    set_property(TARGET brpc::urma PROPERTY
+        INTERFACE_INCLUDE_DIRECTORIES "${_brpc_urma_include}")
+    if(_brpc_urma_bond_include)
+        set_property(TARGET brpc::urma APPEND PROPERTY
+            INTERFACE_INCLUDE_DIRECTORIES "${_brpc_urma_bond_include}")
+    endif()
+    if(@BRPC_COMPONENT_URMA_REAL@)
+        set_property(TARGET brpc::urma PROPERTY
+            INTERFACE_LINK_LIBRARIES "${_brpc_urma_library}")
+    endif()
+endif()
+
+foreach(_brpc_dep glog mesalink unwind unwind_x86_64 thrift rdma snappy ub)

Review Comment:
   [replied by brpc-oncall robot] `brpc-config.cmake.in` still hand-reimplements discovery for gflags/leveldb/OpenSSL/BoringSSL/glog/thrift/rdma/snappy/urma/unwind with bespoke `find_library`/`find_path` blocks, duplicating the logic that now lives in the per-module CMakeLists (src/butil, src/brpc, src/bthread). Each optional dependency must be kept in sync across the module files, this template and the pkg-config strings, and the URMA mock/real split shows how quickly this grows. Consider deriving the exported dependency list from the component targets, or at least documenting the sync points next to these loops, so a new `WITH_*` feature cannot silently be handled in only some of them.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [PR] Add optional standalone CMake component libraries (brpc)

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #3596:
URL: https://github.com/apache/brpc/pull/3596#discussion_r4238199297


##########
src/brpc/CMakeLists.txt:
##########
@@ -0,0 +1,345 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set(WITH_RDMA_VAL "0")
+if(WITH_RDMA)
+    set(WITH_RDMA_VAL "1")
+endif()
+
+set(WITH_URMA_VAL "0")
+if(WITH_URMA)
+    set(WITH_URMA_VAL "1")
+endif()
+
+string(TOUPPER "${URMA_USE_MOCK}" URMA_USE_MOCK_MODE)
+if(NOT URMA_USE_MOCK_MODE STREQUAL "AUTO" AND
+   NOT URMA_USE_MOCK_MODE STREQUAL "ON" AND
+   NOT URMA_USE_MOCK_MODE STREQUAL "OFF")
+    message(FATAL_ERROR
+        "URMA_USE_MOCK must be AUTO, ON, or OFF, got: ${URMA_USE_MOCK}")
+endif()
+
+set(WITH_UBRING_VAL "0")
+if(WITH_UBRING)
+        set(WITH_UBRING_VAL "1")
+endif()
+
+set(BRPC_DEFINITIONS
+    BRPC_WITH_RDMA=${WITH_RDMA_VAL}
+    BRPC_WITH_URMA=${WITH_URMA_VAL}
+    BRPC_WITH_UBRING=${WITH_UBRING_VAL})
+set(BRPC_INCLUDE_DIRS)
+if(WITH_THRIFT)
+    list(APPEND BRPC_DEFINITIONS ENABLE_THRIFT_FRAMED_PROTOCOL)
+    find_library(THRIFT_LIB NAMES thrift)
+    if (NOT THRIFT_LIB)
+        message(FATAL_ERROR "Fail to find Thrift")
+    endif()
+endif()
+
+if(WITH_THRIFT)
+    find_path(THRIFT_INCLUDE_PATH NAMES thrift/Thrift.h)
+    if(NOT THRIFT_INCLUDE_PATH)
+        message(FATAL_ERROR "Fail to find Thrift headers")
+    endif()
+    list(APPEND BRPC_INCLUDE_DIRS ${THRIFT_INCLUDE_PATH})
+endif()
+find_package(ZLIB REQUIRED)
+list(APPEND BRPC_INCLUDE_DIRS ${ZLIB_INCLUDE_DIRS})
+
+find_path(LEVELDB_INCLUDE_PATH NAMES leveldb/db.h)
+find_library(LEVELDB_LIB NAMES leveldb)
+if ((NOT LEVELDB_INCLUDE_PATH) OR (NOT LEVELDB_LIB))
+    message(FATAL_ERROR "Fail to find leveldb")
+endif()
+
+if(WITH_SNAPPY)
+    find_path(SNAPPY_INCLUDE_PATH NAMES snappy.h)
+    find_library(SNAPPY_LIB NAMES snappy)
+    if ((NOT SNAPPY_INCLUDE_PATH) OR (NOT SNAPPY_LIB))
+        message(FATAL_ERROR "Fail to find snappy")
+    endif()
+    list(APPEND BRPC_INCLUDE_DIRS ${SNAPPY_INCLUDE_PATH})
+endif()
+
+if(WITH_RDMA)
+    message("brpc compile with rdma")
+    find_path(RDMA_INCLUDE_PATH NAMES infiniband/verbs.h)
+    find_library(RDMA_LIB NAMES ibverbs)
+    if((NOT RDMA_INCLUDE_PATH) OR (NOT RDMA_LIB))
+        message(FATAL_ERROR "Fail to find ibverbs")
+    endif()
+    list(APPEND BRPC_INCLUDE_DIRS ${RDMA_INCLUDE_PATH})
+endif()
+
+if(WITH_URMA)
+    # UrmaTransport and its link-time mock both compile against the upstream
+    # UMDK API. Prefer installed headers; otherwise fetch a pinned upstream
+    # commit, following Mooncake's URMA mock setup.
+    find_path(URMA_INCLUDE_PATH NAMES urma_api.h
+              HINTS ENV URMA_ROOT
+              PATHS /usr/include /usr/local/include
+              PATH_SUFFIXES ub/umdk/urma umdk/urma urma
+                            src/urma/lib/urma/core/include)
+    find_path(URMA_BOND_INCLUDE_PATH NAMES urma_ubagg.h
+              HINTS ENV URMA_ROOT
+              PATHS /usr/include /usr/local/include
+              PATH_SUFFIXES ub/umdk/urma umdk/urma urma
+                            src/urma/lib/urma/bond/include)
+    if(NOT URMA_INCLUDE_PATH AND DOWNLOAD_URMA_HEADERS)
+        include(FetchContent)
+        FetchContent_Declare(
+            urma_headers
+            GIT_REPOSITORY https://atomgit.com/openeuler/umdk.git
+            GIT_TAG 564ee727a55523d4351a8fb3c94292b388ebb924
+            # brpc only consumes UMDK headers; avoid cloning unrelated UMDK
+            # submodules such as CAM dependencies during configuration.
+            GIT_SUBMODULES ""
+            GIT_SHALLOW TRUE)
+        FetchContent_GetProperties(urma_headers)
+        if(NOT urma_headers_POPULATED)
+            FetchContent_Populate(urma_headers)
+        endif()
+        set(URMA_INCLUDE_PATH
+            "${urma_headers_SOURCE_DIR}/src/urma/lib/urma/core/include")
+        set(URMA_BOND_INCLUDE_PATH
+            "${urma_headers_SOURCE_DIR}/src/urma/lib/urma/bond/include")
+        message(STATUS "Using downloaded UMDK headers: ${URMA_INCLUDE_PATH}")
+    endif()
+    if(NOT URMA_INCLUDE_PATH)
+        message(FATAL_ERROR
+            "Fail to find urma_api.h. Install UMDK headers, set URMA_ROOT, "
+            "or enable DOWNLOAD_URMA_HEADERS.")
+    endif()
+
+    find_library(URMA_LIB NAMES urma
+                 HINTS ENV URMA_ROOT
+                 PATH_SUFFIXES lib lib64)
+    if(URMA_USE_MOCK_MODE STREQUAL "ON")
+        message(STATUS "URMA_USE_MOCK=ON; forcing the link-time URMA mock")
+        set(URMA_USE_MOCK_ENABLED 1)
+    elseif(URMA_USE_MOCK_MODE STREQUAL "OFF")
+        if(NOT URMA_LIB)
+            message(FATAL_ERROR
+                "URMA_USE_MOCK=OFF requires liburma; install it or use AUTO/ON.")
+        endif()
+        message(STATUS "URMA_USE_MOCK=OFF; using liburma")
+        set(URMA_USE_MOCK_ENABLED 0)
+    elseif(URMA_LIB)
+        message(STATUS "Found URMA library: ${URMA_LIB}")
+        set(URMA_USE_MOCK_ENABLED 0)
+    else()
+        message(STATUS
+            "liburma not found; building with the URMA link-time mock")
+        set(URMA_USE_MOCK_ENABLED 1)
+    endif()
+endif()
+
+if(WITH_URMA)
+    list(APPEND BRPC_INCLUDE_DIRS ${URMA_INCLUDE_PATH})
+    if(URMA_BOND_INCLUDE_PATH)
+        list(APPEND BRPC_INCLUDE_DIRS ${URMA_BOND_INCLUDE_PATH})
+    endif()
+    # The bundle/package need the selected mode and downloaded header paths.
+    set(URMA_USE_MOCK_ENABLED ${URMA_USE_MOCK_ENABLED} PARENT_SCOPE)
+    set(URMA_INCLUDE_PATH ${URMA_INCLUDE_PATH} PARENT_SCOPE)
+    set(URMA_BOND_INCLUDE_PATH ${URMA_BOND_INCLUDE_PATH} PARENT_SCOPE)
+endif()
+list(APPEND BRPC_INCLUDE_DIRS ${LEVELDB_INCLUDE_PATH})
+add_library(brpc_build_config INTERFACE)
+target_link_libraries(brpc_build_config INTERFACE
+    mcpack2pb_build_config bthread_build_config)
+target_include_directories(brpc_build_config BEFORE INTERFACE
+    ${CMAKE_CURRENT_BINARY_DIR})
+target_compile_definitions(brpc_build_config INTERFACE ${BRPC_DEFINITIONS})
+target_include_directories(brpc_build_config INTERFACE ${BRPC_INCLUDE_DIRS})
+
+function(check_thrift_version target_arg)
+    #use thrift command to get version
+    execute_process(
+        COMMAND thrift --version
+        OUTPUT_VARIABLE THRIFT_VERSION_OUTPUT
+        ERROR_QUIET
+        OUTPUT_STRIP_TRAILING_WHITESPACE
+    )
+
+    string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" THRIFT_VERSION ${THRIFT_VERSION_OUTPUT})
+    string(REGEX REPLACE "\\." ";" THRIFT_VERSION_LIST ${THRIFT_VERSION})
+
+    list(GET THRIFT_VERSION_LIST 0 THRIFT_MAJOR_VERSION)
+    list(GET THRIFT_VERSION_LIST 1 THRIFT_MINOR_VERSION)
+
+    if (THRIFT_MAJOR_VERSION EQUAL 0 AND THRIFT_MINOR_VERSION LESS 11)
+        message(STATUS "Thrift version is less than 0.11.0")
+        target_compile_definitions(${target_arg} INTERFACE _THRIFT_VERSION_LOWER_THAN_0_11_0_)
+    else()
+        message(STATUS "Thrift version is equal to or greater than 0.11.0")
+    endif()
+endfunction()
+
+if(WITH_THRIFT)
+    check_thrift_version(brpc_build_config)
+endif()
+
+file(GLOB_RECURSE BRPC_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
+file(GLOB_RECURSE THRIFT_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/thrift*.cpp")
+file(GLOB_RECURSE EXCLUDE_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/event_dispatcher_*.cpp")
+
+# When building with the real liburma, exclude the link-time mock so its urma_*
+# symbols do not clash with the library. When liburma is absent, keep it so CI
+# can build and test UrmaTransport without URMA hardware.
+if(WITH_URMA AND NOT URMA_USE_MOCK_ENABLED)
+    list(REMOVE_ITEM BRPC_SOURCES
+         "${CMAKE_CURRENT_SOURCE_DIR}/urma/mock_urma.cpp")
+endif()
+
+if(WITH_THRIFT)
+    message("brpc compile with thrift protocol")
+else()
+    # Remove thrift sources
+    foreach(v ${THRIFT_SOURCES})
+        list(REMOVE_ITEM BRPC_SOURCES ${v})
+    endforeach()
+    set(THRIFT_SOURCES "")
+endif()
+
+foreach(v ${EXCLUDE_SOURCES})
+    list(REMOVE_ITEM BRPC_SOURCES ${v})
+endforeach()
+
+include(CompileProto)
+set(PROTO_FILES brpc/builtin_service.proto
+                brpc/errno.proto
+                brpc/get_favicon.proto
+                brpc/get_js.proto
+                brpc/grpc_health_check.proto
+                brpc/nshead_meta.proto
+                brpc/options.proto
+                brpc/policy/baidu_rpc_meta.proto
+                brpc/policy/hulu_pbrpc_meta.proto
+                brpc/policy/mongo.proto
+                brpc/policy/public_pbrpc_meta.proto
+                brpc/policy/sofa_pbrpc_meta.proto
+                brpc/proto_base.proto
+                brpc/rdma/rdma_handshake.proto
+                brpc/rpc_dump.proto
+                brpc/rtmp.proto
+                brpc/span.proto
+                brpc/streaming_rpc_meta.proto
+                brpc/trackme.proto
+                brpc/urma/urma_handshake.proto)
+compile_proto(PROTO_HDRS PROTO_SRCS ${CMAKE_CURRENT_BINARY_DIR}
+                                    ${CMAKE_CURRENT_SOURCE_DIR}/..
+                                    "${PROTO_FILES}")
+add_library(PROTO_LIB OBJECT ${PROTO_SRCS} ${PROTO_HDRS})

Review Comment:
   `PROTO_LIB` is inserted directly into `brpc-shared` and the shared `brpc` component, but its object files are not built with PIC. Since PIC on a consuming shared library does not retroactively affect an object library, shared builds can fail on platforms that reject non-PIC relocations. Set `POSITION_INDEPENDENT_CODE` on this object target as is already done for `BRPC_LIB`.
   
   This issue also appears on line 313 of the same file.



##########
src/mcpack2pb/CMakeLists.txt:
##########
@@ -0,0 +1,74 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set(MCPACK2PB_SOURCES
+    ${CMAKE_CURRENT_SOURCE_DIR}/field_type.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/mcpack2pb.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/parser.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/serializer.cpp)
+
+include(CompileProto)
+compile_proto(IDL_OPTIONS_HDRS IDL_OPTIONS_SRCS ${CMAKE_CURRENT_BINARY_DIR}
+    ${CMAKE_CURRENT_SOURCE_DIR}
+    "idl_options.proto")
+add_library(mcpack2pb_build_config INTERFACE)
+target_include_directories(mcpack2pb_build_config BEFORE INTERFACE
+    ${CMAKE_CURRENT_BINARY_DIR})
+target_link_libraries(mcpack2pb_build_config INTERFACE butil_build_config)
+add_library(IDL_OPTIONS_LIB OBJECT ${IDL_OPTIONS_SRCS} ${IDL_OPTIONS_HDRS})

Review Comment:
   When `BUILD_SHARED_LIBS=ON`, these generated protobuf objects are embedded in the shared `mcpack2pb` component (and the shared bundle), but this object library is not compiled as position-independent code. Object-library sources do not inherit PIC from the consuming shared target, so this can fail at link time with relocation errors. Compile `IDL_OPTIONS_LIB` with PIC like the other production object targets.



##########
test/cmake_components/CMakeLists.txt:
##########
@@ -0,0 +1,73 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+cmake_minimum_required(VERSION 3.16)
+project(brpc_component_consumers CXX)
+enable_testing()

Review Comment:
   These consumer checks are currently never run by the repository's automated build: no top-level CMake entry or workflow configures this directory, and the CMake CI matrix does not enable `BRPC_BUILD_COMPONENT_LIBS`. As a result, neither the new libraries nor their installed exports are exercised on a pull request. Add an automated configure/build/install step that then configures and runs this consumer project.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [PR] Add optional standalone CMake component libraries (brpc)

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #3596:
URL: https://github.com/apache/brpc/pull/3596#discussion_r4238310300


##########
.github/workflows/ci-linux.yml:
##########
@@ -115,6 +115,18 @@ jobs:
           "${cmake_options[@]}"
         cmake --build build -j ${{env.proc_num}}
 
+    - name: Check installed component consumers
+      if: matrix.name == 'gcc-default' || matrix.name == 'clang-default'

Review Comment:
   The consumer check only runs for the two default Linux configurations, while the all-options jobs do not enable component libraries at all. Consequently, the newly added package branches for glog, Thrift, RDMA, ubring, bthread tracing/Abseil, and ASAN are never configured, installed, or consumed; the macOS-specific component linkage/RPATH path is also untested. Please add component-consumer coverage for representative optional-feature and macOS builds, since these exported dependency closures are part of the new public behavior.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [PR] Add optional standalone CMake component libraries (brpc)

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #3596:
URL: https://github.com/apache/brpc/pull/3596#discussion_r4240332600


##########
src/butil/CMakeLists.txt:
##########
@@ -0,0 +1,338 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set(WITH_GLOG_VAL "0")
+if(WITH_GLOG)
+    set(WITH_GLOG_VAL "1")
+    set(BRPC_WITH_GLOG 1)
+endif()
+
+set(WITH_CPU_FREQUENCY_VAL "0")
+if(WITH_CPU_FREQUENCY)
+    set(WITH_CPU_FREQUENCY_VAL "1")
+    set(BUTIL_USE_CPU_FREQUENCY 1)
+endif()
+
+set(BUTIL_DEFINITIONS
+    BRPC_WITH_GLOG=${WITH_GLOG_VAL}
+    BUTIL_USE_CPU_FREQUENCY=${WITH_CPU_FREQUENCY_VAL})
+if(WITH_MESALINK)
+    list(APPEND BUTIL_DEFINITIONS USE_MESALINK)
+endif()
+if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+    include(CheckFunctionExists)
+    CHECK_FUNCTION_EXISTS(clock_gettime HAVE_CLOCK_GETTIME)
+    if(NOT HAVE_CLOCK_GETTIME)
+        list(APPEND BUTIL_DEFINITIONS NO_CLOCK_GETTIME_IN_MAC)
+    endif()
+endif()
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
+    ${CMAKE_CURRENT_SOURCE_DIR}/config.h @ONLY)

Review Comment:
   Generate `butil/config.h` in the build tree rather than the source tree. This file records `WITH_GLOG` and `WITH_CPU_FREQUENCY`, so two build directories configured with different options overwrite the same header; whichever configures last can make the other build compile or install a header that disagrees with its object files. The generated path also needs to be added ahead of the source include root and installed explicitly.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [PR] Add optional standalone CMake component libraries (brpc)

Posted by "wasphin (via GitHub)" <gi...@apache.org>.
wasphin commented on code in PR #3596:
URL: https://github.com/apache/brpc/pull/3596#discussion_r4242178681


##########
src/butil/CMakeLists.txt:
##########
@@ -0,0 +1,351 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set(WITH_GLOG_VAL "0")
+if(WITH_GLOG)
+    set(WITH_GLOG_VAL "1")
+    set(BRPC_WITH_GLOG 1)
+endif()
+
+set(WITH_CPU_FREQUENCY_VAL "0")
+if(WITH_CPU_FREQUENCY)
+    set(WITH_CPU_FREQUENCY_VAL "1")
+    set(BUTIL_USE_CPU_FREQUENCY 1)
+endif()
+
+set(BUTIL_DEFINITIONS
+    BRPC_WITH_GLOG=${WITH_GLOG_VAL}
+    BUTIL_USE_CPU_FREQUENCY=${WITH_CPU_FREQUENCY_VAL})
+if(WITH_MESALINK)
+    list(APPEND BUTIL_DEFINITIONS USE_MESALINK)
+endif()
+if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+    include(CheckFunctionExists)
+    CHECK_FUNCTION_EXISTS(clock_gettime HAVE_CLOCK_GETTIME)
+    if(NOT HAVE_CLOCK_GETTIME)
+        list(APPEND BUTIL_DEFINITIONS NO_CLOCK_GETTIME_IN_MAC)
+    endif()
+endif()
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
+    ${CMAKE_CURRENT_SOURCE_DIR}/config.h @ONLY)
+
+set(BUTIL_INCLUDE_DIRS ${GFLAGS_INCLUDE_PATH} ${PROTOBUF_INCLUDE_DIRS})
+if(WITH_GLOG)
+    find_path(GLOG_INCLUDE_PATH NAMES glog/logging.h)
+    find_library(GLOG_LIB NAMES glog)
+    if((NOT GLOG_INCLUDE_PATH) OR (NOT GLOG_LIB))
+        message(FATAL_ERROR "Fail to find glog")
+    endif()
+    list(APPEND BUTIL_INCLUDE_DIRS ${GLOG_INCLUDE_PATH})
+endif()
+
+if(WITH_MESALINK)
+    find_path(MESALINK_INCLUDE_PATH NAMES mesalink/openssl/ssl.h)
+    find_library(MESALINK_LIB NAMES mesalink)
+    if((NOT MESALINK_INCLUDE_PATH) OR (NOT MESALINK_LIB))
+        message(FATAL_ERROR "Fail to find MesaLink")
+    else()
+        message(STATUS "Found MesaLink: ${MESALINK_LIB}")
+    endif()
+    list(APPEND BUTIL_INCLUDE_DIRS ${MESALINK_INCLUDE_PATH})
+endif()
+
+if(WITH_BORINGSSL)
+    find_package(BoringSSL REQUIRED)
+    list(APPEND BUTIL_INCLUDE_DIRS ${BORINGSSL_INCLUDE_DIR})
+else()
+    if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT OPENSSL_ROOT_DIR)
+        set(OPENSSL_ROOT_DIR
+            "/usr/local/opt/openssl" # Homebrew installed OpenSSL
+        )
+    endif()
+
+    find_package(OpenSSL REQUIRED)
+    list(APPEND BUTIL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR})
+endif()
+
+add_library(butil_build_config INTERFACE)
+target_link_libraries(butil_build_config INTERFACE brpc_common_config)
+target_compile_definitions(butil_build_config INTERFACE ${BUTIL_DEFINITIONS})
+target_include_directories(butil_build_config INTERFACE ${BUTIL_INCLUDE_DIRS})
+
+set(butil_crc32c_options)
+if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+    if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
+        # Only CRC32C needs the SSE4.2 intrinsics and feature macro.
+        list(APPEND butil_crc32c_options -msse4.2)
+    elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "riscv64")
+        option(WITH_RISCV_ZBC "Enable RISC-V Zbc carry-less multiplication for CRC32C acceleration" OFF)
+        option(WITH_RISCV_ZVBC "Enable RISC-V Zvbc vector carry-less multiplication for CRC32C acceleration" OFF)
+        if(WITH_RISCV_ZVBC)
+            list(APPEND butil_crc32c_options -march=rv64gcv_zbc_zvbc)
+            # Preserve the existing RVV base64 implementation as well.
+            set_property(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/third_party/modp_b64/modp_b64_rvv.cc
+                APPEND PROPERTY COMPILE_OPTIONS -march=rv64gcv_zbc_zvbc)

Review Comment:
   The fix restores the previous target-wide ISA setting for GNU RISC-V builds. With WITH_RISCV_ZVBC=ON, brpc_common_config supplies -march=rv64gcv_zbc_zvbc to the internal module build configurations, covering the CRC32C and base64 implementations as well as modp_b64.cc, iobuf.cpp, string_piece.cc, and string_compare_rvv.cc. This setting is not conditional on the build type.
   
   I checked the generated compile commands for the Zvbc, Zbc-only, and baseline configurations, including the test debug-object targets. This was configure-only validation, not a RISC-V compile or runtime test. I am leaving this thread open pending a real GNU RISC-V build with WITH_RISCV_ZVBC=ON, including Debug/test objects, followed by the affected tests.



##########
test/CMakeLists.txt:
##########
@@ -202,9 +205,29 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
     )
 endif()
 
+# Read module-owned sources from their targets, not parent-scope variables.
+get_target_property(BUTIL_SOURCES BUTIL_LIB SOURCES)
+# Source properties are directory-scoped; reuse production CRC32C settings.
+get_target_property(butil_crc32c_options BUTIL_LIB BRPC_CRC32C_COMPILE_OPTIONS)
+if(butil_crc32c_options)
+    set_property(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/../src/butil/crc32c.cc
+        APPEND PROPERTY COMPILE_OPTIONS ${butil_crc32c_options})
+endif()
+if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND
+   CMAKE_SYSTEM_PROCESSOR MATCHES "riscv64" AND WITH_RISCV_ZVBC)
+    set_property(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/../src/butil/third_party/modp_b64/modp_b64_rvv.cc
+        APPEND PROPERTY COMPILE_OPTIONS -march=rv64gcv_zbc_zvbc)

Review Comment:
   The test debug-object targets now inherit the same ISA options as production through brpc_test_config -> brpc_build_config -> the module configurations -> brpc_common_config. The partial per-source RISC-V assignments have been removed, so BUTIL_DEBUG_LIB gets the architecture setting for the complete source list, including the RVV callers and implementations.
   
   Generated compile-command checks confirmed the option reaches these debug objects. However, I have not performed a real RISC-V build, and those checks were not a completed Debug build. I am leaving this thread open; the remaining validation is an actual GNU RISC-V Debug build with WITH_RISCV_ZVBC=ON and the affected tests.



##########
src/brpc/CMakeLists.txt:
##########
@@ -0,0 +1,358 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set(WITH_RDMA_VAL "0")
+if(WITH_RDMA)
+    set(WITH_RDMA_VAL "1")
+endif()
+
+set(WITH_URMA_VAL "0")
+if(WITH_URMA)
+    set(WITH_URMA_VAL "1")
+endif()
+
+string(TOUPPER "${URMA_USE_MOCK}" URMA_USE_MOCK_MODE)
+if(NOT URMA_USE_MOCK_MODE STREQUAL "AUTO" AND
+   NOT URMA_USE_MOCK_MODE STREQUAL "ON" AND
+   NOT URMA_USE_MOCK_MODE STREQUAL "OFF")
+    message(FATAL_ERROR
+        "URMA_USE_MOCK must be AUTO, ON, or OFF, got: ${URMA_USE_MOCK}")
+endif()
+
+set(WITH_UBRING_VAL "0")
+if(WITH_UBRING)
+        set(WITH_UBRING_VAL "1")
+endif()
+
+set(BRPC_DEFINITIONS
+    BRPC_WITH_RDMA=${WITH_RDMA_VAL}
+    BRPC_WITH_URMA=${WITH_URMA_VAL}
+    BRPC_WITH_UBRING=${WITH_UBRING_VAL})
+set(BRPC_INCLUDE_DIRS)
+if(WITH_THRIFT)
+    list(APPEND BRPC_DEFINITIONS ENABLE_THRIFT_FRAMED_PROTOCOL)
+    find_library(THRIFT_LIB NAMES thrift)
+    if (NOT THRIFT_LIB)
+        message(FATAL_ERROR "Fail to find Thrift")
+    endif()
+endif()
+
+if(WITH_THRIFT)
+    find_path(THRIFT_INCLUDE_PATH NAMES thrift/Thrift.h)
+    if(NOT THRIFT_INCLUDE_PATH)
+        message(FATAL_ERROR "Fail to find Thrift headers")
+    endif()
+    list(APPEND BRPC_INCLUDE_DIRS ${THRIFT_INCLUDE_PATH})
+endif()
+find_package(ZLIB REQUIRED)
+list(APPEND BRPC_INCLUDE_DIRS ${ZLIB_INCLUDE_DIRS})
+
+find_path(LEVELDB_INCLUDE_PATH NAMES leveldb/db.h)
+find_library(LEVELDB_LIB NAMES leveldb)
+if ((NOT LEVELDB_INCLUDE_PATH) OR (NOT LEVELDB_LIB))
+    message(FATAL_ERROR "Fail to find leveldb")
+endif()
+
+if(WITH_SNAPPY)
+    find_path(SNAPPY_INCLUDE_PATH NAMES snappy.h)
+    find_library(SNAPPY_LIB NAMES snappy)
+    if ((NOT SNAPPY_INCLUDE_PATH) OR (NOT SNAPPY_LIB))
+        message(FATAL_ERROR "Fail to find snappy")
+    endif()
+    list(APPEND BRPC_INCLUDE_DIRS ${SNAPPY_INCLUDE_PATH})
+endif()
+
+if(WITH_RDMA)
+    message("brpc compile with rdma")
+    find_path(RDMA_INCLUDE_PATH NAMES infiniband/verbs.h)
+    find_library(RDMA_LIB NAMES ibverbs)
+    if((NOT RDMA_INCLUDE_PATH) OR (NOT RDMA_LIB))
+        message(FATAL_ERROR "Fail to find ibverbs")
+    endif()
+    list(APPEND BRPC_INCLUDE_DIRS ${RDMA_INCLUDE_PATH})
+endif()
+
+if(WITH_URMA)
+    # UrmaTransport and its link-time mock both compile against the upstream
+    # UMDK API. Prefer installed headers; otherwise fetch a pinned upstream
+    # commit, following Mooncake's URMA mock setup.
+    find_path(URMA_INCLUDE_PATH NAMES urma_api.h
+              HINTS ENV URMA_ROOT
+              PATHS /usr/include /usr/local/include
+              PATH_SUFFIXES ub/umdk/urma umdk/urma urma
+                            src/urma/lib/urma/core/include)
+    find_path(URMA_BOND_INCLUDE_PATH NAMES urma_ubagg.h
+              HINTS ENV URMA_ROOT
+              PATHS /usr/include /usr/local/include
+              PATH_SUFFIXES ub/umdk/urma umdk/urma urma
+                            src/urma/lib/urma/bond/include)
+    if(NOT URMA_INCLUDE_PATH AND DOWNLOAD_URMA_HEADERS)
+        include(FetchContent)
+        FetchContent_Declare(
+            urma_headers
+            GIT_REPOSITORY https://atomgit.com/openeuler/umdk.git
+            GIT_TAG 564ee727a55523d4351a8fb3c94292b388ebb924
+            # brpc only consumes UMDK headers; avoid cloning unrelated UMDK
+            # submodules such as CAM dependencies during configuration.
+            GIT_SUBMODULES ""
+            GIT_SHALLOW TRUE)
+        FetchContent_GetProperties(urma_headers)
+        if(NOT urma_headers_POPULATED)
+            FetchContent_Populate(urma_headers)
+        endif()
+        set(URMA_INCLUDE_PATH
+            "${urma_headers_SOURCE_DIR}/src/urma/lib/urma/core/include")
+        set(URMA_BOND_INCLUDE_PATH
+            "${urma_headers_SOURCE_DIR}/src/urma/lib/urma/bond/include")
+        message(STATUS "Using downloaded UMDK headers: ${URMA_INCLUDE_PATH}")
+    endif()
+    if(NOT URMA_INCLUDE_PATH)
+        message(FATAL_ERROR
+            "Fail to find urma_api.h. Install UMDK headers, set URMA_ROOT, "
+            "or enable DOWNLOAD_URMA_HEADERS.")
+    endif()
+
+    find_library(URMA_LIB NAMES urma
+                 HINTS ENV URMA_ROOT
+                 PATH_SUFFIXES lib lib64)
+    if(URMA_USE_MOCK_MODE STREQUAL "ON")
+        message(STATUS "URMA_USE_MOCK=ON; forcing the link-time URMA mock")
+        set(URMA_USE_MOCK_ENABLED 1)
+    elseif(URMA_USE_MOCK_MODE STREQUAL "OFF")
+        if(NOT URMA_LIB)
+            message(FATAL_ERROR
+                "URMA_USE_MOCK=OFF requires liburma; install it or use AUTO/ON.")
+        endif()
+        message(STATUS "URMA_USE_MOCK=OFF; using liburma")
+        set(URMA_USE_MOCK_ENABLED 0)
+    elseif(URMA_LIB)
+        message(STATUS "Found URMA library: ${URMA_LIB}")
+        set(URMA_USE_MOCK_ENABLED 0)
+    else()
+        message(STATUS
+            "liburma not found; building with the URMA link-time mock")
+        set(URMA_USE_MOCK_ENABLED 1)
+    endif()
+endif()
+
+if(WITH_URMA)
+    list(APPEND BRPC_INCLUDE_DIRS ${URMA_INCLUDE_PATH})
+    if(URMA_BOND_INCLUDE_PATH)
+        list(APPEND BRPC_INCLUDE_DIRS ${URMA_BOND_INCLUDE_PATH})
+    endif()
+    # The bundle/package need the selected mode and downloaded header paths.
+    set(URMA_USE_MOCK_ENABLED ${URMA_USE_MOCK_ENABLED} PARENT_SCOPE)
+    set(URMA_INCLUDE_PATH ${URMA_INCLUDE_PATH} PARENT_SCOPE)
+    set(URMA_BOND_INCLUDE_PATH ${URMA_BOND_INCLUDE_PATH} PARENT_SCOPE)
+endif()
+list(APPEND BRPC_INCLUDE_DIRS ${LEVELDB_INCLUDE_PATH})
+add_library(brpc_build_config INTERFACE)
+target_link_libraries(brpc_build_config INTERFACE
+    mcpack2pb_build_config bthread_build_config)
+target_include_directories(brpc_build_config BEFORE INTERFACE
+    ${CMAKE_CURRENT_BINARY_DIR})
+target_compile_definitions(brpc_build_config INTERFACE ${BRPC_DEFINITIONS})
+target_include_directories(brpc_build_config INTERFACE ${BRPC_INCLUDE_DIRS})
+
+function(check_thrift_version target_arg)
+    #use thrift command to get version
+    execute_process(
+        COMMAND thrift --version
+        OUTPUT_VARIABLE THRIFT_VERSION_OUTPUT
+        ERROR_QUIET
+        OUTPUT_STRIP_TRAILING_WHITESPACE
+    )
+
+    string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" THRIFT_VERSION ${THRIFT_VERSION_OUTPUT})
+    string(REGEX REPLACE "\\." ";" THRIFT_VERSION_LIST ${THRIFT_VERSION})
+
+    list(GET THRIFT_VERSION_LIST 0 THRIFT_MAJOR_VERSION)
+    list(GET THRIFT_VERSION_LIST 1 THRIFT_MINOR_VERSION)
+
+    if (THRIFT_MAJOR_VERSION EQUAL 0 AND THRIFT_MINOR_VERSION LESS 11)
+        message(STATUS "Thrift version is less than 0.11.0")
+        target_compile_definitions(${target_arg} INTERFACE _THRIFT_VERSION_LOWER_THAN_0_11_0_)
+    else()
+        message(STATUS "Thrift version is equal to or greater than 0.11.0")
+    endif()
+endfunction()
+
+if(WITH_THRIFT)
+    check_thrift_version(brpc_build_config)
+endif()
+
+file(GLOB_RECURSE BRPC_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
+file(GLOB_RECURSE THRIFT_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/thrift*.cpp")
+file(GLOB_RECURSE EXCLUDE_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/event_dispatcher_*.cpp")
+
+# When building with the real liburma, exclude the link-time mock so its urma_*
+# symbols do not clash with the library. When liburma is absent, keep it so CI
+# can build and test UrmaTransport without URMA hardware.
+if(WITH_URMA AND NOT URMA_USE_MOCK_ENABLED)
+    list(REMOVE_ITEM BRPC_SOURCES
+         "${CMAKE_CURRENT_SOURCE_DIR}/urma/mock_urma.cpp")
+endif()
+
+if(WITH_THRIFT)
+    message("brpc compile with thrift protocol")
+else()
+    # Remove thrift sources
+    foreach(v ${THRIFT_SOURCES})
+        list(REMOVE_ITEM BRPC_SOURCES ${v})
+    endforeach()
+    set(THRIFT_SOURCES "")
+endif()
+
+foreach(v ${EXCLUDE_SOURCES})
+    list(REMOVE_ITEM BRPC_SOURCES ${v})
+endforeach()
+
+include(CompileProto)
+set(PROTO_FILES brpc/builtin_service.proto
+                brpc/errno.proto
+                brpc/get_favicon.proto
+                brpc/get_js.proto
+                brpc/grpc_health_check.proto
+                brpc/nshead_meta.proto
+                brpc/options.proto
+                brpc/policy/baidu_rpc_meta.proto
+                brpc/policy/hulu_pbrpc_meta.proto
+                brpc/policy/mongo.proto
+                brpc/policy/public_pbrpc_meta.proto
+                brpc/policy/sofa_pbrpc_meta.proto
+                brpc/proto_base.proto
+                brpc/rdma/rdma_handshake.proto
+                brpc/rpc_dump.proto
+                brpc/rtmp.proto
+                brpc/span.proto
+                brpc/streaming_rpc_meta.proto
+                brpc/trackme.proto
+                brpc/urma/urma_handshake.proto)
+compile_proto(PROTO_HDRS PROTO_SRCS ${CMAKE_CURRENT_BINARY_DIR}
+                                    ${CMAKE_CURRENT_SOURCE_DIR}/..
+                                    "${PROTO_FILES}")
+add_library(PROTO_LIB OBJECT ${PROTO_SRCS} ${PROTO_HDRS})
+set_property(TARGET PROTO_LIB PROPERTY POSITION_INDEPENDENT_CODE 1)
+target_link_libraries(PROTO_LIB PRIVATE brpc_build_config)
+
+set(brpc_libraries ${LEVELDB_LIB} ZLIB::ZLIB)
+set(brpc_private_libs "-lleveldb -lz")
+if(WITH_THRIFT)
+    list(APPEND brpc_libraries ${THRIFT_LIB})
+endif()
+if(WITH_SNAPPY)
+    list(APPEND brpc_libraries ${SNAPPY_LIB})
+    string(APPEND brpc_private_libs " -lsnappy")
+endif()
+if(WITH_RDMA)
+    list(APPEND brpc_libraries ${RDMA_LIB})
+endif()
+if(WITH_URMA)
+    message(STATUS "brpc compile with URMA (mock=${URMA_USE_MOCK_ENABLED})")
+    if(NOT URMA_USE_MOCK_ENABLED)
+        list(APPEND brpc_libraries ${URMA_LIB})
+    endif()
+endif()
+if(WITH_UBRING)
+    message(STATUS "brpc compile with ubring")
+    list(APPEND brpc_libraries ${UB_LIB})
+endif()
+
+add_library(brpc_runtime_dependencies INTERFACE)
+target_link_libraries(brpc_runtime_dependencies INTERFACE ${brpc_libraries})
+
+add_library(BRPC_LIB OBJECT ${BRPC_SOURCES})
+target_link_libraries(BRPC_LIB PRIVATE brpc_build_config)
+set_property(TARGET BRPC_LIB PROPERTY POSITION_INDEPENDENT_CODE 1)
+set_property(TARGET BRPC_LIB PROPERTY BRPC_BUNDLE_LIBRARIES brpc_runtime_dependencies)
+set_property(TARGET BRPC_LIB PROPERTY BRPC_PRIVATE_LIBS "${brpc_private_libs}")
+add_dependencies(BRPC_LIB PROTO_LIB IDL_OPTIONS_LIB)
+
+if(BRPC_BUILD_COMPONENT_LIBS)
+    # Prefer the dependency's package metadata, including static-link dependencies
+    # and per-configuration locations. Retain support for system installations
+    # that do not provide a CMake package.
+    find_package(leveldb CONFIG QUIET)
+    if(TARGET leveldb::leveldb)
+        # Some LevelDB packages export a bare snappy library name rather than
+        # a target. Resolve it so non-system library prefixes also work.
+        get_target_property(leveldb_link_libraries leveldb::leveldb
+            INTERFACE_LINK_LIBRARIES)
+        if("snappy" IN_LIST leveldb_link_libraries AND NOT TARGET snappy)
+            find_library(LEVELDB_SNAPPY_LIB NAMES snappy)
+            if(NOT LEVELDB_SNAPPY_LIB)
+                message(FATAL_ERROR "LevelDB requires the Snappy development library")
+            endif()
+            add_library(snappy UNKNOWN IMPORTED)
+            set_property(TARGET snappy PROPERTY IMPORTED_LOCATION "${LEVELDB_SNAPPY_LIB}")
+        endif()
+        add_library(brpc::leveldb INTERFACE IMPORTED)
+        set_property(TARGET brpc::leveldb PROPERTY
+            INTERFACE_LINK_LIBRARIES leveldb::leveldb)
+    else()
+        add_library(brpc::leveldb UNKNOWN IMPORTED)
+        set_target_properties(brpc::leveldb PROPERTIES
+            IMPORTED_LOCATION "${LEVELDB_LIB}"
+            INTERFACE_INCLUDE_DIRECTORIES "${LEVELDB_INCLUDE_PATH}")
+    endif()
+
+    set(BRPC_COMPONENT_URMA_REAL OFF)
+    if(WITH_URMA AND NOT URMA_USE_MOCK_ENABLED)
+        set(BRPC_COMPONENT_URMA_REAL ON)
+    endif()
+    set(BRPC_COMPONENT_UB_NAME "")
+    if(WITH_UBRING AND UB_LIB)
+        get_filename_component(BRPC_COMPONENT_UB_NAME "${UB_LIB}" NAME_WE)
+        string(REGEX REPLACE "^lib|\\..*$" "" BRPC_COMPONENT_UB_NAME "${BRPC_COMPONENT_UB_NAME}")
+    endif()
+    foreach(dep THRIFT RDMA SNAPPY URMA UB)
+        if((dep STREQUAL "THRIFT" AND WITH_THRIFT) OR
+           (dep STREQUAL "RDMA" AND WITH_RDMA) OR
+           (dep STREQUAL "SNAPPY" AND WITH_SNAPPY) OR
+           (dep STREQUAL "URMA" AND BRPC_COMPONENT_URMA_REAL) OR

Review Comment:
   Fixed in the component-packaging commit. Whenever WITH_URMA=ON, brpc::urma is now an exported dependency supplying the UMDK core headers and optional bonding headers. Mock mode does not require or link liburma; real mode additionally requires the library. Both build-tree and installed package configuration reconstruct this dependency, and missing UMDK headers produce an explicit diagnostic. URMA_ROOT can be used for dependency discovery without manually adding include directories to consumers.
   
   The brpc consumer now includes brpc/urma/urma_endpoint.h. The existing Linux GCC static and Clang shared all-options jobs enable the URMA mock with pinned UMDK headers. Both full builds passed, and both build-tree and installed consumer suites passed 6/6 for each compiler. Clang also exposed the mock's C++17 requirement; that is now set on the internal brpc build configuration only when the mock is selected. CI: https://github.com/apache/brpc/actions/runs/38151687754



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [PR] Add optional standalone CMake component libraries (brpc)

Posted by "wasphin (via GitHub)" <gi...@apache.org>.
wasphin commented on code in PR #3596:
URL: https://github.com/apache/brpc/pull/3596#discussion_r4242179301


##########
example/cmake/BrpcExample.cmake:
##########
@@ -29,7 +29,7 @@ endfunction()
 
 macro(brpc_example_find_common_deps out_libs)
     execute_process(
-        COMMAND bash -c "find ${PROJECT_SOURCE_DIR}/../.. -type d -regex \".*output/include$\" | head -n1 | xargs dirname | tr -d '\n'"
+        COMMAND bash -c "find ${CMAKE_CURRENT_SOURCE_DIR}/../.. -type d -regex \".*output/include$\" | head -n1 | xargs dirname | tr -d '\n'"

Review Comment:
   Fixed both the shared example helper and the independent ubring_performance configuration. They no longer search for output/include or overwrite the caller's CMAKE_PREFIX_PATH. Instead, the examples use an explicit installed prefix; the English and Chinese getting-started instructions now show installation followed by configuring the example with that prefix.
   
   The existing gcc-default CMake job installs the bundle into a fresh prefix, builds the echo client/server executables against it, and configures ubring_performance using that prefix. This check passed. The ubring check is configuration-only, not a build or runtime test, because this job retains the default WITH_UBRING=OFF configuration. No additional CI jobs were introduced. CI: https://github.com/apache/brpc/actions/runs/38151687754



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org