1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-14 14:32:42 +01:00

Remove static data from headers

We don't want to duplicate any of these across libraries, which is what
happens when the platform doesn't support unique symbols.

(cherry picked from commit 1b5af49fd0)
This commit is contained in:
David McFarland 2025-11-12 19:52:29 -04:00 committed by github-actions[bot]
parent d7fc293353
commit 4a8b515260
10 changed files with 37 additions and 26 deletions

View file

@ -2,6 +2,7 @@
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include "nix/cmd/command.hh" #include "nix/cmd/command.hh"
#include "nix/cmd/legacy.hh"
#include "nix/cmd/markdown.hh" #include "nix/cmd/markdown.hh"
#include "nix/store/store-open.hh" #include "nix/store/store-open.hh"
#include "nix/store/local-fs-store.hh" #include "nix/store/local-fs-store.hh"
@ -14,6 +15,18 @@
namespace nix { namespace nix {
RegisterCommand::Commands & RegisterCommand::commands()
{
static RegisterCommand::Commands commands;
return commands;
}
RegisterLegacyCommand::Commands & RegisterLegacyCommand::commands()
{
static RegisterLegacyCommand::Commands commands;
return commands;
}
nix::Commands RegisterCommand::getCommandsFor(const std::vector<std::string> & prefix) nix::Commands RegisterCommand::getCommandsFor(const std::vector<std::string> & prefix)
{ {
nix::Commands res; nix::Commands res;

View file

@ -286,11 +286,7 @@ struct RegisterCommand
{ {
typedef std::map<std::vector<std::string>, std::function<ref<Command>()>> Commands; typedef std::map<std::vector<std::string>, std::function<ref<Command>()>> Commands;
static Commands & commands() static Commands & commands();
{
static Commands commands;
return commands;
}
RegisterCommand(std::vector<std::string> && name, std::function<ref<Command>()> command) RegisterCommand(std::vector<std::string> && name, std::function<ref<Command>()> command)
{ {

View file

@ -13,11 +13,7 @@ struct RegisterLegacyCommand
{ {
typedef std::map<std::string, MainFunction> Commands; typedef std::map<std::string, MainFunction> Commands;
static Commands & commands() static Commands & commands();
{
static Commands commands;
return commands;
}
RegisterLegacyCommand(const std::string & name, MainFunction fun) RegisterLegacyCommand(const std::string & name, MainFunction fun)
{ {

View file

@ -12,11 +12,7 @@ struct RegisterPrimOp
{ {
typedef std::vector<PrimOp> PrimOps; typedef std::vector<PrimOp> PrimOps;
static PrimOps & primOps() static PrimOps & primOps();
{
static PrimOps primOps;
return primOps;
}
/** /**
* You can register a constant by passing an arity of 0. fun * You can register a constant by passing an arity of 0. fun

View file

@ -110,7 +110,7 @@ struct PrintOptions
* `PrintOptions` for unknown and therefore potentially large values in error messages, * `PrintOptions` for unknown and therefore potentially large values in error messages,
* to avoid printing "too much" output. * to avoid printing "too much" output.
*/ */
static PrintOptions errorPrintOptions = PrintOptions{ static constexpr PrintOptions errorPrintOptions = PrintOptions{
.ansiColors = true, .ansiColors = true,
.maxDepth = 10, .maxDepth = 10,
.maxAttrs = 10, .maxAttrs = 10,

View file

@ -39,6 +39,12 @@
namespace nix { namespace nix {
RegisterPrimOp::PrimOps & RegisterPrimOp::primOps()
{
static RegisterPrimOp::PrimOps primOps;
return primOps;
}
/************************************************************* /*************************************************************
* Miscellaneous * Miscellaneous
*************************************************************/ *************************************************************/

View file

@ -10,6 +10,12 @@
namespace nix { namespace nix {
RegisterBuiltinBuilder::BuiltinBuilders & RegisterBuiltinBuilder::builtinBuilders()
{
static RegisterBuiltinBuilder::BuiltinBuilders builders;
return builders;
}
namespace { namespace {
struct State struct State

View file

@ -20,11 +20,7 @@ struct RegisterBuiltinBuilder
{ {
typedef std::map<std::string, BuiltinBuilder> BuiltinBuilders; typedef std::map<std::string, BuiltinBuilder> BuiltinBuilders;
static BuiltinBuilders & builtinBuilders() static BuiltinBuilders & builtinBuilders();
{
static BuiltinBuilders builders;
return builders;
}
RegisterBuiltinBuilder(const std::string & name, BuiltinBuilder && fun) RegisterBuiltinBuilder(const std::string & name, BuiltinBuilder && fun)
{ {

View file

@ -4,6 +4,12 @@
namespace nix { namespace nix {
GlobalConfig::ConfigRegistrations & GlobalConfig::configRegistrations()
{
static GlobalConfig::ConfigRegistrations configRegistrations;
return configRegistrations;
}
bool GlobalConfig::set(const std::string & name, const std::string & value) bool GlobalConfig::set(const std::string & name, const std::string & value)
{ {
for (auto & config : configRegistrations()) for (auto & config : configRegistrations())

View file

@ -9,11 +9,7 @@ struct GlobalConfig : public AbstractConfig
{ {
typedef std::vector<Config *> ConfigRegistrations; typedef std::vector<Config *> ConfigRegistrations;
static ConfigRegistrations & configRegistrations() static ConfigRegistrations & configRegistrations();
{
static ConfigRegistrations configRegistrations;
return configRegistrations;
}
bool set(const std::string & name, const std::string & value) override; bool set(const std::string & name, const std::string & value) override;