-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
RFC: Merging the avr-rust fork upstream #44052
Comments
+1! Avr rust built into the compiler proper would be super useful. It's almost free of bugs now. |
Not completely free of bugs :) I will update the description to include some information about the state of the backend w.r.t bugs |
Almost though 😄. Just a couple to go |
In general we're quite welcoming of platforms upstream in rust-lang/rust so long as they don't place a maintenance burden on us! Some specific thoughts from what you're thinking:
In general we currently have all platforms with the same uniform interface of libcore/libstd, but it's not clear that'll remain true into as we keep picking up more platforms. |
It is because of bugs in LLVM. The only question in my mind is on support of It is still quite likely that we could get I think that the best way forward would be to propose the patch for real once libcore does compile without modification, or at least without many. |
Sounds reasonable to me! |
My main fear of not supporting |
I don't think that it's a terribly huge deal here. Small embedded devices already have giant limitations (no stdin / stdout, generally no allocator, etc.) that make it real hard to just drop in an arbitrary library. I recently learned that AVR GCC's I think we are always going to have special features that are used to make a crate suitable for embedded, just like we do for no-std. |
You are describing the
Interesting! I do agree that if we'd alias |
Absolutely, and I realize I didn't clearly state that I think we should implement i128 for AVR. However, any code that actually uses an
Consistency with what, is the question. Consistency with GCC (
Yep, which is why I said "special features that are used to make a crate suitable for embedded, just like we do for no-std." 😇 |
A larger problem that's been in the back of my mind since we originally landed the 16-bit |
The name |
Good points here, I can see the concern around 128-bit integers. I definitely think that they should be supported, even though we shouldn't encourage their usage. I would hate to see crates having to add feature flags for things like trait impls on The f32/64 problem is an interesting one. My main concern with making f64 actually 64-bits is that it means that C FFI could be very brittle. If developers don't know that AVR-GCC uses 32-bit doubles, then calls through FFI could read uninitialised memory or segfault. I imagine we could solve this more-or-less by expecting users to use types from the |
Something to remember for merging, need to update the Edit: opened an issue for this since it affects MSP430 as well: #44934 |
@mattico Maybe I've just been doing things in a weird way, but none of my code has made use of Rust's #[no_mangle]
pub extern fn main() { More importantly, we can't really return because there's nothing to return to. Every program needs to run forever. |
@mattico We will still definitely have to modify libc so the types match GCC for AVR |
Oh, absolutely, I just don't know that |
@shepmaster Even on non-embedded platforms, the size of It probably would've taken the same amount of time to submit a fix as it did to type this out, now that I think about it 😄 |
Is it just the libcore issues preventing this merge? Just so we know where to concentrate efforts. |
The only issues I've had out of libcore are weird linker errors caused by I don't know what and also 32 bit bitshifting errors (missing intrinsic I think). I don't know if those are blocking the merge though. |
Yes - all of the required work here needs to be done within LLVM.
That's because all of the code that makes the AVR backend choke is commented out :)
Not directly, but it'd be good to have fixed before the backend is merged. There are a couple of really annoying bugs like this that we should consider fixing before we merge, but they may not necessarily hold it up. |
@dylanmckay LLVM6 has been merged #47828 - what does that mean to this RFC? |
@kellerkindt all of the issues listed in "Current issues in the AVR backend" are still true. It's likely that the current HEAD of avr-rust could be rebased and the interesting Rust-specific code merged, but that still doesn't get working code. I'm personally still in favor of
Although having to avoid extra rebasing is nice. |
I wonder the current state of Rust on AVR, now that we're half of a year later in development. I run a little Arduino projects group in my town, and I would love to be able to use Rust instead. |
…nas-schievink Enable AVR as a Tier 3 target upstream Tracking issue: rust-lang#44052. Things intentionally left out of the initial upstream: * The `target_cpu` flag I have made the cleanup suggestions by @jplatte and @jplatte in avr-rust@043550d. Anybody feel free to give the branch a test and see how it fares, or make suggestions on the code patch itself.
…s-schievink Enable AVR as a Tier 3 target upstream Tracking issue: rust-lang#44052. Things intentionally left out of the initial upstream: * The `target_cpu` flag I have made the cleanup suggestions by @jplatte and @jplatte in avr-rust@043550d. Anybody feel free to give the branch a test and see how it fares, or make suggestions on the code patch itself.
The fork has been merged! I will write a proper update this afternoon |
I am interested in said update. Where do you plan to post it @dylanmckay (so I know where to look 🙂)? |
I've been eagerly awaiting this addition to the Rust ecosystem for literally years now! My naive attempts to use this on master seem flawed however. I built master rust with the standard
This fails with:
I'm assuming there's configuration still required which I'm missing. |
@nixpulvis see #44052 (comment) I wouldn’t expect much of anything to work now as libcore is part of what is miscompiled. |
The AVR rustc fork has been merged upstream. The upstream fork is not usable in general yet. There are a few things that need to happen first. AVR LLVM upstream fixes that Rust doesn't have yet need to be cherry-pickedTo answer @nikic's question, there are a maximum of 20 LLVM commits that need to be cherry-picked. I have been using a script to automatically cherry-pick all AVR commits from LLVM upstream into a local fork. Compiling the AVR LED blink program from the upstream Rust master branchAs the upstream effort has been going on for a few months now, the downstream avr-rust fork I am not sure if there have been other changes in upstream Rust which need changes for AVR - likely not. Once I've gotten the blink program working, I will post another update because at that point, the upstream AVR support should be ready for use/experimentation. Where should AVR communication occur/be posted@wezm you raise a good point - there isn't necessarily a "blessed" communication channel for updates. This ticket has served well, but it will be inevitably closed soon. The AVR-Rust Gitter channel is the most natural existing choice. I like the idea of a mailing list (but I don't like the idea of hosting a mail server if possible). The Gitter channel does have discussion in it so perhaps something like a mailing list would be helpful. Open questions
The most important stuff for the future (read: priorities)
For the moment, I will make sure to repost updates into this GitHub issue, until a better medium can be found. I will post them in Gitter too. |
My personal preference is strongly in favour of a blog (with an RSS feed). I think blogs typically show up better in search engine results and are nicer to link to than mailing list threads. The RSS feed solves the checking/notification aspect. |
I’m not 100% sure it’s the best place for it, but there is the Embedded WG blog. Might be a low effort channel for communication. |
Perhaps also a Twitter account? It can be used to share new blog posts (to stay up to date). |
I think the embedded working group would be happy to help here. We have a Twitter account @rustembedded and can certainly include AVR-related news in the newsletter too. I've also created the |
Update. There are two things remaining before
Once these two things are done, the upstreamed Rust AVR target will be able to compile AVR code to the same level as the current avr-rust/rust fork, and we can then begin the process of updating the |
One more TODO:
Here's the branch with everything: https://github.com/dylanmckay/rust/commits/dylan/avr-workable-upstream-candidate. This branch is sufficient to compile libcore. It is built from upstream |
Update: Opened a pull request that includes all of the upstream LLVM fixes. Here is an exhaustive list of the remaining work before the LED blink program can be compiled and run successfully. Remaining work
|
I'm assuming this is the correct issue: rust-lang/cargo#4959. |
|
@shepmaster that seems to be getting me closer anyway, thanks! I just seem to be stuck on the bitcast stuff now, so I'll wait for that to be merged in (since I appear to be missing a file needed to build the PR, and IDK what I'm doing). In the process of using |
|
I don't think this matters too much on the user side. This was easy enough to find through ddg and/or this-week-in-rust. |
I think the instructions for compiling Rust with AVR should be somehow in https://docs.rust-embedded.org/ |
Alright, update time. All of the required patches for AVR exist in the current Rust nightly compiler as of today's nighty
The Rust nightly compiler can now be considered the recommended channel for Rust with AVR support. I am closing this issue now - we did it! Steps for reporting bugs can be found in the AVR Guidebook. The AVR Guidebook and the blink example at https://github.com/avr-rust/blink are the best resources to start using the target. A deep, deep thanks to everybody who discussed and supported the project through this upstreaming effort - it is very appreciated. FIN |
Wow wow wow. Thanks for everyone who contributed to this – I've been looking forward to this day since forever! |
Hello all,
I would like to know the general opinions on merging the avr-rust fork into Rust proper.
The fork itself has became a lot more stable with less bugs in the recent months. It has also started attracting a number of people interested in using it.
You can find one of the more interesting projects using avr-rust on GitHub.
Blockers
LLVM 5.0
Rust is currently on LLVM 4.0, which contains a working AVR backend, but there have been many bugfixes since then. We would need to wait for LLVM 5.0 to be supported (nearly finished: #43370) before we get a version of the AVR backend that has a few important bugs fixed.This is no longer a blocker. Upstream Rust is at LLVM 6.0 as of 2018-02-20.
Questions
Cherry-picking fixes
If AVR support was built into mainline, we'd need to be able to cherry-pick patches into Rust's LLVM fork. I don't imagine this would be much of a problem, as we already cherry-pick a number of important fixes into there.
All of the bugfixes cherry-picked into the avr-rust repository have already been upstreamed into LLVM trunk, which would continue to be the case if we merged the fork, as I am not a fan of the LLVM fork diverging too far from trunk.
Cherry-picking is necessary because of LLVM's 6-month release cycle.
Current issues in the AVR backend
There aren't any known bugs in the avr-rust/rust repository - all of the known bugs are issues in the AVR LLVM backend; here are some of the more interesting/impactful ones.
libcore
cannot be compiled without modificationThere is a milestone set up to track what bugs need to be fixed in order to get
libcore
compiling successfully without modification.This hasn't been much of a problem for users so far, as xargo will transparently compile
libcore
on the fly when needed, and we can override libcore inXargo.toml
.I am unsure what the Rust team thinks of merging a target which can't use the stock libcore.
Any operations on function pointers other than 'call' access RAM, not program memory (avr-rust#68)
This is a symptom of AVR being the very first in-tree LLVM backend for a Harvard architecture. LLVM currently assumes that all functions reside in "the generic address space", which corresponds to RAM. Because of this, if you attempt to load/store through a function pointer, it will access RAM instead of the program memory.
Good news is that I have pending upstream LLVM patches to fix it (D37052, D37053, D37054, D37057).
32-bit shifts generate calls to a
compiler-rt
routine that doesn't exist (avr-llvm/llvm#163)Because there aren't many (if any) targets that don't support 32-bit shifts natively,
libgcc
andcompiler-rt
do not have 32-bit versions of shift routine, even though LLVM still happily generates a call to it.This causes an undefined symbol error whilst linking. This will only happen if you actually write code or use code that performs 32-bit shifts, as the linker is quite good at removing all dead code.
Note that I've had one user hit the missing shift bug due to compiling in release mode, which promoted a multiplication to a shift as an "optimisation".
Actual changes to merge
You can find all AVR-specific differences by looking at this diff.
Note that over half of that diff is just the README and Travis CI configuration - the actual code being upstreamed is very small; just some glue code to enable the AVR backend and a target specification.
This diff also conditionally disables parts of
libcore
for AVR - these fixes would not upstreamed, and are not strictly required as downstream users can use Xargo to compile a minifiedlibcore
for AVR).Links
AVR-Rust on Gitter
AVR-Rust on GitHub
The text was updated successfully, but these errors were encountered: