Skip to content

Commit

Permalink
Merge pull request #341 from elBoberido/iox2-329-bazel-for-c-and-cpp-…
Browse files Browse the repository at this point in the history
…bindings

[#329] Bazel support for C and C++ Bindings
  • Loading branch information
elBoberido authored Aug 6, 2024
2 parents 67aefe3 + 70e35eb commit d9024b7
Show file tree
Hide file tree
Showing 27 changed files with 712 additions and 7 deletions.
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
5 changes: 5 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build --spawn_strategy=standalone --strategy=Genrule=standalone

build:gcc --cxxopt="-std=c++17"
build:clang --cxxopt="-std=c++17"
build:msvc --cxxopt="/std:c++17"
2 changes: 1 addition & 1 deletion .github/actions/build-and-cache-rust-tool/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ runs:
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.artifact-upload-name }}
path: ~/.cargo/bin/${{ inputs.artifact-artifact-bin-name }}
path: ~/.cargo/bin/${{ inputs.artifact-bin-name }}
retention-days: 1
if-no-files-found: error
- name: Upload artifact
Expand Down
44 changes: 43 additions & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -402,14 +402,56 @@ jobs:
- uses: vmactions/freebsd-vm@v1
with:
release: ${{ matrix.freebsd_version }}
mem: 8192
mem: 16384
copyback: false
prepare: pkg install -y cmake curl gcc git llvm
run: |
git config --global --add safe.directory /home/runner/work/iceoryx2/iceoryx2
./internal/scripts/ci_prepare_freebsd.sh
./internal/scripts/ci_build_and_test_freebsd.sh --toolchain ${{ matrix.toolchain }} --mode ${{ matrix.mode }}
x86_64_bazel:
needs: [preflight-check, static-code-analysis]
if: ${{ needs.changes.outputs.source-code == 'true' }}
strategy:
matrix:
os: [windows-latest, ubuntu-latest]
toolchain: [stable]
timeout-minutes: 60
runs-on: ${{ matrix.os }}
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Setup Rust
uses: dtolnay/rust-toolchain@v1
with:
toolchain: ${{ matrix.toolchain }}
components: rustfmt, clippy

- name: Prepare Windows
if: ${{ matrix.os == 'windows-latest' }}
run: internal\scripts\ci_prepare_windows.ps1
- name: Prepare Linux
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
internal/scripts/ci_prepare_ubuntu.sh
uname -a
- name: Run bazel build on Windows MSVC
if: ${{ matrix.os == 'windows-latest' }}
run: bazel build --config=msvc //...
- name: Run bazel build on Linux
if: ${{ matrix.os == 'ubuntu-latest' }}
run: bazel build --config=gcc //...

- name: Run bazel test on Windows MSVC
if: ${{ matrix.os == 'windows-latest' }}
run: bazel test --config=msvc //...
- name: Run bazel test on Linux
if: ${{ matrix.os == 'ubuntu-latest' }}
run: bazel test --config=gcc //...

grcov:
needs: [preflight-check, static-code-analysis]
if: ${{ needs.changes.outputs.source-code == 'true' }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ debug/
.cache
.idea
build
bazel-*
MODULE.bazel*

Cargo.lock
**/*.rs.bk
Expand Down
76 changes: 76 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Copyright (c) 2024 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache Software License 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
# which is available at https://opensource.org/licenses/MIT.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT

load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")

#
# Config & Platform support
#
config_setting(
name = "linux",
constraint_values = ["@platforms//os:linux"],
)

config_setting(
name = "win-gcc",
constraint_values = ["@platforms//os:windows"],
flag_values = {"@bazel_tools//tools/cpp:compiler": "mingw-gcc"},
)

config_setting(
name = "win-msvc",
constraint_values = ["@platforms//os:windows"],
flag_values = {"@bazel_tools//tools/cpp:compiler": "msvc-cl"},
)

cmake(
name = "iceoryx_platform",
cache_entries = {
"BUILD_SHARED_LIBS": "OFF",
},
lib_source = "@iceoryx_platform//:all_srcs",
out_static_libs = select({
"//:win-msvc": ["iceoryx_platform.lib"],
"//conditions:default": ["libiceoryx_platform.a"],
}),
out_include_dir = "include/iceoryx/v2.95.0/",
visibility = ["//visibility:public"],
)

cmake(
name = "iceoryx_hoofs",
cache_entries = {
"BUILD_SHARED_LIBS": "OFF",
},
lib_source = "@iceoryx_hoofs//:all_srcs",
out_static_libs = select({
"//:win-msvc": ["iceoryx_hoofs.lib"],
"//conditions:default": ["libiceoryx_hoofs.a"],
}),
out_include_dir = "include/iceoryx/v2.95.0/",
deps = [
"//:iceoryx_platform",
],
visibility = ["//visibility:public"],
)

alias(
name = "iceoryx2-c",
actual = "//iceoryx2-ffi/c:iceoryx2-c",
visibility = ["//visibility:public"],
)

alias(
name = "iceoryx2-cxx",
actual = "//iceoryx2-ffi/cxx:iceoryx2-cxx",
visibility = ["//visibility:public"],
)
66 changes: 66 additions & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright (c) 2024 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache Software License 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
# which is available at https://opensource.org/licenses/MIT.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT

workspace(name = "org_eclipse_iceoryx_iceoryx2")

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

http_archive(
name = "rules_foreign_cc",
sha256 = "4b33d62cf109bcccf286b30ed7121129cc34cf4f4ed9d8a11f38d9108f40ba74",
strip_prefix = "rules_foreign_cc-0.11.1",
url = "https://github.com/bazelbuild/rules_foreign_cc/releases/download/0.11.1/rules_foreign_cc-0.11.1.tar.gz",
)

load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")

# This sets up some common toolchains for building targets. For more details, please see
# https://bazelbuild.github.io/rules_foreign_cc/0.11.1/flatten.html#rules_foreign_cc_dependencies
rules_foreign_cc_dependencies()

# Setup gtest
GOOGLETEST_VERSION = "1.14.0"
maybe(
name = "googletest",
repo_rule = http_archive,
urls = ["https://github.com/google/googletest/archive/refs/tags/v{version}.zip".format(version = GOOGLETEST_VERSION)],
sha256 = "1f357c27ca988c3f7c6b4bf68a9395005ac6761f034046e9dde0896e3aba00e4",
strip_prefix = "googletest-{version}".format(version = GOOGLETEST_VERSION),
)

# TODO use http_archive once iceoyx v3.0 is release

_ALL_CONTENT = """\
filegroup(
name = "all_srcs",
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)
"""

git_repository(
name = "iceoryx_platform",
strip_prefix = "iceoryx_platform",
build_file_content = _ALL_CONTENT,
remote = "https://github.com/eclipse-iceoryx/iceoryx.git",
tag = "v2.95.0",
)

git_repository(
name = "iceoryx_hoofs",
strip_prefix = "iceoryx_hoofs",
build_file_content = _ALL_CONTENT,
remote = "https://github.com/eclipse-iceoryx/iceoryx.git",
tag = "v2.95.0",
)
1 change: 1 addition & 0 deletions doc/release-notes/iceoryx2-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
* `FixedSizeVec`
* TryInto implemented for `{Node|Service}Name` [#243](https://github.com/eclipse-iceoryx/iceoryx2/issues/243)
* Add custom user header [#253](https://github.com/eclipse-iceoryx/iceoryx2/issues/253)
* Build the C and C++ language bindings with bazel [#329](https://github.com/eclipse-iceoryx/iceoryx2/issues/329)
* Add `Subscriber::has_samples` [#335](https://github.com/eclipse-iceoryx/iceoryx2/issues/335)

### Bugfixes
Expand Down
23 changes: 23 additions & 0 deletions examples/c/discovery/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (c) 2024 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache Software License 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
# which is available at https://opensource.org/licenses/MIT.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT

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

cc_binary(
name = "example_c_discovery",
srcs = [
"src/main.c",
],
deps = [
"//:iceoryx2-c",
],
)
33 changes: 33 additions & 0 deletions examples/c/event/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (c) 2024 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache Software License 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
# which is available at https://opensource.org/licenses/MIT.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT

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

cc_binary(
name = "example_c_event_listener",
srcs = [
"src/listener.c",
],
deps = [
"//:iceoryx2-c",
],
)

cc_binary(
name = "example_c_event_notifier",
srcs = [
"src/notifier.c",
],
deps = [
"//:iceoryx2-c",
],
)
1 change: 0 additions & 1 deletion examples/c/event/src/notifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ int main(void) {
goto drop_service;
}
iox2_notifier_ref_h notifier_ref = iox2_cast_notifier_ref_h(notifier);
iox2_event_id_t event_id;

uint64_t counter = 0;
while (iox2_node_wait(node_ref_handle, 0, 0) == iox2_node_event_e_TICK) {
Expand Down
35 changes: 35 additions & 0 deletions examples/c/publish_subscribe/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (c) 2024 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache Software License 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
# which is available at https://opensource.org/licenses/MIT.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT

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

cc_binary(
name = "example_c_publisher",
srcs = [
"src/publisher.c",
"src/transmission_data.h",
],
deps = [
"//:iceoryx2-c",
],
)

cc_binary(
name = "example_c_subscriber",
srcs = [
"src/subscriber.c",
"src/transmission_data.h",
],
deps = [
"//:iceoryx2-c",
],
)
35 changes: 35 additions & 0 deletions examples/c/publish_subscribe_with_user_header/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (c) 2024 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache Software License 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
# which is available at https://opensource.org/licenses/MIT.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT

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

cc_binary(
name = "example_c_with_user_header_publisher",
srcs = [
"src/custom_header.h",
"src/publisher.c",
],
deps = [
"//:iceoryx2-c",
],
)

cc_binary(
name = "example_c_with_user_header_subscriber",
srcs = [
"src/custom_header.h",
"src/subscriber.c",
],
deps = [
"//:iceoryx2-c",
],
)
24 changes: 24 additions & 0 deletions examples/cxx/complex_data_types/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) 2024 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache Software License 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
# which is available at https://opensource.org/licenses/MIT.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT

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

cc_binary(
name = "example_cxx_complex_data_types",
srcs = [
"src/complex_data_types.cpp",
],
deps = [
"//:iceoryx_hoofs",
"//:iceoryx2-cxx",
],
)
Loading

0 comments on commit d9024b7

Please sign in to comment.