chore(tvix/store): make importable

This allows other crates to import tvix_store.

Rename the bin crate to tvix-store-bin, to avoid having multiple crates
with the same name (https://github.com/rust-lang/cargo/issues/6313)

Change-Id: I857768d6115640dbf102e79ed03e8474090df2fe
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7728
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
Florian Klink 2023-01-02 14:37:08 +01:00 committed by flokli
parent d0bbc8c821
commit ceb2c0ba89
6 changed files with 35 additions and 26 deletions

2
tvix/Cargo.lock generated
View file

@ -2223,7 +2223,7 @@ dependencies = [
] ]
[[package]] [[package]]
name = "tvix-store" name = "tvix-store-bin"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",

View file

@ -103,10 +103,10 @@ rec {
# File a bug if you depend on any for non-debug work! # File a bug if you depend on any for non-debug work!
debug = internal.debugCrate { inherit packageId; }; debug = internal.debugCrate { inherit packageId; };
}; };
"tvix-store" = rec { "tvix-store-bin" = rec {
packageId = "tvix-store"; packageId = "tvix-store-bin";
build = internal.buildRustCrateWithFeatures { build = internal.buildRustCrateWithFeatures {
packageId = "tvix-store"; packageId = "tvix-store-bin";
}; };
# Debug support which might change between releases. # Debug support which might change between releases.
@ -6641,13 +6641,13 @@ rec {
]; ];
}; };
"tvix-store" = rec { "tvix-store-bin" = rec {
crateName = "tvix-store"; crateName = "tvix-store-bin";
version = "0.1.0"; version = "0.1.0";
edition = "2021"; edition = "2021";
crateBin = [ crateBin = [
{ {
name = "tvix-store"; name = "tvix-store-bin";
path = "src/main.rs"; path = "src/main.rs";
requiredFeatures = [ ]; requiredFeatures = [ ];
} }
@ -6658,6 +6658,7 @@ rec {
if (lib.versionOlder builtins.nixVersion "2.4pre20211007") if (lib.versionOlder builtins.nixVersion "2.4pre20211007")
then lib.cleanSourceWith { filter = sourceFilter; src = ./store; } then lib.cleanSourceWith { filter = sourceFilter; src = ./store; }
else ./store; else ./store;
libName = "tvix_store";
dependencies = [ dependencies = [
{ {
name = "anyhow"; name = "anyhow";

View file

@ -1,8 +1,11 @@
[package] [package]
name = "tvix-store" name = "tvix-store-bin"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
[lib]
name = "tvix_store"
[dependencies] [dependencies]
anyhow = "1.0.68" anyhow = "1.0.68"
blake3 = { version = "1.3.1", features = ["rayon", "std"] } blake3 = { version = "1.3.1", features = ["rayon", "std"] }

View file

@ -11,7 +11,7 @@ let
protobufDep = prev: (prev.nativeBuildInputs or [ ]) ++ [ pkgs.protobuf ]; protobufDep = prev: (prev.nativeBuildInputs or [ ]) ++ [ pkgs.protobuf ];
in in
depot.tvix.crates.workspaceMembers.tvix-store.build.override { depot.tvix.crates.workspaceMembers.tvix-store-bin.build.override {
# Ensure protobuf dependencies are available. # Ensure protobuf dependencies are available.
# TODO: figure out a way to embed this directly in the //tvix # TODO: figure out a way to embed this directly in the //tvix
# crate2nix config. # crate2nix config.
@ -28,6 +28,11 @@ depot.tvix.crates.workspaceMembers.tvix-store.build.override {
PROTO_ROOT = protoRoot; PROTO_ROOT = protoRoot;
nativeBuildInputs = protobufDep prev; nativeBuildInputs = protobufDep prev;
}; };
tvix-store-bin = prev: {
PROTO_ROOT = protoRoot;
nativeBuildInputs = protobufDep prev;
};
}; };
runTests = true; runTests = true;

10
tvix/store/src/lib.rs Normal file
View file

@ -0,0 +1,10 @@
pub mod nixbase32;
pub mod nixpath;
pub mod proto;
pub mod dummy_blob_service;
pub mod dummy_directory_service;
pub mod dummy_path_info_service;
#[cfg(test)]
mod tests;

View file

@ -1,24 +1,14 @@
use crate::proto::blob_service_server::BlobServiceServer; use tvix_store::proto::blob_service_server::BlobServiceServer;
use crate::proto::directory_service_server::DirectoryServiceServer; use tvix_store::proto::directory_service_server::DirectoryServiceServer;
use crate::proto::path_info_service_server::PathInfoServiceServer; use tvix_store::proto::path_info_service_server::PathInfoServiceServer;
#[cfg(feature = "reflection")] #[cfg(feature = "reflection")]
use crate::proto::FILE_DESCRIPTOR_SET; use tvix_store::proto::FILE_DESCRIPTOR_SET;
use clap::Parser; use clap::Parser;
use tonic::{transport::Server, Result}; use tonic::{transport::Server, Result};
use tracing::{info, Level}; use tracing::{info, Level};
mod dummy_blob_service;
mod dummy_directory_service;
mod dummy_path_info_service;
mod nixbase32;
mod nixpath;
mod proto;
#[cfg(test)]
mod tests;
#[derive(Parser)] #[derive(Parser)]
#[command(author, version, about, long_about = None)] #[command(author, version, about, long_about = None)]
struct Cli { struct Cli {
@ -44,9 +34,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut server = Server::builder(); let mut server = Server::builder();
let blob_service = dummy_blob_service::DummyBlobService {}; let blob_service = tvix_store::dummy_blob_service::DummyBlobService {};
let directory_service = dummy_directory_service::DummyDirectoryService {}; let directory_service = tvix_store::dummy_directory_service::DummyDirectoryService {};
let path_info_service = dummy_path_info_service::DummyPathInfoService {}; let path_info_service = tvix_store::dummy_path_info_service::DummyPathInfoService {};
let mut router = server let mut router = server
.add_service(BlobServiceServer::new(blob_service)) .add_service(BlobServiceServer::new(blob_service))