From 276b313a2b80f47e5c665717f0ac47e2457d5b24 Mon Sep 17 00:00:00 2001 From: Weijia Wang <9713184+wegank@users.noreply.github.com> Date: Fri, 23 Feb 2024 05:47:53 +0100 Subject: llvmPackages_git.mlir: init --- pkgs/development/compilers/llvm/17/default.nix | 2 +- .../development/compilers/llvm/17/mlir/default.nix | 71 ---------------------- .../compilers/llvm/17/mlir/gnu-install-dirs.patch | 15 ----- .../compilers/llvm/common/mlir/default.nix | 71 ++++++++++++++++++++++ .../llvm/common/mlir/gnu-install-dirs.patch | 15 +++++ pkgs/development/compilers/llvm/git/default.nix | 4 ++ 6 files changed, 91 insertions(+), 87 deletions(-) delete mode 100644 pkgs/development/compilers/llvm/17/mlir/default.nix delete mode 100644 pkgs/development/compilers/llvm/17/mlir/gnu-install-dirs.patch create mode 100644 pkgs/development/compilers/llvm/common/mlir/default.nix create mode 100644 pkgs/development/compilers/llvm/common/mlir/gnu-install-dirs.patch (limited to 'pkgs/development/compilers') diff --git a/pkgs/development/compilers/llvm/17/default.nix b/pkgs/development/compilers/llvm/17/default.nix index 67076da64941b..60cae920945b7 100644 --- a/pkgs/development/compilers/llvm/17/default.nix +++ b/pkgs/development/compilers/llvm/17/default.nix @@ -144,7 +144,7 @@ in let inherit llvm_meta; }; - mlir = callPackage ./mlir { + mlir = callPackage ../common/mlir { inherit llvm_meta; }; diff --git a/pkgs/development/compilers/llvm/17/mlir/default.nix b/pkgs/development/compilers/llvm/17/mlir/default.nix deleted file mode 100644 index 8e99fa0fe337f..0000000000000 --- a/pkgs/development/compilers/llvm/17/mlir/default.nix +++ /dev/null @@ -1,71 +0,0 @@ -{ lib, stdenv, llvm_meta -, buildLlvmTools -, monorepoSrc, runCommand -, cmake -, ninja -, libxml2 -, libllvm -, version -, doCheck ? (!stdenv.isx86_32 /* TODO: why */) && (!stdenv.hostPlatform.isMusl) -}: - -stdenv.mkDerivation rec { - pname = "mlir"; - inherit version doCheck; - - # Blank llvm dir just so relative path works - src = runCommand "${pname}-src-${version}" {} '' - mkdir -p "$out" - cp -r ${monorepoSrc}/cmake "$out" - cp -r ${monorepoSrc}/${pname} "$out" - cp -r ${monorepoSrc}/third-party "$out/third-party" - - mkdir -p "$out/llvm" - ''; - - sourceRoot = "${src.name}/${pname}"; - - patches = [ - ./gnu-install-dirs.patch - ]; - - nativeBuildInputs = [ cmake ninja ]; - buildInputs = [ libllvm libxml2 ]; - - ninjaFlags = [ "-v " ]; - cmakeFlags = [ - "-DLLVM_BUILD_TOOLS=ON" - # Install headers as well - "-DLLVM_INSTALL_TOOLCHAIN_ONLY=OFF" - "-DMLIR_TOOLS_INSTALL_DIR=${placeholder "out"}/bin/" - "-DLLVM_ENABLE_IDE=OFF" - "-DLLD_INSTALL_PACKAGE_DIR=${placeholder "out"}/lib/cmake/mlir" - "-DLLVM_BUILD_TESTS=${if doCheck then "ON" else "OFF"}" - "-DLLVM_ENABLE_FFI=ON" - "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" - "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" - "-DLLVM_ENABLE_DUMP=ON" - ] ++ lib.optionals stdenv.hostPlatform.isStatic [ - # Disables building of shared libs, -fPIC is still injected by cc-wrapper - "-DLLVM_ENABLE_PIC=OFF" - "-DLLVM_BUILD_STATIC=ON" - "-DLLVM_LINK_LLVM_DYLIB=off" - ] ++ lib.optionals ((stdenv.hostPlatform != stdenv.buildPlatform) && !(stdenv.buildPlatform.canExecute stdenv.hostPlatform)) [ - "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" - "-DMLIR_TABLEGEN_EXE=${buildLlvmTools.mlir}/bin/mlir-tblgen" - ]; - - outputs = [ "out" "dev" ]; - - meta = llvm_meta // { - homepage = "https://mlir.llvm.org/"; - description = "Multi-Level IR Compiler Framework"; - longDescription = '' - The MLIR project is a novel approach to building reusable and extensible - compiler infrastructure. MLIR aims to address software fragmentation, - improve compilation for heterogeneous hardware, significantly reduce - the cost of building domain specific compilers, and aid in connecting - existing compilers together. - ''; - }; -} diff --git a/pkgs/development/compilers/llvm/17/mlir/gnu-install-dirs.patch b/pkgs/development/compilers/llvm/17/mlir/gnu-install-dirs.patch deleted file mode 100644 index 95191022d1a38..0000000000000 --- a/pkgs/development/compilers/llvm/17/mlir/gnu-install-dirs.patch +++ /dev/null @@ -1,15 +0,0 @@ -diff --git a/CMakeLists.txt b/CMakeLists.txt -index c91e9cd93dc8..23b6032a46b7 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -32,8 +32,8 @@ if(MLIR_STANDALONE_BUILD) - endif() - - set(CMAKE_LIBRARY_OUTPUT_DIRECTORY -- "${CMAKE_CURRENT_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}") -- set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") -+ "${CMAKE_INSTALL_LIBDIR}/${LLVM_LIBDIR_SUFFIX}") -+ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_INSTALL_BINDIR}") - - set(LLVM_LIT_ARGS "-sv" CACHE STRING "Default options for lit") - endif() diff --git a/pkgs/development/compilers/llvm/common/mlir/default.nix b/pkgs/development/compilers/llvm/common/mlir/default.nix new file mode 100644 index 0000000000000..8e99fa0fe337f --- /dev/null +++ b/pkgs/development/compilers/llvm/common/mlir/default.nix @@ -0,0 +1,71 @@ +{ lib, stdenv, llvm_meta +, buildLlvmTools +, monorepoSrc, runCommand +, cmake +, ninja +, libxml2 +, libllvm +, version +, doCheck ? (!stdenv.isx86_32 /* TODO: why */) && (!stdenv.hostPlatform.isMusl) +}: + +stdenv.mkDerivation rec { + pname = "mlir"; + inherit version doCheck; + + # Blank llvm dir just so relative path works + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + cp -r ${monorepoSrc}/third-party "$out/third-party" + + mkdir -p "$out/llvm" + ''; + + sourceRoot = "${src.name}/${pname}"; + + patches = [ + ./gnu-install-dirs.patch + ]; + + nativeBuildInputs = [ cmake ninja ]; + buildInputs = [ libllvm libxml2 ]; + + ninjaFlags = [ "-v " ]; + cmakeFlags = [ + "-DLLVM_BUILD_TOOLS=ON" + # Install headers as well + "-DLLVM_INSTALL_TOOLCHAIN_ONLY=OFF" + "-DMLIR_TOOLS_INSTALL_DIR=${placeholder "out"}/bin/" + "-DLLVM_ENABLE_IDE=OFF" + "-DLLD_INSTALL_PACKAGE_DIR=${placeholder "out"}/lib/cmake/mlir" + "-DLLVM_BUILD_TESTS=${if doCheck then "ON" else "OFF"}" + "-DLLVM_ENABLE_FFI=ON" + "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_ENABLE_DUMP=ON" + ] ++ lib.optionals stdenv.hostPlatform.isStatic [ + # Disables building of shared libs, -fPIC is still injected by cc-wrapper + "-DLLVM_ENABLE_PIC=OFF" + "-DLLVM_BUILD_STATIC=ON" + "-DLLVM_LINK_LLVM_DYLIB=off" + ] ++ lib.optionals ((stdenv.hostPlatform != stdenv.buildPlatform) && !(stdenv.buildPlatform.canExecute stdenv.hostPlatform)) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + "-DMLIR_TABLEGEN_EXE=${buildLlvmTools.mlir}/bin/mlir-tblgen" + ]; + + outputs = [ "out" "dev" ]; + + meta = llvm_meta // { + homepage = "https://mlir.llvm.org/"; + description = "Multi-Level IR Compiler Framework"; + longDescription = '' + The MLIR project is a novel approach to building reusable and extensible + compiler infrastructure. MLIR aims to address software fragmentation, + improve compilation for heterogeneous hardware, significantly reduce + the cost of building domain specific compilers, and aid in connecting + existing compilers together. + ''; + }; +} diff --git a/pkgs/development/compilers/llvm/common/mlir/gnu-install-dirs.patch b/pkgs/development/compilers/llvm/common/mlir/gnu-install-dirs.patch new file mode 100644 index 0000000000000..95191022d1a38 --- /dev/null +++ b/pkgs/development/compilers/llvm/common/mlir/gnu-install-dirs.patch @@ -0,0 +1,15 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index c91e9cd93dc8..23b6032a46b7 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -32,8 +32,8 @@ if(MLIR_STANDALONE_BUILD) + endif() + + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY +- "${CMAKE_CURRENT_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}") +- set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") ++ "${CMAKE_INSTALL_LIBDIR}/${LLVM_LIBDIR_SUFFIX}") ++ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_INSTALL_BINDIR}") + + set(LLVM_LIT_ARGS "-sv" CACHE STRING "Default options for lit") + endif() diff --git a/pkgs/development/compilers/llvm/git/default.nix b/pkgs/development/compilers/llvm/git/default.nix index 5b540c1bd12a4..1efaa0402fc71 100644 --- a/pkgs/development/compilers/llvm/git/default.nix +++ b/pkgs/development/compilers/llvm/git/default.nix @@ -144,6 +144,10 @@ in let inherit llvm_meta; }; + mlir = callPackage ../common/mlir { + inherit llvm_meta; + }; + lldb = callPackage ../common/lldb.nix { src = callPackage ({ runCommand }: runCommand "lldb-src-${version}" {} '' mkdir -p "$out" -- cgit 1.4.1