From 4fa8068b78444f691a9a3d3c16efdcfcd540ce9a Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 27 Jun 2024 10:19:03 -0400 Subject: [PATCH] Mesonify other external API --- meson.build | 7 ++ src/libexpr-c/.version | 1 + src/libexpr-c/meson.build | 159 ++++++++++++++++++++++++++++++++++++ src/libexpr/meson.build | 8 +- src/libfetchers/meson.build | 4 +- src/libflake/meson.build | 6 +- src/libstore-c/.version | 1 + src/libstore-c/meson.build | 151 ++++++++++++++++++++++++++++++++++ src/libstore/meson.build | 6 +- src/libutil-c/meson.build | 81 ++++++++++++------ src/libutil/meson.build | 4 +- src/perl/lib/Nix/Store.xs | 4 +- 12 files changed, 392 insertions(+), 40 deletions(-) create mode 120000 src/libexpr-c/.version create mode 100644 src/libexpr-c/meson.build create mode 120000 src/libstore-c/.version create mode 100644 src/libstore-c/meson.build diff --git a/meson.build b/meson.build index 7832eb488..2a3932a40 100644 --- a/meson.build +++ b/meson.build @@ -18,6 +18,8 @@ subproject('external-api-docs') # C wrappers subproject('libutil-c') +subproject('libstore-c') +subproject('libexpr-c') # Language Bindings subproject('perl') @@ -25,3 +27,8 @@ subproject('perl') # Testing subproject('libutil-test-support') subproject('libutil-test') +#subproject('libstore-test-support') +#subproject('libstore-test') +#subproject('libexpr-test-support') +#subproject('libexpr-test') +#subproject('libflake-test') diff --git a/src/libexpr-c/.version b/src/libexpr-c/.version new file mode 120000 index 000000000..b7badcd0c --- /dev/null +++ b/src/libexpr-c/.version @@ -0,0 +1 @@ +../../.version \ No newline at end of file diff --git a/src/libexpr-c/meson.build b/src/libexpr-c/meson.build new file mode 100644 index 000000000..5abf2b477 --- /dev/null +++ b/src/libexpr-c/meson.build @@ -0,0 +1,159 @@ +project('nix-expr-c', '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_private_subproject = [ ] + +# See note in ../nix-util/meson.build +deps_public = [ ] + +# See note in ../nix-util/meson.build +deps_public_subproject = [ ] + +# See note in ../nix-util/meson.build +deps_other = [ ] + +configdata = configuration_data() + +foreach nix_dep : [ + dependency('nix-util'), + dependency('nix-store'), + dependency('nix-expr'), +] + if nix_dep.type_name() == 'internal' + deps_private_subproject += nix_dep + # subproject sadly no good for pkg-config module + deps_other += nix_dep + else + deps_private += nix_dep + endif +endforeach + +foreach nix_dep : [ + dependency('nix-util-c'), + dependency('nix-store-c'), +] + if nix_dep.type_name() == 'internal' + deps_public_subproject += nix_dep + # subproject sadly no good for pkg-config module + deps_other += nix_dep + else + deps_public += nix_dep + endif +endforeach + +config_h = configure_file( + configuration : configdata, + output : 'config-expr.h', +) + +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. + + # From C++ libraries, only for internals + '-include', 'config-util.hh', + '-include', 'config-store.hh', + '-include', 'config-expr.hh', + + # From C libraries, for our public, installed headers too + '-include', 'config-util.h', + '-include', 'config-store.h', + '-include', 'config-expr.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( + 'nix_api_expr.cc', + 'nix_api_external.cc', + 'nix_api_value.cc', +) + +include_dirs = [include_directories('.')] + +headers = [config_h] + files( + 'nix_api_expr.h', + 'nix_api_external.h', + 'nix_api_value.h', +) + +if host_machine.system() == 'cygwin' or host_machine.system() == 'windows' + # Windows DLLs are stricter ab_subprojectout 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 + +this_library = library( + 'nixexprc', + sources, + dependencies : deps_public + deps_private + deps_other, + include_directories : include_dirs, + link_args: linker_export_flags, + install : true, +) + +install_headers(headers, subdir : 'nix', preserve_path : true) + +requires_private = [] +foreach dep : deps_private_subproject + requires_private += dep.name() +endforeach +requires_private += deps_private + +requires_public = [] +foreach dep : deps_public_subproject + requires_public += dep.name() +endforeach +requires_public += 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_public, + requires_private : requires_private, +) + +meson.override_dependency(meson.project_name(), declare_dependency( + include_directories : include_dirs, + link_with : this_library, + compile_args : ['-std=c++2a'], + dependencies : [], +)) diff --git a/src/libexpr/meson.build b/src/libexpr/meson.build index 8f08decd4..34e4dec3b 100644 --- a/src/libexpr/meson.build +++ b/src/libexpr/meson.build @@ -77,16 +77,16 @@ configdata.set('HAVE_BOEHMGC', bdw_gc.found().to_int()) config_h = configure_file( configuration : configdata, - output : 'config-expr.h', + output : 'config-expr.hh', ) 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-util.hh', + '-include', 'config-store.hh', # '-include', 'config-fetchers.h', - '-include', 'config-expr.h', + '-include', 'config-expr.hh', '-Wno-deprecated-declarations', '-Wimplicit-fallthrough', '-Werror=switch', diff --git a/src/libfetchers/meson.build b/src/libfetchers/meson.build index c17021527..938ee27d4 100644 --- a/src/libfetchers/meson.build +++ b/src/libfetchers/meson.build @@ -48,8 +48,8 @@ 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-util.hh', + '-include', 'config-store.hh', # '-include', 'config-fetchers.h', '-Wno-deprecated-declarations', '-Wimplicit-fallthrough', diff --git a/src/libflake/meson.build b/src/libflake/meson.build index c0862a484..1c0a3ae77 100644 --- a/src/libflake/meson.build +++ b/src/libflake/meson.build @@ -50,10 +50,10 @@ 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-util.hh', + '-include', 'config-store.hh', # '-include', 'config-fetchers.h', - '-include', 'config-expr.h', + '-include', 'config-expr.hh', '-Wno-deprecated-declarations', '-Wimplicit-fallthrough', '-Werror=switch', diff --git a/src/libstore-c/.version b/src/libstore-c/.version new file mode 120000 index 000000000..b7badcd0c --- /dev/null +++ b/src/libstore-c/.version @@ -0,0 +1 @@ +../../.version \ No newline at end of file diff --git a/src/libstore-c/meson.build b/src/libstore-c/meson.build new file mode 100644 index 000000000..049dda0e2 --- /dev/null +++ b/src/libstore-c/meson.build @@ -0,0 +1,151 @@ +project('nix-store-c', '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_private_subproject = [ ] + +# See note in ../nix-util/meson.build +deps_public = [ ] + +# See note in ../nix-util/meson.build +deps_public_subproject = [ ] + +# See note in ../nix-util/meson.build +deps_other = [ ] + +configdata = configuration_data() + +foreach nix_dep : [ + dependency('nix-util'), + dependency('nix-store'), +] + if nix_dep.type_name() == 'internal' + deps_private_subproject += nix_dep + # subproject sadly no good for pkg-config module + deps_other += nix_dep + else + deps_private += nix_dep + endif +endforeach + +foreach nix_dep : [ + dependency('nix-util-c'), +] + if nix_dep.type_name() == 'internal' + deps_public_subproject += nix_dep + # subproject sadly no good for pkg-config module + deps_other += nix_dep + else + deps_public += nix_dep + endif +endforeach + +config_h = configure_file( + configuration : configdata, + output : 'config-store.h', +) + +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. + + # From C++ libraries, only for internals + '-include', 'config-util.hh', + '-include', 'config-store.hh', + + # From C libraries, for our public, installed headers too + '-include', 'config-util.h', + '-include', 'config-store.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( + 'nix_api_store.cc', +) + +include_dirs = [include_directories('.')] + +headers = [config_h] + files( + 'nix_api_store.h', +) + +if host_machine.system() == 'cygwin' or host_machine.system() == 'windows' + # Windows DLLs are stricter ab_subprojectout 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 + +this_library = library( + 'nixstorec', + sources, + dependencies : deps_public + deps_private + deps_other, + include_directories : include_dirs, + link_args: linker_export_flags, + install : true, +) + +install_headers(headers, subdir : 'nix', preserve_path : true) + +requires_private = [] +foreach dep : deps_private_subproject + requires_private += dep.name() +endforeach +requires_private += deps_private + +requires_public = [] +foreach dep : deps_public_subproject + requires_public += dep.name() +endforeach +requires_public += 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_public, + requires_private : requires_private, +) + +meson.override_dependency(meson.project_name(), declare_dependency( + include_directories : include_dirs, + link_with : this_library, + compile_args : ['-std=c++2a'], + dependencies : [], +)) diff --git a/src/libstore/meson.build b/src/libstore/meson.build index c2384dd78..7277eb49d 100644 --- a/src/libstore/meson.build +++ b/src/libstore/meson.build @@ -162,14 +162,14 @@ endif config_h = configure_file( configuration : configdata, - output : 'config-store.h', + output : 'config-store.hh', ) 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-util.hh', + '-include', 'config-store.hh', '-Wno-deprecated-declarations', '-Wimplicit-fallthrough', '-Werror=switch', diff --git a/src/libutil-c/meson.build b/src/libutil-c/meson.build index 5de288e18..7ebbe3d06 100644 --- a/src/libutil-c/meson.build +++ b/src/libutil-c/meson.build @@ -17,19 +17,60 @@ cxx = meson.get_compiler('cpp') # See note in ../nix-util/meson.build deps_private = [ ] +# See note in ../nix-util/meson.build +deps_private_subproject = [ ] + # See note in ../nix-util/meson.build deps_public = [ ] +# See note in ../nix-util/meson.build +deps_public_subproject = [ ] + # See note in ../nix-util/meson.build deps_other = [ ] configdata = configuration_data() +foreach nix_dep : [ + dependency('nix-util'), +] + if nix_dep.type_name() == 'internal' + deps_private_subproject += nix_dep + # subproject sadly no good for pkg-config module + deps_other += nix_dep + else + deps_private += nix_dep + endif +endforeach + +foreach nix_dep : [ +] + if nix_dep.type_name() == 'internal' + deps_public_subproject += nix_dep + # subproject sadly no good for pkg-config module + deps_other += nix_dep + else + deps_public += nix_dep + endif +endforeach + +# 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.h', +) + 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. + + # From C++ libraries, only for internals + '-include', 'config-util.hh', + + # From C libraries, for our public, installed headers too '-include', 'config-util.h', - # '-include', 'config-store.h', '-Wno-deprecated-declarations', '-Wimplicit-fallthrough', '-Werror=switch', @@ -52,13 +93,12 @@ sources = files( include_dirs = [include_directories('.')] -headers = files( +headers = [config_h] + files( 'nix_api_util.h', - 'nix_api_util_internal.h', ) if host_machine.system() == 'cygwin' or host_machine.system() == 'windows' - # Windows DLLs are stricter about symbol visibility than Unix shared + # Windows DLLs are stricter ab_subprojectout 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. @@ -69,22 +109,6 @@ 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 - -# 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.h', -) - this_library = library( 'nixutilc', sources, @@ -96,7 +120,17 @@ this_library = library( install_headers(headers, subdir : 'nix', preserve_path : true) -libraries_private = [] +requires_private = [] +foreach dep : deps_private_subproject + requires_private += dep.name() +endforeach +requires_private += deps_private + +requires_public = [] +foreach dep : deps_public_subproject + requires_public += dep.name() +endforeach +requires_public += deps_public import('pkgconfig').generate( this_library, @@ -105,9 +139,8 @@ import('pkgconfig').generate( description : 'Nix Package Manager', subdirs : ['nix'], extra_cflags : ['-std=c++2a'], - requires : deps_public, - requires_private : deps_private, - libraries_private : libraries_private, + requires : requires_public, + requires_private : requires_private, ) meson.override_dependency(meson.project_name(), declare_dependency( diff --git a/src/libutil/meson.build b/src/libutil/meson.build index 099c0c65f..c9dfee651 100644 --- a/src/libutil/meson.build +++ b/src/libutil/meson.build @@ -132,13 +132,13 @@ deps_public += nlohmann_json config_h = configure_file( configuration : configdata, - output : 'config-util.h', + output : 'config-util.hh', ) 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-util.hh', '-Wno-deprecated-declarations', '-Wimplicit-fallthrough', '-Werror=switch', diff --git a/src/perl/lib/Nix/Store.xs b/src/perl/lib/Nix/Store.xs index acce25f3a..f951437c8 100644 --- a/src/perl/lib/Nix/Store.xs +++ b/src/perl/lib/Nix/Store.xs @@ -1,5 +1,5 @@ -#include "config-util.h" -#include "config-store.h" +#include "config-util.hh" +#include "config-store.hh" #include "EXTERN.h" #include "perl.h"