From 706edf26eb3ec1781afe16c925db5b7071494539 Mon Sep 17 00:00:00 2001 From: Tom Bereknyei Date: Wed, 5 Jun 2024 21:36:18 -0400 Subject: [PATCH] build: meson for libfetchers --- flake.nix | 12 +++ maintainers/hydra.nix | 1 + meson.build | 1 + src/libfetchers/.version | 1 + src/libfetchers/meson.build | 141 ++++++++++++++++++++++++++++++++++++ src/libfetchers/package.nix | 106 +++++++++++++++++++++++++++ src/libstore/meson.build | 5 +- src/libutil/package.nix | 1 + 8 files changed, 266 insertions(+), 2 deletions(-) create mode 120000 src/libfetchers/.version create mode 100644 src/libfetchers/meson.build create mode 100644 src/libfetchers/package.nix diff --git a/flake.nix b/flake.nix index 77b0870a276..5c8d84a7566 100644 --- a/flake.nix +++ b/flake.nix @@ -180,6 +180,15 @@ busybox-sandbox-shell = final.busybox-sandbox-shell or final.default-busybox-sandbox-shell; }; + nix-fetchers = final.callPackage ./src/libfetchers/package.nix { + inherit + fileset + stdenv + officialRelease + versionSuffix + ; + }; + nix = final.callPackage ./package.nix { inherit @@ -288,6 +297,7 @@ # system, we should reenable these. #"nix-util" = { }; #"nix-store" = { }; + #"nix-fetchers" = { }; "nix-internal-api-docs" = { }; } // lib.optionalAttrs (builtins.elem system linux64BitSystems) { @@ -351,12 +361,14 @@ mesonFlags = map (transformFlag "libutil") pkgs.nix-util.mesonFlags ++ map (transformFlag "libstore") pkgs.nix-store.mesonFlags + ++ map (transformFlag "libfetchers") pkgs.nix-fetchers.mesonFlags ++ lib.optionals havePerl (map (transformFlag "perl") pkgs.nix-perl-bindings.mesonFlags) ; nativeBuildInputs = attrs.nativeBuildInputs or [] ++ pkgs.nix-util.nativeBuildInputs ++ pkgs.nix-store.nativeBuildInputs + ++ pkgs.nix-fetchers.nativeBuildInputs ++ lib.optionals havePerl pkgs.nix-perl-bindings.nativeBuildInputs ++ [ modular.pre-commit.settings.package diff --git a/maintainers/hydra.nix b/maintainers/hydra.nix index 235752979c9..293dee5cdac 100644 --- a/maintainers/hydra.nix +++ b/maintainers/hydra.nix @@ -37,6 +37,7 @@ let "nix" "nix-util" "nix-store" + "nix-fetchers" ]; in { diff --git a/meson.build b/meson.build index 95a6665a727..ebad238b1fc 100644 --- a/meson.build +++ b/meson.build @@ -8,5 +8,6 @@ project('nix-dev-shell', 'cpp', subproject('libutil') subproject('libstore') +subproject('libfetchers') subproject('perl') subproject('internal-api-docs') diff --git a/src/libfetchers/.version b/src/libfetchers/.version new file mode 120000 index 00000000000..b7badcd0cc8 --- /dev/null +++ b/src/libfetchers/.version @@ -0,0 +1 @@ +../../.version \ No newline at end of file diff --git a/src/libfetchers/meson.build b/src/libfetchers/meson.build new file mode 100644 index 00000000000..cab8d63eb22 --- /dev/null +++ b/src/libfetchers/meson.build @@ -0,0 +1,141 @@ +project('nix-fetchers', 'cpp', + version : files('.version'), + default_options : [ + 'cpp_std=c++2a', + # TODO(Qyriad): increase the warning level + 'warning_level=1', + 'debug=true', + 'optimization=2', + 'errorlogs=true', # Please print logs for tests that fail + ], + meson_version : '>= 1.1', + license : 'LGPL-2.1-or-later', +) + +cxx = meson.get_compiler('cpp') + +# See note in ../nix-util/meson.build +deps_private = [ ] + +# See note in ../nix-util/meson.build +deps_public = [ ] + +# See note in ../nix-util/meson.build +deps_other = [ ] + +configdata = configuration_data() + +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_store = dependency('nix-store') +if nix_store.type_name() == 'internal' + # subproject sadly no good for pkg-config module + deps_other += nix_store +else + deps_public += nix_store +endif + + +nlohmann_json = dependency('nlohmann_json', version : '>= 3.9') +deps_public += nlohmann_json + +libgit2 = dependency('libgit2') +deps_public += libgit2 + +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.h', + '-include', 'config-store.h', + # '-include', 'config-fetchers.h', + '-Wno-deprecated-declarations', + '-Wimplicit-fallthrough', + '-Werror=switch', + '-Werror=switch-enum', + '-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', + language : 'cpp', +) + +sources = files( + 'attrs.cc', + 'cache.cc', + 'fetch-settings.cc', + 'fetch-to-store.cc', + 'fetchers.cc', + 'filtering-source-accessor.cc', + 'git.cc', + 'git-utils.cc', + 'github.cc', + 'indirect.cc', + 'mercurial.cc', + 'mounted-source-accessor.cc', + 'path.cc', + 'store-path-accessor.cc', + 'registry.cc', + 'tarball.cc', +) + +headers = files( + 'attrs.hh', + 'cache.hh', + 'fetch-settings.hh', + 'fetch-to-store.hh', + 'filtering-source-accessor.hh', + 'git-utils.hh', + 'mounted-source-accessor.hh', + 'fetchers.hh', + 'registry.hh', + 'store-path-accessor.hh', + 'tarball.hh', +) + +this_library = library( + 'nixfetchers', + sources, + dependencies : deps_public + deps_private + deps_other, + install : true, +) + +install_headers(headers, subdir : 'nix', preserve_path : true) + +requires = [] +if nix_util.type_name() == 'internal' + # `requires` cannot contain declared dependencies (from the + # subproject), so we need to do this manually + requires += 'nix-util' +endif +if nix_store.type_name() == 'internal' + requires += 'nix-store' +endif +requires += deps_public + +import('pkgconfig').generate( + this_library, + filebase : meson.project_name(), + name : 'Nix', + description : 'Nix Package Manager', + subdirs : ['nix'], + extra_cflags : ['-std=c++2a'], + requires : requires, + requires_private : deps_private, +) + +meson.override_dependency(meson.project_name(), declare_dependency( + include_directories : include_directories('.'), + link_with : this_library, + compile_args : ['-std=c++2a'], + dependencies : [nix_util, nix_store], +)) diff --git a/src/libfetchers/package.nix b/src/libfetchers/package.nix new file mode 100644 index 00000000000..80025603082 --- /dev/null +++ b/src/libfetchers/package.nix @@ -0,0 +1,106 @@ +{ lib +, stdenv +, releaseTools +, fileset + +, meson +, ninja +, pkg-config + +, nix-util +, nix-store +, nlohmann_json +, libgit2 +, man + +# Configuration Options + +, versionSuffix ? "" +, officialRelease ? false + +# Check test coverage of Nix. Probably want to use with with at least +# one of `doCheck` or `doInstallCheck` enabled. +, withCoverageChecks ? false + +# Avoid setting things that would interfere with a functioning devShell +, forDevShell ? false +}: + +let + 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-fetchers"; + inherit version; + + src = fileset.toSource { + root = ./.; + fileset = fileset.unions [ + ./meson.build + (fileset.fileFilter (file: file.hasExt "cc") ./.) + (fileset.fileFilter (file: file.hasExt "hh") ./.) + ]; + }; + + outputs = [ "out" "dev" ]; + + nativeBuildInputs = [ + meson + ninja + pkg-config + ]; + + buildInputs = [ + libgit2 + ]; + + propagatedBuildInputs = [ + nix-store + nix-util + nlohmann_json + ]; + + preConfigure = + # "Inline" .version so its not a symlink, and includes the suffix + '' + echo ${version} > .version + ''; + + env = lib.optionalAttrs (stdenv.isLinux && !(stdenv.hostPlatform.isStatic && stdenv.system == "aarch64-linux")) { + LDFLAGS = "-fuse-ld=gold"; + }; + + enableParallelBuilding = true; + + postInstall = + # Remove absolute path to boost libs + '' + ''; + + separateDebugInfo = !stdenv.hostPlatform.isStatic; + + # TODO `releaseTools.coverageAnalysis` in Nixpkgs needs to be updated + # to work with `strictDeps`. + strictDeps = !withCoverageChecks; + + hardeningDisable = lib.optional stdenv.hostPlatform.isStatic "pie"; + + meta = { + platforms = lib.platforms.unix ++ lib.platforms.windows; + }; + +} // lib.optionalAttrs withCoverageChecks { + lcovFilter = [ "*-tab.*" ]; + + hardeningDisable = ["fortify"]; +}) diff --git a/src/libstore/meson.build b/src/libstore/meson.build index c9c6f66f15e..a605b43e1a6 100644 --- a/src/libstore/meson.build +++ b/src/libstore/meson.build @@ -425,12 +425,13 @@ this_library = library( install_headers(headers, subdir : 'nix', preserve_path : true) -requires = deps_public +requires = [] if nix_util.type_name() == 'internal' # `requires` cannot contain declared dependencies (from the # subproject), so we need to do this manually - requires = [ 'nix-util' ] + requires + requires += 'nix-util' endif +requires += deps_public import('pkgconfig').generate( this_library, diff --git a/src/libutil/package.nix b/src/libutil/package.nix index dd93e5663e0..b36e3879c21 100644 --- a/src/libutil/package.nix +++ b/src/libutil/package.nix @@ -72,6 +72,7 @@ mkDerivation (finalAttrs: { ; propagatedBuildInputs = [ + boost.dev libarchive nlohmann_json ];