mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Several fixes for Nix build (#2389)
* Fixed a bug for build via nix, when c3c-checks and c3c-debug didn't have a git hash * Got rid of python3 requirement for checks in nix as it's no longer needed * Now c3c properly displays it's build date in nix build * Add more platforms for checks in nix build * Add installation and compilation on Nix to README
This commit is contained in:
@@ -2,12 +2,11 @@
|
||||
lib,
|
||||
llvmPackages,
|
||||
cmake,
|
||||
python3,
|
||||
curl,
|
||||
libxml2,
|
||||
libffi,
|
||||
xar,
|
||||
rev ? "unknown",
|
||||
rev,
|
||||
debug ? false,
|
||||
checks ? false,
|
||||
}: let
|
||||
@@ -16,8 +15,8 @@
|
||||
inherit (lib.lists) findFirst;
|
||||
inherit (lib.asserts) assertMsg;
|
||||
inherit (lib.strings) hasInfix splitString removeSuffix removePrefix optionalString;
|
||||
in llvmPackages.stdenv.mkDerivation (finalAttrs: {
|
||||
|
||||
in llvmPackages.stdenv.mkDerivation (_:
|
||||
{
|
||||
pname = "c3c${optionalString debug "-debug"}";
|
||||
|
||||
version = let
|
||||
@@ -28,13 +27,19 @@ in llvmPackages.stdenv.mkDerivation (finalAttrs: {
|
||||
|
||||
src = ../.;
|
||||
|
||||
cmakeBuildType = if debug then "Debug" else "Release";
|
||||
|
||||
postPatch = ''
|
||||
substituteInPlace git_hash.cmake \
|
||||
--replace-fail "\''${GIT_HASH}" "${rev}"
|
||||
# Here we substitute GIT_HASH which is not set for cmake in nix builds.
|
||||
# Similar situation is with __DATE__ and __TIME__ macros, which are
|
||||
# set to "Jan 01 1980 00:00:00" by default.
|
||||
patchPhase = ''
|
||||
substituteInPlace git_hash.cmake --replace-fail "\''${GIT_HASH}" "${rev}"
|
||||
|
||||
local FILE_NAMES="$(find src -type f)"
|
||||
substituteInPlace $FILE_NAMES --replace-quiet "__DATE__" "\"$(date '+%b %d %Y')\""
|
||||
substituteInPlace $FILE_NAMES --replace-quiet "__TIME__" "\"$(date '+%T')\""
|
||||
'';
|
||||
|
||||
cmakeBuildType = if debug then "Debug" else "Release";
|
||||
|
||||
cmakeFlags = [
|
||||
"-DC3_ENABLE_CLANGD_LSP=${if debug then "ON" else "OFF"}"
|
||||
"-DC3_LLD_DIR=${llvmPackages.lld.lib}/lib"
|
||||
@@ -54,17 +59,25 @@ in llvmPackages.stdenv.mkDerivation (finalAttrs: {
|
||||
libffi
|
||||
] ++ lib.optionals llvmPackages.stdenv.hostPlatform.isDarwin [ xar ];
|
||||
|
||||
nativeCheckInputs = [ python3 ];
|
||||
|
||||
doCheck = llvmPackages.stdenv.system == "x86_64-linux" && checks;
|
||||
doCheck = checks && lib.elem llvmPackages.stdenv.system [
|
||||
"x86_64-linux"
|
||||
"x86_64-darwin"
|
||||
"aarch64-darwin"
|
||||
];
|
||||
|
||||
# In check phase we preserve BUILD directory as
|
||||
# we need to return to it before install phase
|
||||
checkPhase = ''
|
||||
runHook preCheck
|
||||
( cd ../resources/testproject; ../../build/c3c build --trust=full )
|
||||
( cd ../test; ../build/c3c compile-run -O1 src/test_suite_runner.c3 -- ../build/c3c test_suite )
|
||||
runHook postCheck
|
||||
'';
|
||||
local BUILD_DIR=$(pwd)
|
||||
|
||||
cd ../resources/testproject
|
||||
../../build/c3c build --trust=full
|
||||
|
||||
cd ../../test
|
||||
../build/c3c compile-run -O1 src/test_suite_runner.c3 -- ../build/c3c ./test_suite
|
||||
|
||||
cd $BUILD_DIR
|
||||
'';
|
||||
|
||||
meta = with lib; {
|
||||
description = "Compiler for the C3 language";
|
||||
|
||||
Reference in New Issue
Block a user