Open nicholasbishop opened 1 year ago
I took a look at this, and I think it would be quite difficult to do right now with const types and functions. Many of the tools we want are available in unstable Rust, but it may be a while before it becomes straightforward to do in stable Rust. A couple specific things:
BuildNode
interface wouldn't work at all. There is a fairly straightforward workaround for this one, albeit not super ergonomic: we could generate a big BuildNode
enum containing all the node types.copy_from_slice
or anything like that. You could copy the bytes one at a time in a loop, but you can't even use a for loop in a const fn, so it all has to be done very manually and verbosely. EDIT: mut refs in const fns were stabilized in 1.83Given the difficulties, and the fact that this will (probably) get easier in the future as more things get stabilized, and the fact that I suspect fully const/static device paths are rare, I recommend we not try to add a const device path builder yet. Some potential alternatives for projects that want this:
build.rs
. You can add uefi-rs as a build dependency and use the regular DevicePathBuilder
to create a path, then call as_bytes
to get the raw bytes. Write those raw bytes out to a file and include_bytes!
in your source. Or generate a bit of Rust code containing the raw bytes and include!
that.DevicePathBuilder
. Compare the byte slices and make sure they match.Lastly, it's totally possible I missed something in my exploration of what const fns can do, and maybe it's not actually as hard to add a const device path builder as I think -- happy to hear if I missed anything!
The approach with build.rs
might be a good solution. That's a good idea.
Splitting this off from https://github.com/rust-osdev/uefi-rs/issues/970.
Originally posted by @blitz in https://github.com/rust-osdev/uefi-rs/issues/970#issuecomment-1775618414