Skip to content

Demonstrate how to get the target JSON file #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
shepmaster opened this issue Jul 24, 2020 · 6 comments
Open

Demonstrate how to get the target JSON file #10

shepmaster opened this issue Jul 24, 2020 · 6 comments

Comments

@shepmaster
Copy link
Member

e.g.

rustc -Z unstable-options --print target-spec-json --target avr-unknown-unknown > my-target.json
@SimonSapin
Copy link

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?

@shepmaster
Copy link
Member Author

@dylanmckay
Copy link
Member

Note: Make sure to document the --eh-frame-hdr option referred to in #17.

@couchand
Copy link

couchand commented Jul 31, 2020

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

@dylanmckay
Copy link
Member

Once rust-lang/rust#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 66db0fb, thanks @couchand

@dylanmckay
Copy link
Member

dylanmckay commented Jul 31, 2020

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.

laris added a commit to laris/avr-rust-template that referenced this issue Oct 11, 2020
…ook.avr-rust.com](avr-rust/book.avr-rust.com#10);  rustup override set nightly; rustc --print target-spec-json -Z unstable-options --target avr-unknown-gnu-atmega328p > my-custom-avr-unknown-gnu-atmega328.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants