Implementing QEMU devices in Rust

Like any new convert, I fervidly want to use Rust for everything. Right now, I want to use it to write a device simulator for QEMU on Linux. Right now I'm writing the glue Make code to compile rust. It is pretty close to working. i.e. I can get it to run what looks like the right rustc command:

rustc -C panic=abort --emit=obj -o hw/ft/hord-rust.o /home/working/git/qemu/hw/ft/hord-rust.rs

Unfortunately, I get the following message:

error: could not copy "hw/ft/hord-rust.hord_rust.7rcbfp3g-cgu.0.rcgu.o" to "hw/ft/hord-rust.o": No such file or directory (os error 2)

I know that the directory hw/ft exists in the current directory and have verified that this is the directory in which the rustc command is being run, so it seems like hw/ft/hord-rust.hord_rust.7rcbfp3g-cgu.0.rcgu.o is the file that doesn't exist. But this doesn't make sense since this should be a file created by rustc.

So, anyone see anything dumb I'm missing?

2 Likes

Is there any reason for you not to use Cargo, aside from learning?

1 Like

By setting the RUSTC_LOG environment variable you can tweak rustc's internal logging. If you set RUSTC_LOG=debug, does it show anything interesting?

RUSTC_LOG=debug rustc -C panic=abort --emit=obj -o hw/ft/hord-rust.o /home/working/git/qemu/hw/ft/hord-rust.rs

(note: you may want to pipe stderr and stdout to a file because it can generate a lot of output)

I recommend you to check Linux Kernel modules in Rust, qemu uses Kconfig like Linux kernel does, and the building system roughly similar. It should help to understand how to build some skeleton driver.

Thanks, that's probably going to be helpful. I'm a Linux kernel developer, so this was the next step anyway.

This turned out to my an error unrelated to using rustc. Rustc compiles things just fine.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.