11 pname = circt.pname + "-llvm";
12 inherit (circt) version src;
14 requiredSystemFeatures = [ "big-parallel" ];
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"
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}")'
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"'")'
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
72 # Replace all references to @rpath with absolute paths and remove the rpaths.
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.
81 # Inspired by fixDarwinDylibNames.
82 postFixup = lib.optionalString stdenv.hostPlatform.isDarwin ''
84 for file in "$lib"/lib/*.dylib; do
85 flags+=(-change @rpath/"$(basename "$file")" "$file")
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"
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.
99 checkTarget = "check-mlir";
101 meta = llvm.meta // {
102 inherit (circt.meta) maintainers;