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

Build failure with libc dependency #348

Open
snyball opened this issue Feb 21, 2025 · 1 comment
Open

Build failure with libc dependency #348

snyball opened this issue Feb 21, 2025 · 1 comment

Comments

@snyball
Copy link

snyball commented Feb 21, 2025

Using the following nix flake definition, I get a build failure (full project here.)

{
  inputs = {
    nixpkgs.url = github:NixOS/nixpkgs/nixpkgs-unstable;
    naersk = {
      url = github:nmattia/naersk;
      inputs.nixpkgs.follows = "nixpkgs";
    };
    fenix = {
      url = github:nix-community/fenix;
      inputs.nixpkgs.follows = "nixpkgs";
    };
    flake-utils.url = github:numtide/flake-utils;
  };

  outputs = { self, nixpkgs, naersk, fenix, flake-utils }:
    flake-utils.lib.eachDefaultSystem (
      system: let
        pkgs = nixpkgs.legacyPackages.${system};
        manifest = (pkgs.lib.importTOML ./Cargo.toml).package;
        toolchain = fenix.packages.${system}.fromToolchainFile {
          file = ./rust-toolchain.toml;
          sha256 = "sha256-vMlz0zHduoXtrlu0Kj1jEp71tYFXyymACW8L4jzrzNA=";
        };
        naersk-lib = naersk.lib.${system}.override {
          cargo = toolchain;
          rustc = toolchain;
        };
        rev = self.rev or self.dirtyRev;
      in
        rec {
          defaultPackage = packages.x86_64-unknown-linux-musl;
          packages.docker = pkgs.dockerTools.buildImage {
            name = manifest.name;
            tag = "v" + manifest.version + "-g" + rev;
            config = {
              Cmd = [ "${defaultPackage}/bin/${manifest.default-run}" ];
              WorkingDir = "/";
              Volumes = { "/data" = { }; };
            };
          };
          packages.x86_64-unknown-linux-gnu = naersk-lib.buildPackage {
            src = ./.;
          };
          packages.x86_64-unknown-linux-musl = naersk-lib.buildPackage {
            src = ./.;
            nativeBuildInputs = with pkgs; [pkgsStatic.stdenv.cc];
            CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
            CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static";
            CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER = with pkgs.pkgsStatic.stdenv;
              "${cc}/bin/${cc.targetPrefix}gcc";
          };
          devShell = pkgs.mkShell {
            nativeBuildInputs = [ toolchain ];
          };
        }
    );
}

Error:

Compiling libc v0.2.169
error: failed to run custom build command for `libc v0.2.169`

Caused by:
  process didn't exit successfully: `/home/sanoj/dev/buildscripttest/target/debug/build/libc-b19ddf8e2d903ce4/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-changed=build.rs

  --- stderr
  thread 'main' panicked at /home/sanoj/.local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.169/build.rs:143:9:
  failed to run rustc: rustc: error while loading shared libraries: libLLVM.so.19.1-rust-1.84.1-stable: cannot open shared object file: No such file or directory

  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

If I set LD_LIBRARY_PATH manually, I get this instead:

Compiling libc v0.2.169
error[E0463]: can't find crate for `core`
  |
  = note: the `x86_64-unknown-linux-gnu` target may not be installed
  = help: consider downloading the target with `rustup target add x86_64-unknown-linux-gnu`

For more information about this error, try `rustc --explain E0463`.
error: could not compile `libc` (lib) due to 1 previous error

The build failure doesn't seem to be entirely deterministic, it occasionally works, but usually fails with that error. Sometimes I've seen different errors. I also have projects that build successfully with that flake, but the linked repo contains only a simple hello world using libc, and I observer the build failure there too.

I've confirmed this on two different machines, to rule out RAM issues.

@snyball
Copy link
Author

snyball commented Feb 24, 2025

Solved:

[toolchain]
channel = "1.84.1"
components = [ "rustfmt", "rustc-dev", "rust-analyzer" ]
targets = [ "x86_64-unknown-linux-gnu", "x86_64-unknown-linux-musl", "x86_64-pc-windows-gnu" ]

Removing rustc-dev from components fixes it. I'd consider this a bug, because the file is given the same hashsum with or without that component.

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

1 participant