mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +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
|
outputs = { self, ... } @ inputs: inputs.flake-utils.lib.eachDefaultSystem
|
||||||
(system:
|
(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 = {
|
packages = {
|
||||||
default = self.packages.${system}.c3c;
|
default = self.packages.${system}.c3c;
|
||||||
|
|
||||||
c3c = pkgs.callPackage ./nix/default.nix {};
|
c3c = call {};
|
||||||
|
|
||||||
c3c-checks = pkgs.callPackage ./nix/default.nix {
|
c3c-checks = pkgs.callPackage ./nix/default.nix {
|
||||||
checks = true;
|
checks = true;
|
||||||
|
|||||||
@@ -7,53 +7,46 @@
|
|||||||
libxml2,
|
libxml2,
|
||||||
libffi,
|
libffi,
|
||||||
xar,
|
xar,
|
||||||
|
rev ? "unknown",
|
||||||
debug ? false,
|
debug ? false,
|
||||||
checks ? false,
|
checks ? false,
|
||||||
}: let
|
}: let
|
||||||
inherit (builtins) baseNameOf toString readFile elemAt;
|
inherit (builtins) readFile elemAt;
|
||||||
inherit (lib.sources) cleanSourceWith cleanSource;
|
# inherit (lib.sources) cleanSourceWith cleanSource;
|
||||||
inherit (lib.lists) findFirst;
|
inherit (lib.lists) findFirst;
|
||||||
inherit (lib.asserts) assertMsg;
|
inherit (lib.asserts) assertMsg;
|
||||||
inherit (lib.strings) hasInfix hasSuffix splitString removeSuffix removePrefix optionalString;
|
inherit (lib.strings) hasInfix splitString removeSuffix removePrefix optionalString;
|
||||||
in
|
in llvmPackages.stdenv.mkDerivation (finalAttrs: {
|
||||||
llvmPackages.stdenv.mkDerivation (finalAttrs: {
|
|
||||||
pname = "c3c${optionalString debug "-debug"}";
|
pname = "c3c${optionalString debug "-debug"}";
|
||||||
|
|
||||||
version = let
|
version = let
|
||||||
findLine = findFirst (x: hasInfix "COMPILER_VERSION" x) "none";
|
foundLine = findFirst (x: hasInfix "COMPILER_VERSION" x) "none" ( splitString "\n" ( readFile ../src/version.h ) );
|
||||||
foundLine = findLine ( splitString "\n" ( readFile ../src/version.h ) );
|
|
||||||
version = removeSuffix "\"" ( removePrefix "\"" ( elemAt ( splitString " " foundLine ) 2 ) );
|
|
||||||
in
|
in
|
||||||
assert assertMsg (foundLine != "none") "No COMPILER_VERSION substring was found in version.h";
|
assert assertMsg (foundLine != "none") "No COMPILER_VERSION substring was found in version.h";
|
||||||
version;
|
removeSuffix "\"" ( removePrefix "\"" ( elemAt ( splitString " " foundLine ) 2 ) );
|
||||||
|
|
||||||
src = cleanSourceWith {
|
src = ../.;
|
||||||
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"
|
|
||||||
'';
|
|
||||||
|
|
||||||
cmakeBuildType = if debug then "Debug" else "Release";
|
cmakeBuildType = if debug then "Debug" else "Release";
|
||||||
|
|
||||||
cmakeFlags = [
|
postPatch = ''
|
||||||
"-DC3_ENABLE_CLANGD_LSP=${if debug then "ON" else "OFF"}"
|
substituteInPlace git_hash.cmake \
|
||||||
];
|
--replace-fail "\''${GIT_HASH}" "${rev}"
|
||||||
|
|
||||||
nativeBuildInputs = [ cmake ];
|
|
||||||
|
|
||||||
postBuild = optionalString debug ''
|
|
||||||
mkdir $out
|
|
||||||
substituteInPlace compile_commands.json \
|
|
||||||
--replace "/build/source/" "$src/"
|
|
||||||
cp compile_commands.json $out/compile_commands.json
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
buildInputs = [
|
cmakeFlags = [
|
||||||
|
"-DC3_ENABLE_CLANGD_LSP=${if debug then "ON" else "OFF"}"
|
||||||
|
"-DC3_LLD_DIR=${llvmPackages.lld.lib}/lib"
|
||||||
|
];
|
||||||
|
|
||||||
|
nativeBuildInputs = [
|
||||||
|
cmake
|
||||||
llvmPackages.llvm
|
llvmPackages.llvm
|
||||||
llvmPackages.lld
|
llvmPackages.lld
|
||||||
|
];
|
||||||
|
|
||||||
|
buildInputs = [
|
||||||
curl
|
curl
|
||||||
libxml2
|
libxml2
|
||||||
libffi
|
libffi
|
||||||
@@ -70,6 +63,7 @@ llvmPackages.stdenv.mkDerivation (finalAttrs: {
|
|||||||
runHook postCheck
|
runHook postCheck
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
|
||||||
meta = with lib; {
|
meta = with lib; {
|
||||||
description = "Compiler for the C3 language";
|
description = "Compiler for the C3 language";
|
||||||
homepage = "https://github.com/c3lang/c3c";
|
homepage = "https://github.com/c3lang/c3c";
|
||||||
@@ -77,6 +71,7 @@ llvmPackages.stdenv.mkDerivation (finalAttrs: {
|
|||||||
maintainers = with maintainers; [
|
maintainers = with maintainers; [
|
||||||
luc65r
|
luc65r
|
||||||
anas
|
anas
|
||||||
|
vssukharev
|
||||||
];
|
];
|
||||||
platforms = platforms.all;
|
platforms = platforms.all;
|
||||||
mainProgram = "c3c";
|
mainProgram = "c3c";
|
||||||
|
|||||||
@@ -1,20 +1,22 @@
|
|||||||
{
|
{
|
||||||
|
lib,
|
||||||
mkShell,
|
mkShell,
|
||||||
clang-tools,
|
clang-tools,
|
||||||
c3c,
|
c3c,
|
||||||
}:
|
}:
|
||||||
|
mkShell.override {
|
||||||
|
inherit (c3c) stdenv;
|
||||||
|
} {
|
||||||
|
name = "c3c-shell";
|
||||||
|
|
||||||
mkShell {
|
|
||||||
inputsFrom = [
|
inputsFrom = [
|
||||||
c3c
|
c3c
|
||||||
];
|
];
|
||||||
|
|
||||||
packages = [
|
packages = [
|
||||||
clang-tools
|
clang-tools
|
||||||
c3c
|
|
||||||
];
|
];
|
||||||
|
|
||||||
shellHook = ''
|
# Usage: 'cmake . -Bbuild $C3_CMAKE_FLAGS' or 'cmake . -Bbuild $=C3_CMAKE_FLAGS' on zsh
|
||||||
ln -sf ${c3c}/compile_commands.json compile_commands.json
|
C3_CMAKE_FLAGS = lib.concatStringsSep " " c3c.cmakeFlags;
|
||||||
'';
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user