at master 2.8 kB view raw
1{ 2 lib, 3 stdenv, 4 llvm_meta, 5 release_version, 6 buildLlvmTools, 7 monorepoSrc, 8 runCommand, 9 cmake, 10 ninja, 11 libxml2, 12 libllvm, 13 version, 14 devExtraCmakeFlags ? [ ], 15}: 16 17stdenv.mkDerivation (finalAttrs: { 18 pname = "mlir"; 19 inherit version; 20 21 doCheck = 22 ( 23 !stdenv.hostPlatform.isx86_32 # TODO: why 24 ) 25 && (!stdenv.hostPlatform.isMusl); 26 27 # Blank llvm dir just so relative path works 28 src = runCommand "${finalAttrs.pname}-src-${version}" { inherit (monorepoSrc) passthru; } ('' 29 mkdir -p "$out" 30 cp -r ${monorepoSrc}/cmake "$out" 31 cp -r ${monorepoSrc}/mlir "$out" 32 cp -r ${monorepoSrc}/third-party "$out/third-party" 33 34 mkdir -p "$out/llvm" 35 ''); 36 37 sourceRoot = "${finalAttrs.src.name}/mlir"; 38 39 patches = [ 40 ./gnu-install-dirs.patch 41 ]; 42 43 nativeBuildInputs = [ 44 cmake 45 ninja 46 ]; 47 48 buildInputs = [ 49 libllvm 50 libxml2 51 ]; 52 53 cmakeFlags = [ 54 (lib.cmakeBool "LLVM_BUILD_TOOLS" true) 55 # Install headers as well 56 (lib.cmakeBool "LLVM_INSTALL_TOOLCHAIN_ONLY" false) 57 (lib.cmakeFeature "MLIR_TOOLS_INSTALL_DIR" "${placeholder "out"}/bin/") 58 (lib.cmakeBool "LLVM_ENABLE_IDE" false) 59 (lib.cmakeFeature "MLIR_INSTALL_PACKAGE_DIR" "${placeholder "dev"}/lib/cmake/mlir") 60 (lib.cmakeFeature "MLIR_INSTALL_CMAKE_DIR" "${placeholder "dev"}/lib/cmake/mlir") 61 (lib.cmakeBool "LLVM_BUILD_TESTS" finalAttrs.finalPackage.doCheck) 62 (lib.cmakeBool "LLVM_ENABLE_FFI" true) 63 (lib.cmakeFeature "LLVM_HOST_TRIPLE" stdenv.hostPlatform.config) 64 (lib.cmakeFeature "LLVM_DEFAULT_TARGET_TRIPLE" stdenv.hostPlatform.config) 65 (lib.cmakeBool "LLVM_ENABLE_DUMP" true) 66 (lib.cmakeFeature "LLVM_TABLEGEN_EXE" "${buildLlvmTools.tblgen}/bin/llvm-tblgen") 67 (lib.cmakeFeature "MLIR_TABLEGEN_EXE" "${buildLlvmTools.tblgen}/bin/mlir-tblgen") 68 (lib.cmakeBool "LLVM_BUILD_LLVM_DYLIB" (!stdenv.hostPlatform.isStatic)) 69 ] 70 ++ lib.optionals stdenv.hostPlatform.isStatic [ 71 # Disables building of shared libs, -fPIC is still injected by cc-wrapper 72 (lib.cmakeBool "LLVM_ENABLE_PIC" false) 73 (lib.cmakeBool "LLVM_BUILD_STATIC" true) 74 (lib.cmakeBool "LLVM_LINK_LLVM_DYLIB" false) 75 ] 76 ++ devExtraCmakeFlags; 77 78 outputs = [ 79 "out" 80 "dev" 81 ]; 82 83 requiredSystemFeatures = [ "big-parallel" ]; 84 meta = llvm_meta // { 85 homepage = "https://mlir.llvm.org/"; 86 description = "Multi-Level IR Compiler Framework"; 87 longDescription = '' 88 The MLIR project is a novel approach to building reusable and extensible 89 compiler infrastructure. MLIR aims to address software fragmentation, 90 improve compilation for heterogeneous hardware, significantly reduce 91 the cost of building domain specific compilers, and aid in connecting 92 existing compilers together. 93 ''; 94 }; 95})