mirror of
https://github.com/NixOS/nix
synced 2025-07-06 21:41:48 +02:00
Merge pull request #10973 from NixOS/meson-libexpr
Meson build for libexpr libflake, external C API, unit tests
This commit is contained in:
commit
ddff76f667
101 changed files with 2446 additions and 810 deletions
|
@ -1 +0,0 @@
|
|||
2.24.0
|
1
tests/unit/libutil/.version
Symbolic link
1
tests/unit/libutil/.version
Symbolic link
|
@ -0,0 +1 @@
|
|||
../../../.version
|
1
tests/unit/libutil/build-utils-meson
Symbolic link
1
tests/unit/libutil/build-utils-meson
Symbolic link
|
@ -0,0 +1 @@
|
|||
../../../build-utils-meson/
|
|
@ -1,4 +1,4 @@
|
|||
project('nix-util-test', 'cpp',
|
||||
project('nix-util-tests', 'cpp',
|
||||
version : files('.version'),
|
||||
default_options : [
|
||||
'cpp_std=c++2a',
|
||||
|
@ -14,45 +14,34 @@ project('nix-util-test', 'cpp',
|
|||
|
||||
cxx = meson.get_compiler('cpp')
|
||||
|
||||
# See note in ../nix-util/meson.build
|
||||
deps_private = [ ]
|
||||
subdir('build-utils-meson/deps-lists')
|
||||
|
||||
# See note in ../nix-util/meson.build
|
||||
deps_public = [ ]
|
||||
deps_private_maybe_subproject = [
|
||||
dependency('nix-util'),
|
||||
dependency('nix-util-c'),
|
||||
dependency('nix-util-test-support'),
|
||||
]
|
||||
deps_public_maybe_subproject = [
|
||||
]
|
||||
subdir('build-utils-meson/subprojects')
|
||||
|
||||
# See note in ../nix-util/meson.build
|
||||
deps_other = [ ]
|
||||
subdir('build-utils-meson/export-all-symbols')
|
||||
|
||||
configdata = configuration_data()
|
||||
rapidcheck = dependency('rapidcheck')
|
||||
deps_private += rapidcheck
|
||||
|
||||
gtest = dependency('gtest', main : true)
|
||||
deps_private += gtest
|
||||
|
||||
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-test.h',
|
||||
# '-include', 'config-store.h',
|
||||
'-Wno-deprecated-declarations',
|
||||
'-Wimplicit-fallthrough',
|
||||
'-Werror=switch',
|
||||
'-Werror=switch-enum',
|
||||
'-Werror=unused-result',
|
||||
'-Wdeprecated-copy',
|
||||
'-Wignored-qualifiers',
|
||||
# Enable assertions in libstdc++ by default. Harmless on libc++. Benchmarked
|
||||
# at ~1% overhead in `nix search`.
|
||||
#
|
||||
# FIXME: remove when we get meson 1.4.0 which will default this to on for us:
|
||||
# https://mesonbuild.com/Release-notes-for-1-4-0.html#ndebug-setting-now-controls-c-stdlib-assertions
|
||||
'-D_GLIBCXX_ASSERTIONS=1',
|
||||
'-include', 'config-util.hh',
|
||||
'-include', 'config-util.h',
|
||||
language : 'cpp',
|
||||
)
|
||||
|
||||
# TODO rename, because it will conflict with downstream projects
|
||||
configdata.set_quoted('PACKAGE_VERSION', meson.project_version())
|
||||
|
||||
config_h = configure_file(
|
||||
configuration : configdata,
|
||||
output : 'config-util-test.h',
|
||||
)
|
||||
subdir('build-utils-meson/diagnostics')
|
||||
|
||||
sources = files(
|
||||
'args.cc',
|
||||
|
@ -80,52 +69,11 @@ sources = files(
|
|||
|
||||
include_dirs = [include_directories('.')]
|
||||
|
||||
if host_machine.system() == 'cygwin' or host_machine.system() == 'windows'
|
||||
# Windows DLLs are stricter about symbol visibility than Unix shared
|
||||
# objects --- see https://gcc.gnu.org/wiki/Visibility for details.
|
||||
# This is a temporary sledgehammer to export everything like on Unix,
|
||||
# and not detail with this yet.
|
||||
#
|
||||
# TODO do not do this, and instead do fine-grained export annotations.
|
||||
linker_export_flags = ['-Wl,--export-all-symbols']
|
||||
else
|
||||
linker_export_flags = []
|
||||
endif
|
||||
|
||||
nix_util = dependency('nix-util')
|
||||
if nix_util.type_name() == 'internal'
|
||||
# subproject sadly no good for pkg-config module
|
||||
deps_other += nix_util
|
||||
else
|
||||
deps_public += nix_util
|
||||
endif
|
||||
|
||||
nix_util_c = dependency('nix-util-c')
|
||||
if nix_util_c.type_name() == 'internal'
|
||||
# subproject sadly no good for pkg-config module
|
||||
deps_other += nix_util_c
|
||||
else
|
||||
deps_public += nix_util_c
|
||||
endif
|
||||
|
||||
nix_util_test_support = dependency('nix-util-test-support')
|
||||
if nix_util_test_support.type_name() == 'internal'
|
||||
# subproject sadly no good for pkg-config module
|
||||
deps_other += nix_util_test_support
|
||||
else
|
||||
deps_public += nix_util_test_support
|
||||
endif
|
||||
|
||||
rapidcheck = dependency('rapidcheck')
|
||||
deps_public += rapidcheck
|
||||
|
||||
gtest = dependency('gtest', main : true)
|
||||
deps_public += gtest
|
||||
|
||||
this_exe = executable(
|
||||
'nix-util-test',
|
||||
meson.project_name(),
|
||||
sources,
|
||||
dependencies : deps_public + deps_private + deps_other,
|
||||
dependencies : deps_private_subproject + deps_private + deps_other,
|
||||
include_directories : include_dirs,
|
||||
# TODO: -lrapidcheck, see ../libutil-support/build.meson
|
||||
link_args: linker_export_flags + ['-lrapidcheck'],
|
||||
|
@ -133,11 +81,11 @@ this_exe = executable(
|
|||
install : true,
|
||||
)
|
||||
|
||||
test('nix-util-test', this_exe, env : ['_NIX_TEST_UNIT_DATA=' + meson.current_source_dir() + '/data'])
|
||||
|
||||
meson.override_dependency(meson.project_name(), declare_dependency(
|
||||
include_directories : include_dirs,
|
||||
link_with : this_exe,
|
||||
compile_args : ['-std=c++2a'],
|
||||
dependencies : [],
|
||||
))
|
||||
test(
|
||||
meson.project_name(),
|
||||
this_exe,
|
||||
env : {
|
||||
'_NIX_TEST_UNIT_DATA': meson.current_source_dir() / 'data',
|
||||
},
|
||||
protocol : 'gtest',
|
||||
)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{ lib
|
||||
, stdenv
|
||||
, mkMesonDerivation
|
||||
, releaseTools
|
||||
|
||||
, meson
|
||||
|
@ -17,40 +18,29 @@
|
|||
# Configuration Options
|
||||
|
||||
, versionSuffix ? ""
|
||||
|
||||
# Check test coverage of Nix. Probably want to use with at least
|
||||
# one of `doCheck` or `doInstallCheck` enabled.
|
||||
, withCoverageChecks ? false
|
||||
}:
|
||||
|
||||
let
|
||||
inherit (lib) fileset;
|
||||
|
||||
version = lib.fileContents ./.version + versionSuffix;
|
||||
|
||||
mkDerivation =
|
||||
if withCoverageChecks
|
||||
then
|
||||
# TODO support `finalAttrs` args function in
|
||||
# `releaseTools.coverageAnalysis`.
|
||||
argsFun:
|
||||
releaseTools.coverageAnalysis (let args = argsFun args; in args)
|
||||
else stdenv.mkDerivation;
|
||||
in
|
||||
|
||||
mkDerivation (finalAttrs: {
|
||||
pname = "nix-util-test";
|
||||
mkMesonDerivation (finalAttrs: {
|
||||
pname = "nix-util-tests";
|
||||
inherit version;
|
||||
|
||||
src = fileset.toSource {
|
||||
root = ./.;
|
||||
fileset = fileset.unions [
|
||||
./meson.build
|
||||
# ./meson.options
|
||||
(fileset.fileFilter (file: file.hasExt "cc") ./.)
|
||||
(fileset.fileFilter (file: file.hasExt "hh") ./.)
|
||||
];
|
||||
};
|
||||
workDir = ./.;
|
||||
fileset = fileset.unions [
|
||||
../../../build-utils-meson
|
||||
./build-utils-meson
|
||||
../../../.version
|
||||
./.version
|
||||
./meson.build
|
||||
# ./meson.options
|
||||
(fileset.fileFilter (file: file.hasExt "cc") ./.)
|
||||
(fileset.fileFilter (file: file.hasExt "hh") ./.)
|
||||
];
|
||||
|
||||
outputs = [ "out" "dev" ];
|
||||
|
||||
|
@ -69,9 +59,11 @@ mkDerivation (finalAttrs: {
|
|||
];
|
||||
|
||||
preConfigure =
|
||||
# "Inline" .version so it's not a symlink, and includes the suffix
|
||||
# "Inline" .version so it's not a symlink, and includes the suffix.
|
||||
# Do the meson utils, without modification.
|
||||
''
|
||||
echo ${version} > .version
|
||||
chmod u+w ./.version
|
||||
echo ${version} > ../../../.version
|
||||
'';
|
||||
|
||||
mesonFlags = [
|
||||
|
@ -85,8 +77,7 @@ mkDerivation (finalAttrs: {
|
|||
|
||||
separateDebugInfo = !stdenv.hostPlatform.isStatic;
|
||||
|
||||
# TODO Always true after https://github.com/NixOS/nixpkgs/issues/318564
|
||||
strictDeps = !withCoverageChecks;
|
||||
strictDeps = true;
|
||||
|
||||
hardeningDisable = lib.optional stdenv.hostPlatform.isStatic "pie";
|
||||
|
||||
|
@ -96,7 +87,7 @@ mkDerivation (finalAttrs: {
|
|||
} ''
|
||||
PATH="${lib.makeBinPath [ finalAttrs.finalPackage ]}:$PATH"
|
||||
export _NIX_TEST_UNIT_DATA=${./data}
|
||||
nix-util-test
|
||||
nix-util-tests
|
||||
touch $out
|
||||
'';
|
||||
};
|
||||
|
@ -106,8 +97,4 @@ mkDerivation (finalAttrs: {
|
|||
platforms = lib.platforms.unix ++ lib.platforms.windows;
|
||||
};
|
||||
|
||||
} // lib.optionalAttrs withCoverageChecks {
|
||||
lcovFilter = [ "*/boost/*" "*-tab.*" ];
|
||||
|
||||
hardeningDisable = [ "fortify" ];
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue