1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-24 22:11:15 +02:00

nix-fetchers-c: Init with settings object

Also make it a dependency of nix-flake-c; we'll need that.
This commit is contained in:
Robert Hensing 2025-03-27 19:55:00 +00:00
parent 1061a0965a
commit 60bffbd41b
17 changed files with 213 additions and 0 deletions

View file

@ -361,6 +361,7 @@
"nix-store-tests" = { };
"nix-fetchers" = { };
"nix-fetchers-c" = { };
"nix-fetchers-tests" = { };
"nix-expr" = { };

View file

@ -33,6 +33,7 @@ endif
# External C wrapper libraries
subproject('libutil-c')
subproject('libstore-c')
subproject('libfetchers-c')
subproject('libexpr-c')
subproject('libflake-c')
subproject('libmain-c')

View file

@ -333,6 +333,7 @@ in
nix-store-tests = callPackage ../src/libstore-tests/package.nix { };
nix-fetchers = callPackage ../src/libfetchers/package.nix { };
nix-fetchers-c = callPackage ../src/libfetchers-c/package.nix { };
nix-fetchers-tests = callPackage ../src/libfetchers-tests/package.nix { };
nix-expr = callPackage ../src/libexpr/package.nix { };

View file

@ -15,6 +15,7 @@
nix-store-tests,
nix-fetchers,
nix-fetchers-c,
nix-fetchers-tests,
nix-expr,
@ -54,6 +55,7 @@ let
nix-store
nix-store-c
nix-fetchers
nix-fetchers-c
nix-expr
nix-expr-c
nix-flake
@ -230,6 +232,7 @@ stdenv.mkDerivation (finalAttrs: {
"nix-expr"
"nix-expr-c"
"nix-fetchers"
"nix-fetchers-c"
"nix-flake"
"nix-flake-c"
"nix-main"

View file

@ -48,6 +48,7 @@ let
"nix-store-test-support"
"nix-store-tests"
"nix-fetchers"
"nix-fetchers-c"
"nix-fetchers-tests"
"nix-expr"
"nix-expr-c"

1
src/libfetchers-c/.version Symbolic link
View file

@ -0,0 +1 @@
../../.version

View file

@ -0,0 +1,65 @@
project('nix-fetchers-c', 'cpp',
version : files('.version'),
default_options : [
'cpp_std=c++2a',
# TODO(Qyriad): increase the warning level
'warning_level=1',
'errorlogs=true', # Please print logs for tests that fail
],
meson_version : '>= 1.1',
license : 'LGPL-2.1-or-later',
)
cxx = meson.get_compiler('cpp')
subdir('nix-meson-build-support/deps-lists')
deps_private_maybe_subproject = [
dependency('nix-util'),
dependency('nix-store'),
dependency('nix-fetchers'),
]
deps_public_maybe_subproject = [
dependency('nix-util-c'),
dependency('nix-store-c'),
]
subdir('nix-meson-build-support/subprojects')
add_project_arguments(
language : 'cpp',
)
subdir('nix-meson-build-support/common')
sources = files(
'nix_api_fetchers.cc',
)
include_dirs = [include_directories('.')]
headers = files(
'nix_api_fetchers.h',
'nix_api_fetchers_internal.hh',
)
# TODO move this header to libexpr, maybe don't use it in tests?
headers += files('nix_api_fetchers.h')
subdir('nix-meson-build-support/export-all-symbols')
subdir('nix-meson-build-support/windows-version')
this_library = library(
'nixfetchersc',
sources,
dependencies : deps_public + deps_private + deps_other,
include_directories : include_dirs,
link_args: linker_export_flags,
prelink : true, # For C++ static initializers
install : true,
)
install_headers(headers, preserve_path : true)
libraries_private = []
subdir('nix-meson-build-support/export')

View file

@ -0,0 +1 @@
../../nix-meson-build-support

View file

@ -0,0 +1,19 @@
#include "nix_api_fetchers.h"
#include "nix_api_fetchers_internal.hh"
#include "nix_api_util_internal.h"
nix_fetchers_settings * nix_fetchers_settings_new(nix_c_context * context)
{
try {
auto fetchersSettings = nix::make_ref<nix::fetchers::Settings>(nix::fetchers::Settings{});
return new nix_fetchers_settings{
.settings = fetchersSettings,
};
}
NIXC_CATCH_ERRS_NULL
}
void nix_fetchers_settings_free(nix_fetchers_settings * settings)
{
delete settings;
}

View file

@ -0,0 +1,32 @@
#ifndef NIX_API_FETCHERS_H
#define NIX_API_FETCHERS_H
/** @defgroup libfetchers libfetchers
* @brief Bindings to the Nix fetchers library
* @{
*/
/** @file
* @brief Main entry for the libfetchers C bindings
*/
#include "nix_api_util.h"
#ifdef __cplusplus
extern "C" {
#endif
// cffi start
// Type definitions
/**
* @brief Shared settings object
*/
typedef struct nix_fetchers_settings nix_fetchers_settings;
nix_fetchers_settings * nix_fetchers_settings_new(nix_c_context * context);
void nix_fetchers_settings_free(nix_fetchers_settings * settings);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // NIX_API_FETCHERS_H

View file

@ -0,0 +1,12 @@
#pragma once
#include "nix/fetchers/fetch-settings.hh"
#include "nix/util/ref.hh"
/**
* A shared reference to `nix::fetchers::Settings`
* @see nix::fetchers::Settings
*/
struct nix_fetchers_settings
{
nix::ref<nix::fetchers::Settings> settings;
};

View file

@ -0,0 +1,50 @@
{
lib,
mkMesonLibrary,
nix-store-c,
nix-expr-c,
nix-util-c,
nix-fetchers,
# Configuration Options
version,
}:
let
inherit (lib) fileset;
in
mkMesonLibrary (finalAttrs: {
pname = "nix-fetchers-c";
inherit version;
workDir = ./.;
fileset = fileset.unions [
../../nix-meson-build-support
./nix-meson-build-support
../../.version
./.version
./meson.build
# ./meson.options
(fileset.fileFilter (file: file.hasExt "cc") ./.)
(fileset.fileFilter (file: file.hasExt "hh") ./.)
(fileset.fileFilter (file: file.hasExt "h") ./.)
];
propagatedBuildInputs = [
nix-util-c
nix-expr-c
nix-store-c
nix-fetchers
];
mesonFlags = [
];
meta = {
platforms = lib.platforms.unix ++ lib.platforms.windows;
};
})

View file

@ -17,6 +17,7 @@ subdir('nix-meson-build-support/deps-lists')
deps_private_maybe_subproject = [
dependency('nix-store-test-support'),
dependency('nix-fetchers'),
dependency('nix-fetchers-c'),
]
deps_public_maybe_subproject = [
]
@ -39,6 +40,7 @@ subdir('nix-meson-build-support/common')
sources = files(
'access-tokens.cc',
'git-utils.cc',
'nix_api_fetchers.cc',
'public-key.cc',
)

View file

@ -0,0 +1,18 @@
#include "gmock/gmock.h"
#include <gtest/gtest.h>
#include "nix_api_fetchers.h"
#include "nix/store/tests/nix_api_store.hh"
namespace nixC {
TEST_F(nix_api_store_test, nix_api_fetchers_new_free)
{
nix_fetchers_settings * settings = nix_fetchers_settings_new(ctx);
assert_ctx_ok();
ASSERT_NE(nullptr, settings);
nix_fetchers_settings_free(settings);
}
} // namespace nixC

View file

@ -5,6 +5,7 @@
mkMesonExecutable,
nix-fetchers,
nix-fetchers-c,
nix-store-test-support,
libgit2,
@ -40,6 +41,7 @@ mkMesonExecutable (finalAttrs: {
buildInputs = [
nix-fetchers
nix-fetchers-c
nix-store-test-support
rapidcheck
gtest

View file

@ -17,12 +17,14 @@ subdir('nix-meson-build-support/deps-lists')
deps_private_maybe_subproject = [
dependency('nix-util'),
dependency('nix-store'),
dependency('nix-fetchers'),
dependency('nix-expr'),
dependency('nix-flake'),
]
deps_public_maybe_subproject = [
dependency('nix-util-c'),
dependency('nix-store-c'),
dependency('nix-fetchers-c'),
dependency('nix-expr-c'),
]
subdir('nix-meson-build-support/subprojects')

View file

@ -4,6 +4,7 @@
nix-store-c,
nix-expr-c,
nix-fetchers-c,
nix-flake,
# Configuration Options
@ -35,6 +36,7 @@ mkMesonLibrary (finalAttrs: {
propagatedBuildInputs = [
nix-expr-c
nix-store-c
nix-fetchers-c
nix-flake
];