mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 03:51:18 +00:00
Several nix fixes (#1737)
* Fixed nix c3c development shell * Fix unknown git hash on nix build
This commit is contained in:
11
flake.nix
11
flake.nix
@@ -8,12 +8,17 @@
|
||||
|
||||
outputs = { self, ... } @ inputs: inputs.flake-utils.lib.eachDefaultSystem
|
||||
(system:
|
||||
let pkgs = import inputs.nixpkgs { inherit system; }; in
|
||||
{
|
||||
let pkgs = import inputs.nixpkgs { inherit system; };
|
||||
call = set: pkgs.callPackage ./nix/default.nix (
|
||||
set // {
|
||||
rev = self.rev or "unknown";
|
||||
}
|
||||
);
|
||||
in {
|
||||
packages = {
|
||||
default = self.packages.${system}.c3c;
|
||||
|
||||
c3c = pkgs.callPackage ./nix/default.nix {};
|
||||
c3c = call {};
|
||||
|
||||
c3c-checks = pkgs.callPackage ./nix/default.nix {
|
||||
checks = true;
|
||||
|
||||
@@ -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;
|
||||
removeSuffix "\"" ( removePrefix "\"" ( elemAt ( splitString " " foundLine ) 2 ) );
|
||||
|
||||
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"
|
||||
'';
|
||||
src = ../.;
|
||||
|
||||
cmakeBuildType = if debug then "Debug" else "Release";
|
||||
|
||||
cmakeFlags = [
|
||||
"-DC3_ENABLE_CLANGD_LSP=${if debug then "ON" else "OFF"}"
|
||||
];
|
||||
|
||||
nativeBuildInputs = [ cmake ];
|
||||
|
||||
postBuild = optionalString debug ''
|
||||
mkdir $out
|
||||
substituteInPlace compile_commands.json \
|
||||
--replace "/build/source/" "$src/"
|
||||
cp compile_commands.json $out/compile_commands.json
|
||||
postPatch = ''
|
||||
substituteInPlace git_hash.cmake \
|
||||
--replace-fail "\''${GIT_HASH}" "${rev}"
|
||||
'';
|
||||
|
||||
buildInputs = [
|
||||
cmakeFlags = [
|
||||
"-DC3_ENABLE_CLANGD_LSP=${if debug then "ON" else "OFF"}"
|
||||
"-DC3_LLD_DIR=${llvmPackages.lld.lib}/lib"
|
||||
];
|
||||
|
||||
nativeBuildInputs = [
|
||||
cmake
|
||||
llvmPackages.llvm
|
||||
llvmPackages.lld
|
||||
];
|
||||
|
||||
buildInputs = [
|
||||
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";
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user