@@ -119,10 +119,12 @@ By including a C header from ``include/`` into
bindings for the included subsystem. After building, see the ``*_generated.rs``
output files in the ``rust/bindings/`` directory.
-For parts of the C header that ``bindgen`` does not auto generate, e.g. C
-``inline`` functions or non-trivial macros, it is acceptable to add a small
-wrapper function to ``rust/helpers/`` to make it available for the Rust side as
-well.
+C ``inline`` functions will only be generated if the function name is
+specified in ``rust/bindgen_static_functions``.
+
+For parts of the C header that ``bindgen`` does not auto generate, e.g.
+non-trivial macros, it is acceptable to add a small wrapper function
+to ``rust/helpers/`` to make it available for the Rust side as well.
Abstractions
~~~~~~~~~~~~
@@ -1,10 +1,12 @@
# SPDX-License-Identifier: GPL-2.0
bindings_generated.rs
+bindings_generated_static.rs
bindings_helpers_generated.rs
doctests_kernel_generated.rs
doctests_kernel_generated_kunit.c
uapi_generated.rs
exports_*_generated.h
+extern.c
doc/
test/
@@ -10,14 +10,17 @@ always-$(CONFIG_RUST) += exports_core_generated.h
# for Rust only, thus there is no header nor prototypes.
obj-$(CONFIG_RUST) += helpers/helpers.o
CFLAGS_REMOVE_helpers/helpers.o = -Wmissing-prototypes -Wmissing-declarations
+CFLAGS_REMOVE_extern.o = -Wmissing-prototypes -Wmissing-declarations -Wdiscarded-qualifiers
always-$(CONFIG_RUST) += libmacros.so
no-clean-files += libmacros.so
-always-$(CONFIG_RUST) += bindings/bindings_generated.rs bindings/bindings_helpers_generated.rs
-obj-$(CONFIG_RUST) += bindings.o kernel.o
+always-$(CONFIG_RUST) += bindings/bindings_generated.rs bindings/bindings_helpers_generated.rs \
+ bindings/bindings_generated_static.rs
+obj-$(CONFIG_RUST) += bindings.o kernel.o extern.o
always-$(CONFIG_RUST) += exports_helpers_generated.h \
- exports_bindings_generated.h exports_kernel_generated.h
+ exports_bindings_generated.h exports_bindings_static_generated.h \
+ exports_kernel_generated.h
always-$(CONFIG_RUST) += uapi/uapi_generated.rs
obj-$(CONFIG_RUST) += uapi.o
@@ -301,6 +304,21 @@ quiet_cmd_bindgen = BINDGEN $@
-o $@ -- $(bindgen_c_flags_final) -DMODULE \
$(bindgen_target_cflags) $(bindgen_target_extra)
+quiet_cmd_bindgen_static = BINDGEN $@
+ cmd_bindgen_static = \
+ $(BINDGEN) $< $(bindgen_target_flags) \
+ --use-core --with-derive-default --ctypes-prefix core::ffi --no-layout-tests \
+ --no-debug '.*' --enable-function-attribute-detection \
+ --experimental --wrap-static-fns \
+ --wrap-static-fns-path $(src)/extern.c \
+ $(bindgen_static_functions) \
+ -o $@ -- $(bindgen_c_flags_final) -DMODULE \
+ $(bindgen_target_cflags) $(bindgen_target_extra)
+
+$(src)/extern.c: $(obj)/bindings/bindings_generated_static.rs \
+ $(src)/bindings/bindings_helper.h
+ @sed -i 's|#include ".*|#include "bindings/bindings_helper.h"|g' $@
+
$(obj)/bindings/bindings_generated.rs: private bindgen_target_flags = \
$(shell grep -Ev '^#|^$$' $(src)/bindgen_parameters)
$(obj)/bindings/bindings_generated.rs: private bindgen_target_extra = ; \
@@ -309,6 +327,15 @@ $(obj)/bindings/bindings_generated.rs: $(src)/bindings/bindings_helper.h \
$(src)/bindgen_parameters FORCE
$(call if_changed_dep,bindgen)
+$(obj)/bindings/bindings_generated_static.rs: private bindgen_target_flags = \
+ $(shell grep -Ev '^#|^$$' $(src)/bindgen_parameters)
+$(obj)/bindings/bindings_generated_static.rs: private bindgen_static_functions = \
+ $(shell grep -Ev '^#|^$$' $(src)/bindgen_static_functions)
+$(obj)/bindings/bindings_generated_static.rs: $(src)/bindings/bindings_helper.h \
+ $(src)/bindgen_static_functions \
+ $(src)/bindgen_parameters FORCE
+ $(call if_changed_dep,bindgen_static)
+
$(obj)/uapi/uapi_generated.rs: private bindgen_target_flags = \
$(shell grep -Ev '^#|^$$' $(src)/bindgen_parameters)
$(obj)/uapi/uapi_generated.rs: $(src)/uapi/uapi_helper.h \
@@ -352,6 +379,9 @@ $(obj)/exports_helpers_generated.h: $(obj)/helpers/helpers.o FORCE
$(obj)/exports_bindings_generated.h: $(obj)/bindings.o FORCE
$(call if_changed,exports)
+$(obj)/exports_bindings_static_generated.h: $(obj)/extern.o FORCE
+ $(call if_changed,exports)
+
$(obj)/exports_kernel_generated.h: $(obj)/kernel.o FORCE
$(call if_changed,exports)
@@ -431,6 +461,7 @@ $(obj)/bindings.o: private rustc_target_flags = --extern ffi
$(obj)/bindings.o: $(src)/bindings/lib.rs \
$(obj)/ffi.o \
$(obj)/bindings/bindings_generated.rs \
+ $(obj)/bindings/bindings_generated_static.rs \
$(obj)/bindings/bindings_helpers_generated.rs FORCE
+$(call if_changed_rule,rustc_library)
new file mode 100644
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+
+# Don't generate structs
+--blocklist-type '.*'
+
+--allowlist-function blk_mq_rq_to_pdu
@@ -39,6 +39,10 @@ mod bindings_raw {
env!("OBJTREE"),
"/rust/bindings/bindings_generated.rs"
));
+ include!(concat!(
+ env!("OBJTREE"),
+ "/rust/bindings/bindings_generated_static.rs"
+ ));
}
// When both a directly exposed symbol and a helper exists for the same function,
@@ -18,6 +18,7 @@
#include "exports_core_generated.h"
#include "exports_helpers_generated.h"
#include "exports_bindings_generated.h"
+#include "exports_bindings_static_generated.h"
#include "exports_kernel_generated.h"
// For modules using `rust/build_error.rs`.