Skip to content

Commit

Permalink
[nix] add buddy-mlir derivation
Browse files Browse the repository at this point in the history
Signed-off-by: Avimitin <[email protected]>
  • Loading branch information
Avimitin committed Nov 7, 2023
1 parent 38bfd56 commit c86f79b
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,26 @@ $ ninja check-mlir check-clang
$ ninja
$ ninja check-buddy
```

### Use nix

This repository have nix flake support. You can follow the [nix installation instruction](https://nixos.org/manual/nix/stable/installation/installation.html) and enable the [flake features](https://nixos.wiki/wiki/Flakes#Other_Distros.2C_without_Home-Manager) to have nix setup.

- If you want to contribute to this project:

```bash
nix develop .
```

This will setup a bash shell with `clang`, `clangd`, `cmake`, `ninja`, and other necessary dependencies to build buddy-mlir from source.

- If you want to use the buddy-mlir bintools

```bash
nix build .#buddy-mlir
./result/bin/buddy-opt --version
```

## Dialects

### Bud Dialect
Expand Down
51 changes: 51 additions & 0 deletions nix/buddy-mlir.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{ cmake, ninja, python3, llvmPackages_16, fetchFromGitHub, libjpeg, libpng, zlib-ng }:
let
# Using git submodule to obtain the llvm source is really slow.
# So here I use tarball to save time from git index.
llvmSrc = fetchFromGitHub {
owner = "llvm";
repo = "llvm-project";
rev = "6c59f0e1b0fb56c909ad7c9aad4bde37dc006ae0";
sha256 = "sha256-bMJJ2q1hSh7m0ewclHOmIe7lOHv110rz/P7D3pw8Uiw";
};
in
# Use clang instead of gcc to build
llvmPackages_16.stdenv.mkDerivation {
pname = "buddy-mlir";
version = "unstable-2023-11-07+rev=38bfd56";

srcs = [
llvmSrc
../.
];
sourceRoot = "llvm-project";
unpackPhase = ''
sourceArray=($srcs)
cp -r ''${sourceArray[0]} llvm-project
cp -r ''${sourceArray[1]} buddy-mlir
# Directories copied from nix store are read only
chmod -R u+w llvm-project buddy-mlir
'';

# Tablegen in latest commit have bug. See llvm-projects issue #68166
prePatch = "pushd $NIX_BUILD_TOP/llvm-project";
patches = [ ./tblgen.patch ];
postPatch = "popd";

nativeBuildInputs = [ cmake ninja python3 llvmPackages_16.bintools libjpeg libpng zlib-ng ];

cmakeDir = "../llvm";
cmakeFlags = [
"-DCMAKE_BUILD_TYPE=Release"
"-DLLVM_ENABLE_PROJECTS=mlir"
"-DLLVM_TARGETS_TO_BUILD=host;RISCV"
"-DLLVM_ENABLE_ASSERTIONS=ON"
"-DLLVM_USE_LINKER=lld"

"-DLLVM_EXTERNAL_PROJECTS=buddy-mlir"
"-DLLVM_EXTERNAL_BUDDY_MLIR_SOURCE_DIR=../../buddy-mlir"
];

checkTarget = "check-mlir check-buddy";
}
1 change: 1 addition & 0 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ final: prev:
{
# Add an alias here can help future migration
llvmPkgs = final.llvmPackages_16;
buddy-mlir = final.callPackage ./buddy-mlir.nix { };
}

0 comments on commit c86f79b

Please sign in to comment.