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

libc crate fails to build when using fromToolchainFile #123

Open
mediocregopher opened this issue Nov 12, 2023 · 1 comment
Open

libc crate fails to build when using fromToolchainFile #123

mediocregopher opened this issue Nov 12, 2023 · 1 comment

Comments

@mediocregopher
Copy link

mediocregopher commented Nov 12, 2023

Cargo.toml:

[package]
name = "repro"
version = "0.1.0"
edition = "2021"

[dependencies]
libc = "0.2.150"

flake.nix:

{
  inputs = {
    fenix.url = "github:nix-community/fenix";
    naersk.url = "github:nix-community/naersk/master";
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11";
  };

  outputs = { self, nixpkgs, naersk, fenix }: {

    packages.x86_64-linux.default = let
      buildSystem = "x86_64-linux";
      pkgs = import nixpkgs { system = buildSystem; };
      fenixPkgs = fenix.packages.${buildSystem};

      naersk-lib = let
        toolchain = fenixPkgs.fromToolchainFile {
          file = ./rust-toolchain.toml;
          sha256 = "sha256-LU4C/i+maIOqBZagUaXpFyWZyOVfQ3Ah5/JTz7v6CG4=";
        };
      in
        pkgs.callPackage naersk {
          cargo = toolchain;
          rustc = toolchain;
        };

    in
      naersk-lib.buildPackage {
        src = ./.;
      };
  };
}

rust-toolchain.toml:

[toolchain]
channel = "nightly-2023-07-23"
components = [ "rustfmt", "rustc-dev", "clippy", "cargo" ]
targets = [
    "x86_64-unknown-linux-musl",
]

This results in an error when building the libc crate:

repro-deps>    Compiling libc v0.2.150
repro-deps> error: failed to run custom build command for `libc v0.2.150`
repro-deps> Caused by:
repro-deps>   process didn't exit successfully: `/build/dummy-src/target/release/build/libc-d79941b6d8ccf44d/build-script-build` (exit status: 101)
repro-deps>   --- stdout
repro-deps>   cargo:rerun-if-changed=build.rs
repro-deps>   --- stderr
repro-deps>   thread 'main' panicked at 'failed to run rustc: /nix/store/0w7x51qky8wf0y4qmvca5l9asd9sl415-rust-nightly-2023-07-23/bin/rustc: error while loading shared libraries: libLLVM-16-rust-1.73.0-nightly.so: cannot open shared object file: No such file or directory
repro-deps>   ', /sources/libc-0.2.150-89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c/build.rs:204:9
repro-deps>   note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
repro-deps> [naersk] cargo returned with exit code 101, exiting

However if you replace the naersk-lib definition with another using fromToolchainName instead:

      naersk-lib = let
        toolchain = fenixPkgs.fromToolchainName {
          name = "nightly-2023-07-23";
          sha256 = "sha256-LU4C/i+maIOqBZagUaXpFyWZyOVfQ3Ah5/JTz7v6CG4=";
        };
      in
        pkgs.callPackage naersk {
          cargo = toolchain.cargo;
          rustc = toolchain.rustc;
        };

then the project compiles without issue.

I've confirmed that there is indeed a libLLVM-16-rust-1.73.0-nightly.so file in the rust-nightly-2023-07-23 derivation:

 /tmp/repro :: ls -l /nix/store/0w7x51qky8wf0y4qmvca5l9asd9sl415-rust-nightly-2023-07-23/lib/libLLVM-16-rust-1.73.0-nightly.so
lrwxrwxrwx 1 root root 106 Jan  1  1970 /nix/store/0w7x51qky8wf0y4qmvca5l9asd9sl415-rust-nightly-2023-07-23/lib/libLLVM-16-rust-1.73.0-nightly.so -> /nix/store/wih7jgpwmz1sxf00qdzlsg2r1dmvh44m-rustc-nightly-2023-07-23/lib/libLLVM-16-rust-1.73.0-nightly.so

Any help would be much appreciated 🙏

@evanjs
Copy link

evanjs commented Nov 19, 2024

Encountered this as well and also curious if I'm just doing something wrong.

Working around it for now, but this approach only considers the toolchain version/channel/name:

# rust-toolchain.toml
[toolchain]
channel = "1.82.0"
components = [ "rustfmt", "rustc-dev" ]
targets = [ "x86_64-unknown-linux-gnu" ]
profile = "minimal"
# flake.nix
{
  toolchain =
    let
      toolchainRaw = (builtins.fromTOML (builtins.readFile ./rust-toolchain.toml)).toolchain;
    in
    fenix.packages.${system}.fromToolchainName {
      name = toolchainRaw.channel;
      sha256 = "sha256-yMuSb5eQPO/bHv+Bcf/US8LVMbf/G/0MSfiPwBhiPpk=";
    };

  naersk' = naersk.lib.${system}.override {
    cargo = toolchain.cargo;
    rustc = toolchain.rustc;
  };
}

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