mjhouse / ag-lcd

A rust port of the C++ LiquidCrystal library for arduino systems
GNU General Public License v3.0
17 stars 8 forks source link

Some examples can't be run from the root directory #8

Open mjhouse opened 2 years ago

mjhouse commented 2 years ago

Normally, you can run examples with-

cargo run --example <example name>
vcrn commented 2 years ago

I've started looking into this, and if I understand it correctly, in order to let an example be runnable with this command the following things need to be fixed (let's say in the case of nano/blink, to get it to run with cargo run --example nano-blink):

In the root/Cargo.toml, this needs to be added: [[example]] name = "nano-blink" path = "examples/nano/blink/src/main.rs"

Then, since "https://github.com/rahix/avr-hal" is used in all our examples, this dependency seems needed in the root/Cargo.toml, with 'features = ["arduino-nano"]'. (To get the uno-examples to work, I assume 'features = ["arduino-uno"]' needs to be added too.)

After this, cargo complains about this:

`#![feature]` may not be used on the stable release channel
  --> [redacted]/avr-device-0.3.4/src/lib.rs:65:35
   |
65 | #![cfg_attr(avr_device_asm_macro, feature(asm_experimental_arch))]

I saw your Issue "Switch to stable rust #11", so I paused here, since it seemed to add up to a bit too much for these additions to be reasonable. I think we should at least wait until Issue #11 is worked out (either confirming that it can be built using stable and implemented, or that it is not possible), and then considering if it's worth adding dependencies to this crate in the form of avr-hal.

What do you think?

mjhouse commented 2 years ago

Sounds good. I took a stab at building with stable this morning, but didn't get it to work.

vcrn commented 2 years ago

I started looking into this again, and made some progress I believe. A smoother way forward might be to add this to the root/Cargo.toml (in this case, only regarding the Uno example):

[workspace]
resolver = "2"
members = [
    "examples/uno/*"
]

Then, running from root: cargo +nightly run -p ag-lcd-print (or whatever name is listed under [package], name.

After fighting a bit to get it to compile without running into error: ran out of registers during register allocation (actually not sure how I got past this), I eventually ran into this issue:

warning: profiles for the non root package will be ignored, specify profiles at the workspace root.
...
...
error: Ensure that you are using an AVR target! You may need to change directories or pass a --target flag to cargo. See
              https://github.com/Rahix/avr-device/pull/41 for more details.

This is something I haven't been able to get by, and not sure if it will be possible in this case.

I wanted to leave a comment about it here anyway, because this seems to be a better way of running examples in some cases from root instead of the way I started with and outlined in the comments above, and was educational for at least me to look into. This way, we don't seem to any longer have an issue of setting it to nightly or using dependencies in the examples which are not present in the root/Cargo.toml