Skip to content

Commit 729c030

Browse files
authored
Merge pull request #926 from ojeda/rust-build_error
rust: build_error: fix several issues and remove `WARN`
2 parents d9b2e84 + 021f66b commit 729c030

File tree

4 files changed

+15
-34
lines changed

4 files changed

+15
-34
lines changed

lib/Kconfig.debug

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2800,40 +2800,21 @@ config RUST_OVERFLOW_CHECKS
28002800

28012801
If unsure, say Y.
28022802

2803-
choice
2804-
prompt "Build-time assertions"
2805-
default RUST_BUILD_ASSERT_DENY
2803+
config RUST_BUILD_ASSERT_ALLOW
2804+
bool "Allow unoptimized build-time assertions"
28062805
depends on RUST
28072806
help
28082807
Controls how are `build_error!` and `build_assert!` handled during build.
28092808

28102809
If calls to them exist in the binary, it may indicate a violated invariant
28112810
or that the optimizer failed to verify the invariant during compilation.
2812-
You can choose to abort compilation or ignore them during build and let the
2813-
check be carried to runtime.
2814-
2815-
If optimizations are turned off, you cannot select "Deny".
2816-
2817-
If unsure, say "Deny".
2818-
2819-
config RUST_BUILD_ASSERT_ALLOW
2820-
bool "Allow"
2821-
help
2822-
Unoptimized calls to `build_error!` will be converted to `panic!`
2823-
and checked at runtime.
2824-
2825-
config RUST_BUILD_ASSERT_WARN
2826-
bool "Warn"
2827-
help
2828-
Unoptimized calls to `build_error!` will be converted to `panic!`
2829-
and checked at runtime, but warnings will be generated when building.
28302811

2831-
config RUST_BUILD_ASSERT_DENY
2832-
bool "Deny"
2833-
help
2834-
Unoptimized calls to `build_error!` will abort compilation.
2812+
This should not happen, thus by default the build is aborted. However,
2813+
as an escape hatch, you can choose Y here to ignore them during build
2814+
and let the check be carried at runtime (with `panic!` being called if
2815+
the check fails).
28352816

2836-
endchoice
2817+
If unsure, say N.
28372818

28382819
config RUST_KERNEL_KUNIT_TEST
28392820
bool "KUnit test for the `kernel` crate" if !KUNIT_ALL_TESTS

rust/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ obj-$(CONFIG_RUST) += alloc.o bindings.o kernel.o
1919
always-$(CONFIG_RUST) += exports_alloc_generated.h exports_bindings_generated.h \
2020
exports_kernel_generated.h
2121

22-
ifdef CONFIG_RUST_BUILD_ASSERT_DENY
23-
always-$(CONFIG_RUST) += build_error.o
24-
else
22+
ifdef CONFIG_RUST_BUILD_ASSERT_ALLOW
2523
obj-$(CONFIG_RUST) += build_error.o
24+
else
25+
always-$(CONFIG_RUST) += build_error.o
2626
endif
2727

2828
obj-$(CONFIG_RUST) += exports.o

rust/build_error.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,3 @@
2222
pub const fn build_error(msg: &'static str) -> ! {
2323
panic!("{}", msg);
2424
}
25-
26-
#[cfg(CONFIG_RUST_BUILD_ASSERT_WARN)]
27-
#[link_section = ".gnu.warning.rust_build_error"]
28-
#[used]
29-
static BUILD_ERROR_WARNING: [u8; 45] = *b"call to build_error present after compilation";

rust/exports.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@
1919
#include "exports_alloc_generated.h"
2020
#include "exports_bindings_generated.h"
2121
#include "exports_kernel_generated.h"
22+
23+
// For modules using `rust/build_error.rs`.
24+
#ifdef CONFIG_RUST_BUILD_ASSERT_ALLOW
25+
EXPORT_SYMBOL_RUST_GPL(rust_build_error);
26+
#endif

0 commit comments

Comments
 (0)