Skip to content
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

Can't run on Gentoo #390

Closed
w1png opened this issue Jan 9, 2023 · 9 comments
Closed

Can't run on Gentoo #390

w1png opened this issue Jan 9, 2023 · 9 comments

Comments

@w1png
Copy link

w1png commented Jan 9, 2023

Problem

Can't run examples/avr-hal-template under gentoo. Rustup was setup using rustup-init-gentoo -s. Everything was working fine under other Distros.

Some info:

Kernel: 6.1.3-gentoo-dist

❯ cargo run --bin uno-blink -- -P /dev/ttyUSB0

error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `rustc - --crate-name ___ --print=file-names --target /home/w1png/dev/rust/arduino/avr-hal/avr-specs/avr-atmega328p.json --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=cfg` (exit status: 1)
  --- stderr
  error: Could not create LLVM TargetMachine for triple: avr-unknown-unknown: No available targets are compatible with triple "avr-unknown-unknown"

❯ rustup show

Default host: x86_64-unknown-linux-gnu
rustup home:  /home/w1png/.rustup

installed toolchains
--------------------

nightly-2022-07-10-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu
gentoo (default)

active toolchain
----------------

nightly-2022-07-10-x86_64-unknown-linux-gnu (overridden by '/home/w1png/dev/rust/arduino/avr-hal/rust-toolchain.toml')
rustc 1.64.0-nightly (6dba4ed21 2022-07-09)

Would appreciate the help :)

@Rahix
Copy link
Owner

Rahix commented Jan 9, 2023

Hm, I am a bit lost here... The error message makes me believe your LLVM was not compiled with the AVR target enabled. But rustup is supposed to ship vendored LLVM instead of relying on something from the distro? Does this work differently on gentoo maybe?

@w1png
Copy link
Author

w1png commented Jan 10, 2023

The AVR target is enabled:

[ebuild   R    ] sys-devel/llvm-15.0.6-r1:15::gentoo  USE="binutils-plugin libffi ncurses xml -debug -doc -exegesis -libedit -test -verify-sig -xar -z3 -zstd" ABI_X86="32 (64) (-x32)" LLVM_TARGETS="(AArch64) (AMDGPU) (ARM) (AVR) (BPF) (Hexagon) (Lanai) (MSP430) (Mips) (NVPTX) (PowerPC) (RISCV) (Sparc) (SystemZ) (VE) (WebAssembly) (X86) (XCore) (-ARC) (-CSKY) (-DirectX) (-LoongArch) (-M68k) (-SPIRV)" 0 KiB

@w1png
Copy link
Author

w1png commented Jan 10, 2023

Ok I recompiled rust with llvm target use flags and this error dissapeared.

/etc/portage/package.use

---
>=dev-lang/rust-1.66.0:stable/1.66::gentoo llvm_targets_AVR llvm_targets_ARM

@w1png
Copy link
Author

w1png commented Jan 10, 2023

But now there is a different problem:

error[E0463]: can't find crate for `core`
  |
  = note: the `avr-atmega328p` target may not be installed
  = help: consider downloading the target with `rustup target add avr-atmega328p`

error[E0463]: can't find crate for `compiler_builtins`

error: cannot find attribute `derive` in this scope
  --> /home/w1png/.cargo/registry/src/github.com-1ecc6299db9ec823/bare-metal-1.0.0/src/lib.rs:50:3
   |
50 | #[derive(Debug)]
   |   ^^^^^^

error[E0463]: can't find crate for `core`
   --> /home/w1png/.cargo/registry/src/github.com-1ecc6299db9ec823/nb-1.0.0/src/lib.rs:189:5
    |
189 | use core::fmt;
    |     ^^^^ can't find crate
    |
    = note: the `avr-atmega328p` target may not be installed
    = help: consider downloading the target with `rustup target add avr-atmega328p`

error: cannot find attribute `derive` in this scope
  --> /home/w1png/.cargo/registry/src/github.com-1ecc6299db9ec823/bare-metal-1.0.0/src/lib.rs:15:3
   |
15 | #[derive(Clone, Copy, Debug)]
   |   ^^^^^^

error: cannot find attribute `derive` in this scope
   --> /home/w1png/.cargo/registry/src/github.com-1ecc6299db9ec823/nb-1.0.0/src/lib.rs:198:3
    |
198 | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
    |   ^^^^^^

error[E0463]: can't find crate for `core`
   --> /home/w1png/.cargo/registry/src/github.com-1ecc6299db9ec823/nb-1.0.0/src/lib.rs:192:27
    |
192 | pub type Result<T, E> = ::core::result::Result<T, Error<E>>;
    |                           ^^^^ can't find crate
    |
    = note: the `avr-atmega328p` target may not be installed
    = help: consider downloading the target with `rustup target add avr-atmega328p`

error[E0405]: cannot find trait `Copy` in this scope
  --> /home/w1png/.cargo/registry/src/github.com-1ecc6299db9ec823/vcell-0.1.3/src/lib.rs:31:18
   |
31 |         where T: Copy
   |                  ^^^^ not found in this scope

error[E0405]: cannot find trait `Copy` in this scope
  --> /home/w1png/.cargo/registry/src/github.com-1ecc6299db9ec823/vcell-0.1.3/src/lib.rs:39:18
   |
39 |         where T: Copy
   |                  ^^^^ not found in this scope

error[E0405]: cannot find trait `Sync` in this scope
  --> /home/w1png/.cargo/registry/src/github.com-1ecc6299db9ec823/bare-metal-1.0.0/src/lib.rs:87:16
   |
87 | unsafe impl<T> Sync for Mutex<T> where T: Send {}
   |                ^^^^ not found in this scope

error[E0405]: cannot find trait `Send` in this scope
  --> /home/w1png/.cargo/registry/src/github.com-1ecc6299db9ec823/bare-metal-1.0.0/src/lib.rs:87:43
   |
87 | unsafe impl<T> Sync for Mutex<T> where T: Send {}
   |                                           ^^^^ not found in this scope

error[E0463]: can't find crate for `core`
  --> /home/w1png/.cargo/registry/src/github.com-1ecc6299db9ec823/ufmt-write-0.1.0/src/lib.rs:14:5
   |
14 |     core::mem::uninitialized()
   |     ^^^^ can't find crate
   |
   = note: the `avr-atmega328p` target may not be installed
   = help: consider downloading the target with `rustup target add avr-atmega328p`

error[E0463]: can't find crate for `core`
  --> /home/w1png/.cargo/registry/src/github.com-1ecc6299db9ec823/void-1.0.2/src/lib.rs:16:5
   |
16 |     extern crate core;
   |     ^^^^^^^^^^^^^^^^^^ can't find crate
   |
   = note: the `avr-atmega328p` target may not be installed
   = help: consider downloading the target with `rustup target add avr-atmega328p`

error[E0405]: cannot find trait `FnOnce` in this scope
   --> /home/w1png/.cargo/registry/src/github.com-1ecc6299db9ec823/nb-1.0.0/src/lib.rs:223:12
    |
223 |         F: FnOnce(E) -> T,
    |            ^^^^^^ not found in this scope

error[E0405]: cannot find trait `From` in this scope
   --> /home/w1png/.cargo/registry/src/github.com-1ecc6299db9ec823/nb-1.0.0/src/lib.rs:232:9
    |
232 | impl<E> From<E> for Error<E> {
    |         ^^^^ not found in this scope

error: cannot find attribute `derive` in this scope
  --> /home/w1png/.cargo/registry/src/github.com-1ecc6299db9ec823/void-1.0.2/src/lib.rs:28:3
   |
28 | #[derive(Copy)]
   |   ^^^^^^

error[E0412]: cannot find type `Result` in this scope
  --> /home/w1png/.cargo/registry/src/github.com-1ecc6299db9ec823/ufmt-write-0.1.0/src/lib.rs:27:41
   |
27 |     fn write_str(&mut self, s: &str) -> Result<(), Self::Error>;
   |                                         ^^^^^^ not found in this scope

error[E0412]: cannot find type `Result` in this scope
  --> /home/w1png/.cargo/registry/src/github.com-1ecc6299db9ec823/ufmt-write-0.1.0/src/lib.rs:34:42
   |
34 |     fn write_char(&mut self, c: char) -> Result<(), Self::Error> {
   |                                          ^^^^^^ not found in this scope

error[E0405]: cannot find trait `Clone` in this scope
  --> /home/w1png/.cargo/registry/src/github.com-1ecc6299db9ec823/void-1.0.2/src/lib.rs:31:6
   |
31 | impl Clone for Void {
   |      ^^^^^ not found in this scope

error[E0412]: cannot find type `Option` in this scope
  --> /home/w1png/.cargo/registry/src/github.com-1ecc6299db9ec823/void-1.0.2/src/lib.rs:56:37
   |
56 |     fn partial_cmp(&self, _: &T) -> Option<cmp::Ordering> {
   |                                     ^^^^^^ not found in this scope

error[E0405]: cannot find trait `Sized` in this scope
  --> /home/w1png/.cargo/registry/src/github.com-1ecc6299db9ec823/void-1.0.2/src/lib.rs:85:29
   |
85 | pub trait ResultVoidExt<T>: Sized {
   |                             ^^^^^ not found in this scope

error[E0412]: cannot find type `Result` in this scope
  --> /home/w1png/.cargo/registry/src/github.com-1ecc6299db9ec823/void-1.0.2/src/lib.rs:90:30
   |
90 | impl<T> ResultVoidExt<T> for Result<T, Void> {
   |                              ^^^^^^ not found in this scope

error[E0531]: cannot find tuple struct or tuple variant `Ok` in this scope
  --> /home/w1png/.cargo/registry/src/github.com-1ecc6299db9ec823/void-1.0.2/src/lib.rs:97:13
   |
97 |             Ok(val) => val,
   |             ^^ not found in this scope

error[E0531]: cannot find tuple struct or tuple variant `Err` in this scope
  --> /home/w1png/.cargo/registry/src/github.com-1ecc6299db9ec823/void-1.0.2/src/lib.rs:98:13
   |
98 |             Err(e) => unreachable(e)
   |             ^^^ not found in this scope

error[E0405]: cannot find trait `Sized` in this scope
   --> /home/w1png/.cargo/registry/src/github.com-1ecc6299db9ec823/void-1.0.2/src/lib.rs:104:32
    |
104 | pub trait ResultVoidErrExt<E>: Sized {
    |                                ^^^^^ not found in this scope

error[E0412]: cannot find type `Result` in this scope
   --> /home/w1png/.cargo/registry/src/github.com-1ecc6299db9ec823/void-1.0.2/src/lib.rs:109:33
    |
109 | impl<E> ResultVoidErrExt<E> for Result<Void, E> {
    |                                 ^^^^^^ not found in this scope

error[E0531]: cannot find tuple struct or tuple variant `Ok` in this scope
   --> /home/w1png/.cargo/registry/src/github.com-1ecc6299db9ec823/void-1.0.2/src/lib.rs:116:13
    |
116 |             Ok(v) => unreachable(v),
    |             ^^ not found in this scope

error[E0531]: cannot find tuple struct or tuple variant `Err` in this scope
   --> /home/w1png/.cargo/registry/src/github.com-1ecc6299db9ec823/void-1.0.2/src/lib.rs:117:13
    |
117 |             Err(e) => e
    |             ^^^ not found in this scope

For more information about this error, try `rustc --explain E0463`.
Some errors have detailed explanations: E0405, E0463.
For more information about an error, try `rustc --explain E0405`.
error: could not compile `bare-metal` due to 6 previous errors
warning: build failed, waiting for other jobs to finish...
error: could not compile `cfg-if` due to 2 previous errors
Some errors have detailed explanations: E0405, E0412, E0463, E0531.
error: requires `receiver` lang_item

Some errors have detailed explanations: E0412, E0463.
For more information about an error, try `rustc --explain E0412`.
error: could not compile `void` due to 14 previous errors
error: could not compile `vcell` due to 4 previous errors
error: could not compile `ufmt-write` due to 6 previous errors
error: could not compile `nb` due to 7 previous errors
error: requires `sized` lang_item

error: could not compile `cfg-if` due to 2 previous errors
error: could not compile `panic-halt` due to 3 previous errors

I tried running rustup target add avr-atmega328p but it "does not contain component"

@Rahix
Copy link
Owner

Rahix commented Jan 10, 2023

What project are you building and where from? You need to use build-std to build libcore and friends alongside your code. This is usually achieved by some settings in .cargo/config.toml:

[build]
target = "../../avr-specs/avr-atmega328p.json"
[target.'cfg(target_arch = "avr")']
runner = "ravedude uno -cb 57600"
[unstable]
build-std = ["core"]

@w1png
Copy link
Author

w1png commented Jan 10, 2023

I am trying to run cargo run --bin uno-blink -- -P /dev/ttyUSB0 in arduino uno examples.
I also tried running the template repo.

@Rahix
Copy link
Owner

Rahix commented Jan 10, 2023

Hm, and it is not picking up the cargo config? Can you try running this please:

cargo build -Zbuild-std=core --bin uno-blink

@w1png
Copy link
Author

w1png commented Jan 13, 2023

cargo build -Zbuild-std=core --bin uno-blink output that I need to be running nightly version


After I tried every method to use nightly build using rustup nothing worked.
Then I checked the use flags again and it turned out that I needed to enable:

>=dev-lang/rust-1.66.0:stable/1.66::gentoo llvm_targets_AVR rust-src nightly

Everything works now. Thanks for your help :)

@w1png w1png closed this as completed Jan 13, 2023
@w1png
Copy link
Author

w1png commented Jan 13, 2023

Also a quick recap for everyone who found this issue:

  • Emerge rust with the following use flags:
llvm_targets_AVR llvm_targets_ARM rust-src nightly
  • Init rustup:
rustup-init-gentoo -s
  • Install the avr/arduino toolchain (wiki link)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants