refactor(tvix/store): move protobuf build config one level up

This embeds the build config directly at the point where `Cargo.nix`
is imported, making it transparent to library consumers.

Change-Id: I5586e12f02ed14587c32d9ef7d93f079366fb127
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7780
Autosubmit: tazjin <tazjin@tvl.su>
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
This commit is contained in:
Vincent Ambo 2023-01-06 20:20:44 +03:00 committed by tazjin
parent 144d010515
commit 3e03e59893
3 changed files with 37 additions and 35 deletions

View file

@ -1,11 +1,35 @@
# Nix helpers for projects under //tvix # Nix helpers for projects under //tvix
{ pkgs, depot, ... }: { pkgs, depot, ... }:
let
# crate override for crates that need protobuf
protobufDep = prev: (prev.nativeBuildInputs or [ ]) ++ [ pkgs.protobuf ];
in
{ {
# Load the crate2nix crate tree. # Load the crate2nix crate tree.
crates = import ./Cargo.nix { crates = import ./Cargo.nix {
inherit pkgs; inherit pkgs;
nixpkgs = pkgs.path; nixpkgs = pkgs.path;
defaultCrateOverrides = pkgs.defaultCrateOverrides // {
prost-build = prev: {
nativeBuildInputs = protobufDep prev;
};
tonic-reflection = prev: {
nativeBuildInputs = protobufDep prev;
};
tvix-store = prev: {
PROTO_ROOT = depot.tvix.store.protos;
nativeBuildInputs = protobufDep prev;
};
tvix-store-bin = prev: {
PROTO_ROOT = depot.tvix.store.protos;
nativeBuildInputs = protobufDep prev;
};
};
}; };
# Run crate2nix generate in the current working directory, then # Run crate2nix generate in the current working directory, then

View file

@ -1,39 +1,5 @@
{ depot, pkgs, ... }: { depot, ... }:
let
protoRoot = depot.nix.sparseTree depot.path.origSrc [
./protos/castore.proto
./protos/pathinfo.proto
./protos/rpc_blobstore.proto
./protos/rpc_directory.proto
./protos/rpc_pathinfo.proto
];
protobufDep = prev: (prev.nativeBuildInputs or [ ]) ++ [ pkgs.protobuf ];
in
depot.tvix.crates.workspaceMembers.tvix-store-bin.build.override { depot.tvix.crates.workspaceMembers.tvix-store-bin.build.override {
# Ensure protobuf dependencies are available.
# TODO: figure out a way to embed this directly in the //tvix
# crate2nix config.
crateOverrides = {
prost-build = prev: {
nativeBuildInputs = protobufDep prev;
};
tonic-reflection = prev: {
nativeBuildInputs = protobufDep prev;
};
tvix-store = prev: {
PROTO_ROOT = protoRoot;
nativeBuildInputs = protobufDep prev;
};
tvix-store-bin = prev: {
PROTO_ROOT = protoRoot;
nativeBuildInputs = protobufDep prev;
};
};
runTests = true; runTests = true;
} }

View file

@ -0,0 +1,12 @@
# Target containing just the proto files.
{ depot, lib, ... }:
let
inherit (lib.strings) hasSuffix;
inherit (builtins) attrNames filter readDir;
protoFileNames = filter (hasSuffix ".proto") (attrNames (readDir ./.));
protoFiles = map (f: ./. + ("/" + f)) protoFileNames;
in
depot.nix.sparseTree depot.path.origSrc protoFiles