Skip to content
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

iox-#1542 Support Bazel build system #1543

Merged
merged 14 commits into from
Jul 29, 2022
Merged
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
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build --cxxopt="-std=c++14"
22 changes: 22 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,28 @@ jobs:
- uses: actions/checkout@v3
- run: ./tools/ci/build-test-ubuntu-with-gcc54.sh

# Bazel sanitiy check
build-test-ubuntu-bazel:
runs-on: ubuntu-latest
needs: pre-flight-check
steps:
- uses: actions/checkout@v3
- run: sudo apt-get update && sudo apt-get install -y libacl1-dev libncurses5-dev
- uses: bazelbuild/setup-bazelisk@v2
- name: Mount bazel cache
uses: actions/cache@v3
with:
path: "~/.cache/bazel"
key: bazel
- name: Bazel Linting + Build + Test
run: |
# Run linter on complete bazel code
bazel run //:buildifier_lint_check
# Build everything including stresstests
bazel build //...
# We exclude the sofi stresstest in CI since we cannot set the CPU Affinity in the GitHub Action Runners
bazel test //... --deleted_packages=iceoryx_hoofs/test/stresstests

coverage-and-docs:
runs-on: ubuntu-20.04
needs: pre-flight-check
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ doc/website/API-reference/
tools/website/generated/
*.project
__pycache__
/bazel-*
73 changes: 73 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright (c) 2022 by Apex.AI Inc. All rights reserved.
#
# Licensed 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.
#
# SPDX-License-Identifier: Apache-2.0

load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")

exports_files(["VERSION"])

alias(
name = "iceoryx_hoofs",
actual = "//iceoryx_hoofs",
visibility = ["//visibility:public"],
)

alias(
name = "iceoryx_posh",
actual = "//iceoryx_posh",
visibility = ["//visibility:public"],
)

alias(
name = "iceoryx_binding_c",
actual = "//iceoryx_binding_c",
visibility = ["//visibility:public"],
)

alias(
name = "roudi",
actual = "//iceoryx_posh:iox-roudi",
visibility = ["//visibility:public"],
)

# Execute `bazel run //:buildifier` to fix formating of all starlark files in the workspace
buildifier(
name = "buildifier",
verbose = True,
)

# Execute `bazel run //:buildifier_test` to check all starlark files for correctness
buildifier(
name = "buildifier_test",
mode = "check",
verbose = True,
)

# Execute `bazel run //:buildifier_lint` to reformat and run the linter on all starlark files
buildifier(
name = "buildifier_lint",
lint_mode = "fix",
lint_warnings = ["all"],
verbose = True,
)

# Execute `bazel run //:buildifier_lint_check` to reformat and run the linter on all starlark files
buildifier(
name = "buildifier_lint_check",
lint_mode = "warn",
lint_warnings = ["all"],
mode = "check",
verbose = True,
)
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ codebase follows these rules, things are work in progress.
See [error-handling.md](./doc/design/error-handling.md) for additional
information about logging and error handling.

For formatting and linting rules on Bazel files see the [installation guide for contributors](./doc/website/advanced/installation-guide-for-contributors.md#bazel).

### Naming conventions

* File names with `lower_snake_case`: `my_thing.hpp`
Expand Down
27 changes: 27 additions & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) 2022 by Apex.AI Inc. All rights reserved.
#
# Licensed 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.
#
# SPDX-License-Identifier: Apache-2.0

workspace(name = "org_eclipse_iceoryx")

# Load dependency googletest
load("//bazel:load_repositories.bzl", "load_repositories")

load_repositories()

# Load dependency cpptoml
load("//bazel:setup_repositories.bzl", "setup_repositories")

setup_repositories()
Empty file added bazel/BUILD.bazel
Empty file.
Empty file added bazel/bazelbuild/BUILD.bazel
Empty file.
73 changes: 73 additions & 0 deletions bazel/bazelbuild/repositories.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""
Copyright (c) 2022 by Apex.AI Inc. All rights reserved.

Licensed 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.

SPDX-License-Identifier: Apache-2.0

Loads dependent repositories from https://github.com/bazelbuild
"""

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

BAZELBUILD_RULES_CC_VERSION = "0.0.1"

def load_com_github_bazelbuild_rules_cc_repositories():
maybe(
name = "bazelbuild_rules_cc",
repo_rule = http_archive,
sha256 = "4dccbfd22c0def164c8f47458bd50e0c7148f3d92002cdb459c2a96a68498241",
urls = [
"https://github.com/bazelbuild/rules_cc/releases/download/{version}/rules_cc-{version}.tar.gz".format(version = BAZELBUILD_RULES_CC_VERSION),
],
)

COM_GITHUB_BAZELBUILD_BUILDTOOLS_VERSION = "5.1.0"

def load_com_github_bazelbuild_buildtools_repositories():
maybe(
name = "com_github_bazelbuild_buildtools",
repo_rule = http_archive,
sha256 = "e3bb0dc8b0274ea1aca75f1f8c0c835adbe589708ea89bf698069d0790701ea3",
strip_prefix = "buildtools-{version}".format(version = COM_GITHUB_BAZELBUILD_BUILDTOOLS_VERSION),
urls = [
"https://github.com/bazelbuild/buildtools/archive/refs/tags/{version}.tar.gz".format(version = COM_GITHUB_BAZELBUILD_BUILDTOOLS_VERSION),
],
)

IO_BAZEL_RULES_GO_VERSION = "0.29.0"

def load_io_bazel_rules_go_repositories():
maybe(
name = "io_bazel_rules_go",
repo_rule = http_archive,
sha256 = "2b1641428dff9018f9e85c0384f03ec6c10660d935b750e3fa1492a281a53b0f",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v{version}/rules_go-v{version}.zip".format(version = IO_BAZEL_RULES_GO_VERSION),
"https://github.com/bazelbuild/rules_go/releases/download/v{version}/rules_go-v{version}.zip".format(version = IO_BAZEL_RULES_GO_VERSION),
],
)

COM_GOOGLE_PROTOBUF_VERSION = "3.13.0"

def load_com_google_protobuf_repositories():
maybe(
name = "com_google_protobuf",
repo_rule = http_archive,
sha256 = "9b4ee22c250fe31b16f1a24d61467e40780a3fbb9b91c3b65be2a376ed913a1a",
strip_prefix = "protobuf-{version}".format(version = COM_GOOGLE_PROTOBUF_VERSION),
urls = [
"https://github.com/protocolbuffers/protobuf/archive/v{version}.tar.gz".format(version = COM_GOOGLE_PROTOBUF_VERSION),
],
)
29 changes: 29 additions & 0 deletions bazel/bazelbuild/setup.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
Copyright (c) 2022 by Apex.AI Inc. All rights reserved.

Licensed 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.

SPDX-License-Identifier: Apache-2.0

Macro for setting the dependencies for the buildtools of bazel
"""

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

def setup_go_protobuf_for_bazelbuild():
go_rules_dependencies()

go_register_toolchains(version = "1.17.2")

protobuf_deps()
42 changes: 42 additions & 0 deletions bazel/configure_file.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
Copyright (c) 2022 by Apex.AI Inc. All rights reserved.

Licensed 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.

SPDX-License-Identifier: Apache-2.0

The configure_file rule imitates the similar CMake function for template expansion: https://cmake.org/cmake/help/latest/command/configure_file.html
"""

def _configure_file_impl(ctx):
ctx.actions.expand_template(
template = ctx.file.src,
output = ctx.outputs.out,
substitutions = {
"@" + k + "@": v
for k, v in ctx.attr.config.items()
},
)
files = depset(direct = [ctx.outputs.out])
runfiles = ctx.runfiles(files = [ctx.outputs.out])
return [DefaultInfo(files = files, runfiles = runfiles)]

configure_file = rule(
implementation = _configure_file_impl,
provides = [DefaultInfo],
attrs = {
"config": attr.string_dict(mandatory = True),
"out": attr.output(mandatory = True),
"src": attr.label(mandatory = True, allow_single_file = True),
},
)
67 changes: 67 additions & 0 deletions bazel/configure_version.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""
Copyright (c) 2022 by Apex.AI Inc. All rights reserved.

Licensed 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.

SPDX-License-Identifier: Apache-2.0

This module set compile-time variables and set them accordingly in generated files
"""

SCRIPT = """#!/bin/bash

set -e

version_file="{version_file}"
input_file="{input_file}"
output_file="{output_file}"

IFS="-" read version_number version_suffix <<< $(<"$version_file")
IFS="." read major_version minor_version patch_version tweak_version <<< $version_number
[ -z "$version_suffix" ] && version_delim="" || version_delim="-"

data="$(<"$input_file")"
data=${{data/@PROJECT_VERSION_MAJOR@/${{major_version:-0}}}}
data=${{data/@PROJECT_VERSION_MINOR@/${{minor_version:-0}}}}
data=${{data/@PROJECT_VERSION_PATCH@/${{patch_version:-0}}}}
data=${{data/@IOX_VERSION_TWEAK@/${{tweak_version:-0}}}}
data=${{data/@PROJECT_VERSION@/${{version_number}}}}
data=${{data/@IOX_VERSION_SUFFIX@/${{version_delim}}${{version_suffix}}}}
data=${{data/@ICEORYX_BUILDDATE@/builddate_not_set}}
data=${{data/@ICEORYX_SHA1@/sha1_not_set}}

echo "$data" > $output_file
"""

def _configure_version_impl(ctx):
ctx.actions.run_shell(
command = SCRIPT.format(
version_file = ctx.files.version_from[0].path,
input_file = ctx.files.src[0].path,
output_file = ctx.outputs.out.path,
),
inputs = ctx.files.src + ctx.files.version_from,
outputs = [ctx.outputs.out],
)
files = depset(direct = [ctx.outputs.out])
return [DefaultInfo(files = files)]

configure_version = rule(
implementation = _configure_version_impl,
provides = [DefaultInfo],
attrs = {
"out": attr.output(mandatory = True),
"src": attr.label(mandatory = True, allow_single_file = True),
"version_from": attr.label(mandatory = True, allow_single_file = True),
},
)
Empty file added bazel/cpptoml/BUILD.bazel
Empty file.
24 changes: 24 additions & 0 deletions bazel/cpptoml/cpptoml.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) 2022 by Apex.AI Inc. All rights reserved.
#
# Licensed 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.
#
# SPDX-License-Identifier: Apache-2.0

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

cc_library(
name = "cpptoml",
hdrs = ["include/cpptoml.h"],
strip_include_prefix = "include",
visibility = ["//visibility:public"],
)
Loading