diff options
author | Vincent Ambo <tazjin@google.com> | 2020-05-27T21·03+0100 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2020-05-27T23·11+0100 |
commit | 25393d80806f7c7caed188130d3f7c9574e61ece (patch) | |
tree | 1b62bd0547eca920a845820c8142a7cc1962b6bb /third_party/nix/src/libstore | |
parent | 3d7537da7fbb37cb043eaa28acc7ffade9bec99d (diff) |
refactor(3p/nix): Introduce CMake as the build system for Nix r/868
Completes the switch from Meson to CMake for the core build system in Nix. Meson was added originally because someone else had already done the work for integrating it in Nix and it was an upgrade from the previous setup. However over time it became clear that Meson is not quite mature enough for projects like Nix that have occasionally peculiar configuration constraints. Some issues encountered with Meson (some of these are due to the Meson setup in Nix): * Difficulty with generating correct compile_commands.json for external tools like clangd * Difficulty linking to libc++ when using clang * Ugly shell invocations for certain parts of the build system (I want these to be gone!!!) This CMake setup mimics the Meson configuration, but there are some differences (some temporary): * headers are now included separately for each library (see a previous commit that changes includes appropriately) * autoheaders-style configuration is currently hardcoded. Before blindly copying this I want to evaluate how much of it actually exists for portability concerns that I don't have (such as support for OS X). * Nix is built with libc++ by default. * [libstore] SQL schema is now inlined via a generated header, not an included string literal Abseil is still built as part of this build, rather than an external dependency, because it chokes on differently configured compiler invocations. Note that because of the move to libc++ an unwanted behaviour is introduced: glog log messages no longer have a body. I have yet to debug what is going on there.
Diffstat (limited to 'third_party/nix/src/libstore')
-rw-r--r-- | third_party/nix/src/libstore/CMakeLists.txt | 102 | ||||
-rw-r--r-- | third_party/nix/src/libstore/local-store.cc | 9 |
2 files changed, 105 insertions, 6 deletions
diff --git a/third_party/nix/src/libstore/CMakeLists.txt b/third_party/nix/src/libstore/CMakeLists.txt new file mode 100644 index 000000000000..21adb0fb02e5 --- /dev/null +++ b/third_party/nix/src/libstore/CMakeLists.txt @@ -0,0 +1,102 @@ +# -*- mode: cmake; -*- +add_library(nixstore SHARED) +set_property(TARGET nixstore PROPERTY CXX_STANDARD 17) +include_directories(${PROJECT_BINARY_DIR}) # for config.h +target_include_directories(nixstore PUBLIC "${nix_SOURCE_DIR}/src") + +# The database schema is stored in schema.sql, but needs to be +# available during the build as static data. +# +# These commands create an includeable source-file out of it. +file(READ "schema.sql" NIX_SCHEMA) + +string(CONFIGURE + "#pragma once + namespace nix { + constexpr char kNixSqlSchema[] = R\"(${NIX_SCHEMA})\"\; + }" + NIX_SCHEMA_GEN) + +file(WRITE ${PROJECT_BINARY_DIR}/generated/schema.sql.hh ${NIX_SCHEMA_GEN}) + +target_sources(nixstore + PUBLIC + binary-cache-store.hh + builtins.hh + crypto.hh + derivations.hh + download.hh + fs-accessor.hh + globals.hh + local-store.hh + machines.hh + nar-accessor.hh + nar-info-disk-cache.hh + nar-info.hh + parsed-derivations.hh + pathlocks.hh + profiles.hh + references.hh + remote-fs-accessor.hh + remote-store.hh + s3-binary-cache-store.hh + s3.hh + serve-protocol.hh + sqlite.hh + ssh.hh + store-api.hh + worker-protocol.hh + + PRIVATE + ${PROJECT_BINARY_DIR}/generated/schema.sql.hh + binary-cache-store.cc + build.cc + crypto.cc + derivations.cc + download.cc + export-import.cc + gc.cc + globals.cc + http-binary-cache-store.cc + legacy-ssh-store.cc + local-binary-cache-store.cc + local-fs-store.cc + local-store.cc + machines.cc + misc.cc + nar-accessor.cc + nar-info.cc + nar-info-disk-cache.cc + optimise-store.cc + parsed-derivations.cc + pathlocks.cc + profiles.cc + references.cc + remote-fs-accessor.cc + remote-store.cc + s3-binary-cache-store.cc + sqlite.cc + ssh.cc + ssh-store.cc + store-api.cc + builtins/buildenv.cc + builtins/fetchurl.cc +) + +target_link_libraries(nixstore + nixutil + + BZip2::BZip2 + Boost::context + CURL::libcurl + LibLZMA::LibLZMA + SQLite::SQLite3 + absl::strings + brotlidec + brotlienc + glog + seccomp + sodium +) + +INSTALL(TARGETS nixstore DESTINATION lib) diff --git a/third_party/nix/src/libstore/local-store.cc b/third_party/nix/src/libstore/local-store.cc index f9d03c520a7c..2f35dd69c4fb 100644 --- a/third_party/nix/src/libstore/local-store.cc +++ b/third_party/nix/src/libstore/local-store.cc @@ -374,10 +374,7 @@ void LocalStore::openDB(State& state, bool create) { /* Initialise the database schema, if necessary. */ if (create) { - const char* schema = -#include "schema.sql.gen.hh" - ; - db.exec(schema); + db.exec(kNixSqlSchema); } } @@ -435,13 +432,13 @@ static void canonicaliseTimestampAndPermissions(const Path& path, if (errno != ENOSYS || (!S_ISLNK(st.st_mode) && utimes(path.c_str(), times) == -1)) { #else - if (!S_ISLNK(st.st_mode) && utimes(path.c_str(), times) == -1) + if (!S_ISLNK(st.st_mode) && utimes(path.c_str(), times) == -1) { #endif throw SysError(format("changing modification time of '%1%'") % path); } } } // namespace nix -} +} // namespace nix void canonicaliseTimestampAndPermissions(const Path& path) { struct stat st; |