Compare commits

...

2 Commits

6 changed files with 415 additions and 61 deletions

View File

@ -20,10 +20,10 @@
},
"nixpkgs": {
"locked": {
"dirtyRev": "aa8d093e3bede559e5681ca69aa05e6e1ad4ee9a-dirty",
"dirtyShortRev": "aa8d093e3bed-dirty",
"lastModified": 1700918627,
"narHash": "sha256-gcbm/2a4Hp4k2dpOl33hGARAiHMHH5HKyCSkzRGhpLQ=",
"dirtyRev": "60a403eaffc56570ccc2fefebd1e09acd0ceab53-dirty",
"dirtyShortRev": "60a403eaffc5-dirty",
"lastModified": 1701178202,
"narHash": "sha256-WcFAx8yBoAGAUH6bCRJQWohtnzARZwpYh0H17LuAPZI=",
"type": "git",
"url": "file:///home/lxsameer/src/nixpkgs"
},

187
flake.nix
View File

@ -1,3 +1,18 @@
# Serene Programming Language
#
# Copyright (c) 2019-2023 Sameer Rahmani <lxsameer@gnu.org>
#
# 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/>.
{
description = "Serene programming language";
@ -7,6 +22,7 @@
outputs = inputs@{ self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
zshDir = ./scripts/zsh;
llvm = {
url = "https://devheroes.codes/Serene/llvm-project.git";
major = "16";
@ -16,32 +32,36 @@
rev-version = "17-disable-shared-1";
};
overlays = [
(self: super:
{
serene_toolchain = (super.callPackage (super.path + "/pkgs/development/compilers/llvm/${llvm.major}") ({
inherit (super.stdenvAdapters) overrideCC;
buildLlvmTools = super.buildPackages.serene_toolchain.tools;
targetLlvmLibraries = self.targetPackages.serene_toolchain.libraries or self.serene_toolchain.libraries;
targetLlvm = self.targetPackages.serene_toolchain.llvm or self.serene_toolchain.llvm;
monorepoSrc = super.fetchgit {
url = llvm.url;
rev = llvm.rev;
hash = llvm.hash;
};
officialRelease = null;
gitRelease = {
version = llvm.version;
rev = llvm.rev;
rev-version = llvm.rev-version;
};
}));
})
# (self: super:
# {
# serene_toolchain = (super.callPackage (super.path + "/pkgs/development/compilers/llvm/${llvm.major}") ({
# inherit (super.stdenvAdapters) overrideCC;
# buildLlvmTools = super.buildPackages.serene_toolchain.tools;
# targetLlvmLibraries = self.targetPackages.serene_toolchain.libraries or self.serene_toolchain.libraries;
# targetLlvm = self.targetPackages.serene_toolchain.llvm or self.serene_toolchain.llvm;
# monorepoSrc = super.fetchgit {
# url = llvm.url;
# rev = llvm.rev;
# hash = llvm.hash;
# };
# officialRelease = null;
# gitRelease = {
# version = llvm.version;
# rev = llvm.rev;
# rev-version = llvm.rev-version;
# };
# }));
# })
(final: prev: {
cpio = prev.cpio.overrideAttrs (old: {
p11-kit = prev.p11-kit.overrideAttrs (old: {
patches = [
./patches/0001-configure-Include-needed-header-for-major-minor-macr.patch
./scripts/patches/p11-kit_skip_test.patch
];
});
cpio = prev.cpio.overrideAttrs (old: {
nativeBuildInputs = [ prev.autoreconfHook ];
NIX_CFLAGS_COMPILE = "-Wno-implicit-function-declaration";
});
@ -62,17 +82,33 @@
# We don't need systemd at all
util-linux = prev.util-linux.override { systemdSupport = false; };
# iwyu = (prev.include-what-you-use.overrideAttrs (old:
# let
# version = "0.20";
# in {
# inherit version;
# src = prev.fetchurl {
# url = "${old.meta.homepage}/downloads/${old.pname}-${version}.src.tar.gz";
# hash = "sha256-dfzh5khfKA+PE/TC0JCxHS/SECtQhXUHyEE6kZt6+Jk=";
# };
# cmakeFlags = [ "-DCMAKE_PREFIX_PATH=${prev.llvmPackages_16.llvm.dev}" ];
# })).override {
# llvmPackages = prev.__splicedPackages.llvmPackages_16;
# };
})
];
get_pkgs = system:
if system == "x86_64-linux"
then import nixpkgs {
then import nixpkgs {
inherit system overlays;
crossSystem = nixpkgs.lib.systems.examples.musl64 // { useLLVM = true; };
config.replaceCrossStdenv = { buildPackages, baseStdenv }:
buildPackages.stdenvAdapters.overrideCC baseStdenv buildPackages.llvmPackages_16.clangUseLLVM;
}
}
else import nixpkgs {
inherit system overlays;
};
@ -80,57 +116,94 @@
pkgs = get_pkgs system;
sereneLLVM = pkgs.callPackage ./nix/llvm.nix {
inherit (pkgs) lib stdenv cmake ninja ccache zlib libxml2 fetchgit;
};
stdenv = pkgs.stdenvAdapters.overrideCC pkgs.stdenv sereneLLVM;
#with pkgs;
native_build_inputs =
let
filterCmakeFlags = xs: builtins.filter
(x: !(x == "-DCMAKE_CROSSCOMPILING=True" || pkgs.lib.hasPrefix "-DLLVM_TABLEGEN=" x))
xs;
git' = pkgs.git.overrideAttrs (old: {
preInstallCheck =
pkgs.lib.replaceStrings [ ''disable_test t0201-gettext-fallbacks'' ]
[ ''
preInstallCheck =
pkgs.lib.replaceStrings [ ''disable_test t0201-gettext-fallbacks'' ]
[ ''
disable_test t0201-gettext-fallbacks
disable_test t2082-parallel-checkout-attributes
'' ]
old.preInstallCheck;
old.preInstallCheck;
});
in with pkgs; [
cmake
ninja
ccache
# serene_toolchain.lldb
# serene_toolchain.lld
# serene_toolchain.libcxx
# serene_toolchain.libcxxabi
# serene_toolchain.compiler-rt
git'
zsh
python3
];
# iwyu = (pkgs.include-what-you-use.overrideAttrs (old:
# let
# version = "0.20";
# in {
# inherit version;
build_inputs = with pkgs; [
# src = pkgs.fetchurl {
# url = "${old.meta.homepage}/downloads/${old.pname}-${version}.src.tar.gz";
# hash = "sha256-dfzh5khfKA+PE/TC0JCxHS/SECtQhXUHyEE6kZt6+Jk=";
# };
# })).override {
# llvmPackages = pkgs.__splicedPackages.llvmPackages_16;# .overrideAttrs (oldLLVM: {
# # cmakeFlags = builtins.trace ">> ${toString(filterCmakeFlags oldLLVM.cmakeFlags)}" filterCmakeFlags oldLLVM.cmakeFlags;
# # });
# };
# mlir_16' = pkgs.mlir_16.overrideAttrs (old: {
# });
in builtins.trace ">> ${sereneLLVM}" (with pkgs; [
cmake
ninja
ccache
git'
zsh
zsh-autosuggestions
zsh-autocomplete
zsh-syntax-highlighting
python3
sereneLLVM
# iwyu
]);
build_inputs = with pkgs; [
boehmgc
# llvm_16
# llvm_16
# mlir_16
gtest
gmock
# zlib-ng
# zstd
include-what-you-use
];
in {
inherit pkgs;
devShells.default = pkgs.mkShell {
nativeBuildInputs = native_build_inputs;
buildInputs = build_inputs;
shellHook = ''zsh --norcs && exit'';
};
inherit pkgs;
devShells.default = (pkgs.mkShell.override {inherit stdenv;}) {
nativeBuildInputs = native_build_inputs;
buildInputs = build_inputs;
shellHook =
''
ZDOTDIR=${zshDir} zsh -d && exit
'';
};
packages.cmake = pkgs.cmake;
packages.blah = pkgs.stdenv.mkDerivation {
pname = "blah";
version = "0.1";
nativeBuildInputs = native_build_inputs;
buildInputs = build_inputs;
};
}
packages.cmake = pkgs.cmake;
packages.blah = pkgs.stdenv.mkDerivation {
pname = "blah";
version = "0.1";
nativeBuildInputs = native_build_inputs;
buildInputs = build_inputs;
};
packages.mlir = pkgs.mlir_16;
}
);
}

163
nix/llvm.nix Normal file
View File

@ -0,0 +1,163 @@
# Serene Programming Language
#
# Copyright (c) 2019-2023 Sameer Rahmani <lxsameer@gnu.org>
#
# 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/>.
{ lib,
stdenv,
cmake,
ninja,
libxml2,
python3,
fetchgit,
zlib,
ccache ? null,
useCcache ? false,
url ? "https://github.com/llvm/llvm-project.git",
hash ? "sha256-8MEDLLhocshmxoEBRSKlJ/GzJ8nfuzQ8qn0X/vLA+ag=",
version ? "17.0.6",
ref ? "refs/tags/llvmorg-${version}"
}:
let
ncpus = builtins.getEnv "NIX_BUILD_CORES";
in builtins.trace ">>> ${toString ncpus}" stdenv.mkDerivation rec {
inherit version;
pname = "serene_llvm";
src = fetchgit {
inherit url hash;
rev = ref;
};
sourceRoot = "${src.name}/llvm";
nativeBuildInputs = [ cmake ninja python3 zlib ];
buildInputs = [ libxml2 zlib ];
NIX_CFLAGS_COMPILE = ["-fno-rtti"];
#ninjaFlags = [ "-v" ];
cmakeFlags = [
# "-DLLVM_PARALLEL_COMPILE_JOBS=${ncpus}"
# "-DLLVM_PARALLEL_LINK_JOBS=1"
"-DLLVM_BUILD_EXAMPLES=ON"
"-DLLVM_TARGETS_TO_BUILD='X86'"
"-DCMAKE_BUILD_TYPE=Release"
"-DLLVM_ENABLE_ASSERTIONS=ON"
"-DLLVM_CCACHE_BUILD=OFF"
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
# No lldb? Yes, lldb links against liblldb.so and since we use
# -static with our executables that wouldn't be easy to handle
# and I'm lazy. We can just compile the lldb or any other debugger
# on the host
"-DLLVM_ENABLE_PROJECTS='clang;lld;mlir;clang-tools-extra'"
"-DLLVM_RUNTIME_TARGETS='compiler-rt;libcxx;libcxxabi;libunwind'"
"-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}"
"-DLLVM_RUNTIME_TARGET=${stdenv.hostPlatform.config}"
# Serene uses static libs, so no shared lib
"-DLLVM_ENABLE_PIC=OFF"
#"-DLLVM_BUILD_STATIC=ON"
"-DLLVM_LINK_LLVM_DYLIB=off"
"-DLLVM_ENABLE_LIBXML2=OFF"
"-DLLVM_BUILD_DOCS=OFF"
"-DLLVM_ENABLE_SPHINX=OFF"
"-DSPHINX_OUTPUT_MAN=OFF"
"-DSPHINX_OUTPUT_HTML=OFF"
"-DCMAKE_POSITION_INDEPENDENT_CODE=ON"
"-DCLANG_DEFAULT_CXX_STDLIB=libc++"
"-DCLANG_DEFAULT_LINKER=lld"
"-DCLANG_DEFAULT_OBJCOPY=llvm-objcopy"
"-DCLANG_DEFAULT_RTLIB=compiler-rt"
"-DCLANG_VENDOR_UTI=serene.toolchain"
"-DLLVM_ENABLE_LIBCXX=ON"
"-DLLVM_ENABLE_NEW_PASS_MANAGER=ON"
"-DLLVM_BUILD_TESTS=OFF"
"-DLLVM_ENABLE_ASSERTIONS=ON"
"-DLLVM_ENABLE_LIBXML2=OFF"
"-DLLVM_ENABLE_TERMINFO=OFF"
#"-DLLVM_ENABLE_ZLIB=FORCE_ON"
"-DLLVM_INCLUDE_BENCHMARKS=OFF"
"-DLLVM_INCLUDE_EXAMPLES=OFF"
"-DLLVM_INCLUDE_TESTS=OFF"
"-DLLVM_INCLUDE_GO_TESTS=OFF"
"-DLLVM_ENABLE_BINDINGS=OFF"
#"-DLLVM_TARGETS_TO_BUILD": "X86;AArch64;AMDGPU;ARM;RISCV;WebAssembly"
"-DLLVM_STATIC_LINK_CXX_STDLIB=ON"
"-DPACKAGE_VENDOR=Serene"
"-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON"
"-DENABLE_X86_RELAX_RELOCATIONS=ON"
"-DBUILD_SHARED_LIBS=OFF"
"-DCLANG_ENABLE_BOOTSTRAP=ON"
"-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON"
"-DLIBCXXABI_ENABLE_SHARED=OFF"
"-DLIBCXX_ABI_VERSION=2"
"-DLIBCLANG_BUILD_STATIC=ON"
"-DCMAKE_INSTALL_PREFIX=${placeholder "out"}"
"-DCMAKE_INSTALL_BINDIR=${placeholder "out"}/bin"
"-DCMAKE_INSTALL_INCLUDEDIR=${placeholder "out"}/include"
"-DCMAKE_INSTALL_LIBDIR=${placeholder "out"}/lib"
"-DCMAKE_INSTALL_LIBEXECDIR=${placeholder "out"}/libexec"
] ++ lib.optional stdenv.hostPlatform.isMusl [
"-DDLIBCXX_HAS_MUSL_LIBC=ON"
] ++ lib.optional stdenv.hostPlatform.isStatic [
"-DLIBCLANG_BUILD_STATIC=ON"
] ++ lib.optional useCcache [
"-DLLVM_CCACHE_BUILD=ON"
];
meta = {
homepage = "https://llvm.org/";
description = "A collection of modular and reusable compiler and toolchain technologies";
longDescription = ''
The LLVM Project is a collection of modular and reusable compiler and
toolchain technologies. Despite its name, LLVM has little to do with
traditional virtual machines. The name "LLVM" itself is not an acronym; it
is the full name of the project.
LLVM began as a research project at the University of Illinois, with the
goal of providing a modern, SSA-based compilation strategy capable of
supporting both static and dynamic compilation of arbitrary programming
languages. Since then, LLVM has grown to be an umbrella project consisting
of a number of subprojects, many of which are being used in production by
a wide variety of commercial and open source projects as well as being
widely used in academic research. Code in the LLVM project is licensed
under the "Apache 2.0 License with LLVM exceptions".
'';
license = lib.licenses.ncsa;
# TODO: Add the maintainer
# maintainers = "Sameer Rahmani []";
# See llvm/cmake/config-ix.cmake.
platforms =
lib.platforms.aarch64 ++
lib.platforms.arm ++
lib.platforms.mips ++
lib.platforms.power ++
lib.platforms.s390x ++
lib.platforms.wasi ++
lib.platforms.x86 ++
lib.platforms.riscv ++
lib.platforms.m68k;
};
}
# -DCMAKE_C_COMPILER=clang \ # If you have clang installed already
# -DCMAKE_CXX_COMPILER=clang++ \ # If you have clang installed already
# -DLLVM_ENABLE_LLD=ON

19
nix/utils.nix Normal file
View File

@ -0,0 +1,19 @@
# Serene Programming Language
#
# Copyright (c) 2019-2023 Sameer Rahmani <lxsameer@gnu.org>
#
# 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/>.
{ lib }:
{
}

View File

@ -0,0 +1,27 @@
From 132b779414c2236c1350b578b59c8edcfc4c5a14 Mon Sep 17 00:00:00 2001
From: Sameer Rahmani <lxsameer@gnu.org>
Date: Sat, 25 Nov 2023 13:14:42 +0000
Subject: [PATCH] test
---
common/test.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/common/test.c b/common/test.c
index 6cdbd1fa2118..6cd6f84bcdc7 100644
--- a/common/test.c
+++ b/common/test.c
@@ -614,8 +614,9 @@ p11_test_copy_setgid (const char *input,
assert (fd >= 0);
copy_file (input, fd);
- if (fchown (fd, getuid (), group) < 0)
- assert_not_reached ();
+ if (fchown (fd, getuid (), group) < 0) {
+ return NULL;
+ }
if (fchmod (fd, 02750) < 0)
assert_not_reached ();
if (close (fd) < 0)
--
2.41.0

72
scripts/zsh/.zshrc Normal file
View File

@ -0,0 +1,72 @@
#! /bin/zsh
# shellcheck disable=all
# Serene Programming Language
#
# Copyright (c) 2019-2023 Sameer Rahmani <lxsameer@gnu.org>
#
# 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/>.
mkdir -p "$HOME/.config/serene/"
export HISTFILE="$HOME/.config/serene/.zsh_history"
export HISTFILESIZE=500
export SAVEHIST=500
export HISTSIZE=500
setopt HIST_IGNORE_DUPS
setopt NO_HIST_BEEP
setopt PROMPT_SUBST
setopt NO_BEEP
setopt AUTO_CD
setopt CORRECT
setopt SHARE_HISTORY
setopt HIST_IGNORE_ALL_DUPS
function user_prompt () {
if [ $UID != 0 ]; then
echo "%F{028}%F{002}> "
else
echo "%F{001}# "
fi
}
autoload -U colors && colors
autoload -Uz compinit
compinit
# zstyle ':completion:*' auto-description 'specify: %d'
# zstyle ':completion:*' completer _expand _complete _correct _approximate
# zstyle ':completion:*' format 'Completing %d'
# zstyle ':completion:*' group-name ''
# if [ "$(uname 2> /dev/null)" = "Linux" ]; then
# zstyle ':completion:*' menu select=2 eval "$(dircolors -b)"
# fi
# zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
# zstyle ':completion:*' list-colors ''
# zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
# zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
# zstyle ':completion:*' menu select=long
# zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
# zstyle ':completion:*' use-compctl false
# zstyle ':completion:*' verbose true
# zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
# zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
echo "Welcome to serene's development environment"
PROMPT='
%F{015}[%F{099}SERENE%F{015}][%F{198}$(git branch --show-current)%F{015}]
%F{005}%~%F{003} $(user_prompt)%f'
export PROMPT