refactor(core/rust): bindgen wrapper for calling static micropython functions
What changed, and why it matters
This commit is a straightforward internal code refactor. It adds a small C wrapper file so that Rust code can call two specific internal MicroPython functions that are declared as static/inline in headers. There is no user-facing change, no bug fix, and no security-relevant behavior change visible in the diff.
No security action required. Treat as normal refactoring; review the wrapper functions for correctness during routine code review if desired.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change enables bindgen’s wrap_static_fns feature and supplies a manually-written bindgen-static.c containing thin wrappers (mp_obj_list_get__extern, mp_obj_list_set_len__extern) around mp_obj_list_get and mp_obj_list_set_len. The wrappers are added to both firmware and unix build source lists. This is purely plumbing to expose existing MicroPython list APIs to Rust; it does not alter the functions’ semantics or add new call sites.
Changed components
core/embed/rust/build.rscore/embed/upymod/bindgen-static.ccore/embed/upymod/build.rscore/SConscript.firmwarecore/SConscript.unixcore/embed/rust/micropython.hInspect captured patch +20 / −0
diff --git a/core/SConscript.firmware b/core/SConscript.firmware
index 1db15073..ced67a24 100644
--- a/core/SConscript.firmware
+++ b/core/SConscript.firmware
@@ -314,6 +314,7 @@ SOURCE_MOD += [
# rust mods
SOURCE_MOD += [
+ 'embed/upymod/bindgen-static.c',
'embed/upymod/rustmods.c',
]
diff --git a/core/SConscript.unix b/core/SConscript.unix
index 79c88d7d..2cc254c0 100644
--- a/core/SConscript.unix
+++ b/core/SConscript.unix
@@ -296,6 +296,7 @@ SOURCE_MOD += [
# rust mods
SOURCE_MOD += [
+ 'embed/upymod/bindgen-static.c',
'embed/upymod/rustmods.c',
]
diff --git a/core/embed/rust/build.rs b/core/embed/rust/build.rs
index 98dc5ef1..05c26dd4 100644
--- a/core/embed/rust/build.rs
+++ b/core/embed/rust/build.rs
@@ -40,6 +40,9 @@ fn generate_micropython_bindings(lib: &mut CLibrary) -> Result<()> {
lib.add_rust_bindings_ex("micropython", |builder| {
Ok(builder
.header("micropython.h")
+ // Needed to call header statics like mp_obj_list_set_len. See also upymod/build.rs.
+ .wrap_static_fns(true)
+ //.wrap_static_fns_path(PathBuf::from(out_dir.clone()).join("bindgen-static"))
// obj
.new_type_alias("mp_obj_t")
.allowlist_type("mp_obj_type_t")
diff --git a/core/embed/rust/micropython.h b/core/embed/rust/micropython.h
index 8fe33f6b..6951690d 100644
--- a/core/embed/rust/micropython.h
+++ b/core/embed/rust/micropython.h
@@ -2,6 +2,7 @@
#include "py/mphal.h"
#include "py/nlr.h"
#include "py/obj.h"
+#include "py/objlist.h"
#include "py/objstr.h"
#include "py/runtime.h"
diff --git a/core/embed/upymod/bindgen-static.c b/core/embed/upymod/bindgen-static.c
new file mode 100644
index 00000000..c23ca715
--- /dev/null
+++ b/core/embed/upymod/bindgen-static.c
@@ -0,0 +1,11 @@
+#include "py/obj.h"
+#include "py/objlist.h"
+
+// Static wrappers
+
+void mp_obj_list_get__extern(mp_obj_t self_in, size_t *len, mp_obj_t **items) {
+ mp_obj_list_get(self_in, len, items);
+}
+void mp_obj_list_set_len__extern(mp_obj_t self_in, size_t len) {
+ mp_obj_list_set_len(self_in, len);
+}
diff --git a/core/embed/upymod/build.rs b/core/embed/upymod/build.rs
index 077958b8..08892b69 100644
--- a/core/embed/upymod/build.rs
+++ b/core/embed/upymod/build.rs
@@ -95,6 +95,9 @@ fn main() -> Result<()> {
lib.add_private_include("../rust");
lib.add_sources([
+ // Wrappers for micropython static/inline header functions that are called from rust.
+ // Currently needs to be updated manually even though it's generated by bindgen.
+ "bindgen-static.c",
"modtimeq.c",
"modutime.c",
"rustmods.c",
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.