Several nix fixes (#1737)

* Fixed nix c3c development shell

* Fix unknown git hash on nix build
This commit is contained in:
vssukharev
2024-12-29 22:12:26 +02:00
committed by GitHub
parent 1340a47bc2
commit 7b734df09e
3 changed files with 40 additions and 38 deletions

View File

@@ -7,53 +7,46 @@
libxml2,
libffi,
xar,
rev ? "unknown",
debug ? false,
checks ? false,
}: let
inherit (builtins) baseNameOf toString readFile elemAt;
inherit (lib.sources) cleanSourceWith cleanSource;
inherit (builtins) readFile elemAt;
# inherit (lib.sources) cleanSourceWith cleanSource;
inherit (lib.lists) findFirst;
inherit (lib.asserts) assertMsg;
inherit (lib.strings) hasInfix hasSuffix splitString removeSuffix removePrefix optionalString;
in
llvmPackages.stdenv.mkDerivation (finalAttrs: {
inherit (lib.strings) hasInfix splitString removeSuffix removePrefix optionalString;
in llvmPackages.stdenv.mkDerivation (finalAttrs: {
pname = "c3c${optionalString debug "-debug"}";
version = let
findLine = findFirst (x: hasInfix "COMPILER_VERSION" x) "none";
foundLine = findLine ( splitString "\n" ( readFile ../src/version.h ) );
version = removeSuffix "\"" ( removePrefix "\"" ( elemAt ( splitString " " foundLine ) 2 ) );
foundLine = findFirst (x: hasInfix "COMPILER_VERSION" x) "none" ( splitString "\n" ( readFile ../src/version.h ) );
in
assert assertMsg (foundLine != "none") "No COMPILER_VERSION substring was found in version.h";
version;
src = cleanSourceWith {
filter = _path: _type: !(hasSuffix ".nix" (baseNameOf(toString _path)));
src = cleanSource ../.;
};
postPatch = ''
substituteInPlace CMakeLists.txt \
--replace-fail "\''${LLVM_LIBRARY_DIRS}" "${llvmPackages.lld.lib}/lib ${llvmPackages.llvm.lib}/lib"
'';
removeSuffix "\"" ( removePrefix "\"" ( elemAt ( splitString " " foundLine ) 2 ) );
src = ../.;
cmakeBuildType = if debug then "Debug" else "Release";
postPatch = ''
substituteInPlace git_hash.cmake \
--replace-fail "\''${GIT_HASH}" "${rev}"
'';
cmakeFlags = [
"-DC3_ENABLE_CLANGD_LSP=${if debug then "ON" else "OFF"}"
"-DC3_LLD_DIR=${llvmPackages.lld.lib}/lib"
];
nativeBuildInputs = [ cmake ];
postBuild = optionalString debug ''
mkdir $out
substituteInPlace compile_commands.json \
--replace "/build/source/" "$src/"
cp compile_commands.json $out/compile_commands.json
'';
nativeBuildInputs = [
cmake
llvmPackages.llvm
llvmPackages.lld
];
buildInputs = [
llvmPackages.llvm
llvmPackages.lld
curl
libxml2
libffi
@@ -70,6 +63,7 @@ llvmPackages.stdenv.mkDerivation (finalAttrs: {
runHook postCheck
'';
meta = with lib; {
description = "Compiler for the C3 language";
homepage = "https://github.com/c3lang/c3c";
@@ -77,6 +71,7 @@ llvmPackages.stdenv.mkDerivation (finalAttrs: {
maintainers = with maintainers; [
luc65r
anas
vssukharev
];
platforms = platforms.all;
mainProgram = "c3c";

View File

@@ -1,20 +1,22 @@
{
lib,
mkShell,
clang-tools,
c3c,
}:
}:
mkShell.override {
inherit (c3c) stdenv;
} {
name = "c3c-shell";
mkShell {
inputsFrom = [
c3c
];
packages = [
clang-tools
c3c
];
shellHook = ''
ln -sf ${c3c}/compile_commands.json compile_commands.json
'';
# Usage: 'cmake . -Bbuild $C3_CMAKE_FLAGS' or 'cmake . -Bbuild $=C3_CMAKE_FLAGS' on zsh
C3_CMAKE_FLAGS = lib.concatStringsSep " " c3c.cmakeFlags;
}