-
Notifications
You must be signed in to change notification settings - Fork 19
feat: support bazel build for cpp bindings #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@luoyuxia Hi, yuxia. I added bazel build ability for cpp binding. PTAL if u have time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request adds Bazel build system support for the C++ bindings, providing an alternative to the existing CMake build system. The implementation enables users to build the fluss_cpp library and example binary using Bazel.
Key changes:
- Added Bazel build configuration files (MODULE.bazel, BUILD.bazel, .bazelrc) for building C++ bindings
- Introduced a ci.sh script to simplify common Bazel build operations
- Updated .gitignore to exclude Bazel-generated files
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| bindings/cpp/ci.sh | Build automation script providing commands to compile, build examples, run examples, show outputs, and clean Bazel artifacts |
| bindings/cpp/MODULE.bazel | Bazel module definition declaring dependencies on rules_cc and platforms |
| bindings/cpp/BUILD.bazel | Core Bazel build rules defining genrule for cargo compilation, cc_library for the fluss_cpp library, and cc_binary for the example executable |
| bindings/cpp/.bazelrc | Bazel configuration file enabling BzlMod and defining debug build settings |
| bindings/cpp/.gitignore | Updated to ignore Bazel build outputs and generated files |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,7 @@ | |||
| module( | |||
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing Apache License header. All source files in Apache projects should include the standard Apache License header. Add the header at the beginning of the file using '#' comment syntax, similar to CMakeLists.txt or Cargo.toml.
| @@ -0,0 +1,142 @@ | |||
| licenses(["notice"]) | |||
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing Apache License header. All source files in Apache projects should include the standard Apache License header. Add the header at the beginning of the file using '#' comment syntax, similar to CMakeLists.txt or Cargo.toml.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
| @@ -0,0 +1,85 @@ | |||
| #!/bin/bash | |||
|
|
|||
| set -xe | |||
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace after 'set -xe'. This should be 'set -xe' without the trailing space for consistency.
| exit 1 | ||
| ;; | ||
| esac | ||
|
|
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blank line at the end of the file. While this is generally a minor style issue, it's inconsistent with typical bash script conventions. Consider removing this trailing blank line for consistency.
| RUST_BRIDGE_DIR=$$CARGO_TARGET_DIR/cxxbridge/fluss-cpp/src | ||
| RUST_LIB=$$CARGO_TARGET_DIR/debug/libfluss_cpp.a |
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hardcoded library name 'libfluss_cpp.a' doesn't match the expected output based on the Cargo package name 'fluss-cpp' (with hyphen). Cargo converts hyphens to underscores in library names, so this is correct. However, the cxxbridge path uses 'fluss-cpp' with a hyphen. This inconsistency between line 39 (using 'fluss-cpp') and line 40 (using 'fluss_cpp') is potentially confusing and error-prone. Verify that these paths are correct given Cargo's naming conventions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check this suggestion.
| genrule( | ||
| name = "cargo_build_debug", | ||
| srcs = glob([ | ||
| "src/**/*.rs", | ||
| "Cargo.toml", | ||
| ]), | ||
| outs = [ | ||
| "rust_lib_debug.a", | ||
| "rust_bridge_cc.cc", | ||
| "rust_bridge_h.h", | ||
| "src/lib.rs.h", | ||
| "cxxbridge/rust/cxx.h", | ||
| ], | ||
| cmd = """ | ||
| set -e | ||
| EXECROOT=$$(pwd) | ||
| OUTPUT_LIB=$(location rust_lib_debug.a) | ||
| OUTPUT_CC=$(location rust_bridge_cc.cc) | ||
| OUTPUT_H=$(location rust_bridge_h.h) | ||
| OUTPUT_SRC_H=$(location src/lib.rs.h) | ||
| OUTPUT_CXX_H=$(location cxxbridge/rust/cxx.h) | ||
| # Resolve real source path from sandbox symlink | ||
| SANDBOX_CARGO=$(location Cargo.toml) | ||
| REAL_CARGO=$$(readlink -f $$SANDBOX_CARGO 2>/dev/null || python3 -c "import os; print(os.path.realpath('$$SANDBOX_CARGO'))") | ||
| CARGO_DIR=$$(dirname $$REAL_CARGO) | ||
| # Find Cargo workspace root (fluss-rust directory, 2 levels up from bindings/cpp) | ||
| WORKSPACE_ROOT=$$(cd $$CARGO_DIR/../.. && pwd) | ||
| if [ ! -f $$WORKSPACE_ROOT/Cargo.toml ]; then | ||
| echo "Error: Cannot find workspace root Cargo.toml at $$WORKSPACE_ROOT" >&2 | ||
| exit 1 | ||
| fi | ||
| cd $$WORKSPACE_ROOT | ||
| cargo build --manifest-path $$CARGO_DIR/Cargo.toml | ||
| CARGO_TARGET_DIR=$$WORKSPACE_ROOT/target | ||
| RUST_BRIDGE_DIR=$$CARGO_TARGET_DIR/cxxbridge/fluss-cpp/src | ||
| RUST_LIB=$$CARGO_TARGET_DIR/debug/libfluss_cpp.a | ||
| if [ ! -f $$RUST_LIB ]; then | ||
| echo "Error: Rust library not found at $$RUST_LIB" >&2 | ||
| exit 1 | ||
| fi | ||
| if [ ! -f $$RUST_BRIDGE_DIR/lib.rs.cc ]; then | ||
| echo "Error: cxxbridge CC file not found at $$RUST_BRIDGE_DIR/lib.rs.cc" >&2 | ||
| exit 1 | ||
| fi | ||
| if [ ! -f $$RUST_BRIDGE_DIR/lib.rs.h ]; then | ||
| echo "Error: cxxbridge header file not found at $$RUST_BRIDGE_DIR/lib.rs.h" >&2 | ||
| exit 1 | ||
| fi | ||
| cd $$EXECROOT | ||
| mkdir -p $$(dirname $$OUTPUT_SRC_H) $$(dirname $$OUTPUT_CXX_H) | ||
| cp $$RUST_LIB $$OUTPUT_LIB || (echo "Failed to copy $$RUST_LIB to $$OUTPUT_LIB" >&2; exit 1) | ||
| cp $$RUST_BRIDGE_DIR/lib.rs.cc $$OUTPUT_CC || (echo "Failed to copy $$RUST_BRIDGE_DIR/lib.rs.cc to $$OUTPUT_CC" >&2; exit 1) | ||
| cp $$RUST_BRIDGE_DIR/lib.rs.h $$OUTPUT_H || (echo "Failed to copy $$RUST_BRIDGE_DIR/lib.rs.h to $$OUTPUT_H" >&2; exit 1) | ||
| cp $$RUST_BRIDGE_DIR/lib.rs.h $$OUTPUT_SRC_H || (echo "Failed to copy $$RUST_BRIDGE_DIR/lib.rs.h to $$OUTPUT_SRC_H" >&2; exit 1) | ||
| CXX_H_SOURCE=$$CARGO_TARGET_DIR/cxxbridge/rust/cxx.h | ||
| if [ ! -f $$CXX_H_SOURCE ] && [ ! -L $$CXX_H_SOURCE ]; then | ||
| echo "Error: cxx.h not found at $$CXX_H_SOURCE" >&2 | ||
| exit 1 | ||
| fi | ||
| cp -L $$CXX_H_SOURCE $$OUTPUT_CXX_H || (echo "Failed to copy $$CXX_H_SOURCE to $$OUTPUT_CXX_H" >&2; exit 1) | ||
| """, | ||
| message = "Building Rust library with cargo...", | ||
| local = 1, | ||
| ) |
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The genrule name 'cargo_build_debug' suggests this only builds debug variants, but there's no corresponding rule for release builds. This means users can only build debug binaries with Bazel, which limits flexibility compared to the CMake build that supports both debug and release configurations. Consider adding a configuration or additional genrule to support release builds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the suggestion looks reasonable to me.
| copts = [ | ||
| "-std=c++17", | ||
| "-g3", | ||
| "-O0", | ||
| "-ggdb", | ||
| "-fno-omit-frame-pointer", | ||
| "-DDEBUG", | ||
| ], |
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the cc_library rule, debug compilation flags are hardcoded in the cc_binary rule. This prevents building optimized example binaries. Consider making these flags configurable to match the library's build configuration.
| ], | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
|
|
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two trailing blank lines at the end of the file. Consider removing these extra blank lines for consistency with common style guidelines.
|
|
||
| bazel_dep(name = "rules_cc", version = "0.0.17") | ||
| bazel_dep(name = "platforms", version = "0.0.10") | ||
|
|
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing blank line at the end of the file. Consider removing this for consistency with Bazel style guidelines.
| build:debug --copt=-DDEBUG | ||
| build:debug --strip=never | ||
| build:debug --linkopt=-g | ||
|
|
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing blank line at the end of the file. Consider removing this for consistency.
luoyuxia
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zhaohaidao Thanks for the pr. I have no much experience with bazel, but take care about the suggestion by copiot.
| @@ -0,0 +1,15 @@ | |||
| # Bazel configuration for fluss-rust C++ bindings | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
| @@ -0,0 +1,142 @@ | |||
| licenses(["notice"]) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
| RUST_BRIDGE_DIR=$$CARGO_TARGET_DIR/cxxbridge/fluss-cpp/src | ||
| RUST_LIB=$$CARGO_TARGET_DIR/debug/libfluss_cpp.a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check this suggestion.
| genrule( | ||
| name = "cargo_build_debug", | ||
| srcs = glob([ | ||
| "src/**/*.rs", | ||
| "Cargo.toml", | ||
| ]), | ||
| outs = [ | ||
| "rust_lib_debug.a", | ||
| "rust_bridge_cc.cc", | ||
| "rust_bridge_h.h", | ||
| "src/lib.rs.h", | ||
| "cxxbridge/rust/cxx.h", | ||
| ], | ||
| cmd = """ | ||
| set -e | ||
| EXECROOT=$$(pwd) | ||
| OUTPUT_LIB=$(location rust_lib_debug.a) | ||
| OUTPUT_CC=$(location rust_bridge_cc.cc) | ||
| OUTPUT_H=$(location rust_bridge_h.h) | ||
| OUTPUT_SRC_H=$(location src/lib.rs.h) | ||
| OUTPUT_CXX_H=$(location cxxbridge/rust/cxx.h) | ||
| # Resolve real source path from sandbox symlink | ||
| SANDBOX_CARGO=$(location Cargo.toml) | ||
| REAL_CARGO=$$(readlink -f $$SANDBOX_CARGO 2>/dev/null || python3 -c "import os; print(os.path.realpath('$$SANDBOX_CARGO'))") | ||
| CARGO_DIR=$$(dirname $$REAL_CARGO) | ||
| # Find Cargo workspace root (fluss-rust directory, 2 levels up from bindings/cpp) | ||
| WORKSPACE_ROOT=$$(cd $$CARGO_DIR/../.. && pwd) | ||
| if [ ! -f $$WORKSPACE_ROOT/Cargo.toml ]; then | ||
| echo "Error: Cannot find workspace root Cargo.toml at $$WORKSPACE_ROOT" >&2 | ||
| exit 1 | ||
| fi | ||
| cd $$WORKSPACE_ROOT | ||
| cargo build --manifest-path $$CARGO_DIR/Cargo.toml | ||
| CARGO_TARGET_DIR=$$WORKSPACE_ROOT/target | ||
| RUST_BRIDGE_DIR=$$CARGO_TARGET_DIR/cxxbridge/fluss-cpp/src | ||
| RUST_LIB=$$CARGO_TARGET_DIR/debug/libfluss_cpp.a | ||
| if [ ! -f $$RUST_LIB ]; then | ||
| echo "Error: Rust library not found at $$RUST_LIB" >&2 | ||
| exit 1 | ||
| fi | ||
| if [ ! -f $$RUST_BRIDGE_DIR/lib.rs.cc ]; then | ||
| echo "Error: cxxbridge CC file not found at $$RUST_BRIDGE_DIR/lib.rs.cc" >&2 | ||
| exit 1 | ||
| fi | ||
| if [ ! -f $$RUST_BRIDGE_DIR/lib.rs.h ]; then | ||
| echo "Error: cxxbridge header file not found at $$RUST_BRIDGE_DIR/lib.rs.h" >&2 | ||
| exit 1 | ||
| fi | ||
| cd $$EXECROOT | ||
| mkdir -p $$(dirname $$OUTPUT_SRC_H) $$(dirname $$OUTPUT_CXX_H) | ||
| cp $$RUST_LIB $$OUTPUT_LIB || (echo "Failed to copy $$RUST_LIB to $$OUTPUT_LIB" >&2; exit 1) | ||
| cp $$RUST_BRIDGE_DIR/lib.rs.cc $$OUTPUT_CC || (echo "Failed to copy $$RUST_BRIDGE_DIR/lib.rs.cc to $$OUTPUT_CC" >&2; exit 1) | ||
| cp $$RUST_BRIDGE_DIR/lib.rs.h $$OUTPUT_H || (echo "Failed to copy $$RUST_BRIDGE_DIR/lib.rs.h to $$OUTPUT_H" >&2; exit 1) | ||
| cp $$RUST_BRIDGE_DIR/lib.rs.h $$OUTPUT_SRC_H || (echo "Failed to copy $$RUST_BRIDGE_DIR/lib.rs.h to $$OUTPUT_SRC_H" >&2; exit 1) | ||
| CXX_H_SOURCE=$$CARGO_TARGET_DIR/cxxbridge/rust/cxx.h | ||
| if [ ! -f $$CXX_H_SOURCE ] && [ ! -L $$CXX_H_SOURCE ]; then | ||
| echo "Error: cxx.h not found at $$CXX_H_SOURCE" >&2 | ||
| exit 1 | ||
| fi | ||
| cp -L $$CXX_H_SOURCE $$OUTPUT_CXX_H || (echo "Failed to copy $$CXX_H_SOURCE to $$OUTPUT_CXX_H" >&2; exit 1) | ||
| """, | ||
| message = "Building Rust library with cargo...", | ||
| local = 1, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the suggestion looks reasonable to me.
Purpose
Linked issue: close #106
Brief change log
Tests
API and Format
Documentation