Description
Hi! 👋
During Oxidizeconf's impl days @oli-obk and I talked about adding a very restricted version of disk writes to const fn
contexts. This is an issue to continue that conversation.
Motivation
For the CLI WG we want to generate files during compilation such as shell completions, and man pages.
Currently the best way to achieve this is by creating a build.rs
file, and making sure the right structs are exported. This is not great, because it's easy to mess up, the use of build.rs
triggers a double compilation, and certain dependencies also need to be required in as both [dependencies]
and [dev-dependencies]
.
Instead it would be a lot nicer if there was a way to generate output during compilation that wouldn't require any additional setup beyond the usual flow of using crates.
Current Proposal
The idea we discussed was to add a limited form of writing files to const fn
. The reasoning for limited filesystem access, rather than full access is to prevent people from writing output in a prior compile, and reading it back in during a next compile, causing problems for reproducibility.
What we discussed was something akin to read_bytes!
/ const fs::read
, but for writing output to a special folder somewhere in target/
that gets removed at the start of each build to ensure no data from a prior build persists.
Thanks! ✨