Skip to content

Commit

Permalink
Package the Nix CLI with Meson
Browse files Browse the repository at this point in the history
Co-Authored-By: Qyriad <qyriad@qyriad.me>
  • Loading branch information
Ericson2314 and Qyriad committed Jul 8, 2024
1 parent 183dd9d commit 000636b
Show file tree
Hide file tree
Showing 25 changed files with 351 additions and 38 deletions.
9 changes: 9 additions & 0 deletions build-utils-meson/generate-header/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
bash = find_program('bash', native: true)

gen_header = generator(
bash,
arguments : [ '-c', '{ echo \'R"__NIX_STR(\' && cat @INPUT@ && echo \')__NIX_STR"\'; } > "$1"', '_ignored_argv0', '@OUTPUT@' ],
output : '@PLAINNAME@.gen.hh',
#install : true,
#install_dir : get_option('includedir') / 'nix',
)
6 changes: 5 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ project('nix-dev-shell', 'cpp',
subproject_dir : 'src',
)

# Internal Libraries
subproject('libutil')
subproject('libstore')
subproject('libfetchers')
Expand All @@ -14,11 +15,14 @@ subproject('libflake')
subproject('libmain')
subproject('libcmd')

# Executables
subproject('nix')

# Docs
subproject('internal-api-docs')
subproject('external-api-docs')

# C wrappers
# External C wrapper libraries
subproject('libutil-c')
subproject('libstore-c')
subproject('libexpr-c')
Expand Down
3 changes: 3 additions & 0 deletions packaging/components.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ in

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

# Will replace `nix` once the old build system is gone.
nix-ng = callPackage ../src/nix/package.nix { };

nix-internal-api-docs = callPackage ../src/internal-api-docs/package.nix { };
nix-external-api-docs = callPackage ../src/external-api-docs/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 @@ -53,6 +53,7 @@ let
"nix-flake-tests"
"nix-main"
"nix-cmd"
"nix-ng"
];
in
{
Expand Down
9 changes: 3 additions & 6 deletions src/libexpr/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,17 @@ lexer_tab = custom_target(
install_dir : get_option('includedir') / 'nix',
)

subdir('build-utils-meson/generate-header')

generated_headers = []
foreach header : [
'imported-drv-to-derivation.nix',
'fetchurl.nix',
'call-flake.nix',
]
generated_headers += custom_target(
command : [ 'bash', '-c', '{ echo \'R"__NIX_STR(\' && cat @INPUT@ && echo \')__NIX_STR"\'; } > "$1"', '_ignored_argv0', '@OUTPUT@' ],
input : header,
output : '@PLAINNAME@.gen.hh',
)
generated_headers += gen_header.process(header)
endforeach


sources = files(
'attr-path.cc',
'attr-set.cc',
Expand Down
11 changes: 3 additions & 8 deletions src/libexpr/primops/meson.build
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
foreach header : [
generated_headers += gen_header.process(
'derivation.nix',
]
generated_headers += custom_target(
command : [ 'bash', '-c', '{ echo \'R"__NIX_STR(\' && cat @INPUT@ && echo \')__NIX_STR"\'; } > "$1"', '_ignored_argv0', '@OUTPUT@' ],
input : header,
output : '@PLAINNAME@.gen.hh',
)
endforeach
preserve_path_from: meson.project_source_root(),
)

sources += files(
'context.cc',
Expand Down
10 changes: 3 additions & 7 deletions src/libstore/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,14 @@ deps_public += nlohmann_json
sqlite = dependency('sqlite3', 'sqlite', version : '>=3.6.19')
deps_private += sqlite

subdir('build-utils-meson/generate-header')

generated_headers = []
foreach header : [
'schema.sql',
'ca-specific-schema.sql',
]
generated_headers += custom_target(
command : [ 'bash', '-c', '{ echo \'R"__NIX_STR(\' && cat @INPUT@ && echo \')__NIX_STR"\'; } > "$1"', '_ignored_argv0', '@OUTPUT@' ],
input : header,
output : '@PLAINNAME@.gen.hh',
install : true,
install_dir : get_option('includedir') / 'nix',
)
generated_headers += gen_header.process(header)
endforeach

busybox = find_program(get_option('sandbox-shell'), required : false)
Expand Down
1 change: 1 addition & 0 deletions src/nix/.version
1 change: 1 addition & 0 deletions src/nix/build-remote
1 change: 1 addition & 0 deletions src/nix/build-utils-meson
1 change: 1 addition & 0 deletions src/nix/doc
1 change: 1 addition & 0 deletions src/nix/help-stores.md
15 changes: 1 addition & 14 deletions src/nix/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,6 @@ src/nix/main.cc: \
doc/manual/generate-manpage.nix.gen.hh \
doc/manual/utils.nix.gen.hh doc/manual/generate-settings.nix.gen.hh \
doc/manual/generate-store-info.nix.gen.hh \
src/nix/generated-doc/help-stores.md

src/nix/generated-doc/files/%.md: doc/manual/src/command-ref/files/%.md
@mkdir -p $$(dirname $@)
@cp $< $@
src/nix/generated-doc/help-stores.md.gen.hh

src/nix/profile.cc: src/nix/profile.md src/nix/generated-doc/files/profiles.md.gen.hh

src/nix/generated-doc/help-stores.md: doc/manual/src/store/types/index.md.in
@mkdir -p $$(dirname $@)
@echo 'R"(' >> $@.tmp
@echo >> $@.tmp
@cat $^ >> $@.tmp
@echo >> $@.tmp
@echo ')"' >> $@.tmp
@mv $@.tmp $@
2 changes: 1 addition & 1 deletion src/nix/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ struct CmdHelpStores : Command
std::string doc() override
{
return
#include "generated-doc/help-stores.md"
#include "help-stores.md.gen.hh"
;
}

Expand Down
179 changes: 179 additions & 0 deletions src/nix/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
project('nix', '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')

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

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

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.
'-include', 'config-util.hh',
'-include', 'config-store.hh',
'-include', 'config-expr.hh',
#'-include', 'config-fetchers.hh',
'-include', 'config-main.hh',
'-include', 'config-cmd.hh',
language : 'cpp',
)

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

nix_sources = files(
'add-to-store.cc',
'app.cc',
'build.cc',
'bundle.cc',
'cat.cc',
'config-check.cc',
'config.cc',
'copy.cc',
'derivation-add.cc',
'derivation-show.cc',
'derivation.cc',
'develop.cc',
'diff-closures.cc',
'dump-path.cc',
'edit.cc',
'env.cc',
'eval.cc',
'flake.cc',
'fmt.cc',
'hash.cc',
'log.cc',
'ls.cc',
'main.cc',
'make-content-addressed.cc',
'nar.cc',
'optimise-store.cc',
'path-from-hash-part.cc',
'path-info.cc',
'prefetch.cc',
'profile.cc',
'realisation.cc',
'registry.cc',
'repl.cc',
'run.cc',
'search.cc',
'sigs.cc',
'store-copy-log.cc',
'store-delete.cc',
'store-gc.cc',
'store-info.cc',
'store-repair.cc',
'store.cc',
'unix/daemon.cc',
'upgrade-nix.cc',
'verify.cc',
'why-depends.cc',
)

nix_sources += [
gen_header.process('doc/manual/generate-manpage.nix'),
gen_header.process('doc/manual/generate-settings.nix'),
gen_header.process('doc/manual/generate-store-info.nix'),
gen_header.process('doc/manual/utils.nix'),
gen_header.process('get-env.sh'),
gen_header.process('profiles.md'),
gen_header.process('help-stores.md'),
]

if host_machine.system() != 'windows'
nix_sources += files(
'unix/daemon.cc',
)
endif

# The rest of the subdirectories aren't separate components,
# just source files in another directory, so we process them here.

build_remote_sources = files(
'build-remote/build-remote.cc',
)
nix_build_sources = files(
'nix-build/nix-build.cc',
)
nix_channel_sources = files(
'nix-channel/nix-channel.cc',
)
unpack_channel_gen = gen_header.process('nix-channel/unpack-channel.nix')
nix_collect_garbage_sources = files(
'nix-collect-garbage/nix-collect-garbage.cc',
)
nix_copy_closure_sources = files(
'nix-copy-closure/nix-copy-closure.cc',
)
nix_env_buildenv_gen = gen_header.process('nix-env/buildenv.nix')
nix_env_sources = files(
'nix-env/nix-env.cc',
'nix-env/user-env.cc',
)
nix_instantiate_sources = files(
'nix-instantiate/nix-instantiate.cc',
)
nix_store_sources = files(
'nix-store/dotgraph.cc',
'nix-store/graphml.cc',
'nix-store/nix-store.cc',
)

# Hurray for Meson list flattening!
sources = [
nix_sources,
build_remote_sources,
nix_build_sources,
nix_channel_sources,
unpack_channel_gen,
nix_collect_garbage_sources,
nix_copy_closure_sources,
nix_env_buildenv_gen,
nix_env_sources,
nix_instantiate_sources,
nix_store_sources,
]

include_dirs = [include_directories('.')]

this_exe = executable(
meson.project_name(),
sources,
dependencies : deps_private_subproject + deps_private + deps_other,
include_directories : include_dirs,
link_args: linker_export_flags,
install : true,
)

test(
meson.project_name(),
this_exe,
env : {
'_NIX_TEST_UNIT_DATA': meson.current_source_dir() / 'data',
},
protocol : 'gtest',
)
1 change: 1 addition & 0 deletions src/nix/nix-build
1 change: 1 addition & 0 deletions src/nix/nix-channel
1 change: 1 addition & 0 deletions src/nix/nix-collect-garbage
1 change: 1 addition & 0 deletions src/nix/nix-copy-closure
1 change: 1 addition & 0 deletions src/nix/nix-env
1 change: 1 addition & 0 deletions src/nix/nix-instantiate
1 change: 1 addition & 0 deletions src/nix/nix-store
Loading

0 comments on commit 000636b

Please sign in to comment.