evcc: 0.131.4 -> 0.131.5
[NixPkgs.git] / pkgs / by-name / ci / circt / circt-llvm.nix
blob6c9ec00564dd79ee2881aa15c826a012dd250ce5
2   lib,
3   stdenv,
4   cmake,
5   ninja,
6   circt,
7   llvm,
8   python3,
9 }:
10 stdenv.mkDerivation {
11   pname = circt.pname + "-llvm";
12   inherit (circt) version src;
14   requiredSystemFeatures = [ "big-parallel" ];
16   nativeBuildInputs = [
17     cmake
18     ninja
19     python3
20   ];
22   preConfigure = ''
23     cd llvm/llvm
24   '';
26   cmakeFlags = [
27     "-DBUILD_SHARED_LIBS=ON"
28     "-DLLVM_ENABLE_BINDINGS=OFF"
29     "-DLLVM_ENABLE_OCAMLDOC=OFF"
30     "-DLLVM_BUILD_EXAMPLES=OFF"
31     "-DLLVM_OPTIMIZED_TABLEGEN=ON"
32     "-DLLVM_ENABLE_PROJECTS=mlir"
33     "-DLLVM_TARGETS_TO_BUILD=Native"
35     # This option is needed to install llvm-config
36     "-DLLVM_INSTALL_UTILS=ON"
37   ];
39   outputs = [
40     "out"
41     "lib"
42     "dev"
43   ];
45   # Get rid of ${extra_libdir} (which ends up containing a path to circt-llvm.dev
46   # in circt) so that we only have to remove the one fixed rpath.
47   postPatch = lib.optionalString stdenv.hostPlatform.isDarwin ''
48     substituteInPlace llvm/llvm/cmake/modules/AddLLVM.cmake \
49       --replace-fail 'set(_install_rpath "@loader_path/../lib''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' \
50         'set(_install_rpath "@loader_path/../lib''${LLVM_LIBDIR_SUFFIX}")'
51   '';
53   postInstall = ''
54     # move llvm-config to $dev to resolve a circular dependency
55     moveToOutput "bin/llvm-config*" "$dev"
57     # move all lib files to $lib except lib/cmake
58     moveToOutput "lib" "$lib"
59     moveToOutput "lib/cmake" "$dev"
61     # patch configuration files so each path points to the new $lib or $dev paths
62     substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \
63       --replace 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "'"$lib"'")'
64     substituteInPlace \
65       "$dev/lib/cmake/llvm/LLVMExports-release.cmake" \
66       "$dev/lib/cmake/mlir/MLIRTargets-release.cmake" \
67       --replace "\''${_IMPORT_PREFIX}/lib/lib" "$lib/lib/lib" \
68       --replace "\''${_IMPORT_PREFIX}/lib/objects-Release" "$lib/lib/objects-Release" \
69       --replace "$out/bin/llvm-config" "$dev/bin/llvm-config" # patch path for llvm-config
70   '';
72   # Replace all references to @rpath with absolute paths and remove the rpaths.
73   #
74   # This is different from what the regular LLVM package does, which is to make
75   # everything absolute from the start: however, that doesn't work for us because
76   # we have `-DBUILD_SHARED_LIBS=ON`, meaning that many more things are
77   # dynamically rather than statically linked. This includes TableGen, which then
78   # fails to run halfway through the build because it tries to reference $lib when
79   # it hasn't been populated yet.
80   #
81   # Inspired by fixDarwinDylibNames.
82   postFixup = lib.optionalString stdenv.hostPlatform.isDarwin ''
83     local flags
84     for file in "$lib"/lib/*.dylib; do
85       flags+=(-change @rpath/"$(basename "$file")" "$file")
86     done
88     for file in "$out"/bin/* "$lib"/lib/*.dylib; do
89       if [ -L "$file" ]; then continue; fi
90       echo "$file: fixing dylib references"
91       # note that -id does nothing on binaries
92       install_name_tool -id "$file" "''${flags[@]}" "$file"
93     done
94   '';
96   # circt only use the mlir part of llvm, occasionally there are some unrelated failure from llvm,
97   # disable the llvm check, but keep the circt check enabled.
98   doCheck = false;
99   checkTarget = "check-mlir";
101   meta = llvm.meta // {
102     inherit (circt.meta) maintainers;
103   };