NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.64k stars 13.8k forks source link

Cargo doesnt identify rust-toolchain.toml #179575

Open FerrisWasTaken opened 2 years ago

FerrisWasTaken commented 2 years ago

Steps To Reproduce

Steps to reproduce the behavior:

  1. clone https://github.com/muppi090909/ROS
  2. run nix-build default.nix

Build log

this derivation will be built:
  /nix/store/mn12nnx901q76ddk38rpryzb9cpmjhcn-ros-0.1.0.drv
building '/nix/store/mn12nnx901q76ddk38rpryzb9cpmjhcn-ros-0.1.0.drv'...
unpacking sources
unpacking source archive /nix/store/znpmyxzm8n92mbqjhpc8b4qq18lp0rqw-ROS
source root is ROS
patching sources
configuring
no configure script, doing nothing
building
Building kernel
    Updating crates.io index
 Downloading crates ...
  Downloaded bootloader v0.9.22
error: "/nix/store/slmsxfx879zlkdcr1vmm0nlacj9dhwqv-rustc-1.61.0/lib/rustlib/src/rust/Cargo.lock" does not exist, unable to build with the standard library, try:
        rustup component add rust-src
Error: Kernel build failed.
Stderr: 
error: builder for '/nix/store/mn12nnx901q76ddk38rpryzb9cpmjhcn-ros-0.1.0.drv' failed with exit code 1

Additional context

My rust-toolchain.toml

[toolchain]
channel="nightly"
components = ["rust-src", "llvm-tools-preview", "cargo"]
targets = ["x86_64-ros"]

x86_64-ros.json

{
    "llvm-target": "x86_64-unknown-none",
    "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
    "arch": "x86_64",
    "target-endian": "little",
    "target-pointer-width": "64",
    "target-c-int-width": "32",
    "os": "none",
    "executables": true,
    "linker-flavor": "ld.lld",
    "linker": "rust-lld",
    "panic-strategy": "abort",
    "disable-redzone": true,
    "features": "-mmx,-sse,+soft-float"
}

The problem is that cargo is not identifying rust-toolchain.toml.

Notify maintainers

@retrry

Metadata

this path will be fetched (0.00 MiB download, 0.00 MiB unpacked): /nix/store/ym48rw2727g45akp4bd6bgng9wwil5y5-nix-info copying path '/nix/store/ym48rw2727g45akp4bd6bgng9wwil5y5-nix-info' from 'https://cache.nixos.org'...

NickCao commented 2 years ago

rust-toolchain.toml shall be for rustup not cargo, for getting a rust toolchain corresponding to your toolchain file, https://github.com/oxalica/rust-overlay can be your best companion.

FerrisWasTaken commented 2 years ago

What does

./configuration.nix # Your system configuration.

mean?

NickCao commented 2 years ago

That part is for installing the specified toolchain in your NixOS system globally.

FerrisWasTaken commented 2 years ago

Any way I can use

[ (import (builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz")) ]

local only?

NickCao commented 2 years ago

Yes

FerrisWasTaken commented 2 years ago

how

FerrisWasTaken commented 2 years ago

also

{ pkgs ? import <nixpkgs> { overlays = [ (import <rust-overlay>) ]; }
}:
pkgs.stdenv.mkDerivation rec {
  pname = "ros";
  version = "0.1.0";

  buildInputs = [
    pkgs.rustc
    pkgs.cargo
    pkgs.cargo-bootimage
  ];

  src = ./.;
  outputs = { nixpkgs, rust-overlay, ... }: {
    nixosConfigurations = {
      hostname = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          ({ pkgs, ... }: {
            nixpkgs.overlays = [ rust-overlay.overlay ];
            environment.systemPackages = [ pkgs.rust-bin.nightly.latest.default ];
          })
        ];
      };
    };
  };
  PATH = "$PATH:~/.cargo/bin";
  CARGO_MANIFEST_DIR = ./.;
  outputHash = "23ebe1a4b801802ab62c8a024cfb6cff89b9e06dab15fc094b05547fc67755db";
  outputHashAlgo = "sha256";
  outputHashMode = "flat";

  configurePhase = ''
  '';

  buildPhase = ''
    cargo bootimage --release
  '';

  installPhase = ''
    mkdir -p $out/bin
    mv /target/x86_64-ros/release/bootimage-ros.bin $out/bin
  '';
}

Is this the correct way to integrate it/

NickCao commented 2 years ago

more like

{
  pkgs ? import <nixpkgs> { overlays = [ rust-overlay ]; },
  rust-overlay ? import (builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz")
}:
let
  toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
in
pkgs.stdenv.mkDerivation rec {
  pname = "ros";
  version = "0.1.0";

  nativeBuildInputs = [
    toolchain
    pkgs.cargo-bootimage
  ];

  src = ./.;
  PATH = "$PATH:~/.cargo/bin";
  CARGO_MANIFEST_DIR = ./.;
  outputHash = "23ebe1a4b801802ab62c8a024cfb6cff89b9e06dab15fc094b05547fc67755db";
  outputHashAlgo = "sha256";
  outputHashMode = "flat";

  configurePhase = ''
  '';

  buildPhase = ''
    cargo bootimage --release
  '';

  installPhase = ''
    mkdir -p $out/bin
    mv /target/x86_64-ros/release/bootimage-ros.bin $out/bin
  '';
}
NickCao commented 2 years ago

But your target is a bit exotic, I doubt whether there's prebuilt toolchain for that.

FerrisWasTaken commented 2 years ago

Its a custom toolchain.

NickCao commented 2 years ago

This sounds, a bit challenging, what about resorting to rustup for now?

FerrisWasTaken commented 2 years ago

So how do I do that?

NickCao commented 2 years ago

Just do whatever you would do on other distributions? Guess there's a bunch of nice tutorials out there.

Also I checked that there was support for custom rust targets in nixpkgs, but broken now for some reason. I would investigate into that later.