Skip to content

Conversation

@zhaohaidao
Copy link
Contributor

Purpose

Linked issue: close #106

Brief change log

Tests

API and Format

Documentation

@zhaohaidao
Copy link
Contributor Author

@luoyuxia Hi, yuxia. I added bazel build ability for cpp binding. PTAL if u have time.

Copy link

Copilot AI left a 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(
Copy link

Copilot AI Dec 21, 2025

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.

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,142 @@
licenses(["notice"])
Copy link

Copilot AI Dec 21, 2025

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.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

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
Copy link

Copilot AI Dec 21, 2025

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.

Copilot uses AI. Check for mistakes.
exit 1
;;
esac

Copy link

Copilot AI Dec 21, 2025

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.

Suggested change

Copilot uses AI. Check for mistakes.
Comment on lines +39 to +40
RUST_BRIDGE_DIR=$$CARGO_TARGET_DIR/cxxbridge/fluss-cpp/src
RUST_LIB=$$CARGO_TARGET_DIR/debug/libfluss_cpp.a
Copy link

Copilot AI Dec 21, 2025

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.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please check this suggestion.

Comment on lines +5 to +68
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,
)
Copy link

Copilot AI Dec 21, 2025

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.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

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.

Comment on lines +129 to +136
copts = [
"-std=c++17",
"-g3",
"-O0",
"-ggdb",
"-fno-omit-frame-pointer",
"-DDEBUG",
],
Copy link

Copilot AI Dec 21, 2025

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.

Copilot uses AI. Check for mistakes.
],
visibility = ["//visibility:public"],
)

Copy link

Copilot AI Dec 21, 2025

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.

Suggested change

Copilot uses AI. Check for mistakes.

bazel_dep(name = "rules_cc", version = "0.0.17")
bazel_dep(name = "platforms", version = "0.0.10")

Copy link

Copilot AI Dec 21, 2025

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.

Suggested change

Copilot uses AI. Check for mistakes.
build:debug --copt=-DDEBUG
build:debug --strip=never
build:debug --linkopt=-g

Copy link

Copilot AI Dec 21, 2025

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.

Suggested change

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@luoyuxia luoyuxia left a 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
Copy link
Contributor

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"])
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Comment on lines +39 to +40
RUST_BRIDGE_DIR=$$CARGO_TARGET_DIR/cxxbridge/fluss-cpp/src
RUST_LIB=$$CARGO_TARGET_DIR/debug/libfluss_cpp.a
Copy link
Contributor

Choose a reason for hiding this comment

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

Please check this suggestion.

Comment on lines +5 to +68
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,
)
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support bazel build for cpp binding

2 participants