Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ members = [
"core/tools",
"examples/rust",
]
exclude = ["foreign/python"]
exclude = ["foreign/cpp", "foreign/python"]
resolver = "2"

[workspace.dependencies]
Expand Down
41 changes: 41 additions & 0 deletions foreign/cpp/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 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.

# Bazel configuration for iggy C++ bindings

# Enable BzlMod
common --enable_bzlmod

startup --install_base=/tmp/bazel_iggy/install_base
startup --output_base=/tmp/bazel_iggy/output_base
common --symlink_prefix=bazel-bin/

# Debug configuration
build --compilation_mode=dbg
build --copt=-g3
build --copt=-ggdb
build --copt=-O0
build --copt=-fno-omit-frame-pointer
build --copt=-DDEBUG
build --strip=never
build --linkopt=-g

# Release configuration
build:release --compilation_mode=opt
build:release --copt=-O2
build:release --copt=-DNDEBUG
build:release --strip=always
47 changes: 47 additions & 0 deletions foreign/cpp/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 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.

---
BasedOnStyle: Chromium
Standard: Cpp11
IndentWidth: 2
ColumnLimit: 120
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
AfterExternBlock: false
IndentCaseLabels: true
PointerAlignment: Right
AlignOperands: true
AlignConsecutiveAssignments: true
AccessModifierOffset: -2
AllowShortCaseLabelsOnASingleLine: false
KeepEmptyLinesAtTheStartOfBlocks: true
IndentPPDirectives: AfterHash
IncludeBlocks: Preserve
1 change: 1 addition & 0 deletions foreign/cpp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bazel-*
119 changes: 119 additions & 0 deletions foreign/cpp/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# 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.

licenses(["notice"])

load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_import", "cc_library")

genrule(
name = "cargo_build",
srcs = glob([
"src/**/*.rs",
"Cargo.toml",
"Cargo.lock",
"build.rs",
]),
tools = [
"@rules_rust//tools/upstream_wrapper:cargo",
],
outs = [
"libiggy_cpp.a",
"include/lib.rs.h",
"cxxbridge/rust/cxx.h",
],
cmd = """
set -e

# 1. Resolve absolute paths for tools and Bazel outputs
CARGO="$$(pwd)/$(execpath @rules_rust//tools/upstream_wrapper:cargo)"
OUT_LIB="$$(pwd)/$(location libiggy_cpp.a)"
OUT_RS="$$(pwd)/$(location include/lib.rs.h)"
OUT_CXX="$$(pwd)/$(location cxxbridge/rust/cxx.h)"

# 2. Switch to the real project directory (foreign/cpp)
PROJECT_ROOT="$$(dirname $$(readlink -f $(location Cargo.toml)))"
cd "$$PROJECT_ROOT"

# 3. Configure build profile
PROFILE="debug"
FLAGS=""
if [ "$(COMPILATION_MODE)" = "opt" ]; then
PROFILE="release"
FLAGS="--release"
fi

# 4. Build: Output to local 'target/' dir (foreign/cpp/target)
env -u PWD CARGO_TARGET_DIR="target" "$$CARGO" build $$FLAGS

# 5. Copy artifacts to Bazel outputs
# Note: cxx-build hides headers in hash-based subdirectories
cp "target/$$PROFILE/libiggy_cpp.a" "$$OUT_LIB"
find "target/$$PROFILE/build" -name lib.rs.h | head -n 1 | xargs -I{} cp {} "$$OUT_RS"
find "target/$$PROFILE/build" -name cxx.h | head -n 1 | xargs -I{} cp {} "$$OUT_CXX"
""",
local = 1,
)

cc_import(
name = "iggy-cpp-static",
static_library = "libiggy_cpp.a",
)

cc_library(
name = "iggy-cpp",
srcs = [
"src/client.cpp",
"src/identifier.cpp",
"src/message.cpp",
"src/stream_details.cpp",
"src/topic_details.cpp",
],
hdrs = [
"include/iggy.hpp",
"include/lib.rs.h",
"cxxbridge/rust/cxx.h",
],
includes = [
"cxxbridge",
"include",
"src",
],
linkopts = [
"-ldl",
"-lpthread",
] + select({
"@platforms//os:macos": [
"-framework", "CoreFoundation",
"-framework", "Security",
],
"//conditions:default": [],
}),
deps = [
":cargo_build",
":iggy-cpp-static",
"@abseil-cpp//absl/numeric:int128",
],
)

cc_binary(
name = "example",
srcs = ["examples/example.cpp"],
deps = [
":iggy-cpp",
"@abseil-cpp//absl/strings:strings",
],
)
Loading
Loading