Skip to content

Commit

Permalink
[eclipse-iceoryx#460] Add 'dev_permissions' feature flag to bazel
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Oct 14, 2024
1 parent 79123c6 commit 2d27b26
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ build:windows --cxxopt="/std:c++17"
build:mingw --cxxopt="-std=c++17"

build --action_env=CARGO_BAZEL_REPIN=true

#
# feature flags
#

# value [auto, on, off]
# 'auto' is defined by the crate owner ('off' for this feature) and the default value if the flag is not set
#build --//:feature_dev_permissions=on
6 changes: 6 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ config_setting(
flag_values = {"@bazel_tools//tools/cpp:compiler": "msvc-cl"},
)

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

alias(
name = "iceoryx2",
actual = "//iceoryx2:iceoryx2",
Expand Down
17 changes: 17 additions & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,23 @@ load("@crate_index//:defs.bzl", "crate_repositories")

crate_repositories()

BAZEL_SKYLIB_VERSION = "1.7.1"

# Load skylib for custom build config
maybe(
name = "bazel_skylib",
repo_rule = http_archive,
sha256 = "bc283cdfcd526a52c3201279cda4bc298652efa898b10b4db0837dc51652756f",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/{version}/bazel-skylib-{version}.tar.gz".format(version = BAZEL_SKYLIB_VERSION),
"https://github.com/bazelbuild/bazel-skylib/releases/download/{version}/bazel-skylib-{version}.tar.gz".format(version = BAZEL_SKYLIB_VERSION),
],
)

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()


# Load iceoryx rules
ICEORYX_VERSION = "2.95.2"
Expand Down
49 changes: 46 additions & 3 deletions doc/bazel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ or
CARGO_BAZEL_REPIN=1 bazel build //...
```

Alternatively, this can also be achieved by adding the following
line to the `.bazelrc` file:
To make syncing dependencies automatic for every build, add the
following line to your `.bazelrc` file:

```
```bazel
build --action_env=CARGO_BAZEL_REPIN=true
```

Expand Down Expand Up @@ -159,6 +159,49 @@ cc_binary(
* **For C++**: Use `@iceoryx2//:iceoryx2-cxx-static` or
`@iceoryx2//:iceoryx2-cxx-shared`

### Feature Flags

iceoryx2 provides several feature flags that can be configured using bazel
build options. These flags allow you to enable or disable specific features
when building the project.

#### Enabling a Feature Flag via Command Line

To set a feature flag directly from the command line during the build, use the
following format:

```bash
bazel build --@iceoryx2//:<feature_flag> //...
```

For example, to enable a feature flag called `foo`, you would run:

```bash
bazel build --@iceoryx2//:foo //...
```

#### Setting Feature Flags in .bazelrc

You can also persist feature flag configurations by specifying them in the
`.bazelrc` file. This method is useful for keeping your build settings
consistent across different environments.

```bazel
build --@iceoryx2//:<feature_flag>=on
```

For instance, to enable the `foo` feature by default in `.bazelrc`, you would add:

```bazel
build --@iceoryx2//:foo=on
```

#### List of Available Features

| Feature Flag | Valid Values | Crate Default |
| ----------------------- | ---------------------------- | ------------------ |
| dev_permissions | auto, on, off | auto == off |

## Instructions for iceoryx2 Developers

When working with Bazel and Cargo in this project, ensure the following steps are
Expand Down
37 changes: 37 additions & 0 deletions iceoryx2-cal/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,53 @@

package(default_visibility = ["//visibility:public"])

load("@bazel_skylib//lib:selects.bzl", "selects")
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@rules_rust//rust:defs.bzl", "rust_library")

filegroup(
name = "all_srcs",
srcs = glob(["**"]),
)

string_flag(
name = "feature_dev_permissions",
build_setting_default = "auto",
visibility = ["//visibility:public"],
)

config_setting(
name = "dev_permissions_auto",
flag_values = {
":feature_dev_permissions": "auto",
},
)

config_setting(
name = "dev_permissions_enabled",
flag_values = {
":feature_dev_permissions": "on",
},
)

# NOTE: while this seems superfluous, it is the pattern for cases where *_auto is on by default;
# therefore this target is introduced to keep all feature flags consistent
selects.config_setting_group(
name = "cfg_feature_dev_permissions",
match_any = [
":dev_permissions_enabled",
],
)

rust_library(
name = "iceoryx2-cal",
srcs = glob(["src/**/*.rs"]),
crate_features = select({
"cfg_feature_dev_permissions": [
"dev_permissions"
],
"//conditions:default": [],
}),
deps = [
"//iceoryx2-bb/container:iceoryx2-bb-container",
"//iceoryx2-bb/elementary:iceoryx2-bb-elementary",
Expand Down

0 comments on commit 2d27b26

Please sign in to comment.