From 6fb79d08aeed3a0cc9217e95ef5b09eed37ee959 Mon Sep 17 00:00:00 2001 From: Qyriad Date: Fri, 15 Mar 2024 16:44:54 -0600 Subject: [PATCH] meson: getting the nix command building Change-Id: If2f4a82b0d23a11a828bb4b305fabe4e30e1e91b --- meson.build | 13 +----- src/libcmd/meson.build | 5 +++ src/libstore/meson.build | 10 +++-- src/meson.build | 80 +++++++++++++++++++++++++++++++++++++ src/nix-env/meson.build | 4 ++ src/nix/meson.build | 86 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 184 insertions(+), 14 deletions(-) create mode 100644 src/meson.build create mode 100644 src/nix-env/meson.build create mode 100644 src/nix/meson.build diff --git a/meson.build b/meson.build index eecb17e09..7b37c002e 100644 --- a/meson.build +++ b/meson.build @@ -113,6 +113,7 @@ deps += lowdown # # Build-time tools # +bash = find_program('bash') lsof = find_program('lsof') # @@ -196,14 +197,4 @@ add_project_arguments( language : 'cpp', ) -subdir('src/libutil') -# Load-bearing order. libstore depends on libutil. -subdir('src/libstore') -# libfetchers depends on libstore. -subdir('src/libfetchers') -# libexpr depends on libfetchers. -subdir('src/libexpr') -# libmain depends on libutil and libstore. -subdir('src/libmain') -# libcmd depends on everything -subdir('src/libcmd') +subdir('src') diff --git a/src/libcmd/meson.build b/src/libcmd/meson.build index 665001dd7..64046d646 100644 --- a/src/libcmd/meson.build +++ b/src/libcmd/meson.build @@ -28,3 +28,8 @@ libcmd = library( lowdown, ], ) + +liblixcmd = declare_dependency( + include_directories : '.', + link_with : libcmd, +) diff --git a/src/libstore/meson.build b/src/libstore/meson.build index 56f94a3da..0eec541a4 100644 --- a/src/libstore/meson.build +++ b/src/libstore/meson.build @@ -1,5 +1,3 @@ -bash = find_program('bash') - schema_sql_gen = custom_target( input : 'schema.sql', output : 'schema.sql.gen.hh', @@ -90,18 +88,24 @@ all_sources += { 'libstore': libstore_sources, } +prefix = get_option('prefix') + cpp_str_defines = { 'LSOF': lsof.full_path(), 'NIX_PREFIX': get_option('prefix'), 'NIX_STORE_DIR': get_option('store-dir'), 'NIX_DATA_DIR': get_option('prefix') / 'share', # FIXME: make separately-configurable - 'NIX_STATE_DIR': get_option('prefix') / 'nix', # FIXME: same + #'NIX_STATE_DIR': get_option('prefix') / 'nix', # FIXME: same 'NIX_LOG_DIR': get_option('prefix') / 'log' / 'nix', # FIXME: same 'NIX_CONF_DIR': get_option('prefix') / 'etc', # FIXME: same 'NIX_BIN_DIR': get_option('prefix') / 'bin', # FIXME: same 'NIX_MAN_DIR': get_option('prefix') / 'share' / 'man', # FIXME: same } +cpp_str_defines += { + 'NIX_STATE_DIR': '/nix/var/nix', +} + cpp_args = [] foreach name, value : cpp_str_defines diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 000000000..82302dcd3 --- /dev/null +++ b/src/meson.build @@ -0,0 +1,80 @@ +# Subcomponents: these link into artifacts themselves, and have interdependencies. + +subdir('libutil') +# Load-bearing order. libstore depends on libutil. +subdir('libstore') +# libfetchers depends on libstore +subdir('libfetchers') +# libexpr depends on all of the above +subdir('libexpr') +# libmain depends on libutil and libstore +subdir('libmain') +# libcmd depends on everything +subdir('libcmd') + + +# 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 = custom_target( + input : 'nix-channel/unpack-channel.nix', + output : 'unpack-channel.nix.gen.hh', + command : [ + bash, + '-c', + 'echo \'R"foo(\' | cat - @INPUT@ && echo \')foo"\'', + ], + capture : true, +) +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_store_sources = files( + 'nix-store/dotgraph.cc', + 'nix-store/graphml.cc', + 'nix-store/nix-store.cc', +) + +nix_env_buildenv = custom_target( + input : 'nix-env/buildenv.nix', + output : 'buildenv.nix.gen.hh', + command : [ + bash, + '-c', + 'echo \'R"foo(\' | cat - @INPUT@ && echo \')foo"\'', + ], + capture : true, +) +nix_env_sources = files( + 'nix-env/nix-env.cc', + 'nix-env/user-env.cc', +) + +# Hurray for Meson list flattening! +nix2_commands_sources = [ + build_remote_sources, + nix_build_sources, + nix_channel_sources, + unpack_channel_gen, + nix_collect_garbage_sources, + nix_copy_closure_sources, + nix_store_sources, + nix_env_buildenv, + nix_env_sources, +] + +# Finally, the nix command itself, which all of the other commands are implmented in terms of +# as a multicall binary. +subdir('nix') diff --git a/src/nix-env/meson.build b/src/nix-env/meson.build new file mode 100644 index 000000000..f9676a8ca --- /dev/null +++ b/src/nix-env/meson.build @@ -0,0 +1,4 @@ +nix_env_sources = files( + 'nix-env.cc', + 'user-env.cc' +) diff --git a/src/nix/meson.build b/src/nix/meson.build new file mode 100644 index 000000000..af99364e4 --- /dev/null +++ b/src/nix/meson.build @@ -0,0 +1,86 @@ +generate_manpage_gen = custom_target( + input : meson.project_source_root() / 'doc/manual/generate-manpage.nix', + output : 'generate-manpage.nix.gen.hh', + command : [ + bash, + '-c', + 'echo \'R"foo(\' | cat - @INPUT@ && echo \')foo"\'', + ], + capture : true, +) + +utils_gen = custom_target( + input : meson.project_source_root() / 'doc/manual/utils.nix', + output : 'utils.nix.gen.hh', + command : [ + bash, + '-c', + 'echo \'R"foo(\' | cat - @INPUT@ && echo \')foo"\'', + ], + capture : true, +) + +nix_sources = files( + 'add-to-store.cc', + 'app.cc', + 'build.cc', + 'bundle.cc', + 'cat.cc', + 'copy.cc', + 'daemon.cc', + 'derivation-add.cc', + 'derivation-show.cc', + 'derivation.cc', + 'develop.cc', + 'diff-closures.cc', + 'doctor.cc', + 'dump-path.cc', + 'edit.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', + 'ping-store.cc', + 'prefetch.cc', + 'profile.cc', + 'realisation.cc', + 'registry.cc', + 'repl.cc', + 'run.cc', + 'search.cc', + 'show-config.cc', + 'sigs.cc', + 'store-copy-log.cc', + 'store-delete.cc', + 'store-gc.cc', + 'store-repair.cc', + 'store.cc', + 'upgrade-nix.cc', + 'verify.cc', + 'why-depends.cc', +) + +nix = executable( + 'nix', + nix_sources, + generate_manpage_gen, + utils_gen, + nix2_commands_sources, + dependencies : [ + liblixcmd, + liblixutil, + liblixstore, + liblixexpr, + liblixfetchers, + liblixmain, + boehm, + ], +)