Skip to content

[CMake] Attempt to write ClingConfig.cmake.tmp to the external LLVM library directory, causing configuration failure #11920

@ShamrockLee

Description

@ShamrockLee
  • Checked for duplicates

Describe the bug

When building with native LLVM (with CMake flag -Dbuiltin_llvm=OFF) with Nix and Nixpkgs, the builder tries to place lib/cmake/cling/ClingConfig.cmake.tmp under the read-only /path/to/native/llvm/lib/, and gets System Error.

Not sure if this issue is reproducible on other platforms.

Partial command line output:

-- Cling version (from VERSION file): ROOT_1.0~dev
-- Cling will look for C++ headers in '/nix/store/gc7zr7wh575g1i5zs20lf3g45damwwbs-gcc-11.3.0/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../include/c++/11.3.0:/nix/store/gc7zr7wh575g1i5zs20lf3g45damwwbs-gcc-11.3.0/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../include/c++/11.3.0/x86_64-unknown-linux-gnu:/nix/store/gc7zr7wh575g1i5zs20lf3g45damwwbs-gcc-11.3.0/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../include/c++/11.3.0/backward' at runtime.
-- And then fallback to: 'g++'
CMake Error: Could not open file for write in copy operation //nix/store/vqlvh9dv2prsrmk6lng8n66wgfpvra1j-llvm-13.0.1-lib/lib/cmake/cling/ClingConfig.cmake.tmp
CMake Error: : System Error: No such file or directory
CMake Error at interpreter/cling/cmake/modules/CMakeLists.txt:22 (configure_file):
  configure_file Problem configuring file

Possible source of the issue:
https://github.com/root-project/root/blob/master/interpreter/cling/cmake/modules/CMakeLists.txt#L4-L5

Expected behavior

  1. The configurations works, just as it does on the 6.26 branch.
  2. If not feasible, the build error should at least guide the user / package aintainer the configuration option to solve the issue or where to find the solution.

To Reproduce

  1. Build against the master branch (6.27, 0fafc31) with CMake Flag -Dbuiltin_llvm=OFF.
    (See the external context for steps to reproduce the behavior with the Nix package manager and Nixpkgs.)
  2. See error.

Setup

  1. ROOT version: 6.27.* on the master branch (f9d15227e4c92eac7c6499379912d1ed24d0142b).
  2. Operating system: NixOS (Linux), on a x86_64 machine.
    • system: "x86_64-linux"
    • host os: Linux 5.10.156, NixOS, 22.11 (Raccoon), 22.11.20221130.596a8e8
    • multi-user?: yes
    • sandbox: yes
    • version: nix-env (Nix) 2.11.0
    • nixpkgs: /nix/store/qwgw2b19ga8dr7c6wfpd6p87bdjyrnha-source
  3. Build with Nix and get dependencies from Nixpkgs.

Additional context

Here is the build steps to reproduce the issue with Nix. It can be proceed as long as nix or docker is available.

Copyright notice: The default.nix is derived/taken from pkgs/applications/science/misc/root/default.nix in Nixpkgs. The original work is licensed under the MIT license by Eelco Dolstra and the Nixpkgs/NixOS contributors.

  1. Run mkdir test-root-6.27

  2. Place the following files into the test-root-6.27 directory:

    setup-hook.sh and sw_vers.patch from https://github.com/NixOS/nixpkgs/tree/2787fc7d1e51404678614bf0fe92fc296746eec0/pkgs/applications/science/misc/root

    default.nix

{ stdenv
, lib
, callPackage
, fetchFromGitHub
, fetchpatch
, makeWrapper
, cmake
, coreutils
, git
, davix
, ftgl
, gl2ps
, glew
, gnugrep
, gnused
, gsl
, lapack
, libX11
, libXpm
, libXft
, libXext
, libGLU
, libGL
, libxcrypt
, libxml2
, llvm_13
, lsof
, lz4
, xz
, man
, openblas
, openssl
, pcre
, nlohmann_json
, pkg-config
, procps
, python
, which
, xxHash
, zlib
, zstd
, libAfterImage
, giflib
, libjpeg
, libtiff
, libpng
, patchRcPathCsh
, patchRcPathFish
, patchRcPathPosix
, tbb
, Cocoa
, CoreSymbolication
, OpenGL
, noSplash ? false
}:

stdenv.mkDerivation rec {
  pname = "root";
  version = "6.27.00";

  src = fetchFromGitHub {
    owner = "root-project";
    repo = "root";
    rev = "0fafc31efb5a94472af2a6b35ded27796cb141c8";
    sha256 = "sha256-oO5K7AIH3Zhxpox3acuLcoTHD529pyIKXk9rfYi3U4U=";
  };

  nativeBuildInputs = [ makeWrapper cmake pkg-config git ];
  buildInputs = [
    davix
    ftgl
    gl2ps
    glew
    pcre
    zlib
    zstd
    lapack
    libxcrypt
    libxml2
    llvm_13
    lz4
    xz
    gsl
    openblas
    openssl
    xxHash
    libAfterImage
    giflib
    libjpeg
    libtiff
    libpng
    nlohmann_json
    patchRcPathCsh
    patchRcPathFish
    patchRcPathPosix
    python.pkgs.numpy
    tbb
  ]
  ++ lib.optionals (!stdenv.isDarwin) [ libX11 libXpm libXft libXext libGLU libGL ]
  ++ lib.optionals (stdenv.isDarwin) [ Cocoa CoreSymbolication OpenGL ]
  ;

  patches = [
    ./sw_vers.patch
  ];

  preConfigure = ''
    rm -rf builtins/*
    substituteInPlace cmake/modules/SearchInstalledSoftware.cmake \
      --replace 'set(lcgpackages ' '#set(lcgpackages '

    # Don't require textutil on macOS
    : > cmake/modules/RootCPack.cmake

    # Hardcode path to fix use with cmake
    sed -i cmake/scripts/ROOTConfig.cmake.in \
      -e '1iset(nlohmann_json_DIR "${nlohmann_json}/lib/cmake/nlohmann_json/")'

    patchShebangs build/unix/
  '' + lib.optionalString noSplash ''
    substituteInPlace rootx/src/rootx.cxx --replace "gNoLogo = false" "gNoLogo = true"
  '' + lib.optionalString stdenv.isDarwin ''
    # Eliminate impure reference to /System/Library/PrivateFrameworks
    substituteInPlace core/CMakeLists.txt \
      --replace "-F/System/Library/PrivateFrameworks" ""
  '' + lib.optionalString (stdenv.isDarwin && lib.versionAtLeast stdenv.hostPlatform.darwinMinVersion "11") ''
    MACOSX_DEPLOYMENT_TARGET=10.16
  '';

  cmakeFlags = [
    "-Drpath=ON"
    "-DCMAKE_INSTALL_BINDIR=bin"
    "-DCMAKE_INSTALL_LIBDIR=lib"
    "-DCMAKE_INSTALL_INCLUDEDIR=include"
    "-Dbuiltin_llvm=OFF"
    "-Dbuiltin_nlohmannjson=OFF"
    "-Dbuiltin_openui5=OFF"
    "-Dalien=OFF"
    "-Dbonjour=OFF"
    "-Dcastor=OFF"
    "-Dchirp=OFF"
    "-Dclad=OFF"
    "-Ddavix=ON"
    "-Ddcache=OFF"
    "-Dfail-on-missing=ON"
    "-Dfftw3=OFF"
    "-Dfitsio=OFF"
    "-Dfortran=OFF"
    "-Dimt=ON"
    "-Dgfal=OFF"
    "-Dgviz=OFF"
    "-Dhdfs=OFF"
    "-Dhttp=ON"
    "-Dkrb5=OFF"
    "-Dldap=OFF"
    "-Dmonalisa=OFF"
    "-Dmysql=OFF"
    "-Dodbc=OFF"
    "-Dopengl=ON"
    "-Doracle=OFF"
    "-Dpgsql=OFF"
    "-Dpythia6=OFF"
    "-Dpythia8=OFF"
    "-Drfio=OFF"
    "-Droot7=OFF"
    "-Dsqlite=OFF"
    "-Dssl=ON"
    "-Dtmva=ON"
    "-Dvdt=OFF"
    "-Dwebgui=OFF"
    "-Dxml=ON"
    "-Dxrootd=OFF"
  ]
  ++ lib.optional (stdenv.cc.libc != null) "-DC_INCLUDE_DIRS=${lib.getDev stdenv.cc.libc}/include"
  ++ lib.optionals stdenv.isDarwin [
    "-DOPENGL_INCLUDE_DIR=${OpenGL}/Library/Frameworks"
    "-DCMAKE_DISABLE_FIND_PACKAGE_Python2=TRUE"

    # fatal error: module map file '/nix/store/<hash>-Libsystem-osx-10.12.6/include/module.modulemap' not found
    # fatal error: could not build module '_Builtin_intrinsics'
    "-Druntime_cxxmodules=OFF"
  ];

  NIX_LDFLAGS = lib.optionalString (stdenv.isLinux && stdenv.isAarch64 && stdenv.cc.isGNU) "-lgcc";

  postInstall = ''
    for prog in rootbrowse rootcp rooteventselector rootls rootmkdir rootmv rootprint rootrm rootslimtree; do
      wrapProgram "$out/bin/$prog" \
        --set PYTHONPATH "$out/lib" \
        --set ${lib.optionalString stdenv.isDarwin "DY"}LD_LIBRARY_PATH "$out/lib"
    done

    # Make ldd and sed available to the ROOT executable
    wrapProgram "$out/bin/root" --prefix PATH : "${lib.makeBinPath [
      gnused # sed
      stdenv.cc # c++ ld etc.
      stdenv.cc.libc # ldd
    ]}"

    # Patch thisroot.{sh,csh,fish}

    # The main target of `thisroot.sh` is "bash-like shells",
    # but it also need to support Bash-less POSIX shell like dash,
    # as they are mentioned in `thisroot.sh`.

    # `thisroot.sh` would include commands `lsof` and `procps` since ROOT 6.28.
    # See https://github.com/root-project/root/pull/10332

    patchRcPathPosix "$out/bin/thisroot.sh" "${lib.makeBinPath [
      coreutils # dirname tail
      gnugrep # grep
      gnused # sed
      lsof # lsof # for ROOT (>=6.28)
      man # manpath
      procps # ps # for ROOT (>=6.28)
      which # which
    ]}"
    patchRcPathCsh "$out/bin/thisroot.csh" "${lib.makeBinPath [
      coreutils
      gnugrep
      gnused
      lsof # lsof # for ROOT (>=6.28)
      man
      which
    ]}"
    patchRcPathFish "$out/bin/thisroot.fish" "${lib.makeBinPath [
      coreutils
      man
      which
    ]}"
  '';

  setupHook = ./setup-hook.sh;
}
`flake.nix`
{
  inputs.flake-utils.url = "github:numtide/flake-utils";
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/2787fc7d1e51404678614bf0fe92fc296746eec0";

  outputs = { flake-utils, nixpkgs, ... }: flake-utils.lib.eachDefaultSystem (system:
    let
      lib = nixpkgs.lib;
      pkgs = nixpkgs.legacyPackages.${system};
      root = with pkgs; callPackage ./. {
        python = python3;
        inherit (darwin.apple_sdk.frameworks) Cocoa CoreSymbolication OpenGL;
        # https://github.com/NixOS/nixpkgs/issues/201254
        stdenv = if stdenv.isLinux && stdenv.isAarch64 && stdenv.cc.isGNU then gcc11Stdenv else stdenv;
      };
    in
    {
      packages = {
        default = root;
        inherit root;
      };
    });
}
 `flake.lock`
{
  "nodes": {
    "flake-utils": {
      "locked": {
        "lastModified": 1667395993,
        "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
        "owner": "numtide",
        "repo": "flake-utils",
        "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
        "type": "github"
      },
      "original": {
        "owner": "numtide",
        "repo": "flake-utils",
        "type": "github"
      }
    },
    "nixpkgs": {
      "locked": {
        "lastModified": 1670507980,
        "narHash": "sha256-riNZa0xzM1it3pzxciwALeMs+0CsBMWIW2FqulzK8vM=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "2787fc7d1e51404678614bf0fe92fc296746eec0",
        "type": "github"
      },
      "original": {
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "2787fc7d1e51404678614bf0fe92fc296746eec0",
        "type": "github"
      }
    },
    "root": {
      "inputs": {
        "flake-utils": "flake-utils",
        "nixpkgs": "nixpkgs"
      }
    }
  },
  "root": "root",
  "version": 7
}
  1. Run nix --extra-experimental-features 'nix-command flakes' build --no-link --keep-failed --print-build-logs ./test-root-6.27#root. If nix is not available, run docker run -ti -v "$PWD:/mnt" -v /tmp:/tmp --rm nixos/nix nix --extra-experimental-features 'nix-command flakes' build --no-link --keep-failed --print-build-logs /mnt/test-root-6.27#root instead.
  2. The remaining build directory can be found inside /tmp, with a folder name like nix-build-root-6.27.00.drv-*.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions