2023-12-03 19:00:20 +00:00
|
|
|
# Serene Programming Language
|
|
|
|
#
|
2024-01-15 23:53:22 +00:00
|
|
|
# Copyright (c) 2019-2024 Sameer Rahmani <lxsameer@gnu.org>
|
2023-12-03 19:00:20 +00:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, version 2.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2023-11-25 21:18:22 +00:00
|
|
|
{
|
|
|
|
description = "Serene programming language";
|
|
|
|
|
2024-04-07 22:32:36 +01:00
|
|
|
inputs.nixpkgs.url =
|
|
|
|
"github:lxsameer/nixpkgs/c738ee8ad1c35383037c20fa13eaac17c8ae98c5";
|
|
|
|
#inputs.nixpkgs.url = "/home/lxsameer/src/nixpkgs/";
|
2024-04-06 22:40:08 +01:00
|
|
|
inputs.git-hooks.url = "github:cachix/git-hooks.nix";
|
2023-11-25 21:18:22 +00:00
|
|
|
inputs.flake-utils.url = "github:numtide/flake-utils";
|
|
|
|
|
2024-04-07 22:32:36 +01:00
|
|
|
outputs = { self, nixpkgs, git-hooks, flake-utils, ... }:
|
2023-11-25 21:18:22 +00:00
|
|
|
flake-utils.lib.eachDefaultSystem (system:
|
|
|
|
let
|
2024-04-06 20:05:01 +01:00
|
|
|
version = "1.0.0";
|
2024-04-07 22:32:36 +01:00
|
|
|
|
|
|
|
overlays = [ (import ./nix/overlays.nix { }).muslComp ];
|
2023-11-25 21:18:22 +00:00
|
|
|
|
2024-01-14 21:47:50 +00:00
|
|
|
utils = import ./nix/utils.nix { inherit nixpkgs; };
|
2023-11-25 21:18:22 +00:00
|
|
|
|
2024-01-14 21:47:50 +00:00
|
|
|
# Create a package set based on the build system
|
2024-04-06 20:05:01 +01:00
|
|
|
pkgs_set = utils.get_pkgs system overlays;
|
|
|
|
hostPkgs = pkgs_set.host;
|
|
|
|
pkgs = pkgs_set.target;
|
2023-12-21 22:51:47 +00:00
|
|
|
|
2024-04-06 20:05:01 +01:00
|
|
|
# Create a stdenv based on LLVM
|
2024-04-06 22:40:08 +01:00
|
|
|
stdenv = pkgs.stdenvAdapters.overrideCC pkgs.stdenv
|
|
|
|
pkgs.llvmPackages_18.clangUseLLVM;
|
2023-12-21 22:51:47 +00:00
|
|
|
|
2024-01-14 19:58:43 +00:00
|
|
|
gc = pkgs.callPackage ./nix/boehmgc.nix { inherit stdenv; };
|
2023-12-21 22:51:47 +00:00
|
|
|
|
2024-01-14 21:47:50 +00:00
|
|
|
zlib' = pkgs.zlib-ng.overrideAttrs (old: {
|
|
|
|
cmakeFlags = [
|
|
|
|
"-DCMAKE_INSTALL_PREFIX=/"
|
|
|
|
"-DBUILD_SHARED_LIBS=OFF"
|
|
|
|
"-DINSTALL_UTILS=ON"
|
|
|
|
"-DZLIB_COMPAT=ON"
|
|
|
|
];
|
2023-12-21 22:51:47 +00:00
|
|
|
});
|
|
|
|
|
2024-01-14 21:47:50 +00:00
|
|
|
# By default llvm adds zlib to `propagatedBuildInputs` which means any
|
|
|
|
# package that uses llvm will indirectly depends on zlib. And since
|
|
|
|
# by default that zlib is built as a shared lib (since our packageset
|
|
|
|
# is not static), We can't statically link to it. So, we just replace
|
|
|
|
# that zlib with our override of zlib-ng
|
|
|
|
clang' = stdenv.cc.overrideAttrs (old: {
|
2024-04-07 22:32:36 +01:00
|
|
|
propagatedBuildInputs = [ stdenv.cc.bintools ]
|
|
|
|
++ [ pkgs.zlib.static ];
|
2024-01-14 21:47:50 +00:00
|
|
|
});
|
2024-04-07 22:32:36 +01:00
|
|
|
|
2024-04-06 22:40:08 +01:00
|
|
|
llvm = pkgs.llvmPackages_18.llvm.overrideAttrs
|
2024-04-07 22:32:36 +01:00
|
|
|
(old: { propagatedBuildInputs = [ pkgs.zlib.static ]; });
|
2023-12-03 22:03:33 +00:00
|
|
|
|
2024-01-14 21:47:50 +00:00
|
|
|
# This is the actual stdenv that we need to use anywhere else
|
|
|
|
stdenv' = pkgs.stdenvAdapters.overrideCC pkgs.stdenv clang';
|
2023-12-03 19:00:20 +00:00
|
|
|
|
2024-04-06 22:40:08 +01:00
|
|
|
nativeBuildToolsDeps = (with hostPkgs; [ cmake ninja ccache ]);
|
2024-01-16 17:23:26 +00:00
|
|
|
|
2024-04-06 22:40:08 +01:00
|
|
|
buildToolsDeps =
|
|
|
|
(with pkgs; [ llvm llvmPackages_18.mlir llvmPackages_18.clang iwyu ]);
|
2024-01-16 17:23:26 +00:00
|
|
|
|
|
|
|
buildDeps = (with pkgs; [
|
2024-01-14 19:58:43 +00:00
|
|
|
gc
|
2024-01-14 21:47:50 +00:00
|
|
|
zlib'
|
2024-01-14 19:58:43 +00:00
|
|
|
llvm
|
2024-04-06 20:05:01 +01:00
|
|
|
llvmPackages_18.mlir
|
|
|
|
llvmPackages_18.clang
|
2024-01-16 17:23:26 +00:00
|
|
|
]);
|
|
|
|
|
2024-04-06 22:40:08 +01:00
|
|
|
testDeps = (with hostPkgs; [ gtest gmock gbenchmark ]);
|
2024-01-28 22:01:19 +00:00
|
|
|
|
2023-11-25 21:18:22 +00:00
|
|
|
in {
|
2023-12-03 19:00:20 +00:00
|
|
|
inherit pkgs;
|
2024-04-06 22:40:08 +01:00
|
|
|
devShells.default = (pkgs.mkShell.override { stdenv = stdenv'; }) {
|
|
|
|
inherit (self.checks.${system}.git-hook-check) shellHook;
|
2024-01-26 20:20:46 +00:00
|
|
|
|
2024-04-06 22:40:08 +01:00
|
|
|
nativeBuildInputs = nativeBuildToolsDeps ++ buildToolsDeps;
|
|
|
|
buildInputs = buildDeps ++ testDeps
|
|
|
|
++ self.checks.${system}.git-hook-check.enabledPackages;
|
|
|
|
CPP_LS = "serene-clangd";
|
2023-12-03 19:00:20 +00:00
|
|
|
};
|
2023-11-25 21:18:22 +00:00
|
|
|
|
2024-04-06 20:05:01 +01:00
|
|
|
packages.devshell = stdenv'.mkDerivation {
|
|
|
|
inherit version;
|
|
|
|
name = "devshell";
|
|
|
|
|
|
|
|
doUnpack = false;
|
|
|
|
doCheck = false;
|
2024-04-06 22:40:08 +01:00
|
|
|
nativeBuildInputs = nativeBuildToolsDeps ++ buildToolsDeps;
|
2024-04-06 20:05:01 +01:00
|
|
|
buildInputs = buildDeps ++ testDeps;
|
2024-04-06 22:40:08 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
checks = {
|
|
|
|
git-hook-check = git-hooks.lib.${system}.run {
|
|
|
|
src = ./.;
|
|
|
|
hooks = {
|
|
|
|
nixfmt.enable = true;
|
|
|
|
clang-format = {
|
|
|
|
enable = true;
|
|
|
|
types_or = hostPkgs.lib.mkForce [ "c" "c++" ];
|
|
|
|
};
|
|
|
|
shellcheck.enable = true;
|
|
|
|
cmake-format.enable = true;
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
2023-11-25 21:18:22 +00:00
|
|
|
}
|