Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ConnorBaker committed Oct 30, 2024
1 parent 63f9159 commit 0dbef74
Show file tree
Hide file tree
Showing 32 changed files with 473 additions and 523 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ result-*
# IDE
.vscode/
.idea/
.direnv/
.envrc

.pre-commit-config.yaml

Expand Down
32 changes: 31 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,32 @@
useLLVM = true;
};
overlays = [
# Update immer to the latest
# TODO(@connorbaker): Upstream this.
(final: prev: {
immer =
let
inherit (final.lib.strings) cmakeBool;
in
prev.immer.overrideAttrs (finalAttrs: _: {
strictDeps = true;
version = "0.8.1-unstable-2024-09-18";
src = final.fetchFromGitHub {
owner = "arximboldi";
repo = "immer";
rev = "df6ef46d97e1fe81f397015b9aeb32505cef653b";
hash = "sha256-fV6Rqbg/vtUH2DdgLYULl0zLM3WUSG1qYLZtqAhaWQw=";
};
doCheck = false;
# TODO(@connorbaker): Add support for doCheck = true;
cmakeFlags = [
(cmakeBool "immer_BUILD_DOCS" false)
(cmakeBool "immer_BUILD_EXAMPLES" finalAttrs.doCheck)
(cmakeBool "immer_BUILD_EXTRAS" false)
(cmakeBool "immer_BUILD_TESTS" finalAttrs.doCheck)
];
});
})
(overlayFor (p: p.${stdenv}))
];
};
Expand Down Expand Up @@ -372,7 +398,11 @@
# TODO: Remove the darwin check once
# https://github.com/NixOS/nixpkgs/pull/291814 is available
++ lib.optional (stdenv.cc.isClang && !stdenv.buildPlatform.isDarwin) pkgs.buildPackages.bear
++ lib.optional (stdenv.cc.isClang && stdenv.hostPlatform == stdenv.buildPlatform) (lib.hiPrio pkgs.buildPackages.clang-tools);
++ lib.optional (stdenv.cc.isClang && stdenv.hostPlatform == stdenv.buildPlatform) [
(lib.hiPrio pkgs.buildPackages.clang-tools)
# LLDB 18 is required to use VSCode's LLDB DAP extension
pkgs.buildPackages.lldb_18
];

buildInputs = attrs.buildInputs or []
++ [
Expand Down
2 changes: 2 additions & 0 deletions package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
, flex
, git
, gtest
, immer
, jq
, libarchive
, libcpuid
Expand Down Expand Up @@ -243,6 +244,7 @@ in {

propagatedBuildInputs = lib.optionals doBuild ([
boost
immer
nlohmann_json
] ++ lib.optional enableGC boehmgc
);
Expand Down
5 changes: 0 additions & 5 deletions src/libexpr-c/nix_api_expr_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ struct BindingsBuilder
nix::BindingsBuilder builder;
};

struct ListBuilder
{
nix::ListBuilder builder;
};

struct nix_value
{
nix::Value value;
Expand Down
49 changes: 1 addition & 48 deletions src/libexpr-c/nix_api_value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ nix_value * nix_get_list_byidx(nix_c_context * context, const nix_value * value,
try {
auto & v = check_value_in(value);
assert(v.type() == nix::nList);
auto * p = v.listElems()[ix];
auto * p = v.list()[ix];
nix_gc_incref(nullptr, p);
if (p != nullptr)
state->state.forceValue(*p, nix::noPos);
Expand Down Expand Up @@ -490,53 +490,6 @@ nix_err nix_init_external(nix_c_context * context, nix_value * value, ExternalVa
NIXC_CATCH_ERRS
}

ListBuilder * nix_make_list_builder(nix_c_context * context, EvalState * state, size_t capacity)
{
if (context)
context->last_err_code = NIX_OK;
try {
auto builder = state->state.buildList(capacity);
return new
#if HAVE_BOEHMGC
(NoGC)
#endif
ListBuilder{std::move(builder)};
}
NIXC_CATCH_ERRS_NULL
}

nix_err
nix_list_builder_insert(nix_c_context * context, ListBuilder * list_builder, unsigned int index, nix_value * value)
{
if (context)
context->last_err_code = NIX_OK;
try {
auto & e = check_value_not_null(value);
list_builder->builder[index] = &e;
}
NIXC_CATCH_ERRS
}

void nix_list_builder_free(ListBuilder * list_builder)
{
#if HAVE_BOEHMGC
GC_FREE(list_builder);
#else
delete list_builder;
#endif
}

nix_err nix_make_list(nix_c_context * context, ListBuilder * list_builder, nix_value * value)
{
if (context)
context->last_err_code = NIX_OK;
try {
auto & v = check_value_out(value);
v.mkList(list_builder->builder);
}
NIXC_CATCH_ERRS
}

nix_err nix_init_primop(nix_c_context * context, nix_value * value, PrimOp * p)
{
if (context)
Expand Down
42 changes: 0 additions & 42 deletions src/libexpr-c/nix_api_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,6 @@ typedef struct EvalState EvalState;
*/
typedef struct BindingsBuilder BindingsBuilder;

/** @brief Stores an under-construction list
* @ingroup value_manip
*
* Do not reuse.
* @see nix_make_list_builder, nix_list_builder_free, nix_make_list
* @see nix_list_builder_insert
*/
typedef struct ListBuilder ListBuilder;

/** @brief PrimOp function
* @ingroup primops
*
Expand Down Expand Up @@ -394,39 +385,6 @@ nix_err nix_init_apply(nix_c_context * context, nix_value * value, nix_value * f
*/
nix_err nix_init_external(nix_c_context * context, nix_value * value, ExternalValue * val);

/** @brief Create a list from a list builder
* @param[out] context Optional, stores error information
* @param[in] list_builder list builder to use. Make sure to unref this afterwards.
* @param[out] value Nix value to modify
* @return error code, NIX_OK on success.
*/
nix_err nix_make_list(nix_c_context * context, ListBuilder * list_builder, nix_value * value);

/** @brief Create a list builder
* @param[out] context Optional, stores error information
* @param[in] state nix evaluator state
* @param[in] capacity how many bindings you'll add. Don't exceed.
* @return owned reference to a list builder. Make sure to unref when you're done.
*/
ListBuilder * nix_make_list_builder(nix_c_context * context, EvalState * state, size_t capacity);

/** @brief Insert bindings into a builder
* @param[out] context Optional, stores error information
* @param[in] list_builder ListBuilder to insert into
* @param[in] index index to manipulate
* @param[in] value value to insert
* @return error code, NIX_OK on success.
*/
nix_err
nix_list_builder_insert(nix_c_context * context, ListBuilder * list_builder, unsigned int index, nix_value * value);

/** @brief Free a list builder
*
* Does not fail.
* @param[in] builder the builder to free
*/
void nix_list_builder_free(ListBuilder * list_builder);

/** @brief Create an attribute set from a bindings builder
* @param[out] context Optional, stores error information
* @param[out] value Nix value to modify
Expand Down
2 changes: 2 additions & 0 deletions src/libexpr-tests/nix_api_expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ TEST_F(nix_api_expr_test, nix_expr_realise_context_bad_value)

TEST_F(nix_api_expr_test, nix_expr_realise_context_bad_build)
{
// TODO(@connorbaker): Fails because "allow-import-from-derivation" is disabled on host.
auto expr = R"(
derivation { name = "letsbuild";
system = builtins.currentSystem;
Expand All @@ -136,6 +137,7 @@ TEST_F(nix_api_expr_test, nix_expr_realise_context_bad_build)
TEST_F(nix_api_expr_test, nix_expr_realise_context)
{
// TODO (ca-derivations): add a content-addressed derivation output, which produces a placeholder
// TODO(@connorbaker): Fails because "allow-import-from-derivation" is disabled on host.
auto expr = R"(
''
a derivation output: ${
Expand Down
29 changes: 0 additions & 29 deletions src/libexpr-tests/nix_api_value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,35 +143,6 @@ TEST_F(nix_api_expr_test, nix_build_and_init_list_invalid)
assert_ctx_err();
}

TEST_F(nix_api_expr_test, nix_build_and_init_list)
{
int size = 10;
ListBuilder * builder = nix_make_list_builder(ctx, state, size);

nix_value * intValue = nix_alloc_value(ctx, state);
nix_value * intValue2 = nix_alloc_value(ctx, state);

// `init` and `insert` can be called in any order
nix_init_int(ctx, intValue, 42);
nix_list_builder_insert(ctx, builder, 0, intValue);
nix_list_builder_insert(ctx, builder, 1, intValue2);
nix_init_int(ctx, intValue2, 43);

nix_make_list(ctx, builder, value);
nix_list_builder_free(builder);

ASSERT_EQ(42, nix_get_int(ctx, nix_get_list_byidx(ctx, value, state, 0)));
ASSERT_EQ(43, nix_get_int(ctx, nix_get_list_byidx(ctx, value, state, 1)));
ASSERT_EQ(nullptr, nix_get_list_byidx(ctx, value, state, 2));
ASSERT_EQ(10, nix_get_list_size(ctx, value));

ASSERT_STREQ("a list", nix_get_typename(ctx, value));
ASSERT_EQ(NIX_TYPE_LIST, nix_get_type(ctx, value));

// Clean up
nix_gc_decref(ctx, intValue);
}

TEST_F(nix_api_expr_test, nix_build_and_init_attr_invalid)
{
ASSERT_EQ(nullptr, nix_get_attr_byname(ctx, nullptr, state, 0));
Expand Down
Loading

0 comments on commit 0dbef74

Please sign in to comment.