-
Notifications
You must be signed in to change notification settings - Fork 83
Conversation
I can't add example's dependency, so I used dev-dependency. I'm curious, in Rust 2018, we no longer need extern crates. In that era how rustc knows what lib to be linked for example programs? |
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.
Thanks for the PR!
We don't run examples by default so could you add cargo run --example qemu --target $TARGET
to ci/script.sh
? This should only run when the target is thumbv7m-none-eabi
.
examples/qemu.rs
Outdated
|
||
#[exception] | ||
#[inline(always)] | ||
fn HardFault(_ef: &ExceptionFrame) -> ! { |
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.
nit: this (the whole function) is not required because there is a default implementation so it can be removed
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.
done.
examples/qemu.rs
Outdated
|
||
#[exception] | ||
#[inline(always)] | ||
fn DefaultHandler(_irqn: i16) {} |
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.
nit: same case as HardFault; this can be removed
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.
done.
.cargo/config
Outdated
@@ -0,0 +1,3 @@ | |||
[target.thumbv7m-none-eabi] | |||
# uncomment this to make `cargo run` execute programs on QEMU | |||
runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -semihosting-config enable=on,target=native -nographic -kernel" |
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 forgot that we didn't have a .cargo/config in this repo. You'll at least need -C link-arg=-Tlink.x
to produce a valid binary. It'd be easiest to just copy over this part and you can remove the commented out bits.
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.
@japaric The above did a trick and qemu
now prints and exits as expected.
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.
done.
examples/qemu.rs
Outdated
|
||
// hint to the optimizer that any code path which calls this function is statically unreachable | ||
unsafe { | ||
unreachable::unreachable(); |
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 would prefer to omit this line because this may be run on hardware with semihosting disabled and then debug::exit
would return and this line would be executed and that'd be equivalent to UB (undefined behavior). We usually add a loop {}
to the end of main to make it type check (since it's a divergent function).
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 unsafe block removed.
Yes, that's OK. Dependencies that are only used by examples should be dev-dependencies. That way they don't get compiled when this crate is compiled as a dependency of another (reduces compile time).
If you write something like use foo::bar;
// .. then rustc assumes that there is an implicit This crate is still using the 2015 edition though so we still need the |
Thanks, @japaric for the Rust 2018 explanation! Now CI fails to compile examples/alignment which I didn't touch.
|
The failure is due to redundant options |
Of course, I also need to install |
You can use addons for that. |
https://travis-ci.org/rust-embedded/cortex-m-rt/jobs/431175116#L891 Interesting. It seems that the version of QEMU that's shipped with Ubuntu trusty doesn't understand the Perhaps it's possible to install addons:
apt:
sources:
- debian-sid
packages:
- qemu-system-arm I think that's the correct syntax. |
@sekineh the debian-sid stuff doesn't work; I tried it in rust-embedded/embedonomicon#24. But you can use this pre-compiled version of QEMU; you can use rust-embedded/embedonomicon#24 as a reference. |
It seems precompiled version is handier than docker images. Thanks. I’ll do it in this week! |
@japaric I think it can be merged. Notable change other than |
@sekineh Great! Thank you. bors r+ |
👎 Rejected by too few approved reviews |
bors r+ |
128: Add qemu example and run in CI r=japaric a=sekineh As @japaric has suggested I ported `lm3s6965evb/src/main.rs` into `example/qemu.rs`. All errors were fixed, ~but qemu never exits automatically~ `qemu` prints text and exits. ``` sekineh@sekineh-VirtualBox:~/cortex-m-rt_me$ cargo run --example qemu --target thumbv7m-none-eabi Compiling cortex-m-rt v0.6.3 (file:///home/sekineh/cortex-m-rt_me) Finished dev [unoptimized + debuginfo] target(s) in 0.17s Running `qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel target/thumbv7m-none-eabi/debug/examples/qemu` x = 42 sekineh@sekineh-VirtualBox:~/cortex-m-rt_me$ ``` ## supported targets - thumbv6m-none-eabi - thumbv7m-none-eabi ## code size ~code size is 0, which is apparently wrong:~ ``` sekineh@sekineh-VirtualBox:~/cortex-m-rt_me$ size target/thumbv7m-none-eabi/debug/examples/qemu text data bss dec hex filename 10776 0 0 10776 2a18 target/thumbv7m-none-eabi/debug/examples/qemu ``` ## code size (original) (deleted; different compiler version) Co-authored-by: Hideki Sekine <[email protected]>
Build succeeded |
This code not work as expected (.cargo/config):
I use cortex-m-rt in examples for my library (Cargo.toml):
Examples runs by gitlab-ci and qemu-system-arm to test library.
If I run
Then I run
And on deploy machine I get link error also but sometimes building is good. If I remove link-arg from .cargo/config then build is ok but binary is wrong (linking by default link script). I found such a solution: remove link-arg from .cargo/config and run I think that cargo does not handle correctly link-arg in .cargo/config in requirements library. It must be only in binary crate. Please let me know what you think about this. |
I reproduce problem. If exists this folder structure: Then linking of OtherRustRepo (by cargo build) used It's fantastic! I doubt it is bug or feature of cargo? |
As @japaric has suggested I ported
lm3s6965evb/src/main.rs
intoexample/qemu.rs
.All errors were fixed,
but qemu never exits automaticallyqemu
prints text and exits.supported targets
code size
code size is 0, which is apparently wrong:code size (original)
(deleted; different compiler version)