<re_irc>
<@korken89:matrix.org> What's the easiest way to get libs that use "defmt" to also be testable? If one simply has "defmt" and runs "cargo test" one gets errors on the from of missing symbols to "_defmt_acquire", "_defmt_release", "_defmt_write", "_defmt_timestamp" - and I think I'm not the first to run into this :)
<re_irc>
<@jamesmunns:beeper.com> (I don't think aarch64 cores actually use the nvic? Tho some of the side cores which are -m profiles certainly do)
<re_irc>
<@2:0x2c.org> how do you typically integrate bindgen in a crate if you don't auto-generate bindings on build? xtask?
<re_irc>
<@2:0x2c.org> plain shell script?
<re_irc>
<@jamesmunns:beeper.com> You have three main choices imo:
<re_irc>
- If the bindings/config don't change often, better to build them and check them in, maybe have bash or xtask for regenerating when needed
<re_irc>
- If you don't mind having bindgen installed, you can "shell out" from the build rs, which saves a lot of time building bindgen itself
<re_irc>
- Then the typical "bindgen as a lib import in your build rs"
<re_irc>
<@jamesmunns:beeper.com> I basically prefer them in that order, and honestly if I'm doing choice one I just use a bash script, but if you have xtask or just or whatever already, any of those work too.
<re_irc>
<@2:0x2c.org> thanks!
<re_irc>
<@jamesmunns:beeper.com> Bindgen publishes release binaries on GH I think, so you can always grab them in CI as well instead of "cargo install bindgen", which saves an absolute ton of CI time, and serves to pin your bindgen version
<re_irc>
<@jamesmunns:beeper.com> (works for both option 1 + 2)
re_irc has quit [*.net *.split]
dnm has quit [*.net *.split]
re_irc has joined #rust-embedded
dnm_ has joined #rust-embedded
<re_irc>
<@2:0x2c.org> i'm not at CI yet
<re_irc>
<@jamesmunns:beeper.com> Gotcha! But yeah, even just having the bash script (or whatever) serves as good documentation on how to rebuild things next time.
<re_irc>
<@2:0x2c.org> now i need to figure out what it means by "error: requires "start" lang_item"
<re_irc>
<@jamesmunns:beeper.com> What are you building? That usually means you are building a binary without an rt crate like cortex-m-rt
<re_irc>
<@jamesmunns:beeper.com> Or, if you meant to build a staticlib, you have a bin crate instead of a staticlib crate
<re_irc>
<@jamesmunns:beeper.com> tldr, it means you are trying to build a binary with no defined entry point
<re_irc>
<@jamesmunns:beeper.com> Or honestly just get a full mask instead lol
lehmrob has joined #rust-embedded
lehmrob has quit [Client Quit]
limpkin has quit [Quit: limpkin]
limpkin has joined #rust-embedded
<re_irc>
<@2:0x2c.org> yea, i'm building a cortex-m system using silicon labs gecko sdk
<re_irc>
<@2:0x2c.org> so i'm using their startup and libc crt
<re_irc>
<@jamesmunns:beeper.com> What gets booted into after the crt? Rust or C?
<re_irc>
<@jamesmunns:beeper.com> If C, you probably want to change your crate type to staticlib instead of bin.
<re_irc>
<@jamesmunns:beeper.com> If Rust, you might want to consider switching to cortex-m-rt instead, or you'll need to strategically copy some of the things it does, specifically defining a start/entry point.
<re_irc>
<@2:0x2c.org> yea i just made a pub extern "C" fn main
<re_irc>
<@jamesmunns:beeper.com> Yeah, theres a bit more life before main you need to make happen.
<re_irc>
<@2:0x2c.org> i'm still deciding how to arrange things
<re_irc>
<@jamesmunns:beeper.com> Usually start calls main
<re_irc>
<@2:0x2c.org> oh yea that all comes from my library crate
<re_irc>
<@2:0x2c.org> well, startup and then libc crt takes over
<re_irc>
<@jamesmunns:beeper.com> : You also probably need no_mangle
<re_irc>
<@adamgreig:matrix.org> have you got "#![no_main]" and what target are you building for?
<re_irc>
<@2:0x2c.org> : yea i copied the macro "#[export_name = "main"]"
<re_irc>
<@2:0x2c.org> it's linking now
<re_irc>
<@jamesmunns:beeper.com> : Oh that's a good call too, forgot that
<re_irc>
<@2:0x2c.org> 200KB... lots of vendor stuff
<re_irc>
<@jamesmunns:beeper.com> (these bits aren't needed if you are making a staticlib crate and calling into it from C/ASM)
<re_irc>
<@2:0x2c.org> yea i'm using the bin crate to link the binary
<re_irc>
<@2:0x2c.org> that way i can have several different bin crates for different binaries
<re_irc>
<@jamesmunns:beeper.com> When mixing C and Rust, it's a pretty good idea to make a clear decision of which lang is the "host" and which is the "guest".
<re_irc>
<@2:0x2c.org> i'm making a C/rust/C sandwich
<re_irc>
<@jamesmunns:beeper.com> So if Rust is the host, use cmrt and have a rust main that calls c, if C is the host, make a C main that calls into rust as a lib
<re_irc>
<@jamesmunns:beeper.com> : _in general_, I'd advise not-this, but ymmv, and you know your details better than I do :)
<re_irc>
<@2:0x2c.org> is there something i need to call to initialized core or alloc?
<re_irc>
<@2:0x2c.org> * initialize
<re_irc>
<@jamesmunns:beeper.com> Nope, just make sure bss is zeroed and .data is initialized
<re_irc>
<@2:0x2c.org> : I'd prefer not to use the enormous vendor SDK, but it's so much code, and they do lots of codegen, and they do some RTOS shenanigans
<re_irc>
<@jamesmunns:beeper.com> This comes mostly from the fact that every time you cross the lang boundary, you have to be an expert at C and Rust to debug when things go wrong, and write a fair bit of unsafe code in Rust, which is harder to get right
<re_irc>
<@jamesmunns:beeper.com> So the less you do that (in general), the better. But I totally understand real world details change the equation.
<re_irc>
<@2:0x2c.org> it's already a bit of a gamble to use rust instead of C/C++
<re_irc>
<@jamesmunns:beeper.com> Yeah, sometimes I would even lean on "use less rust", and limit it to a well segmented application layer, like a full rtos task, or "black box" business logic library/component
<re_irc>
<@2:0x2c.org> that's my goal
<re_irc>
<@2:0x2c.org> i'm just using a rust main to see what's up
<re_irc>
<@2:0x2c.org> and i'm not sure how i can do a bin crate with C code
<re_irc>
<@2:0x2c.org> now i can do cargo build and get a binary
<re_irc>
<@jamesmunns:beeper.com> With a staticlib, you'd use C's build system (make, cmake, whatever the SDK provides) and use cargo to build a .a file to link in.
<re_irc>
<@2:0x2c.org> yea, i didn't want that
<re_irc>
<@2:0x2c.org> seems cargo doesn't set "CARGO_BIN_NAME" for build.rs
<re_irc>
<@2:0x2c.org> i tried to place a map file next to the binary in the target directory, but i can't figure out how to get to that path
<re_irc>
<@2:0x2c.org> ah yes exactly what i thought would happen is happening - the vendor code cannot be linked as a static library because sections/symbols are being dropped
<re_irc>
<@2:0x2c.org> i need to use some --whole-archive thing from build.rs
<re_irc>
<@jamesmunns:beeper.com> What linker script are you trying cargo to use?
<re_irc>
<@jamesmunns:beeper.com> * telling
<re_irc>
<@jamesmunns:beeper.com> Cortex m rt provides a base linker script, but it may not be retaining symbols from your SDK, especially if you are not interacting with them.
<re_irc>
<@2:0x2c.org> yea, i'm using the linker script from the sdk
<re_irc>
<@2:0x2c.org> bummer, can't use bundled libraries and link:+whole-archive in stable
<re_irc>
<@2:0x2c.org> ok i guess i need to completely change how i do this build
<re_irc>
<@2:0x2c.org> or find a way to force the linker script to use all objects
<re_irc>
<@2:0x2c.org> oh cool, i managed to do it
<re_irc>
<@2:0x2c.org> you need to output something like: "cargo:rustc-link-lib=static:+whole-archive,-bundle=efr32bg22-sys"
<re_irc>
<@2:0x2c.org> the "-bundle" is the key
<re_irc>
<@2:0x2c.org> now i have a stack and everything is running
dc740 has quit [Remote host closed the connection]