Add the cpp env via nix
This commit is contained in:
parent
55989fa4b5
commit
789ac4670d
|
@ -1 +1,33 @@
|
|||
/target
|
||||
*~
|
||||
/build
|
||||
CMakeLists.txt.user
|
||||
CMakeCache.txt
|
||||
CMakeFiles
|
||||
CMakeScripts
|
||||
Testing
|
||||
Makefile
|
||||
cmake_install.cmake
|
||||
install_manifest.txt
|
||||
compile_commands.json
|
||||
CTestTestfile.cmake
|
||||
_deps
|
||||
.ccls-cache
|
||||
.clangd
|
||||
.cache/
|
||||
.vscode/
|
||||
CMakeDoxyfile.in
|
||||
CMakeDoxygenDefaults.cmake
|
||||
DartConfiguration.tcl
|
||||
bin/serenec_CXX_cotire.cmake
|
||||
/config.h
|
||||
|
||||
docs/Doxyfile.docs
|
||||
.ccache/
|
||||
docs/spec.tex
|
||||
docs/spec.pdf
|
||||
.tmp
|
||||
.env
|
||||
.tex
|
||||
.pdf
|
||||
docs/overall_picture.png
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
# git-journal - A git plugin to manage journal entries in git
|
||||
#
|
||||
# Copyright (c) 2023-2024 Sameer Rahmani <lxsameer@gnu.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, version 2.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#A git plugin to manage journal entries in git
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
cmake_minimum_required(VERSION 3.19)
|
||||
|
||||
project(Serene
|
||||
VERSION 1.0.0
|
||||
DESCRIPTION "A modern typed Lisp."
|
||||
LANGUAGES CXX C)
|
||||
|
||||
# Clangd command file
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
|
||||
|
||||
# =============================================================================
|
||||
# Policies
|
||||
# =============================================================================
|
||||
cmake_policy(SET CMP0116 OLD)
|
||||
|
||||
# =============================================================================
|
||||
# User Options
|
||||
# =============================================================================
|
||||
option(CPP_20_SUPPORT "C++20 Support" ON)
|
||||
option(ENABLE_CCACHE "Enable ccache support" ON)
|
||||
option(ENABLE_DOCS "Enable docs" OFF)
|
||||
option(ENABLE_TESTS "Enable testing" OFF)
|
||||
|
||||
find_program(CLANG_TIDY_PATH NAMES clang-tidy REQUIRED)
|
||||
find_program(iwyu NAMES include-what-you-use iwyu REQUIRED)
|
||||
set(iwyu_path ${iwyu})
|
||||
|
||||
# Let's ensure -std=c++xx instead of -std=g++xx
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
|
||||
set(MemoryCheckCommand "valgrind")
|
||||
|
||||
# Let's nicely support folders in IDEs
|
||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
|
||||
# Setup the basic compiler flags
|
||||
add_compile_options(
|
||||
-Wall
|
||||
-Wextra
|
||||
-Werror
|
||||
-Wpedantic
|
||||
-Wabstract-final-class
|
||||
-Walloca
|
||||
-Warray-bounds-pointer-arithmetic
|
||||
-Warray-parameter
|
||||
-Wassign-enum
|
||||
-Wsign-conversion
|
||||
-Wnon-virtual-dtor
|
||||
-Wold-style-cast
|
||||
-Wcast-align
|
||||
-Wunused
|
||||
-Woverloaded-virtual
|
||||
-Wdouble-promotion
|
||||
-Wformat=2)
|
||||
|
||||
add_link_options(-Wl,-Map=output.map)
|
||||
|
||||
# CCache support ==============================
|
||||
if(ENABLE_CCACHE)
|
||||
find_program(CCACHE_PROGRAM ccache)
|
||||
|
||||
if(CCACHE_PROGRAM)
|
||||
message(STATUS "Found CCache")
|
||||
set(CCACHE_MAXSIZE "" CACHE STRING "Size of ccache")
|
||||
set(CCACHE_DIR "" CACHE STRING "Directory to keep ccached data")
|
||||
set(CCACHE_PARAMS "CCACHE_CPP2=yes CCACHE_HASHDIR=yes"
|
||||
CACHE STRING "Parameters to pass through to ccache")
|
||||
|
||||
set(CCACHE_PROGRAM "${CCACHE_PARAMS} ${CCACHE_PROGRAM}")
|
||||
|
||||
if (CCACHE_MAXSIZE)
|
||||
set(CCACHE_PROGRAM "CCACHE_MAXSIZE=${CCACHE_MAXSIZE} ${CCACHE_PROGRAM}")
|
||||
endif()
|
||||
if (CCACHE_DIR)
|
||||
set(CCACHE_PROGRAM "CCACHE_DIR=${CCACHE_DIR} ${CCACHE_PROGRAM}")
|
||||
endif()
|
||||
message(STATUS "Using CCACHE: ${CCACHE_PROGRAM}")
|
||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PROGRAM})
|
||||
else()
|
||||
message(FATAL_ERROR "Unable to find the program ccache. Set ENABLE_CCACHE to OFF")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (ENABLE_DOCS)
|
||||
add_subdirectory(docs)
|
||||
endif()
|
||||
|
||||
add_subdirectory(git-journal)
|
|
@ -1,8 +0,0 @@
|
|||
[package]
|
||||
name = "git-journal"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
12
flake.lock
12
flake.lock
|
@ -37,17 +37,17 @@
|
|||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1707451808,
|
||||
"narHash": "sha256-UwDBUNHNRsYKFJzyTMVMTF5qS4xeJlWoeyJf+6vvamU=",
|
||||
"owner": "nixos",
|
||||
"lastModified": 1705092417,
|
||||
"narHash": "sha256-01pTqprf3NvQijvxkQjwx2c6uevB4MZKooIcf+RTYHA=",
|
||||
"owner": "lxsameer",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "442d407992384ed9c0e6d352de75b69079904e4e",
|
||||
"rev": "e1f7865bce4d52d30dd1d61e79798ee2765cc2b0",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"owner": "lxsameer",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "442d407992384ed9c0e6d352de75b69079904e4e",
|
||||
"rev": "e1f7865bce4d52d30dd1d61e79798ee2765cc2b0",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
|
|
179
flake.nix
179
flake.nix
|
@ -17,31 +17,170 @@
|
|||
description = "A git plugin to manage journal entries in git";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/442d407992384ed9c0e6d352de75b69079904e4e";
|
||||
#nixpkgs.url = "github:nixos/nixpkgs/442d407992384ed9c0e6d352de75b69079904e4e";
|
||||
nixpkgs.url = "github:lxsameer/nixpkgs/e1f7865bce4d52d30dd1d61e79798ee2765cc2b0";
|
||||
flake_utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils, ... } @ inputs:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
overlays = [
|
||||
(final: prev: {
|
||||
p11-kit = prev.p11-kit.overrideAttrs (old: {
|
||||
patches = [
|
||||
./nix/patches/p11-kit_skip_test.patch
|
||||
];
|
||||
});
|
||||
|
||||
nativeDeps = (with pkgs; [
|
||||
fish
|
||||
rustc
|
||||
cargo
|
||||
git
|
||||
]);
|
||||
cpio = prev.cpio.overrideAttrs (old: {
|
||||
nativeBuildInputs = [ prev.autoreconfHook ];
|
||||
NIX_CFLAGS_COMPILE = "-Wno-implicit-function-declaration";
|
||||
});
|
||||
|
||||
# deps = (with pkgs; [
|
||||
libedit = prev.libedit.overrideAttrs (old: {
|
||||
# Musl is ISO 10646 compliant but doesn't define __STDC_ISO_10646__ we need to do it ourselves
|
||||
NIX_CFLAGS_COMPILE = "-D__STDC_ISO_10646__=201103L";
|
||||
});
|
||||
|
||||
# ]);
|
||||
in {
|
||||
devShells.default = pkgs.mkShell {
|
||||
nativeBuildInputs = nativeDeps;
|
||||
shellHook = ''
|
||||
fish && exit
|
||||
'';
|
||||
};
|
||||
});
|
||||
elfutils = prev.elfutils.overrideAttrs (old: {
|
||||
# libcxx does not have __cxa_demangle
|
||||
configureFlags = old.configureFlags ++ [ "--disable-demangler" ];
|
||||
});
|
||||
|
||||
ccache = prev.ccache.overrideAttrs (old: {
|
||||
nativeBuildInputs = old.nativeBuildInputs ++ [ final.elfutils ];
|
||||
});
|
||||
|
||||
# We don't need systemd at all
|
||||
util-linux = prev.util-linux.override { systemdSupport = false; };
|
||||
|
||||
# libpam exmaples use glibc. We need to disable them
|
||||
linux-pam = prev.linux-pam.overrideAttrs (old: {
|
||||
postConfigure = ''
|
||||
sed 's/examples//' -i Makefile
|
||||
'';
|
||||
});
|
||||
|
||||
#=============================================================
|
||||
# Since we're using lld-17, and --no-undefined-version is the
|
||||
# default in lld-17. We need to explicitely turn it off for
|
||||
# these problematic packages untill they fix it upstream.
|
||||
libgcrypt = prev.libgcrypt.overrideAttrs (old: {
|
||||
NIX_LDFLAGS = if prev.stdenv.cc.isClang
|
||||
then [ "--undefined-version" ]
|
||||
else [];
|
||||
});
|
||||
libxcrypt = prev.libxcrypt.overrideAttrs (old: {
|
||||
NIX_LDFLAGS = if prev.stdenv.cc.isClang
|
||||
then [ "--undefined-version" ]
|
||||
else [];
|
||||
});
|
||||
ncurses = prev.ncurses.overrideAttrs (old: {
|
||||
NIX_LDFLAGS = if prev.stdenv.cc.isClang
|
||||
then [ "--undefined-version" ]
|
||||
else [];
|
||||
});
|
||||
|
||||
libbsd = prev.libbsd.overrideAttrs (old: { #old.NIX_LDFLAGS ++
|
||||
NIX_LDFLAGS = if prev.stdenv.cc.isClang
|
||||
then [ "--undefined-version" ]
|
||||
else [];
|
||||
});
|
||||
libidn2 = prev.libidn2.overrideAttrs (old: { #old.NIX_LDFLAGS ++
|
||||
NIX_LDFLAGS = if prev.stdenv.cc.isClang
|
||||
then [ "--undefined-version" ]
|
||||
else [];
|
||||
});
|
||||
|
||||
fmt = prev.fmt.overrideAttrs (old: {
|
||||
doCheck = false;
|
||||
});
|
||||
|
||||
# libapparmor = prev.libapparmor.overrideAttrs (old: {
|
||||
# NIX_CFLAGS_COMPILE = "--no-"
|
||||
# });
|
||||
#==============================================================
|
||||
|
||||
iwyu = (prev.include-what-you-use.overrideAttrs (old:
|
||||
let
|
||||
version = "0.21";
|
||||
in {
|
||||
inherit version;
|
||||
|
||||
src = prev.fetchurl {
|
||||
url = "${old.meta.homepage}/downloads/${old.pname}-${version}.src.tar.gz";
|
||||
hash = "sha256-ajUZGf+JvafJXIlUcmAYaNs9qrlqlYs44DYokNWHYLY=";
|
||||
};
|
||||
cmakeFlags = [ "-DCMAKE_PREFIX_PATH=${prev.llvmPackages_17.llvm.dev}" ];
|
||||
|
||||
})).override {
|
||||
llvmPackages = prev.__splicedPackages.llvmPackages_17;
|
||||
};
|
||||
})
|
||||
];
|
||||
|
||||
get_pkgs = overlays:
|
||||
if system == "x86_64-linux"
|
||||
then import nixpkgs {
|
||||
inherit system overlays;
|
||||
linker = "lld";
|
||||
crossSystem = nixpkgs.lib.systems.examples.musl64;
|
||||
}
|
||||
else import nixpkgs {
|
||||
inherit system overlays;
|
||||
};
|
||||
|
||||
pkgs = get_pkgs overlays;
|
||||
# Just disabling the tests that fails under musl
|
||||
git' = pkgs.git.overrideAttrs (old: {
|
||||
preInstallCheck =
|
||||
pkgs.lib.replaceStrings [ ''disable_test t0201-gettext-fallbacks'' ]
|
||||
[ ''
|
||||
disable_test t0201-gettext-fallbacks
|
||||
disable_test t2082-parallel-checkout-attributes
|
||||
'' ]
|
||||
old.preInstallCheck;
|
||||
});
|
||||
|
||||
|
||||
buildToolsDeps = (with pkgs; [
|
||||
cmake
|
||||
ninja
|
||||
llvmPackages_17.clang
|
||||
llvmPackages_17.lld
|
||||
iwyu
|
||||
git'
|
||||
valgrind
|
||||
zsh
|
||||
]);
|
||||
|
||||
deps = (with pkgs; [
|
||||
fmt
|
||||
libgit2
|
||||
argparse
|
||||
]);
|
||||
|
||||
stdenv = pkgs.overrideCC pkgs.stdenv pkgs.llvmPackages_17.clangUseLLVM;
|
||||
in {
|
||||
|
||||
packages.default = stdenv.mkDerivation {
|
||||
pname = "git-journal";
|
||||
version = "0.1.0";
|
||||
|
||||
src = ./.;
|
||||
|
||||
nativeBuildInputs = buildToolsDeps;
|
||||
buildInputs = deps;
|
||||
};
|
||||
|
||||
devShells.default = (pkgs.mkShell.override { inherit stdenv; }) {
|
||||
nativeBuildInputs = buildToolsDeps;
|
||||
buildInputs = deps;
|
||||
shellHook = ''zsh && exit'';
|
||||
# shellHook = ''
|
||||
# fish && exit
|
||||
# '';
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
|
@ -0,0 +1,129 @@
|
|||
# git-journal - A git plugin to manage journal entries in git
|
||||
#
|
||||
# Copyright (c) 2023-2024 Sameer Rahmani <lxsameer@gnu.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, version 2.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
add_executable(git-journal)
|
||||
|
||||
set_target_properties(git-journal PROPERTIES
|
||||
VERSION ${PROJECT_VERSION}
|
||||
SOVERSION ${PROJECT_VERSION_MAJOR}
|
||||
C_INCLUDE_WHAT_YOU_USE ${iwyu}
|
||||
CXX_INCLUDE_WHAT_YOU_USE ${iwyu}
|
||||
# Warn on unused libs
|
||||
LINK_WHAT_YOU_USE TRUE
|
||||
)
|
||||
|
||||
target_compile_features(git-journal PRIVATE cxx_std_20)
|
||||
|
||||
# Setup header directory and auto generated headers
|
||||
target_include_directories(git-journal
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
target_include_directories(git-journal SYSTEM PUBLIC
|
||||
# We don't want the generated files from table gen
|
||||
# to be treated as local since the contain warnings
|
||||
${PROJECT_BINARY_DIR}/git-journal/include)
|
||||
|
||||
target_link_libraries(git-journal PRIVATE
|
||||
LLVMSupport
|
||||
)
|
||||
|
||||
# Autogenerate the `config.h` file
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/git-journal/config.h.in include/git-journal/config.h)
|
||||
|
||||
target_compile_options(git-journal
|
||||
PRIVATE
|
||||
$<$<BOOL:${ENABLE_LIBCXX}>:-stdlib=libc++>
|
||||
|
||||
-fno-builtin-strlen
|
||||
|
||||
# Dedicate a section to each function, so the linker
|
||||
# can do a better job on dead code elimination
|
||||
-ffunction-sections
|
||||
-fdata-sections
|
||||
|
||||
$<$<CONFIG:DEBUG>:-fsanitize=address>
|
||||
$<$<CONFIG:DEBUG>:-static-libsan>
|
||||
$<$<CONFIG:DEBUG>:-g3>
|
||||
$<$<CONFIG:DEBUG>:-O0>
|
||||
$<$<CONFIG:DEBUG>:-ggdb>
|
||||
# For the sake of debugging
|
||||
$<$<CONFIG:DEBUG>:-fno-inline>
|
||||
# To make the local ccache happy
|
||||
$<$<CONFIG:DEBUG>:-fdebug-prefix-map=${PROJECT_SOURCE_DIR}=.>
|
||||
|
||||
# No tail call elimination on Debug to let asan provide
|
||||
# better stacktrackes
|
||||
$<$<CONFIG:DEBUG>:-fno-optimize-sibling-calls>
|
||||
|
||||
$<$<CONFIG:DEBUG>:-fno-omit-frame-pointer>
|
||||
$<$<CONFIG:RELEASE>:-fomit-frame-pointer>
|
||||
$<$<CONFIG:RELEASE>:-O3>
|
||||
$<$<CONFIG:RELEASE>:-fmerge-all-constants>
|
||||
)
|
||||
|
||||
target_link_options(git-journal PRIVATE
|
||||
$<$<BOOL:${ENABLE_LIBCXX}>:-stdlib=libc++>
|
||||
$<$<BOOL:${ENABLE_LIBCXX}>:-lc++abi>
|
||||
$<$<BOOL:${ENABLE_COMPILER_RT}>:--rtlib=compiler-rt>
|
||||
|
||||
-Wl,--gc-sections
|
||||
$<$<CONFIG:RELEASE>:-s>
|
||||
|
||||
$<$<CONFIG:DEBUG>:-fsanitize=address>
|
||||
$<$<CONFIG:DEBUG>:-static-libsan>
|
||||
# Do not link against shared libraries
|
||||
--static
|
||||
)
|
||||
|
||||
if (CMAKE_BUILD_TYPE EQUAL "DEBUG")
|
||||
set_target_properties(serene PROPERTIES CXX_CLANG_TIDY ${CLANG_TIDY_PATH})
|
||||
endif()
|
||||
|
||||
include(CheckIPOSupported)
|
||||
|
||||
# Optional IPO. Do not use IPO if it's not supported by compiler.
|
||||
check_ipo_supported(RESULT result OUTPUT output)
|
||||
if(result)
|
||||
message(STATUS "IPO is supported and is turned on")
|
||||
set_property(TARGET git-journal PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||
else()
|
||||
message(WARNING "IPO is not supported: ${output}")
|
||||
message(WARNING "Make sure to use lld")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
install(TARGETS git-journal EXPORT Git-JournalTargets
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(include)
|
||||
|
||||
if(ENABLE_TESTS)
|
||||
enable_testing()
|
||||
find_package(GTest REQUIRED)
|
||||
add_subdirectory(tests)
|
||||
# For Windows: Prevent overriding the parent project's compiler/linker settings
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
endif()
|
|
@ -0,0 +1,27 @@
|
|||
From 132b779414c2236c1350b578b59c8edcfc4c5a14 Mon Sep 17 00:00:00 2001
|
||||
From: Sameer Rahmani <lxsameer@gnu.org>
|
||||
Date: Sat, 25 Nov 2023 13:14:42 +0000
|
||||
Subject: [PATCH] test
|
||||
|
||||
---
|
||||
common/test.c | 5 +++--
|
||||
1 file changed, 3 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/common/test.c b/common/test.c
|
||||
index 6cdbd1fa2118..6cd6f84bcdc7 100644
|
||||
--- a/common/test.c
|
||||
+++ b/common/test.c
|
||||
@@ -614,8 +614,9 @@ p11_test_copy_setgid (const char *input,
|
||||
assert (fd >= 0);
|
||||
|
||||
copy_file (input, fd);
|
||||
- if (fchown (fd, getuid (), group) < 0)
|
||||
- assert_not_reached ();
|
||||
+ if (fchown (fd, getuid (), group) < 0) {
|
||||
+ return NULL;
|
||||
+ }
|
||||
if (fchmod (fd, 02750) < 0)
|
||||
assert_not_reached ();
|
||||
if (close (fd) < 0)
|
||||
--
|
||||
2.41.0
|
|
@ -1,3 +0,0 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
Loading…
Reference in New Issue