[PATCH] rust: hw: Add the extensible Meson compilation method

0 views
Skip to first unread message

chenmiao

unread,
Oct 21, 2025, 8:18:08 AM (2 days ago) Oct 21
to chao...@openatom.club, luo...@openatom.club, dz...@openatom.club, plu...@openatom.club, hust-os-ker...@googlegroups.com
Currently, although there are only two available devices under rust/hw (one
at each level, pl011 and hpet), I believe we should also perform operations
similar to those in hw/char/meson.build, as shown below:

system_ss.add(when: 'CONFIG_PL011_C', if_true: files('pl011.c'))

Additionally, since Meson does not support directly including a subdir using
the above syntax, I will check based on <target>-config-device.h/mak and then
include the subdir in the compilation.

Now, rust/hw can simply decide whether to build the corresponding device in a
manner similar to the above. This is a very simple and effective approach.

Signed-off-by: chenmiao <chen...@openatom.club>
---
rust/hw/char/meson.build | 10 +++++++++-
rust/hw/timer/meson.build | 10 +++++++++-
2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/rust/hw/char/meson.build b/rust/hw/char/meson.build
index 5716dc4..9d61d6b 100644
--- a/rust/hw/char/meson.build
+++ b/rust/hw/char/meson.build
@@ -1 +1,9 @@
-subdir('pl011')
+char_configuration = {
+ 'pl011': config_devices_data.get('CONFIG_X_PL011_RUST', 0) == 1,
+}
+
+foreach k, v : char_configuration
+ if v
+ subdir(k)
+ endif
+endforeach
diff --git a/rust/hw/timer/meson.build b/rust/hw/timer/meson.build
index 22a84f1..d211b87 100644
--- a/rust/hw/timer/meson.build
+++ b/rust/hw/timer/meson.build
@@ -1 +1,9 @@
-subdir('hpet')
+timer_configuration = {
+ 'hpet': config_devices_data.get('CONFIG_X_HPET_RUST', 0) == 1,
+}
+
+foreach k, v : timer_configuration
+ if v
+ subdir(k)
+ endif
+endforeach
--
2.43.0

Chao Liu(openatom.club)

unread,
Oct 21, 2025, 9:14:38 AM (2 days ago) Oct 21
to chenmiao, luo...@openatom.club, dz...@openatom.club, plu...@openatom.club, hust-os-ker...@googlegroups.com
On 10/21/2025 8:17 PM, chenmiao wrote:
> Currently, although there are only two available devices under rust/hw (one
> at each level, pl011 and hpet), I believe we should also perform operations
> similar to those in hw/char/meson.build, as shown below:
>
> system_ss.add(when: 'CONFIG_PL011_C', if_true: files('pl011.c'))
>
> Additionally, since Meson does not support directly including a subdir using
> the above syntax, I will check based on <target>-config-device.h/mak and then
> include the subdir in the compilation.
>
> Now, rust/hw can simply decide whether to build the corresponding device in a
> manner similar to the above. This is a very simple and effective approach.
>

A conditional check has been added in the meson.build file under the
path rust/hw/char/pl011:

rust_devices_ss.add(when: 'CONFIG_X_PL011_RUST', if_true: [declare_dependency(
link_whole: [_libpl011_rs],
variables: {'crate': 'pl011'},
)])

Therefore, the upper-level meson.build only needs to include the subdirectory.
Reply all
Reply to author
Forward
0 new messages