Skip to content

Commit 4dc37ec

Browse files
authored
Merge pull request #479 from elBoberido/iox2-349-enable-all-cargo-feature-flags-on-bazel
[#349] Add remaining cargo feature flags to bazel
2 parents a657228 + 97264ae commit 4dc37ec

File tree

16 files changed

+179
-47
lines changed

16 files changed

+179
-47
lines changed

.cirrus.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ iox2_common_build_debug_template: &IOX2_COMMON_BUILD_DEBUG
8181

8282
iox2_common_build_and_test_debug_template: &IOX2_COMMON_BUILD_AND_TEST_DEBUG
8383
<<: *IOX2_COMMON_BUILD_DEBUG
84-
test_script: cargo nextest run --workspace --no-fail-fast
84+
test_script: cargo nextest run --workspace --all-targets --no-fail-fast
8585

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

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

9393
iox2_ffi_common_debug_template: &IOX2_FFI_COMMON_DEBUG
9494
ffi_script:
@@ -134,14 +134,14 @@ iox2_freebsd_setup_template: &IOX2_FREEBSD_SETUP
134134
# Filter to run the CI only on the main branch or for pull request to the main branch
135135
#
136136

137-
only_if: ( $CIRRUS_BRANCH == 'main' || ($CIRRUS_PR != '' && $CIRRUS_BASE_BRANCH == 'main'))
137+
only_if: false && ( $CIRRUS_BRANCH == 'main' || ($CIRRUS_PR != '' && $CIRRUS_BASE_BRANCH == 'main'))
138138

139139
#
140140
# Global environment variables
141141
#
142142

143-
env:
144-
RUSTFLAGS: "-C debug-assertions"
143+
# env:
144+
# RUSTFLAGS: "-C debug-assertions"
145145

146146
#
147147
# Preflight-Check with Ubuntu x86 stable debug
@@ -226,6 +226,8 @@ ubuntu_22_04_x64_stable_release_task:
226226
# Pipeline 4
227227

228228
ubuntu_22_04_aarch64_min_version_debug_task:
229+
# TODO run only after merge on main branch
230+
only_if: $CIRRUS_BRANCH == 'main'
229231
depends_on: preflight_check
230232
skip: "changesIncludeOnly('.github/**', '**.md')"
231233
<<: *IOX2_CONTAINER_UBUNTU_22_04_AARCH64
@@ -254,6 +256,8 @@ ubuntu_22_04_aarch64_beta_debug_task:
254256
# Pipeline 5
255257

256258
ubuntu_22_04_aarch64_stable_release_task:
259+
# TODO run only after merge on main branch
260+
only_if: $CIRRUS_BRANCH == 'main'
257261
depends_on: preflight_check
258262
skip: "changesIncludeOnly('.github/**', '**.md')"
259263
<<: *IOX2_CONTAINER_UBUNTU_22_04_AARCH64
@@ -268,6 +272,8 @@ ubuntu_22_04_aarch64_stable_release_task:
268272
# Pipeline 6
269273

270274
arch_linux_x64_stable_debug_task:
275+
# TODO commented out due to limited CI time
276+
only_if: false
271277
depends_on: preflight_check
272278
skip: "changesIncludeOnly('.github/**', '**.md')"
273279
<<: *IOX2_CONTAINER_ARCH_LINUX_X64

.github/workflows/build-test.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ on:
66
pull_request:
77
branches: [ main, release* ]
88

9-
env:
10-
RUSTFLAGS: "-C debug-assertions"
9+
# env:
10+
# RUSTFLAGS: "-C debug-assertions"
1111

1212
jobs:
1313
changes:
@@ -208,7 +208,7 @@ jobs:
208208
run: cargo build --workspace --all-targets ${{ matrix.mode.arg }} --target i686-unknown-linux-gnu
209209

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

213213
- name: Build language bindings
214214
run: |
@@ -313,7 +313,7 @@ jobs:
313313
run: cargo build --workspace --all-targets ${{ matrix.mode.arg }}
314314

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

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

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

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

432432
freebsd:
433433
needs: [preflight-check, static-code-analysis]
@@ -457,7 +457,7 @@ jobs:
457457
if: ${{ needs.changes.outputs.source-code == 'true' }}
458458
strategy:
459459
matrix:
460-
os: [ubuntu-latest]
460+
os: [ubuntu-24.04]
461461
toolchain: [stable]
462462
timeout-minutes: 60
463463
runs-on: ${{ matrix.os }}
@@ -480,7 +480,6 @@ jobs:
480480
run: bazel build //...
481481

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

486485
grcov:

BUILD.bazel

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

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

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

1718
exports_files([
@@ -22,6 +23,7 @@ exports_files([
2223
#
2324
# Config & Platform support
2425
#
26+
2527
config_setting(
2628
name = "linux",
2729
constraint_values = ["@platforms//os:linux"],
@@ -39,11 +41,91 @@ config_setting(
3941
flag_values = {"@bazel_tools//tools/cpp:compiler": "msvc-cl"},
4042
)
4143

44+
#
45+
# Rust Feature Flags
46+
#
47+
4248
string_flag(
4349
name = "feature_dev_permissions",
4450
build_setting_default = "auto",
4551
visibility = ["//visibility:public"],
4652
)
53+
config_setting(
54+
name = "dev_permissions_auto",
55+
flag_values = {
56+
"//:feature_dev_permissions": "auto",
57+
},
58+
)
59+
config_setting(
60+
name = "dev_permissions_enabled",
61+
flag_values = {
62+
"//:feature_dev_permissions": "on",
63+
},
64+
)
65+
# NOTE: while this seems superfluous, it is the pattern for cases where *_auto is on by default;
66+
# therefore this target is introduced to keep all feature flags consistent
67+
selects.config_setting_group(
68+
name = "cfg_feature_dev_permissions",
69+
match_any = [
70+
"//:dev_permissions_enabled",
71+
],
72+
)
73+
74+
string_flag(
75+
name = "feature_logger_log",
76+
build_setting_default = "auto",
77+
visibility = ["//visibility:public"],
78+
)
79+
config_setting(
80+
name = "logger_log_auto",
81+
flag_values = {
82+
"//:feature_logger_log": "auto",
83+
},
84+
)
85+
config_setting(
86+
name = "logger_log_enabled",
87+
flag_values = {
88+
"//:feature_logger_log": "on",
89+
},
90+
)
91+
# NOTE: while this seems superfluous, it is the pattern for cases where *_auto is on by default;
92+
# therefore this target is introduced to keep all feature flags consistent
93+
selects.config_setting_group(
94+
name = "cfg_feature_logger_log",
95+
match_any = [
96+
":logger_log_enabled",
97+
],
98+
)
99+
100+
string_flag(
101+
name = "feature_logger_tracing",
102+
build_setting_default = "auto",
103+
visibility = ["//visibility:public"],
104+
)
105+
config_setting(
106+
name = "logger_tracing_auto",
107+
flag_values = {
108+
"//:feature_logger_tracing": "auto",
109+
},
110+
)
111+
config_setting(
112+
name = "logger_tracing_enabled",
113+
flag_values = {
114+
"//:feature_logger_tracing": "on",
115+
},
116+
)
117+
# NOTE: while this seems superfluous, it is the pattern for cases where *_auto is on by default;
118+
# therefore this target is introduced to keep all feature flags consistent
119+
selects.config_setting_group(
120+
name = "cfg_feature_logger_tracing",
121+
match_any = [
122+
":logger_tracing_enabled",
123+
],
124+
)
125+
126+
#
127+
# Alias
128+
#
47129

48130
alias(
49131
name = "iceoryx2",
@@ -75,6 +157,10 @@ alias(
75157
visibility = ["//visibility:public"],
76158
)
77159

160+
#
161+
# all_srcs
162+
#
163+
78164
filegroup(
79165
name = "all_srcs",
80166
srcs = glob([

FAQ_ICEORYX_DEVS.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Frequently Asked Questions - iceoryx Developer Edition
2+
3+
## Tests marked with `#[should_panic]` attribute do not panic in release builds
4+
5+
This usually happens when the panic is triggert via a `debug_assert` macro.
6+
This macro is not active when the `-C debug-assertions` flag is not set, which
7+
is the case for release builds.
8+
To fix this problem, just add a `#[cfg(debug_assertions)]` to the test.
9+
10+
```rs
11+
#[test]
12+
#[should_panic]
13+
#[cfg(debug_assertions)]
14+
fn accessing_uninitialized_foo_fails() {
15+
// ...
16+
}
17+
```
18+
19+
## The bazel build fails with an error mentioning `crate_index`, `manifest` and `Cargo.toml`
20+
21+
The error looks similar to this:
22+
23+
```ascii
24+
An error occurred during the fetch of repository 'crate_index'
25+
...
26+
Error computing the main repository mapping: no such package '@@crate_index//'
27+
...
28+
Error: Some manifests are not being tracked. Please add the following labels to the `manifests` key: {
29+
"//iceoryx2-foo/bar:Cargo.toml",
30+
}
31+
```
32+
33+
It seems a new crate is added to the root `Cargo.toml` and bazel is complaining
34+
that it is not added to the `WORKSPACE.bazel` file for the `crate_index` target.

doc/bazel/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ build --@iceoryx2//:foo=on
241241
| Feature Flag | Valid Values | Crate Default |
242242
| ----------------------- | ---------------------------- | ------------------ |
243243
| dev_permissions | auto, on, off | auto == off |
244+
| logger_log | auto, on, off | auto == off |
245+
| logger_tracing | auto, on, off | auto == off |
244246

245247
## Instructions for iceoryx2 Developers
246248

iceoryx2-bb/lock-free/tests/bitset_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ fn bit_set_set_single_bit_works() {
106106

107107
#[test]
108108
#[should_panic]
109+
#[cfg(debug_assertions)]
109110
fn bit_set_set_bit_outside_of_bitset_leads_to_panic() {
110111
const CAPACITY: usize = 1551;
111112
let sut = BitSet::new(CAPACITY);

iceoryx2-bb/log/BUILD.bazel

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

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

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

1718
filegroup(
@@ -22,10 +23,19 @@ filegroup(
2223
rust_library(
2324
name = "iceoryx2-bb-log",
2425
srcs = glob(["src/**/*.rs"]),
26+
crate_features = select({
27+
"//:cfg_feature_logger_log": [
28+
"logger_log"
29+
],
30+
"//conditions:default": [],
31+
}) + select({
32+
"//:cfg_feature_logger_tracing": [
33+
"logger_tracing"
34+
],
35+
"//conditions:default": [],
36+
}),
2537
deps = [
2638
"//iceoryx2-pal/concurrency-sync:iceoryx2-pal-concurrency-sync",
2739
"@crate_index//:termsize",
2840
],
2941
)
30-
31-
# TODO: [349] add feature flags

iceoryx2-bb/posix/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,4 @@ rust_library(
3838
],
3939
)
4040

41-
# TODO: [349] add feature flags
4241
# TODO: [349] add tests

iceoryx2-bb/posix/tests/ipc_capable_trait_tests.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ mod ipc_capable {
3939

4040
#[test]
4141
#[should_panic]
42+
#[cfg(debug_assertions)]
4243
fn creating_ipc_construct_from_uninitialized_handle_panics<Sut: TestSut>() {
4344
let sut_handle = Sut::Handle::new();
4445

@@ -47,6 +48,7 @@ mod ipc_capable {
4748

4849
#[test]
4950
#[should_panic]
51+
#[cfg(debug_assertions)]
5052
fn creating_ipc_construct_from_process_local_handle_panics<Sut: TestSut>() {
5153
let sut_handle = Sut::Handle::new();
5254
Sut::init_process_local_handle(&sut_handle);
@@ -65,6 +67,7 @@ mod ipc_capable {
6567

6668
#[test]
6769
#[should_panic]
70+
#[cfg(debug_assertions)]
6871
fn init_handle_twice_panics<Sut: TestSut>() {
6972
let sut_handle = Sut::Handle::new();
7073
Sut::init_process_local_handle(&sut_handle);

iceoryx2-bb/posix/tests/semaphore_tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ fn unnamed_semaphore_multiple_ipc_semaphores_are_working() {
425425

426426
#[test]
427427
#[should_panic]
428+
#[cfg(debug_assertions)]
428429
fn unnamed_semaphore_acquire_uninitialized_ipc_handle_failes() {
429430
let handle = UnnamedSemaphoreHandle::new();
430431

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

434435
#[test]
435436
#[should_panic]
437+
#[cfg(debug_assertions)]
436438
fn unnamed_semaphore_acquiring_non_ipc_capable_handle_fails() {
437439
let handle = UnnamedSemaphoreHandle::new();
438440
let _sut1 = UnnamedSemaphoreBuilder::new()

0 commit comments

Comments
 (0)