wip: add nix flake

This commit is contained in:
Jake Hillion 2023-11-20 23:14:50 +00:00
parent f9cb0115e1
commit d5b33c0d72
4 changed files with 323 additions and 80 deletions

View File

@ -31,78 +31,103 @@ option(FORCE_LLVM_STATIC "Build with static llvm and clang" ON)
find_package(gflags REQUIRED)
### tomlplusplus (for configuration files)
FetchContent_Declare(
tomlplusplus
GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git
GIT_TAG 4b166b69f28e70a416a1a04a98f365d2aeb90de8 # v3.2.0
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(tomlplusplus)
find_package(tomlplusplus 3.2.0)
if (NOT tomlplusplus_FOUND)
FetchContent_Declare(
tomlplusplus
GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git
GIT_TAG 4b166b69f28e70a416a1a04a98f365d2aeb90de8 # v3.2.0
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(tomlplusplus)
endif()
### glog
FetchContent_Declare(
glog
GIT_REPOSITORY https://github.com/google/glog.git
GIT_TAG 96a2f23dca4cc7180821ca5f32e526314395d26a
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(glog)
find_package(glog 0.4.0)
if (NOT glog_FOUND)
FetchContent_Declare(
glog
GIT_REPOSITORY https://github.com/google/glog.git
GIT_TAG 96a2f23dca4cc7180821ca5f32e526314395d26a
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(glog)
endif()
# These glog executable targets still generate warnings - disable warnings for
# them explicitly
target_compile_options(demangle_unittest PRIVATE "-w")
target_compile_options(logging_unittest PRIVATE "-w")
target_compile_options(stl_logging_unittest PRIVATE "-w")
target_compile_options(symbolize_unittest PRIVATE "-w")
target_compile_options(utilities_unittest PRIVATE "-w")
# target_compile_options(demangle_unittest PRIVATE "-w")
# target_compile_options(logging_unittest PRIVATE "-w")
# target_compile_options(stl_logging_unittest PRIVATE "-w")
# target_compile_options(symbolize_unittest PRIVATE "-w")
# target_compile_options(utilities_unittest PRIVATE "-w")
### googletest
# Do this in the main file so it can be fetched before setting project warnings.
# After this is fixed with FetchContent, move to test/CMakeLists.txt.
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG 1ed6a8c67a0bd675149ece27bbec0ef1759854cf
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(googletest)
find_package(googletest 1.14.0)
if (NOT googletest_FOUND)
FetchContent_Declare(
googletest
# GIT_REPOSITORY https://github.com/google/googletest.git
# GIT_TAG 1ed6a8c67a0bd675149ece27bbec0ef1759854cf
# GIT_PROGRESS TRUE
SOURCE_DIR @gtest_src@
)
FetchContent_MakeAvailable(googletest)
endif()
### rocksdb
FetchContent_Declare(
rocksdb
GIT_REPOSITORY https://github.com/facebook/rocksdb.git
GIT_TAG f32521662acf3352397d438b732144c7813bbbec # v8.5.3
GIT_PROGRESS TRUE
)
FetchContent_Populate(rocksdb)
add_custom_target(librocksdb ALL
WORKING_DIRECTORY ${rocksdb_SOURCE_DIR}
COMMAND cmake -G Ninja -B ${rocksdb_BINARY_DIR} -DCMAKE_BUILD_TYPE=Release -DWITH_GFLAGS=Off -DWITH_LIBURING=Off -DWITH_ZSTD=On -DFAIL_ON_WARNINGS=Off
COMMAND cmake --build ${rocksdb_BINARY_DIR} --target rocksdb
BYPRODUCTS ${rocksdb_BINARY_DIR}/librocksdb.a
COMMENT "Building RocksDB"
USES_TERMINAL
)
include_directories(SYSTEM "${rocksdb_SOURCE_DIR}/include")
find_package(rocksdb 8.5.3)
if (NOT RocksDB_FOUND)
FetchContent_Declare(
rocksdb
GIT_REPOSITORY https://github.com/facebook/rocksdb.git
GIT_TAG f32521662acf3352397d438b732144c7813bbbec # v8.5.3
GIT_PROGRESS TRUE
)
FetchContent_Populate(rocksdb)
add_custom_target(librocksdb_build ALL
WORKING_DIRECTORY ${rocksdb_SOURCE_DIR}
COMMAND CXX_FLAGS=-Wno-error cmake -G Ninja -B ${rocksdb_BINARY_DIR} -DCMAKE_BUILD_TYPE=Release -DWITH_GFLAGS=Off -DWITH_LIBURING=Off -DWITH_ZSTD=On -DFAIL_ON_WARNINGS=Off
COMMAND cmake --build ${rocksdb_BINARY_DIR} --target rocksdb
BYPRODUCTS ${rocksdb_BINARY_DIR}/librocksdb.a
COMMENT "Building RocksDB"
USES_TERMINAL
)
add_library(librocksdb INTERFACE)
add_dependencies(librocksdb librocksdb_build)
target_include_directories(librocksdb INTERFACE SYSTEM "${rocksdb_SOURCE_DIR}/include")
add_library(RocksDB::rocksdb ALIAS librocksdb)
### zstd (for rocksdb)
find_package(zstd REQUIRED)
target_link_libraries(librocksdb INTERFACE zstd::zstd ${rocksdb_BINARY_DIR}/librocksdb.a)
endif()
### folly
### use folly as a header only library. some features won't be supported.
FetchContent_Declare(
folly
GIT_REPOSITORY https://github.com/JakeHillion/folly.git
GIT_TAG 8db54418e3ccdd97619ac8b69bb3702f82bb0f66
GIT_PROGRESS TRUE
# GIT_REPOSITORY https://github.com/JakeHillion/folly.git
# GIT_TAG 8db54418e3ccdd97619ac8b69bb3702f82bb0f66
# GIT_PROGRESS TRUE
SOURCE_DIR @folly_src@
)
FetchContent_Populate(folly)
### range-v3
FetchContent_Declare(
range-v3
GIT_REPOSITORY https://github.com/ericniebler/range-v3.git
GIT_TAG a81477931a8aa2ad025c6bda0609f38e09e4d7ec # 0.12.0
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(range-v3)
find_package(Range-v3 0.12.0)
if (NOT Range-v3_FOUND)
FetchContent_Declare(
range-v3
GIT_REPOSITORY https://github.com/ericniebler/range-v3.git
GIT_TAG a81477931a8aa2ad025c6bda0609f38e09e4d7ec # 0.12.0
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(range-v3)
endif()
set_project_warnings()
@ -123,9 +148,13 @@ endif()
### (Re)download submodules
find_package(Git QUIET)
if (NOT DEFINED drgn_SOURCE_DIR)
SET(drgn_SOURCE_DIR "${PROJECT_SOURCE_DIR}/extern/drgn")
endif()
# TODO: No idea if this huge block is required, just picked from an example. There may be a short-hand.
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed
if(NOT EXISTS "${drgn_SOURCE_DIR}" AND GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Submodule update")
@ -144,11 +173,11 @@ if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
endif()
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/drgn")
message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
if(NOT EXISTS "${drgn_SOURCE_DIR}")
message(FATAL_ERROR "The submodules were not downloaded! Please update submodules and try again.")
endif()
endif()
endif()
### Select Python version
@ -222,37 +251,39 @@ set(DRGN_CONFIGURE_FLAGS "--with-libkdumpfile=no")
if (ASAN)
list(APPEND DRGN_CONFIGURE_FLAGS "--enable-asan=yes")
endif()
set(drgn_BUILD_DIR "${drgn_SOURCE_DIR}/build")
add_custom_target(libdrgn ALL
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/extern/drgn
COMMAND unset BISON_PKGDATADIR && CC=gcc CFLAGS="${DRGN_CFLAGS}" CONFIGURE_FLAGS="${DRGN_CONFIGURE_FLAGS}" ${PYTHON} ./setup.py build --build-temp build
BYPRODUCTS ${CMAKE_CURRENT_SOURCE_DIR}/extern/drgn/build/.libs/libdrgnimpl.a
${CMAKE_CURRENT_SOURCE_DIR}/extern/drgn/build/velfutils/libdw/libdw.a
${CMAKE_CURRENT_SOURCE_DIR}/extern/drgn/build/velfutils/libelf/libelf.a
${CMAKE_CURRENT_SOURCE_DIR}/extern/drgn/build/velfutils/libdwelf/libdwelf.a
WORKING_DIRECTORY ${drgn_SOURCE_DIR}
COMMAND unset BISON_PKGDATADIR && CC=gcc CFLAGS="${DRGN_CFLAGS}" CONFIGURE_FLAGS="${DRGN_CONFIGURE_FLAGS}" ${PYTHON} ./setup.py build --build-temp "${drgn_BUILD_DIR}"
BYPRODUCTS ${drgn_BUILD_DIR}/.libs/libdrgnimpl.a
${drgn_BUILD_DIR}/velfutils/libdw/libdw.a
${drgn_BUILD_DIR}/velfutils/libelf/libelf.a
${drgn_BUILD_DIR}/velfutils/libdwelf/libdwelf.a
COMMENT "Building drgn"
USES_TERMINAL
)
set(DRGN_PATH "${PROJECT_SOURCE_DIR}/extern/drgn/build")
# Ideally drgn stuff should be together at the end. But looks like rpath needs
# to be set before add_executable() unfortunately. Maybe split libdrgn stuff
# into a separate file later.
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_INSTALL_RPATH
"${DRGN_PATH}/.libs"
"${DRGN_PATH}/velfutils/libdw"
"${DRGN_PATH}/velfutils/libelf"
"${DRGN_PATH}/velfutils/libdwelf"
"${drgn_BUILD_DIR}/.libs"
"${drgn_BUILD_DIR}/velfutils/libdw"
"${drgn_BUILD_DIR}/velfutils/libelf"
"${drgn_BUILD_DIR}/velfutils/libdwelf"
)
set(CMAKE_BUILD_RPATH
"${DRGN_PATH}/.libs"
"${DRGN_PATH}/velfutils/libdw"
"${DRGN_PATH}/velfutils/libelf"
"${DRGN_PATH}/velfutils/libdwelf"
"${drgn_BUILD_DIR}/.libs"
"${drgn_BUILD_DIR}/velfutils/libdw"
"${drgn_BUILD_DIR}/velfutils/libelf"
"${drgn_BUILD_DIR}/velfutils/libdwelf"
)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
include_directories(SYSTEM "${DRGN_PATH}")
include_directories(SYSTEM "${drgn_BUILD_DIR}")
if (STATIC_LINK)
# glog links against the `gflags` target, which is an alias for `gflags_shared`
@ -322,7 +353,7 @@ else()
endif()
target_link_libraries(oicore
"-L${DRGN_PATH}/.libs"
"-L${drgn_BUILD_DIR}/.libs"
drgn
dw
pthread
@ -333,9 +364,8 @@ add_library(treebuilder
oi/TreeBuilder.cpp
oi/exporters/TypeCheckingWalker.cpp
)
add_dependencies(treebuilder librocksdb)
target_link_libraries(treebuilder
${rocksdb_BINARY_DIR}/librocksdb.a
RocksDB::rocksdb
oicore # overkill but it does need a lot of stuff
zstd::zstd
)
@ -373,9 +403,8 @@ target_link_libraries(oip oicore)
### Object Introspection RocksDB Printer (OIRP)
add_executable(oirp tools/OIRP.cpp)
add_dependencies(oirp librocksdb)
target_link_libraries(oirp
${rocksdb_BINARY_DIR}/librocksdb.a
rocksdb::rocksdb
zstd::zstd
msgpackc
)

2
extern/drgn vendored

@ -1 +1 @@
Subproject commit de2480353e73a48063f4eca4b620d72e80e5246f
Subproject commit f54be805ec0e8d63f54f513b5246f47e4ee100c5

97
flake.lock Normal file
View File

@ -0,0 +1,97 @@
{
"nodes": {
"drgn": {
"flake": false,
"locked": {
"lastModified": 1694096687,
"narHash": "sha256-D7nEVjOlNEZWVK2l7xJ7I1cHqEqyBWDvF3GUGVP1SF8=",
"owner": "JakeHillion",
"repo": "drgn",
"rev": "f54be805ec0e8d63f54f513b5246f47e4ee100c5",
"type": "github"
},
"original": {
"owner": "JakeHillion",
"repo": "drgn",
"rev": "f54be805ec0e8d63f54f513b5246f47e4ee100c5",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"folly": {
"flake": false,
"locked": {
"lastModified": 1677193012,
"narHash": "sha256-ZXLmLF5xaysHv1rP5yEEkSdFskoeTAEPaikA1L1GSN0=",
"owner": "JakeHillion",
"repo": "folly",
"rev": "8db54418e3ccdd97619ac8b69bb3702f82bb0f66",
"type": "github"
},
"original": {
"owner": "JakeHillion",
"repo": "folly",
"rev": "8db54418e3ccdd97619ac8b69bb3702f82bb0f66",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1700390070,
"narHash": "sha256-de9KYi8rSJpqvBfNwscWdalIJXPo8NjdIZcEJum1mH0=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "e4ad989506ec7d71f7302cc3067abd82730a4beb",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"drgn": "drgn",
"flake-utils": "flake-utils",
"folly": "folly",
"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
}

117
flake.nix Normal file
View File

@ -0,0 +1,117 @@
{
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.drgn = {
flake = false;
type = "github";
owner = "JakeHillion";
repo = "drgn";
rev = "f54be805ec0e8d63f54f513b5246f47e4ee100c5";
};
inputs.folly = {
flake = false;
type = "github";
owner = "JakeHillion";
repo = "folly";
rev = "8db54418e3ccdd97619ac8b69bb3702f82bb0f66";
};
description = "A flake for building and developing Object Introspection";
outputs = { self, nixpkgs, drgn, folly, flake-utils }: (
flake-utils.lib.eachSystem [ flake-utils.lib.system.x86_64-linux ]
(system:
let
pkgs =
import nixpkgs
{
system = "x86_64-linux";
overlays = [
(self: super: {
boost = super.boost.override { enableShared = false; enableStatic = true; };
rocksdb = super.rocksdb.overrideAttrs ( old: rec {
version = "8.5.3";
src = super.fetchFromGitHub {
owner = "facebook";
repo = "rocksdb";
rev = "v${version}";
sha256 = "sha256-Qa4bAprXptA79ilNE5KSfggEDvNFHdrvDQ6SvzWMQus=";
};
});
})
];
};
in
{
packages.oid = with pkgs;
pkgs.llvmPackages_12.stdenv.mkDerivation {
name = "oid";
src = self;
postPatch = with pkgs; ''
substituteInPlace CMakeLists.txt --replace '@gtest_src@' '${gtest.src}'
substituteInPlace CMakeLists.txt --replace '@folly_src@' '${folly}'
'';
cmakeFlags = [
"-Ddrgn_SOURCE_DIR=${drgn}"
"-DGIT_SUBMODULES=Off"
"-DWARNINGS_AS_ERRORS=Off"
];
installPhase = ''
mkdir -p $out/bin
install -t $out/bin /build/source/build/oid
'';
nativeBuildInputs = with pkgs; [
autoconf
automake
cmake
gettext
git
libtool
ninja
pkgconf
python310
python310Packages.toml
python310Packages.setuptools
];
buildInputs = with pkgs; [
bison
boost
bzip2
curl
double-conversion
elfutils
flex
fmt
gflags
glog
gtest
icu
jemalloc
libarchive
libmicrohttpd
llvmPackages_15.libclang
llvmPackages_15.llvm
lzma
msgpack
range-v3
rocksdb
sqlite
tomlplusplus
libxml2
zstd
];
};
packages.default = self.packages.${system}.oid;
}) // flake-utils.lib.eachSystem flake-utils.lib.allSystems (system: {
formatter = nixpkgs.legacyPackages.${system}.nixpkgs-fmt;
})
);
}