Skip to content

Commit

Permalink
meson: Attempt to build a basic zbus Rust program with meson
Browse files Browse the repository at this point in the history
```
$ meson setup build --wipe --reconfigure \
  -Dconcurrent-queue-2-rs:feature-default=true \
  -Dfutures-io-0.3-rs:feature-default=true \
  -Dfutures-lite-2-rs:feature-default=true
```

Error:

```
Executing subproject zbus-5.1.1-rs:async-io-2-rs:rustix-0.38-rs method cargo

rustix-0.38-rs| Generated Meson AST: /root/openbmc/dbus-sensors/build/subprojects/rustix-0.38.37/meson.build
rustix-0.38-rs| Project name: rustix
rustix-0.38-rs| Project version: 0.38.37
rustix-0.38-rs| Rust compiler for the host machine: rustc -C linker=cc (rustc 1.83.0)
rustix-0.38-rs| Rust linker for the host machine: rustc -C linker=cc ld.bfd 2.43.1-2

subprojects/rustix-0.38.37/meson.build:105:-1: ERROR: Unknown variable "linux_raw_sys_options".
```

Change-Id: I3283f7b5d23546fef48fcbeb6dc1736606fb7939
Signed-off-by: Peter Delevoryas <[email protected]>
peterdelevoryas committed Nov 30, 2024
1 parent d7be555 commit bffbb42
Showing 4 changed files with 61 additions and 1 deletion.
8 changes: 7 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
project(
'dbus-sensors',
'cpp',
default_options: ['warning_level=3', 'werror=true', 'cpp_std=c++23'],
'rust',
default_options: [
'warning_level=3',
'werror=true',
'cpp_std=c++23',
'rust_std=2021',
],
license: 'Apache-2.0',
version: '0.1',
meson_version: '>=1.1.1',
12 changes: 12 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -116,3 +116,15 @@ endif
if get_option('tests').allowed()
subdir('tests')
endif

subproject('zbus-5.1.1-rs', required: true)
zbus_dep = dependency('zbus-5.1.1-rs')

executable(
'smbpbisensor',
'smbpbi.rs',
install: true,
dependencies: [
zbus_dep,
],
)
33 changes: 33 additions & 0 deletions src/smbpbi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use std::{error::Error, future::pending};
use zbus::{connection, interface};

struct Greeter {
count: u64
}

#[interface(name = "org.zbus.MyGreeter1")]
impl Greeter {
// Can be `async` as well.
fn say_hello(&mut self, name: &str) -> String {
self.count += 1;
format!("Hello {}! I have been called {} times.", name, self.count)
}
}

// Although we use `tokio` here, you can use any async runtime of choice.
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let greeter = Greeter { count: 0 };
let _conn = connection::Builder::session()?
.name("org.zbus.MyGreeter")?
.serve_at("/org/zbus/MyGreeter", greeter)?
.build()
.await?;

// Do other things or go to wait forever
pending::<()>().await;

Ok(())
}


9 changes: 9 additions & 0 deletions subprojects/zbus-5.1.1-rs.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[wrap-file]
method = cargo
directory = zbus-5.1.1
source_url = https://crates.io/api/v1/crates/zbus/5.1.1/download
source_filename = zbus-5.1.1.tar.gz
source_hash = 1162094dc63b1629fcc44150bcceeaa80798cd28bcbe7fa987b65a034c258608

[provide]
dependency_names = zbus-5.1.1-rs

0 comments on commit bffbb42

Please sign in to comment.