-
Notifications
You must be signed in to change notification settings - Fork 721
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
Migrate build to be entirely cargo-based, with make as integration tool #4075
Conversation
If recursive includes work in the Cargo config, I'm wondering whether it would perhaps make sense to create configs for both ARM and RISC-V, and have those in turn include the common Tock config. I think it'd be nice if we could have boards only include one config file. |
I think there is benefit to a pick-and-choose approach. Boards (specifically out-of-tree boards) can just pick what they need without worrying about nesting. Maybe no one needs that, though. |
If you want to see what we can remove from make with this change, my branch is here: https://github.com/tock/tock/compare/pr4054-bradjc2-makefile?expand=1 |
Why is this happening now:
|
rustflags = [ | ||
"-Z", "virtual-function-elimination" | ||
] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, maybe I'm being obnoxious, but this is exactly what we don't want I think. Letting one-offs / "this magic line is necessary for this board to work" slip into the hidden config file. I feel like we should add a cargo/earlgrey-cw310.toml
or similar somewhere and include it to pull this in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, need to look into this and what happened here. That line should have already been there (aka not be green).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As explained here in the original PR, this is not "magically need it for this board to work," this is already in the Makefiles as a "magic" VFUNC
variable that is only enabled for the earlgrey board.
This is a code size optimization that is still considered unstable and dangerous (because I guess it is not always correct) but saves a bunch of code size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In particular, I'd argue this is significantly more hidden and obscure in the Makefiles where it is abstracted behind some custom variable name you have to chase down (basically via the Makefile equivalent of #ifdef
s).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I define "hidden" as if I grep
for virtual-function-elimination
will it show up. Living in a hidden file / directory, the answer is no; living in a Makefile or anything not hidden, the answer is yes. The .
of .cargo
is a cancer.
Example: | ||
|
||
```toml | ||
include = [ | ||
"../../cargo/tock_flags.toml", | ||
"../../cargo/unstable_flags.toml", | ||
] | ||
|
||
[unstable] | ||
config-include = true | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every board also seems to have some build target.
[build]
target = "thumbv7em-none-eabi"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This guide is how to use the extra configs, not how to configure a board. Maybe that fits in the porting guide.
boards/cargo/panic_abort_tests.toml
Outdated
[unstable] | ||
# Build test crates with the `panic = "abort"` strategy. Tests use `unwind` by | ||
# default which causes incompatability with `core` built via `-Zbuild-std`. | ||
panic-abort-tests = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have a comment about when a board might want this, and when they wouldn't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If and only if they have tests
"../../../cargo/virtual_function_elimination.toml", | ||
"../../../cargo/panic_abort_tests.toml", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to leave a comment about why these are needed for earlgrey but not other boards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fear the answer might be "I don't know. The Makefile already did that for some reason."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate that, but that should have been requested when first added.
[target.'cfg(target_arch = "riscv32")'] | ||
runner = "./run.sh" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, it would be great to comment why this exists here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, that is already there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, this is a super standard Cargo thing. We can comment, but it basically invokes the run.sh
command in the earlgray crate directory when running cargo run
(in turn, this is script basically runs the opentitan qemu).
Anyone willing to bite on why CI fails? I don't know what's different. |
Any cargo aficionados know how to replicate
in cargo-land?
Also this issue seems the same? rust-lang/cargo#13146 |
Okay, We still have some mutable references to mutable statics in tests. I looked into fixing this proper, as there's not really a good reason for all of these to be mutable statics in the first place. However, that is a much more invasive change and will take some time to get ready. This is orthogonal to this PR, and as such I don't think we should block this on that. Another lesson learned is that we don't promote warnings to errors in |
Anyone know how we can suppress the following warning that shows up in our docs builds (and generally in builds, depending on your toolchain)?
FWIW, I've been seeing this locally for a while now, even before these changes. Edit: @alevy working on this! |
I don't think this is actually a problem. I can run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me apart from these comments.
boards/nordic/.cargo/config.toml
Outdated
@@ -0,0 +1,14 @@ | |||
# Licensed under the Apache License, Version 2.0 or the MIT License. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm skittish about having these configs in directories other than the board crate itself. It would seem to me like this inconsistency could result in confusion down the line. Same applies to, e.g., the LiteX boards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah... you're probably right. The small bit of savings isn't worth the inconsistency. Will fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The linker file is shared, what's the difference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is appropriate to put the config in the parent directory. That is consistent with not using the .cargo files for customization beyond what is strictly necessary, and our other shared build system features (eg build.rs, linker files, cargo/ toml files, Makefile.common).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel particularly strongly about this, but one thing that's different from our build.rs
, linker files, cargo/*.toml
files is that these are all shared resources that are explicitly referenced by something that's in a board directory.
On the other hand, .cargo/config.toml
files in any parent directory are implicitly picked up by Cargo. Once consequence of relying on configs in parent directories then is that, were you to copy a Nordic board crate to somewhere else (e.g., use it as a template for a top-level board crate in boards/
), it would silently no longer take this shared config into account. This is different from, e.g., our linker script, where you'd get an error because the relative path to it has changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could get behind a restriction that .cargo dirs can only exist in a folder with a Cargo.toml in Tock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could get behind a restriction that .cargo dirs can only exist in a folder with a Cargo.toml in Tock.
I'd support that, with the additional restriction that that Cargo.toml
must not be a workspace root Cargo.toml
(i.e., only actual crates should have a .cargo/config.toml
). The rest we'd solve with includes, which implies that their contents will not be hidden.
We have a remaining problem, which is that
Which means that when it's set in the Makefiles at all, it replaces anything set in the config. |
Why is it set in the makefile? |
Well, in |
I think I've addressed all the outstanding issues, including:
|
? |
Hrm... It worked for me, sorry! Perhaps my environment is actually picking a different cargo than yours. Will investigate. |
Instead, just override the rules in earlgrey that are the only ones that rely on it (to set features).
@bradjc fixed I think (turns out with Nix we're not using Not ideal, but at least it's not an error. I don't have a concrete suggestion for what to do otherwise. |
That's what I was thinking we would have to do. Hopefully cargo stabilizes this soon-ish. It doesn't seem controversial to want to see the configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did not go through all files again, but these incremental changes all look good to me and I'm in favor of this overall direction.
Pull Request Overview
(Supplants #4054)
Adds support to all boards for building using plain-old-cargo with make as an instrumentation tool. Building in both ways are identical to building using
make
before this PR.Without this change, in order to build with
cargo
, one needs a large number ofRUSTFLAGS
along with cargo-specific arguments. With this change, simply:$ cd boards/[BOARD-OF-CHOICE] $ cargo build --release
This is done by adding
.cargo/config.toml
files to each board which include config TOMLs fromboards/cargo
.With this change, it is also easy to use tools such as
cargo-binutils
andprobe-rs
which rely on being able to runcargo build
with normal arguments. For example, in the sma_q3 board, it is now possible to flash and attach the JLink RTT by simply installingprobe-rs
and running:Testing Strategy
Continuous Integration
TODO or Help Wanted
Documentation Updated
/docs
, or no updates are required.Formatting
make prepush
.