mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Add support for nix flakes (#1614)
* Add support for nix flakes * Added debug build type for flake.nix; Got rid of redundant version check in nix/default.nix * Added dev shell with compile_commands.json into flake.nix * Fixed issue with generated compile_commands.json while creating c3c derivation with nix. Deduced devShells in flake.nix to nix/shell.nix
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -75,3 +75,6 @@ TAGS
|
|||||||
/.cache/
|
/.cache/
|
||||||
/compile_commands.json
|
/compile_commands.json
|
||||||
|
|
||||||
|
# 'nix build' resulting symlink
|
||||||
|
result
|
||||||
|
|
||||||
|
|||||||
61
flake.lock
generated
Normal file
61
flake.lock
generated
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1726560853,
|
||||||
|
"narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1730958623,
|
||||||
|
"narHash": "sha256-JwQZIGSYnRNOgDDoIgqKITrPVil+RMWHsZH1eE1VGN0=",
|
||||||
|
"owner": "nixos",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "85f7e662eda4fa3a995556527c87b2524b691933",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nixos",
|
||||||
|
"ref": "nixpkgs-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
35
flake.nix
Normal file
35
flake.nix
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
description = "C3 compiler flake";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:nixos/nixpkgs?ref=nixpkgs-unstable";
|
||||||
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = { self, ... } @ inputs: inputs.flake-utils.lib.eachDefaultSystem
|
||||||
|
(system:
|
||||||
|
let pkgs = import inputs.nixpkgs { inherit system; }; in
|
||||||
|
{
|
||||||
|
packages = {
|
||||||
|
default = self.packages.${system}.c3c;
|
||||||
|
|
||||||
|
c3c = pkgs.callPackage ./nix/default.nix {};
|
||||||
|
|
||||||
|
c3c-debug = pkgs.callPackage ./nix/default.nix {
|
||||||
|
debug = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
c3c-nochecks = pkgs.callPackage ./nix/default.nix {
|
||||||
|
debug = true;
|
||||||
|
checks = false;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
devShells = {
|
||||||
|
default = pkgs.callPackage ./nix/shell.nix {
|
||||||
|
c3c = self.packages.${system}.c3c-nochecks;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
85
nix/default.nix
Normal file
85
nix/default.nix
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
{
|
||||||
|
lib,
|
||||||
|
llvmPackages,
|
||||||
|
cmake,
|
||||||
|
python3,
|
||||||
|
curl,
|
||||||
|
libxml2,
|
||||||
|
libffi,
|
||||||
|
xar,
|
||||||
|
debug ? false,
|
||||||
|
checks ? true,
|
||||||
|
}: let
|
||||||
|
inherit (builtins) baseNameOf toString 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: {
|
||||||
|
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 ) );
|
||||||
|
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"
|
||||||
|
'';
|
||||||
|
|
||||||
|
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
|
||||||
|
'';
|
||||||
|
|
||||||
|
buildInputs = [
|
||||||
|
llvmPackages.llvm
|
||||||
|
llvmPackages.lld
|
||||||
|
curl
|
||||||
|
libxml2
|
||||||
|
libffi
|
||||||
|
] ++ lib.optionals llvmPackages.stdenv.hostPlatform.isDarwin [ xar ];
|
||||||
|
|
||||||
|
nativeCheckInputs = [ python3 ];
|
||||||
|
|
||||||
|
doCheck = llvmPackages.stdenv.system == "x86_64-linux" && checks;
|
||||||
|
|
||||||
|
checkPhase = ''
|
||||||
|
runHook preCheck
|
||||||
|
( cd ../resources/testproject; ../../build/c3c build )
|
||||||
|
( cd ../test; python src/tester.py ../build/c3c test_suite )
|
||||||
|
runHook postCheck
|
||||||
|
'';
|
||||||
|
|
||||||
|
meta = with lib; {
|
||||||
|
description = "Compiler for the C3 language";
|
||||||
|
homepage = "https://github.com/c3lang/c3c";
|
||||||
|
license = licenses.lgpl3Only;
|
||||||
|
maintainers = with maintainers; [
|
||||||
|
luc65r
|
||||||
|
anas
|
||||||
|
];
|
||||||
|
platforms = platforms.all;
|
||||||
|
mainProgram = "c3c";
|
||||||
|
};
|
||||||
|
})
|
||||||
|
|
||||||
20
nix/shell.nix
Normal file
20
nix/shell.nix
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
mkShell,
|
||||||
|
clang-tools,
|
||||||
|
c3c,
|
||||||
|
}:
|
||||||
|
|
||||||
|
mkShell {
|
||||||
|
inputsFrom = [
|
||||||
|
c3c
|
||||||
|
];
|
||||||
|
|
||||||
|
packages = [
|
||||||
|
clang-tools
|
||||||
|
c3c
|
||||||
|
];
|
||||||
|
|
||||||
|
shellHook = ''
|
||||||
|
ln -sf ${c3c}/compile_commands.json compile_commands.json
|
||||||
|
'';
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user