From e0767328cc1a12386bb0bc8626e28816840a1c70 Mon Sep 17 00:00:00 2001 From: Qyriad Date: Mon, 18 Mar 2024 09:22:28 -0600 Subject: [PATCH] meson: handle directory and sandbox options correctly Change-Id: If6d8c97edac5eeae1648a72b809b58df2f1b18ed --- meson.build | 61 ++++++++++++++++++++++++++++++++++------ meson.options | 12 ++++++-- package.nix | 2 +- src/libexpr/meson.build | 17 +++++------ src/libstore/meson.build | 26 ++++++++--------- 5 files changed, 82 insertions(+), 36 deletions(-) diff --git a/meson.build b/meson.build index d28e78739..951ba56cd 100644 --- a/meson.build +++ b/meson.build @@ -2,12 +2,39 @@ project('lix', 'cpp', version : run_command('bash', '-c', 'echo -n $(cat ./.version)$VERSION_SUFFIX', check : true).stdout().strip(), default_options : [ 'cpp_std=c++20', + # TODO(Qyriad): increase the warning level 'warning_level=1', 'debug=true', 'optimization=2', ], ) +fs = import('fs') + +prefix = get_option('prefix') +# For each of these paths, assume that it is relative to the prefix unless +# it is already an absolute path (which is the default for store-dir, state-dir, and log-dir). +path_opts = [ + # Meson built-ins. + 'datadir', + 'sysconfdir', + 'bindir', + 'mandir', + # Homecooked Lix directories. + 'store-dir', + 'state-dir', + 'log-dir', +] +foreach optname : path_opts + varname = optname.replace('-', '_') + path = get_option(optname) + if fs.is_absolute(path) + set_variable(varname, path) + else + set_variable(varname, prefix / path) + endif +endforeach + cxx = meson.get_compiler('cpp') host_system = host_machine.cpu_family() + '-' + host_machine.system() @@ -99,7 +126,7 @@ endif sqlite = dependency('sqlite3', 'sqlite', version : '>=3.6.19', required : true) deps += sqlite -sodium = dependency('sodium', 'libsodium', required : true) +sodium = dependency('libsodium', 'sodium', required : true) deps += sodium curl = dependency('libcurl', 'curl', required : true) @@ -111,10 +138,28 @@ deps += editline lowdown = dependency('lowdown', version : '>=0.9.0', required : true) deps += lowdown +rapidcheck = dependency('rapidcheck', required : false) +deps += rapidcheck + +gtest = dependency('gtest', required : false) +deps += gtest + # # Build-time tools # bash = find_program('bash') +sandbox_shell = get_option('sandbox-shell') +# Consider it required if we're on Linux and the user explicitly specified a non-default value. +sandbox_shell_required = sandbox_shell != 'busybox' and host_machine.system() == 'linux' +# NOTE(Qyriad): package.nix puts busybox in buildInputs for Linux. +# Most builds should not require setting this. +busybox = find_program(sandbox_shell, required : sandbox_shell_required) +if not busybox.found() and host_machine.system() == 'linux' + warning('busybox not found and other sandbox shell was specified') + warning('a sandbox shell is recommended on Linux -- configure with -Dsandbox-shell=/path/to/shell to set') +endif +# FIXME(Qyriad): the autoconf system checks that busybox has the "standalone" feature, indicating +# that busybox sh won't run busybox applets as builtins (which would break out sandbox). lsof = find_program('lsof') # This is how Nix does generated headers... @@ -202,19 +247,17 @@ add_project_arguments( # TODO(Qyriad): Yes this is how the autoconf+Make system did it. # I would love to remove this. '-include', 'config.h', - # TODO(Qyriad): would love to remove these '-Wno-deprecated-declarations', - '-Wno-unused-parameter', - '-Wno-missing-field-initializers', - '-Wno-deprecated-copy', - '-pthread', - #'-fPIC', + '-Wimplicit-fallthrough', + '-Werror=switch', + '-Werror=switch-enum', language : 'cpp', ) -# FIXME(Qyriad): only if not Darwin, Solaris, or FreeBSD -# (...so only if Linux?) add_project_link_arguments( + '-pthread', + # FIXME(Qyriad): autoconf did this only if not Darwin, Solaris, or FreeBSD + # (...so only if Linux?) '-Wl,--no-copy-dt-needed-entries', language : 'cpp', ) diff --git a/meson.options b/meson.options index 393e59733..889fe4a9c 100644 --- a/meson.options +++ b/meson.options @@ -15,10 +15,18 @@ option('seccomp-sandboxing', type : 'feature', description : 'build support for seccomp sandboxing (recommended unless your arch doesn\'t support libseccomp, only relevant on Linux)', ) +option('sandbox-shell', type : 'string', value : 'busybox', + description : 'path to a statically-linked shell to use as /bin/sh in sandboxes (usually busybox)', +) + option('store-dir', type : 'string', value : '/nix/store', description : 'path of the Nix store', ) -option('sandbox-shell', type : 'string', - description : 'path to a statically-linked shell to use as /bin/sh in sandboxes (usually busybox)', +option('state-dir', type : 'string', value : '/nix/var', + description : 'path to store state in for Nix', +) + +option('log-dir', type : 'string', value : '/nix/var/log', + description : 'path to store logs in for Nix', ) diff --git a/package.nix b/package.nix index ca14ae049..60626e909 100644 --- a/package.nix +++ b/package.nix @@ -173,7 +173,7 @@ in stdenv.mkDerivation (finalAttrs: { lowdown libsodium ] - ++ lib.optionals stdenv.isLinux [ libseccomp ] + ++ lib.optionals stdenv.isLinux [ libseccomp busybox-sandbox-shell ] ++ lib.optional stdenv.hostPlatform.isx86_64 libcpuid # There have been issues building these dependencies ++ lib.optional (stdenv.hostPlatform == stdenv.buildPlatform) aws-sdk-cpp-nix diff --git a/src/libexpr/meson.build b/src/libexpr/meson.build index 30ee66b38..65414e5b2 100644 --- a/src/libexpr/meson.build +++ b/src/libexpr/meson.build @@ -81,17 +81,14 @@ libexpr = library( boehm, boost, ], + # for shared.hh include_directories : '../libmain', -) - -liblixexpr = declare_dependency( - include_directories : include_directories('.'), - link_with : libexpr, -) - -liblixexpr = declare_dependency( - include_directories : include_directories('.'), - link_with : libexpr, + cpp_args : [ + # FIXME(Qyriad): can we please fix this. toml11 pls. + # Technically this only applies to fromTOML.cc, but, well + # https://github.com/mesonbuild/meson/issues/1367 + '-Wno-error=switch-enum', + ] ) liblixexpr = declare_dependency( diff --git a/src/libstore/meson.build b/src/libstore/meson.build index d5ef3815a..5d8b73f5b 100644 --- a/src/libstore/meson.build +++ b/src/libstore/meson.build @@ -69,22 +69,20 @@ all_sources += { 'libstore': libstore_sources, } -prefix = get_option('prefix') - +# These variables are created pseudo-dynamically, near the beginning of +# the top-level meson.build. Aside from prefix itself, each of these was +# made into an absolute path by joining it with prefix, unless it was already +# an absolute path (which is the default for store-dir, state-dir, and log-dir). 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_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', + 'NIX_PREFIX': prefix, + 'NIX_STORE_DIR': store_dir, + 'NIX_DATA_DIR': datadir, + 'NIX_STATE_DIR': state_dir, + 'NIX_LOG_DIR': log_dir, + 'NIX_CONF_DIR': sysconfdir, + 'NIX_BIN_DIR': bindir, + 'NIX_MAN_DIR': mandir, } cpp_args = []