meson: handle directory and sandbox options correctly

Change-Id: If6d8c97edac5eeae1648a72b809b58df2f1b18ed
This commit is contained in:
Qyriad 2024-03-18 09:22:28 -06:00
parent 366d0bb11e
commit e0767328cc
5 changed files with 82 additions and 36 deletions

View file

@ -2,12 +2,39 @@ project('lix', 'cpp',
version : run_command('bash', '-c', 'echo -n $(cat ./.version)$VERSION_SUFFIX', check : true).stdout().strip(), version : run_command('bash', '-c', 'echo -n $(cat ./.version)$VERSION_SUFFIX', check : true).stdout().strip(),
default_options : [ default_options : [
'cpp_std=c++20', 'cpp_std=c++20',
# TODO(Qyriad): increase the warning level
'warning_level=1', 'warning_level=1',
'debug=true', 'debug=true',
'optimization=2', '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') cxx = meson.get_compiler('cpp')
host_system = host_machine.cpu_family() + '-' + host_machine.system() host_system = host_machine.cpu_family() + '-' + host_machine.system()
@ -99,7 +126,7 @@ endif
sqlite = dependency('sqlite3', 'sqlite', version : '>=3.6.19', required : true) sqlite = dependency('sqlite3', 'sqlite', version : '>=3.6.19', required : true)
deps += sqlite deps += sqlite
sodium = dependency('sodium', 'libsodium', required : true) sodium = dependency('libsodium', 'sodium', required : true)
deps += sodium deps += sodium
curl = dependency('libcurl', 'curl', required : true) curl = dependency('libcurl', 'curl', required : true)
@ -111,10 +138,28 @@ deps += editline
lowdown = dependency('lowdown', version : '>=0.9.0', required : true) lowdown = dependency('lowdown', version : '>=0.9.0', required : true)
deps += lowdown deps += lowdown
rapidcheck = dependency('rapidcheck', required : false)
deps += rapidcheck
gtest = dependency('gtest', required : false)
deps += gtest
# #
# Build-time tools # Build-time tools
# #
bash = find_program('bash') 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') lsof = find_program('lsof')
# This is how Nix does generated headers... # 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. # TODO(Qyriad): Yes this is how the autoconf+Make system did it.
# I would love to remove this. # I would love to remove this.
'-include', 'config.h', '-include', 'config.h',
# TODO(Qyriad): would love to remove these
'-Wno-deprecated-declarations', '-Wno-deprecated-declarations',
'-Wno-unused-parameter', '-Wimplicit-fallthrough',
'-Wno-missing-field-initializers', '-Werror=switch',
'-Wno-deprecated-copy', '-Werror=switch-enum',
'-pthread',
#'-fPIC',
language : 'cpp', language : 'cpp',
) )
# FIXME(Qyriad): only if not Darwin, Solaris, or FreeBSD
# (...so only if Linux?)
add_project_link_arguments( 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', '-Wl,--no-copy-dt-needed-entries',
language : 'cpp', language : 'cpp',
) )

View file

@ -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)', 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', option('store-dir', type : 'string', value : '/nix/store',
description : 'path of the Nix store', description : 'path of the Nix store',
) )
option('sandbox-shell', type : 'string', option('state-dir', type : 'string', value : '/nix/var',
description : 'path to a statically-linked shell to use as /bin/sh in sandboxes (usually busybox)', 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',
) )

View file

@ -173,7 +173,7 @@ in stdenv.mkDerivation (finalAttrs: {
lowdown lowdown
libsodium libsodium
] ]
++ lib.optionals stdenv.isLinux [ libseccomp ] ++ lib.optionals stdenv.isLinux [ libseccomp busybox-sandbox-shell ]
++ lib.optional stdenv.hostPlatform.isx86_64 libcpuid ++ lib.optional stdenv.hostPlatform.isx86_64 libcpuid
# There have been issues building these dependencies # There have been issues building these dependencies
++ lib.optional (stdenv.hostPlatform == stdenv.buildPlatform) aws-sdk-cpp-nix ++ lib.optional (stdenv.hostPlatform == stdenv.buildPlatform) aws-sdk-cpp-nix

View file

@ -81,17 +81,14 @@ libexpr = library(
boehm, boehm,
boost, boost,
], ],
# for shared.hh
include_directories : '../libmain', include_directories : '../libmain',
) cpp_args : [
# FIXME(Qyriad): can we please fix this. toml11 pls.
liblixexpr = declare_dependency( # Technically this only applies to fromTOML.cc, but, well
include_directories : include_directories('.'), # https://github.com/mesonbuild/meson/issues/1367
link_with : libexpr, '-Wno-error=switch-enum',
) ]
liblixexpr = declare_dependency(
include_directories : include_directories('.'),
link_with : libexpr,
) )
liblixexpr = declare_dependency( liblixexpr = declare_dependency(

View file

@ -69,22 +69,20 @@ all_sources += {
'libstore': libstore_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 = { cpp_str_defines = {
'LSOF': lsof.full_path(), 'LSOF': lsof.full_path(),
'NIX_PREFIX': get_option('prefix'), 'NIX_PREFIX': prefix,
'NIX_STORE_DIR': get_option('store-dir'), 'NIX_STORE_DIR': store_dir,
'NIX_DATA_DIR': get_option('prefix') / 'share', # FIXME: make separately-configurable 'NIX_DATA_DIR': datadir,
#'NIX_STATE_DIR': get_option('prefix') / 'nix', # FIXME: same 'NIX_STATE_DIR': state_dir,
'NIX_LOG_DIR': get_option('prefix') / 'log' / 'nix', # FIXME: same 'NIX_LOG_DIR': log_dir,
'NIX_CONF_DIR': get_option('prefix') / 'etc', # FIXME: same 'NIX_CONF_DIR': sysconfdir,
'NIX_BIN_DIR': get_option('prefix') / 'bin', # FIXME: same 'NIX_BIN_DIR': bindir,
'NIX_MAN_DIR': get_option('prefix') / 'share' / 'man', # FIXME: same 'NIX_MAN_DIR': mandir,
}
cpp_str_defines += {
'NIX_STATE_DIR': '/nix/var/nix',
} }
cpp_args = [] cpp_args = []