Skip to content

Commit b230c01

Browse files
authored
Merge pull request #11014 from obsidiansystems/plugins-libmain
Move plugins infra to `libnixmain`
2 parents 463256b + 0feeab7 commit b230c01

20 files changed

Lines changed: 365 additions & 131 deletions

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ subproject('external-api-docs')
2626
subproject('libutil-c')
2727
subproject('libstore-c')
2828
subproject('libexpr-c')
29+
subproject('libmain-c')
2930

3031
# Language Bindings
3132
subproject('perl')

packaging/components.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ in
2929
nix-flake-tests = callPackage ../tests/unit/libflake/package.nix { };
3030

3131
nix-main = callPackage ../src/libmain/package.nix { };
32+
nix-main-c = callPackage ../src/libmain-c/package.nix { };
3233

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

packaging/hydra.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ let
5252
"nix-flake"
5353
"nix-flake-tests"
5454
"nix-main"
55+
"nix-main-c"
5556
"nix-cmd"
5657
"nix-ng"
5758
];

src/build-remote/build-remote.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "machines.hh"
1313
#include "shared.hh"
14+
#include "plugin.hh"
1415
#include "pathlocks.hh"
1516
#include "globals.hh"
1617
#include "serialise.hh"

src/libmain-c/.version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../.version

src/libmain-c/build-utils-meson

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../build-utils-meson

src/libmain-c/meson.build

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
project('nix-main-c', 'cpp',
2+
version : files('.version'),
3+
default_options : [
4+
'cpp_std=c++2a',
5+
# TODO(Qyriad): increase the warning level
6+
'warning_level=1',
7+
'debug=true',
8+
'optimization=2',
9+
'errorlogs=true', # Please print logs for tests that fail
10+
],
11+
meson_version : '>= 1.1',
12+
license : 'LGPL-2.1-or-later',
13+
)
14+
15+
cxx = meson.get_compiler('cpp')
16+
17+
subdir('build-utils-meson/deps-lists')
18+
19+
configdata = configuration_data()
20+
21+
deps_private_maybe_subproject = [
22+
dependency('nix-util'),
23+
dependency('nix-store'),
24+
dependency('nix-main'),
25+
]
26+
deps_public_maybe_subproject = [
27+
dependency('nix-util-c'),
28+
dependency('nix-store-c'),
29+
]
30+
subdir('build-utils-meson/subprojects')
31+
32+
# TODO rename, because it will conflict with downstream projects
33+
configdata.set_quoted('PACKAGE_VERSION', meson.project_version())
34+
35+
config_h = configure_file(
36+
configuration : configdata,
37+
output : 'config-main.h',
38+
)
39+
40+
add_project_arguments(
41+
# TODO(Qyriad): Yes this is how the autoconf+Make system did it.
42+
# It would be nice for our headers to be idempotent instead.
43+
44+
# From C++ libraries, only for internals
45+
'-include', 'config-util.hh',
46+
'-include', 'config-store.hh',
47+
'-include', 'config-main.hh',
48+
49+
# From C libraries, for our public, installed headers too
50+
'-include', 'config-util.h',
51+
'-include', 'config-store.h',
52+
'-include', 'config-main.h',
53+
language : 'cpp',
54+
)
55+
56+
subdir('build-utils-meson/diagnostics')
57+
58+
sources = files(
59+
'nix_api_main.cc',
60+
)
61+
62+
include_dirs = [include_directories('.')]
63+
64+
headers = [config_h] + files(
65+
'nix_api_main.h',
66+
)
67+
68+
subdir('build-utils-meson/export-all-symbols')
69+
70+
this_library = library(
71+
'nixmainc',
72+
sources,
73+
dependencies : deps_public + deps_private + deps_other,
74+
include_directories : include_dirs,
75+
link_args: linker_export_flags,
76+
prelink : true, # For C++ static initializers
77+
install : true,
78+
)
79+
80+
install_headers(headers, subdir : 'nix', preserve_path : true)
81+
82+
libraries_private = []
83+
84+
subdir('build-utils-meson/export')

src/libmain-c/nix_api_main.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "nix_api_store.h"
2+
#include "nix_api_store_internal.h"
3+
#include "nix_api_util.h"
4+
#include "nix_api_util_internal.h"
5+
6+
#include "plugin.hh"
7+
8+
nix_err nix_init_plugins(nix_c_context * context)
9+
{
10+
if (context)
11+
context->last_err_code = NIX_OK;
12+
try {
13+
nix::initPlugins();
14+
}
15+
NIXC_CATCH_ERRS
16+
}

src/libmain-c/nix_api_main.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifndef NIX_API_MAIN_H
2+
#define NIX_API_MAIN_H
3+
/**
4+
* @defgroup libmain libmain
5+
* @brief C bindings for nix libmain
6+
*
7+
* libmain has misc utilities for CLI commands
8+
* @{
9+
*/
10+
/** @file
11+
* @brief Main entry for the libmain C bindings
12+
*/
13+
14+
#include "nix_api_util.h"
15+
#include <stdbool.h>
16+
17+
#ifdef __cplusplus
18+
extern "C" {
19+
#endif
20+
// cffi start
21+
22+
/**
23+
* @brief Loads the plugins specified in Nix's plugin-files setting.
24+
*
25+
* Call this once, after calling your desired init functions and setting
26+
* relevant settings.
27+
*
28+
* @param[out] context Optional, stores error information
29+
* @return NIX_OK if the initialization was successful, an error code otherwise.
30+
*/
31+
nix_err nix_init_plugins(nix_c_context * context);
32+
33+
// cffi end
34+
#ifdef __cplusplus
35+
}
36+
#endif
37+
/**
38+
* @}
39+
*/
40+
#endif // NIX_API_MAIN_H

src/libmain-c/package.nix

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{ lib
2+
, stdenv
3+
, mkMesonDerivation
4+
, releaseTools
5+
6+
, meson
7+
, ninja
8+
, pkg-config
9+
10+
, nix-util-c
11+
, nix-store
12+
, nix-store-c
13+
, nix-main
14+
15+
# Configuration Options
16+
17+
, version
18+
}:
19+
20+
let
21+
inherit (lib) fileset;
22+
in
23+
24+
mkMesonDerivation (finalAttrs: {
25+
pname = "nix-main-c";
26+
inherit version;
27+
28+
workDir = ./.;
29+
fileset = fileset.unions [
30+
../../build-utils-meson
31+
./build-utils-meson
32+
../../.version
33+
./.version
34+
./meson.build
35+
# ./meson.options
36+
(fileset.fileFilter (file: file.hasExt "cc") ./.)
37+
(fileset.fileFilter (file: file.hasExt "hh") ./.)
38+
(fileset.fileFilter (file: file.hasExt "h") ./.)
39+
];
40+
41+
outputs = [ "out" "dev" ];
42+
43+
nativeBuildInputs = [
44+
meson
45+
ninja
46+
pkg-config
47+
];
48+
49+
propagatedBuildInputs = [
50+
nix-util-c
51+
nix-store
52+
nix-store-c
53+
nix-main
54+
];
55+
56+
preConfigure =
57+
# "Inline" .version so it's not a symlink, and includes the suffix.
58+
# Do the meson utils, without modification.
59+
''
60+
chmod u+w ./.version
61+
echo ${version} > ../../.version
62+
'';
63+
64+
mesonFlags = [
65+
];
66+
67+
env = lib.optionalAttrs (stdenv.isLinux && !(stdenv.hostPlatform.isStatic && stdenv.system == "aarch64-linux")) {
68+
LDFLAGS = "-fuse-ld=gold";
69+
};
70+
71+
enableParallelBuilding = true;
72+
73+
separateDebugInfo = !stdenv.hostPlatform.isStatic;
74+
75+
strictDeps = true;
76+
77+
hardeningDisable = lib.optional stdenv.hostPlatform.isStatic "pie";
78+
79+
meta = {
80+
platforms = lib.platforms.unix ++ lib.platforms.windows;
81+
};
82+
83+
})

0 commit comments

Comments
 (0)