oxalica / rust-overlay

Pure and reproducible nix overlay of binary distributed rust toolchains
MIT License
952 stars 55 forks source link

Can't find crate for std #108

Closed seanybaggins closed 1 year ago

seanybaggins commented 2 years ago

My problem looks very similar to https://github.com/oxalica/rust-overlay/issues/12.

Error message

cargo run --bin fft
   Compiling byteorder v1.4.3
   Compiling cmsis-dsp-sys v0.3.1
error[E0463]: can't find crate for `std`
  |
  = note: the `thumbv7em-none-eabihf` target may not support the standard library
  = note: `std` is required by `byteorder` because it does not declare `#![no_std]`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

error[E0463]: can't find crate for `std`
 --> /home/demo/.cargo/registry/src/github.com-1ecc6299db9ec823/byteorder-1.4.3/src/io.rs:1:5
  |
1 | use std::{
  |     ^^^ can't find crate
  |
  = note: the `thumbv7em-none-eabihf` target may not support the standard library
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

My shell.nix

{ pkgs ? import (fetchTarball https://github.com/NixOS/nixpkgs/archive/abe6ea8ac11de69b7708ca9c70e8cd007600cd73.tar.gz) {} }:

let
  rust_overlay = import (builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz");
  pkgs = import (builtins.fetchTarball https://github.com/NixOS/nixpkgs/archive/abe6ea8ac11de69b7708ca9c70e8cd007600cd73.tar.gz) { overlays = [ rust_overlay ]; };
in
pkgs.mkShell {
  # buildInputs is for dependencies you'd need "at run time",
  # were you to to use nix-build not nix-shell and build whatever you were working on
  buildInputs = with pkgs; [
      (rust-bin.fromRustupToolchainFile ./rust-toolchain.toml)
      #(rust-bin.stable.latest.default.override {
      #  extensions = [ "rust-src" "rust-std"];
      #  targets = [ "thumbv7em-none-eabihf" "x86_64-unknown-linux-gnu" ];
      #})
      cargo-generate
      #cargo
      flip-link
      rustup
      probe-run
      stlink
      stlink-gui
      usbutils
      cargo-binutils

      # FFI binding requirements
      rust-bindgen
      openssl
      pkg-config
  ];
  PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";

  CHIP = "STM32L476ZGTx";
}

My toolchain.toml

[toolchain]
channel = "nightly-2022-10-09"
components = [ "rust-src", "llvm-tools-preview", "rust-std"]
targets = [ "thumbv7em-none-eabihf", "x86_64-unknown-linux-gnu" ]

My .cargo/config.toml

[target.'cfg(all(target_arch = "arm", target_os = "none"))']
runner = "probe-run --chip STM32L476ZGTx"
rustflags = [
  "-C", "linker=flip-link",
  "-C", "link-arg=-Tlink.x",
  "-C", "link-arg=-Tdefmt.x",
  # This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x
  # See https://github.com/rust-embedded/cortex-m-quickstart/pull/95
  "-C", "link-arg=--nmagic",
]

[build]
# (`thumbv6m-*` is compatible with all ARM Cortex-M chips but using the right
# target improves performance)
#target = "thumbv6m-none-eabi"    # Cortex-M0 and Cortex-M0+
# target = "thumbv7m-none-eabi"    # Cortex-M3
# target = "thumbv7em-none-eabi"   # Cortex-M4 and Cortex-M7 (no FPU)
target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU)

[alias]
rb = "run --bin"
rrb = "run --release --bin"
oxalica commented 2 years ago

Seems upstream only ships some core libs but no libstd for thumbv7em-none-eabihf. Maybe because it's only a Tier 3 target or just supports non-std for now?

$ ls /nix/store/7qnqqcy0hbi58dlr0agpba5n1px9ldlr-rust-default-1.66.0-nightly-2022-10-09/lib/rustlib/thumbv7em-none-eabihf/lib
liballoc-68f436ab8d0dfe2e.rlib              libcore-5540dd7ba8ed8010.rlib
libcompiler_builtins-421948f6b935e21d.rlib  librustc_std_workspace_core-d42c30ba205c76a2.rlib