Skip to content

Commit

Permalink
Merge pull request eclipse-iceoryx#479 from elBoberido/iox2-349-enabl…
Browse files Browse the repository at this point in the history
…e-all-cargo-feature-flags-on-bazel

[eclipse-iceoryx#349] Add remaining cargo feature flags to bazel
  • Loading branch information
elBoberido authored Oct 18, 2024
2 parents a657228 + 97264ae commit 4dc37ec
Show file tree
Hide file tree
Showing 16 changed files with 179 additions and 47 deletions.
16 changes: 11 additions & 5 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ iox2_common_build_debug_template: &IOX2_COMMON_BUILD_DEBUG

iox2_common_build_and_test_debug_template: &IOX2_COMMON_BUILD_AND_TEST_DEBUG
<<: *IOX2_COMMON_BUILD_DEBUG
test_script: cargo nextest run --workspace --no-fail-fast
test_script: cargo nextest run --workspace --all-targets --no-fail-fast

iox2_common_build_release_template: &IOX2_COMMON_BUILD_RELEASE
build_script: cargo build --release --workspace --all-targets

iox2_common_build_and_test_no_doc_tests_release_template: &IOX2_COMMON_BUILD_AND_TEST_NO_DOC_TESTS_RELEASE
<<: *IOX2_COMMON_BUILD_RELEASE
test_script: cargo nextest run --release --tests --workspace --no-fail-fast
test_script: cargo nextest run --release --tests --workspace --all-targets --no-fail-fast

iox2_ffi_common_debug_template: &IOX2_FFI_COMMON_DEBUG
ffi_script:
Expand Down Expand Up @@ -134,14 +134,14 @@ iox2_freebsd_setup_template: &IOX2_FREEBSD_SETUP
# Filter to run the CI only on the main branch or for pull request to the main branch
#

only_if: ( $CIRRUS_BRANCH == 'main' || ($CIRRUS_PR != '' && $CIRRUS_BASE_BRANCH == 'main'))
only_if: false && ( $CIRRUS_BRANCH == 'main' || ($CIRRUS_PR != '' && $CIRRUS_BASE_BRANCH == 'main'))

#
# Global environment variables
#

env:
RUSTFLAGS: "-C debug-assertions"
# env:
# RUSTFLAGS: "-C debug-assertions"

#
# Preflight-Check with Ubuntu x86 stable debug
Expand Down Expand Up @@ -226,6 +226,8 @@ ubuntu_22_04_x64_stable_release_task:
# Pipeline 4

ubuntu_22_04_aarch64_min_version_debug_task:
# TODO run only after merge on main branch
only_if: $CIRRUS_BRANCH == 'main'
depends_on: preflight_check
skip: "changesIncludeOnly('.github/**', '**.md')"
<<: *IOX2_CONTAINER_UBUNTU_22_04_AARCH64
Expand Down Expand Up @@ -254,6 +256,8 @@ ubuntu_22_04_aarch64_beta_debug_task:
# Pipeline 5

ubuntu_22_04_aarch64_stable_release_task:
# TODO run only after merge on main branch
only_if: $CIRRUS_BRANCH == 'main'
depends_on: preflight_check
skip: "changesIncludeOnly('.github/**', '**.md')"
<<: *IOX2_CONTAINER_UBUNTU_22_04_AARCH64
Expand All @@ -268,6 +272,8 @@ ubuntu_22_04_aarch64_stable_release_task:
# Pipeline 6

arch_linux_x64_stable_debug_task:
# TODO commented out due to limited CI time
only_if: false
depends_on: preflight_check
skip: "changesIncludeOnly('.github/**', '**.md')"
<<: *IOX2_CONTAINER_ARCH_LINUX_X64
Expand Down
15 changes: 7 additions & 8 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ on:
pull_request:
branches: [ main, release* ]

env:
RUSTFLAGS: "-C debug-assertions"
# env:
# RUSTFLAGS: "-C debug-assertions"

jobs:
changes:
Expand Down Expand Up @@ -208,7 +208,7 @@ jobs:
run: cargo build --workspace --all-targets ${{ matrix.mode.arg }} --target i686-unknown-linux-gnu

- name: Run cargo nextest
run: cargo nextest run --workspace --no-fail-fast ${{ matrix.mode.arg }} --target i686-unknown-linux-gnu
run: cargo nextest run --workspace --all-targets --no-fail-fast ${{ matrix.mode.arg }} --target i686-unknown-linux-gnu

- name: Build language bindings
run: |
Expand Down Expand Up @@ -313,7 +313,7 @@ jobs:
run: cargo build --workspace --all-targets ${{ matrix.mode.arg }}

- name: Run cargo nextest
run: cargo nextest run --workspace --no-fail-fast ${{ matrix.mode.arg }}
run: cargo nextest run --workspace --all-targets --no-fail-fast ${{ matrix.mode.arg }}

- name: Build iceoryx_hoofs on Windows
if: ${{ matrix.os == 'windows-latest' }}
Expand Down Expand Up @@ -401,7 +401,7 @@ jobs:
run: cargo build --workspace --all-targets ${{ matrix.mode.arg }}

- name: Run cargo nextest
run: cargo nextest run --workspace --no-fail-fast ${{ matrix.mode.arg }}
run: cargo nextest run --workspace --all-targets --no-fail-fast ${{ matrix.mode.arg }}

### TODO: does not work yet reliable on the GitHub CI, seems to end up in an infinite loop
### current alternative is a cirrus.yml aarch64 target
Expand All @@ -427,7 +427,7 @@ jobs:
# cargo fmt --all -- --check
# cargo clippy -- -D warnings
# cargo build --workspace --all-targets ${{ matrix.mode }}
# cargo test --workspace --no-fail-fast ${{ matrix.mode }}
# cargo test --workspace --all-targets --no-fail-fast ${{ matrix.mode }}

freebsd:
needs: [preflight-check, static-code-analysis]
Expand Down Expand Up @@ -457,7 +457,7 @@ jobs:
if: ${{ needs.changes.outputs.source-code == 'true' }}
strategy:
matrix:
os: [ubuntu-latest]
os: [ubuntu-24.04]
toolchain: [stable]
timeout-minutes: 60
runs-on: ${{ matrix.os }}
Expand All @@ -480,7 +480,6 @@ jobs:
run: bazel build //...

- name: Run bazel test
if: false # TODO: [349] enable tests in bazel
run: bazel test //...

grcov:
Expand Down
86 changes: 86 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

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

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

exports_files([
Expand All @@ -22,6 +23,7 @@ exports_files([
#
# Config & Platform support
#

config_setting(
name = "linux",
constraint_values = ["@platforms//os:linux"],
Expand All @@ -39,11 +41,91 @@ config_setting(
flag_values = {"@bazel_tools//tools/cpp:compiler": "msvc-cl"},
)

#
# Rust Feature Flags
#

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",
],
)

string_flag(
name = "feature_logger_log",
build_setting_default = "auto",
visibility = ["//visibility:public"],
)
config_setting(
name = "logger_log_auto",
flag_values = {
"//:feature_logger_log": "auto",
},
)
config_setting(
name = "logger_log_enabled",
flag_values = {
"//:feature_logger_log": "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_logger_log",
match_any = [
":logger_log_enabled",
],
)

string_flag(
name = "feature_logger_tracing",
build_setting_default = "auto",
visibility = ["//visibility:public"],
)
config_setting(
name = "logger_tracing_auto",
flag_values = {
"//:feature_logger_tracing": "auto",
},
)
config_setting(
name = "logger_tracing_enabled",
flag_values = {
"//:feature_logger_tracing": "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_logger_tracing",
match_any = [
":logger_tracing_enabled",
],
)

#
# Alias
#

alias(
name = "iceoryx2",
Expand Down Expand Up @@ -75,6 +157,10 @@ alias(
visibility = ["//visibility:public"],
)

#
# all_srcs
#

filegroup(
name = "all_srcs",
srcs = glob([
Expand Down
34 changes: 34 additions & 0 deletions FAQ_ICEORYX_DEVS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Frequently Asked Questions - iceoryx Developer Edition

## Tests marked with `#[should_panic]` attribute do not panic in release builds

This usually happens when the panic is triggert via a `debug_assert` macro.
This macro is not active when the `-C debug-assertions` flag is not set, which
is the case for release builds.
To fix this problem, just add a `#[cfg(debug_assertions)]` to the test.

```rs
#[test]
#[should_panic]
#[cfg(debug_assertions)]
fn accessing_uninitialized_foo_fails() {
// ...
}
```

## The bazel build fails with an error mentioning `crate_index`, `manifest` and `Cargo.toml`

The error looks similar to this:

```ascii
An error occurred during the fetch of repository 'crate_index'
...
Error computing the main repository mapping: no such package '@@crate_index//'
...
Error: Some manifests are not being tracked. Please add the following labels to the `manifests` key: {
"//iceoryx2-foo/bar:Cargo.toml",
}
```

It seems a new crate is added to the root `Cargo.toml` and bazel is complaining
that it is not added to the `WORKSPACE.bazel` file for the `crate_index` target.
2 changes: 2 additions & 0 deletions doc/bazel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ build --@iceoryx2//:foo=on
| Feature Flag | Valid Values | Crate Default |
| ----------------------- | ---------------------------- | ------------------ |
| dev_permissions | auto, on, off | auto == off |
| logger_log | auto, on, off | auto == off |
| logger_tracing | auto, on, off | auto == off |

## Instructions for iceoryx2 Developers

Expand Down
1 change: 1 addition & 0 deletions iceoryx2-bb/lock-free/tests/bitset_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ fn bit_set_set_single_bit_works() {

#[test]
#[should_panic]
#[cfg(debug_assertions)]
fn bit_set_set_bit_outside_of_bitset_leads_to_panic() {
const CAPACITY: usize = 1551;
let sut = BitSet::new(CAPACITY);
Expand Down
14 changes: 12 additions & 2 deletions iceoryx2-bb/log/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

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

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

filegroup(
Expand All @@ -22,10 +23,19 @@ filegroup(
rust_library(
name = "iceoryx2-bb-log",
srcs = glob(["src/**/*.rs"]),
crate_features = select({
"//:cfg_feature_logger_log": [
"logger_log"
],
"//conditions:default": [],
}) + select({
"//:cfg_feature_logger_tracing": [
"logger_tracing"
],
"//conditions:default": [],
}),
deps = [
"//iceoryx2-pal/concurrency-sync:iceoryx2-pal-concurrency-sync",
"@crate_index//:termsize",
],
)

# TODO: [349] add feature flags
1 change: 0 additions & 1 deletion iceoryx2-bb/posix/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@ rust_library(
],
)

# TODO: [349] add feature flags
# TODO: [349] add tests
3 changes: 3 additions & 0 deletions iceoryx2-bb/posix/tests/ipc_capable_trait_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ mod ipc_capable {

#[test]
#[should_panic]
#[cfg(debug_assertions)]
fn creating_ipc_construct_from_uninitialized_handle_panics<Sut: TestSut>() {
let sut_handle = Sut::Handle::new();

Expand All @@ -47,6 +48,7 @@ mod ipc_capable {

#[test]
#[should_panic]
#[cfg(debug_assertions)]
fn creating_ipc_construct_from_process_local_handle_panics<Sut: TestSut>() {
let sut_handle = Sut::Handle::new();
Sut::init_process_local_handle(&sut_handle);
Expand All @@ -65,6 +67,7 @@ mod ipc_capable {

#[test]
#[should_panic]
#[cfg(debug_assertions)]
fn init_handle_twice_panics<Sut: TestSut>() {
let sut_handle = Sut::Handle::new();
Sut::init_process_local_handle(&sut_handle);
Expand Down
2 changes: 2 additions & 0 deletions iceoryx2-bb/posix/tests/semaphore_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ fn unnamed_semaphore_multiple_ipc_semaphores_are_working() {

#[test]
#[should_panic]
#[cfg(debug_assertions)]
fn unnamed_semaphore_acquire_uninitialized_ipc_handle_failes() {
let handle = UnnamedSemaphoreHandle::new();

Expand All @@ -433,6 +434,7 @@ fn unnamed_semaphore_acquire_uninitialized_ipc_handle_failes() {

#[test]
#[should_panic]
#[cfg(debug_assertions)]
fn unnamed_semaphore_acquiring_non_ipc_capable_handle_fails() {
let handle = UnnamedSemaphoreHandle::new();
let _sut1 = UnnamedSemaphoreBuilder::new()
Expand Down
Loading

0 comments on commit 4dc37ec

Please sign in to comment.