avr-device
avr-device copied to clipboard
Investigate crate-size optimizations
Right now we're calling form
and rustfmt
to split out the auto-generated modules into many files. I don't think this provides much value as nobody is going to look at those file anyway.
I have a suspicion that we could reduce the crate (download) size a bit by not calling form
. For rustfmt on the other hand I am completely unsure whether it helps or not. svd2rust
does generate a lot of unnecessary whitespace but I do not know whether rustfmt
generates more or less (due to indentation). A rust minifier would of course be the best solution here ;)
Looks like rustfmt makes files larger. Though if anyone wants to look at the source, a non-formatted file makes it completely impossible while a formatted but large single file (from not calling form) at least leaves some possibility to look at the code.
Another consideration in support of running the generated code through rustfmt are the documentation src links. I think it's more likely users would click through the source links to investigate the code then opening the file directly. Keeping this well formatted seems worth the space tradeoff. For similar reasons I'd be less excited about a minifier as it makes it harder to inspect.
Another potentially interesting approach I tried implementing a while back was moving the code generation to build-time (ref: https://github.com/stm32-rs/stm32-rs/pull/5). Assuming the majority of the crate size is related to carrying the generated files for all supported processors, this approach only requires the input to the code generation. The tradeoff is that the user would need to generate for their target processor (once) during build.rs. One nice aspect was that it used svd2rust as a library and in specifying it as a build dependency could explicitly pin it to a specific version. This is a win as users could more reliably reproduce a build (since the svd2rust version you have installed and build with isn't specified anywhere).
edit: I found some additional discussion on build-time generation here: https://github.com/stm32-rs/stm32-rs/issues/8
Another consideration in support of running the generated code through rustfmt are the documentation src links. I think it's more likely users would click through the source links to investigate the code then opening the file directly. Keeping this well formatted seems worth the space tradeoff. For similar reasons I'd be less excited about a minifier as it makes it harder to inspect.
I was thinking people probably won't be looking at the generated sources much but maybe I am wrong about that.
Another potentially interesting approach I tried implementing a while back was moving the code generation to build-time.
That is actually what we were doing in the past, before avr-device
was published to crates.io. The problem is that we have some python components in the build process which led to dependency hell for getting things to work. Especially for the AVR stuff I think the setup should be as simple as possible because this target attracts a lot of people with little experience in the embedded systems space (coming from Arduino C/C++).
If all the generation tools were rust though, I think the story would be different.
Anyway, I think for now let's keep it like it is until a complaint about crate size/anything else comes in.
Why not try generating more code at build time? atdf2svd
, svd2rust
, form
and svdtools
are all rust packages. With the exception of atdf2svd
all crates have a lib.rs published, so calling out to them from build.rs should be straightforward. You could remove the Makefile and python dependency