Open shepmaster opened 3 years ago
I came here to file this same bug. https://book.avr-rust.com/003-building-a-crate-for-avr.html#compiling-a-crate says
A target specification JSON file should almost always be specified.
But I couldn’t find how to make or obtain such a file. The shepmaster shows how to generate a file, but what customizations are typically needed?
I can't directly answer your question, but I can point at two real-world examples:
Note: Make sure to document the --eh-frame-hdr
option referred to in #17.
More information on this subject can be found in the Embedonomicon chapter on custom targets, which in turn points to the docs on the two rustc
structs populated from this file: Target
and TargetOptions
, and also provides some guidance on the modifications you might need to make to the base file.
It's also worth looking through the target spec JSON files for chips supported by Rahix/avr-hal: https://github.com/Rahix/avr-hal/tree/c9a724f7367772b4d836b0f49ec1237911254b2b/chips
Once https://github.com/rust-lang/rust/pull/74941 lands the preferred way to do this will be rustc -Z unstable-options --print target-spec-json --target avr-unknown-gnu-atmega328 > my-target.json
which will be added to the doc. From there, the only things needed to update the file to a new MCU will be cpu
and the -mmcu
option passed to the linker so that it uses the same CPU.
Added link to Embedonomicon in 66db0fb4bc5c8cfdafa193779faf760ca5b18705, thanks @couchand
Regarding the replacement of avr-unknown-unknown
with avr-unknown-gnu-atmega328
in rust-lang/rust#74941
I want to make a clearer distinction that this target is for the "GNU pathway". I can imagine that some downstream users might not AVR GCC for linking at all - for example, when the build target is a static library for use via FFI in C code which does not need to be linked for distribution.
There has been some work on AVR support in the LLD linker and compiler-rt, at some point in the future it should be possible to use the compiler without the GNU tools.
Note: the avr-unknown-unknown
target as currently in Rust master is not correct - it uses the host linker. rust-lang/rust#74941 will fix it.
e.g.