-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add support for Cargo #10
Comments
I actually took a stab at this the other day. I am really close but ran into an issue. I am happy to dig into it more tonight and this weekend. |
Here's my progress so far: tjpeden@38529b1 There are some formatting changes in Let me know if you want/need me to change anything I've done. I'm compiling a few other libraries from rust but I'm not 100% sure if we need/want them? |
I'm now sure how to tell Cargo to let the makefiles dictate the target dirs. Thoughts? |
@tjpeden Did you forget to commit the Cargo.toml file? AFAIK, you can't call
We only need the core crate in this case.
If you mean telling cargo to use a custom target directory, then you can use a configuration file with the following key: # .cargo/config
[build]
target-dir = "custom/target/directory" Then cargo will output the binary/docs to "custom/target/directory" instead of the default "target" directory. |
Other thoughts: With cargo support we wouldn't need the build_core.sh script. There is cargo crate: rust-libcore that builds the core crate when used as a dependency. Ideally, I'd like to only use cargo to build particle applications. I'm envisioning something like this:
I'm sure this is feasible because I have done the Can anyone point me to information about particle's bootloader or bootloaders in general. Does the bootloader expect an ELF file that starts at some specific address, other than 0x08000000? Does the particle's bootloader expect the ELF file to contain some specific symbols? |
@japaric woah, that would be pretty awesome :) |
@japaric, you're right, I did. Fixed. Also just committed my attempt at using All of that aside, everything I've seen online has cautioned against using that crate, but maybe that's wrong? I like the idea of using only cargo for building and programming the rust code. What crate should we use to test being able to use Unfortunately, my fiance won't let me work on it anymore today. lol |
@japaric, I really like that project you linked. I think that would be an awesome way to model the Particle Rust support |
@japaric This is looking great. Thank you! Photon firmware consists of several dynamically linked modules. If you run
The addresses and number of modules may be different on different platforms. I often reference this file in the CLI: https://github.com/spark/particle-cli/blob/master/lib/deviceSpecs/specifications.js Additionally, there are several pieces of data prepended and appended to our modules using linker scripts. Here's a tool for reading them: https://github.com/spark/binary-version-reader Hope that helps! |
I guess you can let About the *.a file, you should be able to use something like
You mean the rust-libcore crate? What's the argument against it? The zinc project also uses that crate to build the core crate.
You can test with the @towynlin That's pretty helpful. I took a quick look and I'm starting to understand how the pieces fall together. Looks like the |
Added the spin crate and got the following error running
This is how I have the [package]
name = "application"
version = "0.1.0"
authors = ["TJ Peden <[email protected]>"]
[lib]
crate-type = ["staticlib"]
[dependencies]
rust-libcore = "0.0.3"
spin = "0.3.5" I'm not sure how to fix that. |
@tjpeden Ah right, |
IRC? |
Yeah, I asked one of the core devs that's working on Rust cross compilation story. Cargo doesn't support this use case out the box, but there's an RFC with a possible solution for this but requires adding new features to cargo. I also received an idea on how to support this use case without needing new cargo features but hasn't been explored/implemented yet. The idea is that you create a "sysroot" (a directory tree) that contains the cross compiled core crate, and then configure cargo to use |
Awesome! Thanks @japaric |
@japaric love your goal of a cargo build process, would love to see the build process work like that. |
I created a cargo sysroot subcommand that implements the solution I mentioned above. More details in the README. This subcommand depends on this cargo PR, which hasn't landed yet, so it's not currently usable with the latest cargo nightly. @tjpeden You may want to test that ^. You'll need to compile cargo checked out at that PR though. |
I will indeed |
@japaric I am having trouble building Cargo on that branch. Is there something special one has to do other than the instructions in the readme? |
Cargo is a Cargo project, so I just did |
That works a lot better, thanks! |
This is what I got:
|
@tjpeden Ah, yes. |
I'm getting the same thing :-/ |
Could you add --verbose and pass it along? |
done |
Okay, I think I have this setup wrong.
Do I have |
There's a typo in this command
The target is missing a "v": thumbv7m-none-eabi, because that's the name of the spec file: thumbv7m-none-eabi.json. Once you fix the typo you should see this line in the log:
This could have been detected and the tool could have informed you about this, but I haven't implemented nice error reporting (yet). P.S. If you are using zinc's target specification files then delete the "data-layout" field from the file or you'll hit this issue. |
I apologize, I should have caught that. I'm using the target file from However, the
It's not an access issue (I'm on Ubuntu) so I'm not sure what would cause it to fail. Thoughts? |
If you get a LLVM assertion while building the core crate, remove the "data-layout" field from the json file should fix. It's problem that appeared in recent nightlies.
No idea with just that information. But I pushed a debug branch to cargo-sysroot, it'll print the src and dst arguments of the failing fs::copy and will also preserve the temporary directory so you can inspect it. You can install that branch with Also, could we take this discussion somewhere else? Either the cargo-sysroot bug tracker or to IRC (I'm japaric on freenode, I'm on #rust, #cargo, #particle, etc) |
What's the status here? I'm waiting for advances in Cargo support in order to continue working on library features :) |
Any news, @tjpeden? |
I received my Photon this past Monday and got a LED blinking using the P.S. I was hoping to use the |
@japaric Instructions on how to compile the firmware locally can be found here. All the firmware and a ton of information can be found in that repo. There's also this write up which contains more details about the build setup. Thanks for helping out, I'm looking forward to using Cargo with the Photon! |
I took the route (b) I mentioned before and I got a working Cargo project that builds photon apps. |
@japaric that's awesome, could you contribute that as a PR? |
actually, now that I'm looking at your repo, I suppose that doesn't make a ton of sense, since it's a rebuild and not a fork |
Awesome! This week I'm quite busy but I'll take a closer look next week. |
Cargo is the Rust package manager. It handles metadata, compilation and dependencies.
If we want to properly integrate with the Rust library ecosystem, we should support Cargo.
This would replace #7 and #8.
The text was updated successfully, but these errors were encountered: