Migrate to llvm18

This commit is contained in:
Sameer Rahmani 2024-04-06 20:05:01 +01:00
parent 8f46ca7744
commit 45b2a7805b
Signed by: lxsameer
GPG Key ID: 8741FACBF412FFA5
3 changed files with 78 additions and 65 deletions

View File

@ -5,11 +5,11 @@
"systems": "systems" "systems": "systems"
}, },
"locked": { "locked": {
"lastModified": 1701680307, "lastModified": 1710146030,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725", "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -20,18 +20,16 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1705092417, "dirtyRev": "1681ff1c67b9e337c204178d4cd85c9327e35eff-dirty",
"narHash": "sha256-01pTqprf3NvQijvxkQjwx2c6uevB4MZKooIcf+RTYHA=", "dirtyShortRev": "1681ff1c67b9-dirty",
"owner": "lxsameer", "lastModified": 1712254141,
"repo": "nixpkgs", "narHash": "sha256-r283uWBsHhcmTMIcAlGbM8c9wnc8b9AFweeNXnggbD8=",
"rev": "e1f7865bce4d52d30dd1d61e79798ee2765cc2b0", "type": "git",
"type": "github" "url": "file:///home/lxsameer/src/nixpkgs"
}, },
"original": { "original": {
"owner": "lxsameer", "type": "git",
"repo": "nixpkgs", "url": "file:///home/lxsameer/src/nixpkgs"
"rev": "e1f7865bce4d52d30dd1d61e79798ee2765cc2b0",
"type": "github"
} }
}, },
"root": { "root": {

View File

@ -17,17 +17,14 @@
description = "Serene programming language"; description = "Serene programming language";
#inputs.nixpkgs.url = "github:NixOS/nixpkgs/bcb1a9c7e1d8568c5e58316fe3254eb8f4455439"; #inputs.nixpkgs.url = "github:NixOS/nixpkgs/bcb1a9c7e1d8568c5e58316fe3254eb8f4455439";
inputs.nixpkgs.url = "github:lxsameer/nixpkgs/e1f7865bce4d52d30dd1d61e79798ee2765cc2b0"; #inputs.nixpkgs.url = "github:lxsameer/nixpkgs/e1f7865bce4d52d30dd1d61e79798ee2765cc2b0";
#inputs.nixpkgs.url = "/home/lxsameer/src/nixpkgs/"; inputs.nixpkgs.url = "/home/lxsameer/src/nixpkgs/";
inputs.flake-utils.url = "github:numtide/flake-utils"; inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = inputs@{ self, nixpkgs, flake-utils, ... }: outputs = inputs@{ self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system: flake-utils.lib.eachDefaultSystem (system:
let let
# Out zsh configuration directory. mkShell will pick up the .zshrc version = "1.0.0";
# from this directory.
zshDir = ./scripts;
# Most of these overlays are do to bugs and problems # Most of these overlays are do to bugs and problems
# in upstream nixpkgs. But thanks to their design # in upstream nixpkgs. But thanks to their design
# We can fix them using these overlays and contribuete # We can fix them using these overlays and contribuete
@ -70,8 +67,8 @@
}); });
#============================================================= #=============================================================
# Since we're using lld-17, and --no-undefined-version is the # Since we're using lld-18, and --no-undefined-version is the
# default in lld-17. We need to explicitely turn it off for # default in lld-18. We need to explicitly turn it off for
# these problematic packages untill they fix it upstream. # these problematic packages untill they fix it upstream.
libgcrypt = prev.libgcrypt.overrideAttrs (old: { libgcrypt = prev.libgcrypt.overrideAttrs (old: {
NIX_LDFLAGS = if prev.stdenv.cc.isClang NIX_LDFLAGS = if prev.stdenv.cc.isClang
@ -89,32 +86,45 @@
else []; else [];
}); });
libbsd = prev.libbsd.overrideAttrs (old: { #old.NIX_LDFLAGS ++ libbsd = prev.libbsd.overrideAttrs (old: { #
NIX_LDFLAGS = if prev.stdenv.cc.isClang NIX_LDFLAGS = if prev.stdenv.cc.isClang
then [ "--undefined-version" ] then [ "--undefined-version" ]
else []; else [];
}); });
binutils = prev.binutils.overrideAttrs (old: {
NIX_LDFLAGS = [ "-Wl,--undefined-version" ]# if prev.stdenv.cc.isClang
# then
# else []
;
});
libidn2 = prev.libidn2.overrideAttrs (old: { #old.NIX_LDFLAGS ++ libidn2 = prev.libidn2.overrideAttrs (old: { #old.NIX_LDFLAGS ++
NIX_LDFLAGS = if prev.stdenv.cc.isClang NIX_LDFLAGS = if prev.stdenv.cc.isClang
then [ "--undefined-version" ] then [ "--undefined-version" ]
else []; else [];
}); });
nghttp2 = prev.nghttp2.overrideAttrs (old: {
buildInputs = old.buildInputs ++ [ final.zlib ];
});
#============================================================== #==============================================================
iwyu = (prev.include-what-you-use.overrideAttrs (old: iwyu = (prev.include-what-you-use.overrideAttrs (old:
let let
version = "0.21"; version = "0.22";
in { in {
inherit version; inherit version;
src = prev.fetchurl { src = prev.fetchurl {
url = "${old.meta.homepage}/downloads/${old.pname}-${version}.src.tar.gz"; url = "${old.meta.homepage}/downloads/${old.pname}-${version}.src.tar.gz";
hash = "sha256-ajUZGf+JvafJXIlUcmAYaNs9qrlqlYs44DYokNWHYLY="; hash = "sha256-hZB0tGHqS4MlpzQYwgfKM7XmVmsI5rWH65FkQWVppt0=";
}; };
cmakeFlags = [ "-DCMAKE_PREFIX_PATH=${prev.llvmPackages_17.llvm.dev}" ]; cmakeFlags = [ "-DCMAKE_PREFIX_PATH=${prev.llvmPackages_18.llvm.dev}" ];
})).override { })).override {
llvmPackages = prev.__splicedPackages.llvmPackages_17; llvmPackages = prev.__splicedPackages.llvmPackages_18;
}; };
}) })
]; ];
@ -123,12 +133,14 @@
utils = import ./nix/utils.nix { inherit nixpkgs; }; utils = import ./nix/utils.nix { inherit nixpkgs; };
# Create a package set based on the build system # Create a package set based on the build system
pkgs = utils.get_pkgs system overlays; pkgs_set = utils.get_pkgs system overlays;
hostPkgs = pkgs_set.host;
pkgs = pkgs_set.target;
nativePkgs = import nixpkgs { inherit system overlays; }; nativePkgs = import nixpkgs { inherit system overlays; };
# Create a stdenv based on LLVM 17 # Create a stdenv based on LLVM
stdenv = pkgs.stdenvAdapters.overrideCC pkgs.stdenv pkgs.llvmPackages_17.clangUseLLVM; stdenv = pkgs.stdenvAdapters.overrideCC pkgs.stdenv pkgs.llvmPackages_18.clangUseLLVM;
gc = pkgs.callPackage ./nix/boehmgc.nix { inherit stdenv; }; gc = pkgs.callPackage ./nix/boehmgc.nix { inherit stdenv; };
@ -149,7 +161,7 @@
clang' = stdenv.cc.overrideAttrs (old: { clang' = stdenv.cc.overrideAttrs (old: {
propagatedBuildInputs = [ stdenv.cc.bintools ] ++ [ zlib' ]; propagatedBuildInputs = [ stdenv.cc.bintools ] ++ [ zlib' ];
}); });
llvm = pkgs.llvmPackages_17.llvm.overrideAttrs (old: { llvm = pkgs.llvmPackages_18.llvm.overrideAttrs (old: {
propagatedBuildInputs = [ zlib' ]; propagatedBuildInputs = [ zlib' ];
}); });
@ -167,12 +179,18 @@
old.preInstallCheck; old.preInstallCheck;
}); });
nativeBuildToolsDeps = (with hostPkgs; [
cmake
ninja
ccache
git
python3
]);
buildToolsDeps = (with pkgs; [ buildToolsDeps = (with pkgs; [
cmake
ninja
llvm llvm
llvmPackages_17.mlir llvmPackages_18.mlir
llvmPackages_17.clang llvmPackages_18.clang
iwyu iwyu
]); ]);
@ -183,28 +201,20 @@
zsh-syntax-highlighting zsh-syntax-highlighting
]); ]);
buildDevToolsDeps = (with pkgs; [
ccache
git'
python3
]);
buildDeps = (with pkgs; [ buildDeps = (with pkgs; [
gc gc
zlib' zlib'
llvm llvm
llvmPackages_17.mlir llvmPackages_18.mlir
llvmPackages_17.clang llvmPackages_18.clang
]); ]);
testDeps = (with pkgs; [ testDeps = (with hostPkgs; [
gtest gtest
gmock gmock
gbenchmark gbenchmark
]); ]);
tex = nativePkgs.texlive.combine { tex = nativePkgs.texlive.combine {
inherit (nativePkgs.texlive) inherit (nativePkgs.texlive)
scheme-minimal scheme-minimal
@ -242,12 +252,9 @@
in { in {
inherit pkgs; inherit pkgs;
devShells.default = (pkgs.mkShell.override { stdenv = stdenv';}) { devShells.default = (pkgs.mkShell.override { stdenv = stdenv';}) {
nativeBuildInputs = buildDevToolsDeps ++ buildToolsDeps ++ shellTools; nativeBuildInputs = nativeBuildToolsDeps ++ buildToolsDeps ++ shellTools;
buildInputs = buildDeps ++ testDeps; buildInputs = buildDeps ++ testDeps;
shellHook = CPP_LS = "serene-clangd";
''
BUILDER= ZDOTDIR=${zshDir} zsh -d && exit
'';
}; };
# This shell is gcc based and we use it only # This shell is gcc based and we use it only
@ -255,13 +262,17 @@
devShells.math = nativePkgs.mkShell { devShells.math = nativePkgs.mkShell {
#nativeBuildInputs = mathDeps; #nativeBuildInputs = mathDeps;
buildInputs = mathDeps; buildInputs = mathDeps;
shellHook =
''
BUILDER=Math ZDOTDIR=${zshDir} zsh -d && exit
'';
}; };
#packages.llvm = llvm; packages.devshell = stdenv'.mkDerivation {
inherit version;
name = "devshell";
doUnpack = false;
doCheck = false;
nativeBuildInputs = nativeBuildToolsDeps ++ buildToolsDeps ++ shellTools;
buildInputs = buildDeps ++ testDeps;
} ;
} }
); );
} }

View File

@ -16,15 +16,19 @@
{ nixpkgs }: { nixpkgs }:
{ {
get_pkgs = system: overlays: get_pkgs = system: overlays:
if system == "x86_64-linux" {
then import nixpkgs { host = import nixpkgs { inherit system; };
inherit system overlays; target =
linker = "lld"; if system == "x86_64-linux"
crossSystem = nixpkgs.lib.systems.examples.musl64 // { useLLVM = true; }; then import nixpkgs {
# config.replaceCrossStdenv = { buildPackages, baseStdenv }: inherit system overlays;
# buildPackages.stdenvAdapters.overrideCC baseStdenv buildPackages.llvmPackages_17.clangUseLLVM; linker = "lld";
} crossSystem = nixpkgs.lib.systems.examples.musl64 // { useLLVM = true; };
else import nixpkgs { # config.replaceCrossStdenv = { buildPackages, baseStdenv }:
inherit system overlays; # buildPackages.stdenvAdapters.overrideCC baseStdenv buildPackages.llvmPackages_17.clangUseLLVM;
}
else import nixpkgs {
inherit system overlays;
};
}; };
} }