1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 23:11:16 +02:00

Cleanup config headers

There are two big changes:

1. Public and private config is now separated. Configuration variables
   that are only used internally do not go in a header which is
   installed.

   (Additionally, libutil has a unix-specific private config header,
   which should only be used in unix-specific code. This keeps things a
   bit more organized, in a purely private implementation-internal way.)

2. Secondly, there is no more `-include`. There are very few config
   items that need to be publically exposed, so now it is feasible to
   just make the headers that need them just including the (public)
   configuration header.

And there are also a few more small cleanups on top of those:

- The configuration files have better names.

- The few CPP variables that remain exposed in the public headers are
  now also renamed to always start with `NIX_`. This ensures they should
  not conflict with variables defined elsewhere.

- We now always use `#if` and not `#ifdef`/`#ifndef` for our
  configuration variables, which helps avoid bugs by requiring that
  variables must be defined in all cases.
This commit is contained in:
John Ericson 2025-03-28 13:24:50 -04:00
parent 5a8dedc45c
commit c204e307ac
59 changed files with 333 additions and 385 deletions

View file

@ -25,18 +25,6 @@ deps_public_maybe_subproject = [
]
subdir('nix-meson-build-support/subprojects')
add_project_arguments(
# TODO(Qyriad): Yes this is how the autoconf+Make system did it.
# It would be nice for our headers to be idempotent instead.
# From C++ libraries, only for internals
'-include', 'nix/config-util.hh',
'-include', 'nix/config-store.hh',
'-include', 'nix/config-expr.hh',
language : 'cpp',
)
subdir('nix-meson-build-support/common')
sources = files(

View file

@ -15,7 +15,7 @@
#include "nix_api_util.h"
#include "nix_api_util_internal.h"
#if HAVE_BOEHMGC
#if NIX_USE_BOEHMGC
# include <mutex>
#endif
@ -209,7 +209,7 @@ void nix_state_free(EvalState * state)
delete state;
}
#if HAVE_BOEHMGC
#if NIX_USE_BOEHMGC
std::unordered_map<
const void *,
unsigned int,
@ -285,7 +285,7 @@ nix_err nix_value_decref(nix_c_context * context, nix_value *x)
void nix_gc_register_finalizer(void * obj, void * cd, void (*finalizer)(void * obj, void * cd))
{
#if HAVE_BOEHMGC
#if NIX_USE_BOEHMGC
GC_REGISTER_FINALIZER(obj, finalizer, cd, 0, 0);
#endif
}

View file

@ -168,7 +168,7 @@ ExternalValue * nix_create_external_value(nix_c_context * context, NixCExternalV
context->last_err_code = NIX_OK;
try {
auto ret = new
#if HAVE_BOEHMGC
#if NIX_USE_BOEHMGC
(GC)
#endif
NixCExternalValue(*desc, v);

View file

@ -125,7 +125,7 @@ PrimOp * nix_alloc_primop(
try {
using namespace std::placeholders;
auto p = new
#if HAVE_BOEHMGC
#if NIX_USE_BOEHMGC
(GC)
#endif
nix::PrimOp{
@ -497,7 +497,7 @@ ListBuilder * nix_make_list_builder(nix_c_context * context, EvalState * state,
try {
auto builder = state->state.buildList(capacity);
return new
#if HAVE_BOEHMGC
#if NIX_USE_BOEHMGC
(NoGC)
#endif
ListBuilder{std::move(builder)};
@ -519,7 +519,7 @@ nix_list_builder_insert(nix_c_context * context, ListBuilder * list_builder, uns
void nix_list_builder_free(ListBuilder * list_builder)
{
#if HAVE_BOEHMGC
#if NIX_USE_BOEHMGC
GC_FREE(list_builder);
#else
delete list_builder;
@ -578,7 +578,7 @@ BindingsBuilder * nix_make_bindings_builder(nix_c_context * context, EvalState *
try {
auto bb = state->state.buildBindings(capacity);
return new
#if HAVE_BOEHMGC
#if NIX_USE_BOEHMGC
(NoGC)
#endif
BindingsBuilder{std::move(bb)};
@ -600,7 +600,7 @@ nix_err nix_bindings_builder_insert(nix_c_context * context, BindingsBuilder * b
void nix_bindings_builder_free(BindingsBuilder * bb)
{
#if HAVE_BOEHMGC
#if NIX_USE_BOEHMGC
GC_FREE((nix::BindingsBuilder *) bb);
#else
delete (nix::BindingsBuilder *) bb;