Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into new-store-settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericson2314 committed Jul 17, 2024
2 parents d095fa3 + 621c23b commit 121e607
Show file tree
Hide file tree
Showing 34 changed files with 427 additions and 165 deletions.
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ subproject('external-api-docs')
subproject('libutil-c')
subproject('libstore-c')
subproject('libexpr-c')
subproject('libmain-c')

# Language Bindings
subproject('perl')
Expand Down
1 change: 1 addition & 0 deletions packaging/components.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ in
nix-flake-tests = callPackage ../tests/unit/libflake/package.nix { };

nix-main = callPackage ../src/libmain/package.nix { };
nix-main-c = callPackage ../src/libmain-c/package.nix { };

nix-cmd = callPackage ../src/libcmd/package.nix { };

Expand Down
1 change: 1 addition & 0 deletions packaging/hydra.nix
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ let
"nix-flake"
"nix-flake-tests"
"nix-main"
"nix-main-c"
"nix-cmd"
"nix-ng"
];
Expand Down
1 change: 1 addition & 0 deletions src/build-remote/build-remote.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "machines.hh"
#include "shared.hh"
#include "plugin.hh"
#include "pathlocks.hh"
#include "globals.hh"
#include "serialise.hh"
Expand Down
10 changes: 4 additions & 6 deletions src/libexpr/eval-settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ EvalSettings::EvalSettings(bool & readOnlyMode, EvalSettings::LookupPathHooks lo
builtinsAbortOnWarn = true;
}

Strings EvalSettings::getDefaultNixPath() const
Strings EvalSettings::getDefaultNixPath()
{
Strings res;
auto add = [&](const Path & p, const std::string & s = std::string()) {
Expand All @@ -69,11 +69,9 @@ Strings EvalSettings::getDefaultNixPath() const
}
};

if (!restrictEval && !pureEval) {
add(getNixDefExpr() + "/channels");
add(rootChannelsDir() + "/nixpkgs", "nixpkgs");
add(rootChannelsDir());
}
add(getNixDefExpr() + "/channels");
add(rootChannelsDir() + "/nixpkgs", "nixpkgs");
add(rootChannelsDir());

return res;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/eval-settings.hh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct EvalSettings : Config

bool & readOnlyMode;

Strings getDefaultNixPath() const;
static Strings getDefaultNixPath();

static bool isPseudoUrl(std::string_view s);

Expand Down
4 changes: 2 additions & 2 deletions src/libexpr/eval.hh
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ struct Constant
typedef std::map<std::string, Value *> ValMap;
#endif

typedef std::map<PosIdx, DocComment> DocCommentMap;
typedef std::unordered_map<PosIdx, DocComment> DocCommentMap;

struct Env
{
Expand Down Expand Up @@ -335,7 +335,7 @@ private:
* Associate source positions of certain AST nodes with their preceding doc comment, if they have one.
* Grouped by file.
*/
std::map<SourcePath, DocCommentMap> positionToDocComment;
std::unordered_map<SourcePath, DocCommentMap> positionToDocComment;

LookupPath lookupPath;

Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/parser-state.hh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct LexerState
/**
* @brief Maps some positions to a DocComment, where the comment is relevant to the location.
*/
std::map<PosIdx, DocComment> & positionToDocComment;
std::unordered_map<PosIdx, DocComment> & positionToDocComment;

PosTable & positions;
PosTable::Origin origin;
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

namespace nix {

typedef std::map<PosIdx, DocComment> DocCommentMap;
typedef std::unordered_map<PosIdx, DocComment> DocCommentMap;

Expr * parseExprFromBuf(
char * text,
Expand Down
20 changes: 20 additions & 0 deletions src/libexpr/pos-idx.hh
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#pragma once

#include <cinttypes>
#include <functional>

namespace nix {

class PosIdx
{
friend struct LazyPosAcessors;
friend class PosTable;
friend class std::hash<PosIdx>;

private:
uint32_t id;
Expand Down Expand Up @@ -37,8 +39,26 @@ public:
{
return id == other.id;
}

size_t hash() const noexcept
{
return std::hash<uint32_t>{}(id);
}
};

inline PosIdx noPos = {};

}

namespace std {

template<>
struct hash<nix::PosIdx>
{
std::size_t operator()(nix::PosIdx pos) const noexcept
{
return pos.hash();
}
};

} // namespace std
2 changes: 1 addition & 1 deletion src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ static RegisterPrimOp primop_genericClosure(PrimOp {
.doc = R"(
`builtins.genericClosure` iteratively computes the transitive closure over an arbitrary relation defined by a function.
It takes *attrset* with two attributes named `startSet` and `operator`, and returns a list of attrbute sets:
It takes *attrset* with two attributes named `startSet` and `operator`, and returns a list of attribute sets:
- `startSet`:
The initial list of attribute sets.
Expand Down
1 change: 1 addition & 0 deletions src/libmain-c/.version
1 change: 1 addition & 0 deletions src/libmain-c/build-utils-meson
84 changes: 84 additions & 0 deletions src/libmain-c/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
project('nix-main-c', 'cpp',
version : files('.version'),
default_options : [
'cpp_std=c++2a',
# TODO(Qyriad): increase the warning level
'warning_level=1',
'debug=true',
'optimization=2',
'errorlogs=true', # Please print logs for tests that fail
],
meson_version : '>= 1.1',
license : 'LGPL-2.1-or-later',
)

cxx = meson.get_compiler('cpp')

subdir('build-utils-meson/deps-lists')

configdata = configuration_data()

deps_private_maybe_subproject = [
dependency('nix-util'),
dependency('nix-store'),
dependency('nix-main'),
]
deps_public_maybe_subproject = [
dependency('nix-util-c'),
dependency('nix-store-c'),
]
subdir('build-utils-meson/subprojects')

# TODO rename, because it will conflict with downstream projects
configdata.set_quoted('PACKAGE_VERSION', meson.project_version())

config_h = configure_file(
configuration : configdata,
output : 'config-main.h',
)

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', 'config-util.hh',
'-include', 'config-store.hh',
'-include', 'config-main.hh',

# From C libraries, for our public, installed headers too
'-include', 'config-util.h',
'-include', 'config-store.h',
'-include', 'config-main.h',
language : 'cpp',
)

subdir('build-utils-meson/diagnostics')

sources = files(
'nix_api_main.cc',
)

include_dirs = [include_directories('.')]

headers = [config_h] + files(
'nix_api_main.h',
)

subdir('build-utils-meson/export-all-symbols')

this_library = library(
'nixmainc',
sources,
dependencies : deps_public + deps_private + deps_other,
include_directories : include_dirs,
link_args: linker_export_flags,
prelink : true, # For C++ static initializers
install : true,
)

install_headers(headers, subdir : 'nix', preserve_path : true)

libraries_private = []

subdir('build-utils-meson/export')
16 changes: 16 additions & 0 deletions src/libmain-c/nix_api_main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "nix_api_store.h"
#include "nix_api_store_internal.h"
#include "nix_api_util.h"
#include "nix_api_util_internal.h"

#include "plugin.hh"

nix_err nix_init_plugins(nix_c_context * context)
{
if (context)
context->last_err_code = NIX_OK;
try {
nix::initPlugins();
}
NIXC_CATCH_ERRS
}
40 changes: 40 additions & 0 deletions src/libmain-c/nix_api_main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef NIX_API_MAIN_H
#define NIX_API_MAIN_H
/**
* @defgroup libmain libmain
* @brief C bindings for nix libmain
*
* libmain has misc utilities for CLI commands
* @{
*/
/** @file
* @brief Main entry for the libmain C bindings
*/

#include "nix_api_util.h"
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif
// cffi start

/**
* @brief Loads the plugins specified in Nix's plugin-files setting.
*
* Call this once, after calling your desired init functions and setting
* relevant settings.
*
* @param[out] context Optional, stores error information
* @return NIX_OK if the initialization was successful, an error code otherwise.
*/
nix_err nix_init_plugins(nix_c_context * context);

// cffi end
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#endif // NIX_API_MAIN_H
83 changes: 83 additions & 0 deletions src/libmain-c/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{ lib
, stdenv
, mkMesonDerivation
, releaseTools

, meson
, ninja
, pkg-config

, nix-util-c
, nix-store
, nix-store-c
, nix-main

# Configuration Options

, version
}:

let
inherit (lib) fileset;
in

mkMesonDerivation (finalAttrs: {
pname = "nix-main-c";
inherit version;

workDir = ./.;
fileset = fileset.unions [
../../build-utils-meson
./build-utils-meson
../../.version
./.version
./meson.build
# ./meson.options
(fileset.fileFilter (file: file.hasExt "cc") ./.)
(fileset.fileFilter (file: file.hasExt "hh") ./.)
(fileset.fileFilter (file: file.hasExt "h") ./.)
];

outputs = [ "out" "dev" ];

nativeBuildInputs = [
meson
ninja
pkg-config
];

propagatedBuildInputs = [
nix-util-c
nix-store
nix-store-c
nix-main
];

preConfigure =
# "Inline" .version so it's not a symlink, and includes the suffix.
# Do the meson utils, without modification.
''
chmod u+w ./.version
echo ${version} > ../../.version
'';

mesonFlags = [
];

env = lib.optionalAttrs (stdenv.isLinux && !(stdenv.hostPlatform.isStatic && stdenv.system == "aarch64-linux")) {
LDFLAGS = "-fuse-ld=gold";
};

enableParallelBuilding = true;

separateDebugInfo = !stdenv.hostPlatform.isStatic;

strictDeps = true;

hardeningDisable = lib.optional stdenv.hostPlatform.isStatic "pie";

meta = {
platforms = lib.platforms.unix ++ lib.platforms.windows;
};

})
1 change: 1 addition & 0 deletions src/libmain/common-args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "logging.hh"
#include "loggers.hh"
#include "util.hh"
#include "plugin.hh"

namespace nix {

Expand Down
Loading

0 comments on commit 121e607

Please sign in to comment.