Skip to content

Commit

Permalink
Merge pull request #467 from elBoberido/iox2-460-add-dev-permission-f…
Browse files Browse the repository at this point in the history
…lag-to-bazel

[#460] Add dev_permission flag to bazel
  • Loading branch information
elBoberido authored Oct 15, 2024
2 parents 8a61101 + 2d27b26 commit e5b44a9
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@ build:windows --cxxopt="/std:c++17"

# this has to be specified manually
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
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ jobs:
uname -a
- name: Run bazel build
run: CARGO_BAZEL_REPIN=true bazel build //...
run: bazel build //...

- name: Run bazel test
if: false # TODO: [349] enable tests in bazel
Expand Down
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
50 changes: 50 additions & 0 deletions doc/bazel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ or
CARGO_BAZEL_REPIN=1 bazel build //...
```

To make syncing dependencies automatic for every build, add the
following line to your `.bazelrc` file:

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

For more details, refer to the
[Crate Universe Repinning Guide](https://bazelbuild.github.io/rules_rust/crate_universe.html#repinning--updating-dependencies-1).

Expand Down Expand Up @@ -152,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 e5b44a9

Please sign in to comment.