Skip to content

Commit b6aca6c

Browse files
committed
WIP
1 parent 6561be8 commit b6aca6c

File tree

2 files changed

+198
-0
lines changed

2 files changed

+198
-0
lines changed

flake.nix

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
{
2+
description = "Custom-Built MLIR";
3+
# Nixpkgs / NixOS version to use.
4+
inputs.nixpkgs.url = "nixpkgs/nixos-22.11";
5+
6+
outputs = { self, nixpkgs }:
7+
let
8+
9+
# to work with older version of flakes
10+
lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101";
11+
# Generate a user-friendly version number.
12+
version = builtins.substring 0 8 lastModifiedDate;
13+
# System types to support.
14+
supportedSystems = [ "x86_64-linux" ]; #"x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
15+
# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
16+
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
17+
# Nixpkgs instantiated for supported system types.
18+
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; overlays = [ self.overlay ]; });
19+
20+
in
21+
{
22+
23+
# A Nixpkgs overlay.
24+
overlay = final: prev: {
25+
mlir = with final; stdenv.mkDerivation rec {
26+
name = "mlir-${version}";
27+
28+
src = fetchFromGitHub {
29+
owner = "llvm";
30+
repo = "llvm-project";
31+
rev = "49caf7012170422afa84868598063818f9344228";
32+
sha256 = "sha256-j+ladpx8NfJGszj17oRkgvb4U2race+2DTKLtRZGeUM=";
33+
};
34+
35+
sourceRoot = "source/llvm";
36+
37+
nativeBuildInputs = [
38+
ninja
39+
cmake
40+
ccache
41+
llvmPackages_latest.llvm
42+
llvmPackages_latest.clang
43+
llvmPackages_latest.lld
44+
python311
45+
];
46+
propagatedBuildInputs = [ ncurses zlib ];
47+
48+
buildPhase = ''
49+
# this line removes a bug where value of $HOME is set to a non-writable /homeless-shelter dir
50+
export HOME=$(pwd)
51+
export LD_LIBRARY_PATH=$(nix eval --raw nixpkgs#zlib)/lib:$LD_LIBRARY_PATH
52+
'';
53+
cmakeFlags = [
54+
"-GNinja"
55+
# Debug for debug builds
56+
"-DCMAKE_BUILD_TYPE=Release"
57+
# inst will be our installation prefix
58+
"-DCMAKE_INSTALL_PREFIX=../inst" # I know, this has to be patched still
59+
# change this to enable the projects you need
60+
"-DLLVM_ENABLE_PROJECTS=mlir"
61+
"-DLLVM_BUILD_EXAMPLES=ON"
62+
# this makes llvm only to produce code for the current platform, this saves CPU time, change it to what you need
63+
"-DLLVM_TARGETS_TO_BUILD=host"
64+
"-DLLVM_ENABLE_ASSERTIONS=ON"
65+
# Using clang and lld speeds up the build, we recomment adding:
66+
"-DCMAKE_C_COMPILER=clang"
67+
"-DCMAKE_CXX_COMPILER=clang++"
68+
"-DLLVM_ENABLE_LLD=ON"
69+
# CCache can drastically speed up further rebuilds, try adding:
70+
"-DLLVM_CCACHE_BUILD=ON"
71+
# libxml2 needs to be disabled because the LLVM build system ignores its .la
72+
# file and doesn't link zlib as well.
73+
# https://github.com/ClangBuiltLinux/tc-build/issues/150#issuecomment-845418812
74+
"-DLLVM_ENABLE_LIBXML2=OFF"
75+
];
76+
};
77+
78+
};
79+
80+
# Provide some binary packages for selected system types.
81+
packages = forAllSystems (system:
82+
{
83+
inherit (nixpkgsFor.${system}) mlir;
84+
});
85+
86+
# The default package for 'nix build'. This makes sense if the
87+
# flake provides only one package or there is a clear "main"
88+
# package.
89+
defaultPackage = forAllSystems (system: self.packages.${system}.mlir);
90+
91+
# A NixOS module, if applicable (e.g. if the package provides a system service).
92+
nixosModules.mlir =
93+
{ pkgs, ... }:
94+
{
95+
nixpkgs.overlays = [ self.overlay ];
96+
environment.systemPackages = [ pkgs.mlir ];
97+
};
98+
99+
};
100+
}
101+
102+

llvmmlir.nix

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
description = "Custom-Built MLIR";
3+
# Nixpkgs / NixOS version to use.
4+
inputs.nixpkgs.url = "nixpkgs/nixos-22.11";
5+
6+
outputs = { self, nixpkgs }:
7+
let
8+
9+
# to work with older version of flakes
10+
lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101";
11+
# Generate a user-friendly version number.
12+
version = builtins.substring 0 8 lastModifiedDate;
13+
# System types to support.
14+
supportedSystems = [ "x86_64-linux" ]; #"x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
15+
# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
16+
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
17+
# Nixpkgs instantiated for supported system types.
18+
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; overlays = [ self.overlay ]; });
19+
20+
in
21+
{
22+
23+
# A Nixpkgs overlay.
24+
overlay = final: prev: {
25+
mlir = with final; stdenv.mkDerivation rec {
26+
name = "mlir-${version}";
27+
28+
src = fetchFromGitHub {
29+
owner = "llvm";
30+
repo = "llvm-project";
31+
rev = "49caf7012170422afa84868598063818f9344228";
32+
sha256 = "sha256-j+ladpx8NfJGszj17oRkgvb4U2race+2DTKLtRZGeUM=";
33+
};
34+
35+
sourceRoot = "source/llvm";
36+
37+
nativeBuildInputs = [
38+
ninja
39+
cmake
40+
ccache
41+
llvmPackages_latest.llvm
42+
llvmPackages_latest.clang
43+
llvmPackages_latest.lld
44+
];
45+
propagatedBuildInputs = [ ncurses zlib ];
46+
47+
cmakeFlags = [
48+
"-GNinja"
49+
# Debug for debug builds
50+
"-DCMAKE_BUILD_TYPE=Release"
51+
# inst will be our installation prefix
52+
"-DCMAKE_INSTALL_PREFIX=../inst" # I know, this has to be patched still
53+
# change this to enable the projects you need
54+
"-DLLVM_ENABLE_PROJECTS=mlir"
55+
"-DLLVM_BUILD_EXAMPLES=ON"
56+
# this makes llvm only to produce code for the current platform, this saves CPU time, change it to what you need
57+
"-DLLVM_TARGETS_TO_BUILD=host"
58+
"-DLLVM_ENABLE_ASSERTIONS=ON"
59+
# Using clang and lld speeds up the build, we recomment adding:
60+
"-DCMAKE_C_COMPILER=clang"
61+
"-DCMAKE_CXX_COMPILER=clang++"
62+
"-DLLVM_ENABLE_LLD=ON"
63+
# CCache can drastically speed up further rebuilds, try adding:
64+
"-DLLVM_CCACHE_BUILD=ON"
65+
# libxml2 needs to be disabled because the LLVM build system ignores its .la
66+
# file and doesn't link zlib as well.
67+
# https://github.com/ClangBuiltLinux/tc-build/issues/150#issuecomment-845418812
68+
"-DLLVM_ENABLE_LIBXML2=OFF"
69+
];
70+
};
71+
72+
};
73+
74+
# Provide some binary packages for selected system types.
75+
packages = forAllSystems (system:
76+
{
77+
inherit (nixpkgsFor.${system}) mlir;
78+
});
79+
80+
# The default package for 'nix build'. This makes sense if the
81+
# flake provides only one package or there is a clear "main"
82+
# package.
83+
defaultPackage = forAllSystems (system: self.packages.${system}.mlir);
84+
85+
# A NixOS module, if applicable (e.g. if the package provides a system service).
86+
nixosModules.mlir =
87+
{ pkgs, ... }:
88+
{
89+
nixpkgs.overlays = [ self.overlay ];
90+
environment.systemPackages = [ pkgs.mlir ];
91+
};
92+
93+
};
94+
}
95+
96+

0 commit comments

Comments
 (0)