mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 03:56:01 +01:00
Merge pull request #13679 from xokdvium/build-benchmarks-in-ci
libstore-tests: Build benchmarks in GHA CI
This commit is contained in:
commit
51a32e4645
5 changed files with 60 additions and 29 deletions
|
|
@ -59,7 +59,9 @@ in
|
||||||
inherit getStdenv;
|
inherit getStdenv;
|
||||||
}).overrideScope
|
}).overrideScope
|
||||||
(
|
(
|
||||||
_: _: {
|
final: prev: {
|
||||||
|
nix-store-tests = prev.nix-store-tests.override { withBenchmarks = true; };
|
||||||
|
|
||||||
mesonComponentOverrides = finalAttrs: prevAttrs: {
|
mesonComponentOverrides = finalAttrs: prevAttrs: {
|
||||||
mesonFlags =
|
mesonFlags =
|
||||||
(prevAttrs.mesonFlags or [ ])
|
(prevAttrs.mesonFlags or [ ])
|
||||||
|
|
|
||||||
14
src/libstore-tests/bench-main.cc
Normal file
14
src/libstore-tests/bench-main.cc
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
#include <benchmark/benchmark.h>
|
||||||
|
#include "nix/store/globals.hh"
|
||||||
|
|
||||||
|
// Custom main to initialize Nix before running benchmarks
|
||||||
|
int main(int argc, char ** argv)
|
||||||
|
{
|
||||||
|
// Initialize libstore
|
||||||
|
nix::initLibStore(false);
|
||||||
|
|
||||||
|
// Initialize and run benchmarks
|
||||||
|
::benchmark::Initialize(&argc, argv);
|
||||||
|
::benchmark::RunSpecifiedBenchmarks();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
#include "nix/store/derivations.hh"
|
#include "nix/store/derivations.hh"
|
||||||
#include "nix/store/store-api.hh"
|
#include "nix/store/store-api.hh"
|
||||||
#include "nix/util/experimental-features.hh"
|
#include "nix/util/experimental-features.hh"
|
||||||
|
#include "nix/util/environment-variables.hh"
|
||||||
#include "nix/store/store-open.hh"
|
#include "nix/store/store-open.hh"
|
||||||
#include "nix/store/globals.hh"
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
|
@ -29,17 +29,11 @@ static void BM_ParseRealDerivationFile(benchmark::State & state, const std::stri
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register benchmarks for actual test derivation files if they exist
|
// Register benchmarks for actual test derivation files if they exist
|
||||||
BENCHMARK_CAPTURE(BM_ParseRealDerivationFile, hello, std::string(NIX_UNIT_TEST_DATA) + "/derivation/hello.drv");
|
BENCHMARK_CAPTURE(
|
||||||
BENCHMARK_CAPTURE(BM_ParseRealDerivationFile, firefox, std::string(NIX_UNIT_TEST_DATA) + "/derivation/firefox.drv");
|
BM_ParseRealDerivationFile,
|
||||||
|
hello,
|
||||||
// Custom main to initialize Nix before running benchmarks
|
getEnvNonEmpty("_NIX_TEST_UNIT_DATA").value_or(NIX_UNIT_TEST_DATA) + "/derivation/hello.drv");
|
||||||
int main(int argc, char ** argv)
|
BENCHMARK_CAPTURE(
|
||||||
{
|
BM_ParseRealDerivationFile,
|
||||||
// Initialize libstore
|
firefox,
|
||||||
nix::initLibStore(false);
|
getEnvNonEmpty("_NIX_TEST_UNIT_DATA").value_or(NIX_UNIT_TEST_DATA) + "/derivation/firefox.drv");
|
||||||
|
|
||||||
// Initialize and run benchmarks
|
|
||||||
::benchmark::Initialize(&argc, argv);
|
|
||||||
::benchmark::RunSpecifiedBenchmarks();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -110,14 +110,21 @@ test(
|
||||||
if get_option('benchmarks')
|
if get_option('benchmarks')
|
||||||
gbenchmark = dependency('benchmark', required : true)
|
gbenchmark = dependency('benchmark', required : true)
|
||||||
|
|
||||||
|
benchmark_sources = files(
|
||||||
|
'bench-main.cc',
|
||||||
|
'derivation-parser-bench.cc',
|
||||||
|
)
|
||||||
|
|
||||||
benchmark_exe = executable(
|
benchmark_exe = executable(
|
||||||
'nix-store-benchmarks',
|
'nix-store-benchmarks',
|
||||||
'derivation-parser-bench.cc',
|
benchmark_sources,
|
||||||
config_priv_h,
|
config_priv_h,
|
||||||
dependencies : deps_private_subproject + deps_private + deps_other + [gbenchmark],
|
dependencies : deps_private_subproject + deps_private + deps_other + [gbenchmark],
|
||||||
include_directories : include_dirs,
|
include_directories : include_dirs,
|
||||||
link_args: linker_export_flags,
|
link_args: linker_export_flags,
|
||||||
install : false,
|
install : true,
|
||||||
cpp_args : ['-DNIX_UNIT_TEST_DATA="' + meson.current_source_dir() + '/data"'],
|
cpp_args : ['-DNIX_UNIT_TEST_DATA="' + meson.current_source_dir() + '/data"'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
benchmark('nix-store-benchmarks', benchmark_exe)
|
||||||
endif
|
endif
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,14 @@
|
||||||
|
|
||||||
rapidcheck,
|
rapidcheck,
|
||||||
gtest,
|
gtest,
|
||||||
|
gbenchmark,
|
||||||
runCommand,
|
runCommand,
|
||||||
|
|
||||||
# Configuration Options
|
# Configuration Options
|
||||||
|
|
||||||
version,
|
version,
|
||||||
filesetToSource,
|
filesetToSource,
|
||||||
|
withBenchmarks ? false,
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
@ -41,10 +43,14 @@ mkMesonExecutable (finalAttrs: {
|
||||||
];
|
];
|
||||||
|
|
||||||
# Hack for sake of the dev shell
|
# Hack for sake of the dev shell
|
||||||
passthru.externalBuildInputs = [
|
passthru.externalBuildInputs =
|
||||||
|
[
|
||||||
sqlite
|
sqlite
|
||||||
rapidcheck
|
rapidcheck
|
||||||
gtest
|
gtest
|
||||||
|
]
|
||||||
|
++ lib.optionals withBenchmarks [
|
||||||
|
gbenchmark
|
||||||
];
|
];
|
||||||
|
|
||||||
buildInputs = finalAttrs.passthru.externalBuildInputs ++ [
|
buildInputs = finalAttrs.passthru.externalBuildInputs ++ [
|
||||||
|
|
@ -54,6 +60,7 @@ mkMesonExecutable (finalAttrs: {
|
||||||
];
|
];
|
||||||
|
|
||||||
mesonFlags = [
|
mesonFlags = [
|
||||||
|
(lib.mesonBool "benchmarks" withBenchmarks)
|
||||||
];
|
];
|
||||||
|
|
||||||
passthru = {
|
passthru = {
|
||||||
|
|
@ -75,12 +82,19 @@ mkMesonExecutable (finalAttrs: {
|
||||||
meta.broken = !stdenv.hostPlatform.emulatorAvailable buildPackages;
|
meta.broken = !stdenv.hostPlatform.emulatorAvailable buildPackages;
|
||||||
buildInputs = [ writableTmpDirAsHomeHook ];
|
buildInputs = [ writableTmpDirAsHomeHook ];
|
||||||
}
|
}
|
||||||
(''
|
(
|
||||||
|
''
|
||||||
export _NIX_TEST_UNIT_DATA=${data + "/src/libstore-tests/data"}
|
export _NIX_TEST_UNIT_DATA=${data + "/src/libstore-tests/data"}
|
||||||
export NIX_REMOTE=$HOME/store
|
export NIX_REMOTE=$HOME/store
|
||||||
${stdenv.hostPlatform.emulator buildPackages} ${lib.getExe finalAttrs.finalPackage}
|
${stdenv.hostPlatform.emulator buildPackages} ${lib.getExe finalAttrs.finalPackage}
|
||||||
|
''
|
||||||
|
+ lib.optionalString withBenchmarks ''
|
||||||
|
${stdenv.hostPlatform.emulator buildPackages} ${lib.getExe' finalAttrs.finalPackage "nix-store-benchmarks"}
|
||||||
|
''
|
||||||
|
+ ''
|
||||||
touch $out
|
touch $out
|
||||||
'');
|
''
|
||||||
|
);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue