NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.27k stars 13.52k forks source link

libclang seems to get a wrong resource root #141262

Open jansol opened 2 years ago

jansol commented 2 years ago

Describe the bug

Partially a follow-up from #89954, using libclang to compile OpenCL code at runtime fails with an error complaining about missing builtin clang headers.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Grab a checkout of PoCL and set up a dev shell using this derivation.nix
    
    {
    clangStdenv,
    fetchFromGitHub,
    clang-unwrapped,
    cmake,
    hwloc,
    llvm,
    lttng-ust,
    ocl-icd,
    pkgconfig
    }:

stdenv.mkDerivation { name = "pocl"; src = fetchFromGitHub { owner = "pocl"; repo = "pocl"; rev = "160f175900b248923e0b0c3360658d4c5f3567f0"; sha256 = "1i0c349h3ray5h8bqc9s8ak0vhxiw43b8l8hv62fdq518yb4qjqk"; };

buildInputs = [ clang-unwrapped cmake hwloc llvm lttng-ust ocl-icd pkgconfig ];

nativeBuildInputs = [];

}

and shell.nix:

let

pkgs = import {};

pocl = pkgs.callPackage ./derivation.nix { clangStdenv = pkgs.llvmPackages_13.stdenv; clang-unwrapped = pkgs.llvmPackages_13.clang-unwrapped; llvm = pkgs.llvm_13; }; in

pkgs.mkShell.override {stdenv = pkgs.llvmPackages_13.stdenv;} { buildInputs = pocl.buildInputs ++ [pkgs.ninja]; }

3. Build: `cmake -S srcdir -B builddir -GNinja && ninja -C builddir`
4. Attempt to run a basic test: `cd builddir && ctest -R kernel/test_as_type -V`
5. Test fails because clang (used via its C++ library API) can't find `opencl-c-base.h` since it is looking in the wrong directory.

### Expected behavior
Test completes successfully

### Additional context
Clang-wrapped is needed at build time since there is a build step that precompiles some builtin OpenCL functions to LLVM bitcode. This works since the wrapper script sets the resource root correctly. Not sure how it should be done with the library.

Building with the GCC stdenv should also work, but still requires clang for the precompilation step.

### Notify maintainers
@lovek323 @dtzWill @primeos 

### Metadata
nixos-unstable

```console
[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 5.14.9, NixOS, 21.11 (Porcupine)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.3.15`
 - channels(root): `"nixos-21.11pre321644.5e2018f7b38"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute: pkgs.llvmPackages_13.libclang
Artturin commented 2 years ago

fyi here's a a better expr can be built standalone with nix-build -E "with import <nixpkgs> {}; callPackage ./default.nix {}"

{ stdenv
, fetchFromGitHub
, llvmPackages_13
, ninja
, cmake
, hwloc
, lttng-ust
, ocl-icd
, opencl-headers
, pkg-config
}:

stdenv.mkDerivation {
  name = "pocl";

  src = fetchFromGitHub {
    owner = "pocl";
    repo = "pocl";
    rev = "160f175900b248923e0b0c3360658d4c5f3567f0";
    sha256 = "1i0c349h3ray5h8bqc9s8ak0vhxiw43b8l8hv62fdq518yb4qjqk";
  };

  nativeBuildInputs = [
    cmake
    ninja
    pkg-config
    llvmPackages_13.clang
    llvmPackages_13.llvm
  ];

  buildInputs = [
    ocl-icd
    opencl-headers
    hwloc
    lttng-ust
    llvmPackages_13.libclang
  ];

  # This is required because upstreams CMakeLists.txt is wrong and installs stuff in $out/nix/store/..../
  postInstall = ''
    mv $out/nix/store/*/* $out
    rm -r $out/nix
  '';

}
stale[bot] commented 2 years ago

I marked this as stale due to inactivity. → More info