From 9413fb93d5555b737dc5b4eeff15bdb622a71678 Mon Sep 17 00:00:00 2001 From: Abhishek Shah Date: Mon, 12 Feb 2024 16:25:05 +0530 Subject: [PATCH] workspace reorg --- .vscode/launch.json | 21 ++++++++ .vscode/tasks.json | 21 ++++++++ Cargo.lock | 6 +++ Cargo.toml | 61 ++++------------------- crates/kvs-client/Cargo.toml | 15 ++++-- crates/kvs-client/src/main.rs | 15 ++++++ {tests => crates/kvs-client/tests}/cli.rs | 0 lib/Cargo.toml | 29 +++++++++++ {src => lib/src}/bin/main.rs | 0 {src => lib/src}/cli.rs | 0 {src => lib/src}/error.rs | 0 {src => lib/src}/lib.rs | 0 {tests => lib/tests}/kv_store.rs | 3 ++ 13 files changed, 117 insertions(+), 54 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json rename {tests => crates/kvs-client/tests}/cli.rs (100%) create mode 100644 lib/Cargo.toml rename {src => lib/src}/bin/main.rs (100%) rename {src => lib/src}/cli.rs (100%) rename {src => lib/src}/error.rs (100%) rename {src => lib/src}/lib.rs (100%) rename {tests => lib/tests}/kv_store.rs (98%) diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..bc3dded --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,21 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "cppvsdbg", + "request": "launch", + "name": "Debug cmd in executable 'kvs'", + "program": "${workspaceFolder}/target/debug/kvs.exe", + "args": [ + "set", + "horseradish", + "clams" + ], + "cwd": "${workspaceFolder}", + "preLaunchTask": "rust: cargo build", + }, + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..4d8289d --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,21 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "rust: cargo build", + "type": "cargo", + "command": "build", + "args": [ + // "--package kvs", + // "--bin kvs" + ], + "options": { + "cwd": "${workspaceFolder}", + }, + "problemMatcher": [ + "$rustc" + ], + "group": "build", + } + ] +} \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index e86ec86..763cc3a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -479,8 +479,14 @@ dependencies = [ name = "kvs-client" version = "1.2.0" dependencies = [ + "assert_cmd", "clap 4.4.6", + "criterion", "kvs", + "predicates", + "rand", + "tempfile", + "walkdir", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 2f79246..24899d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,65 +2,24 @@ authors = ["Abhishek Shah "] description = "A key-value store called kvs" edition = "2021" -name = "kvstore" -# licenses = ["MIT"] version = "1.2.0" - -[package] -authors.workspace = true -description = "A key-value store called kvs" -# licenses.workspace = true -edition = {workspace = true} -name = "kvs" -version = {workspace = true} -default-run = "kvs" - -[[bin]] -description = "kvs cli to interact with kvs library" -name = "kvs" -path = "src/bin/main.rs" - -[[bin]] -name = "kvs-client" -path = "crates/kvs-client/src/main.rs" - -[[bin]] -name = "kvs-server" -path = "crates/kvs-server/src/main.rs" - -[lib] -doctest = false -name = "kvs" -path = "src/lib.rs" -test = false +license = "MIT" +# https://doc.rust-lang.org/cargo/reference/workspaces.html [workspace] -members = ["crates/kvs-client", "crates/kvs-server"] +resolver = "2" -[dependencies] -clap = {version = "4.1.6", features = ["derive"]} -dotenv = "0.15.0" -env_logger = "0.10.0" -lazy_static = "1.4.0" -log = "0.4.20" -ron = "0.8.1" -serde = {version = "1.0.188", features = ["derive"]} -serde_json = "1.0.104" -thiserror = "1.0.38" +members = ["crates/kvs-client", "crates/kvs-server", "lib"] +default-members = ["lib", "crates/kvs-client"] [workspace.dependencies] -clap = {version = "4.1.6", features = ["derive"]} +clap = { version = "4.1.6", features = ["derive"] } dotenv = "0.15.0" env_logger = "0.10.0" -kvs = {path = "."} +kvs = { path = "lib" } lazy_static = "1.4.0" log = "0.4.20" ron = "0.8.1" - -[dev-dependencies] -assert_cmd = "0.11" -criterion = "0.3" -predicates = "1.0.0" -rand = "0.6.5" -tempfile = "3.0.7" -walkdir = "2.2.7" +serde = { version = "1.0.188", features = ["derive"] } +serde_json = "1.0.104" +thiserror = "1.0.38" diff --git a/crates/kvs-client/Cargo.toml b/crates/kvs-client/Cargo.toml index 2163780..f471709 100644 --- a/crates/kvs-client/Cargo.toml +++ b/crates/kvs-client/Cargo.toml @@ -1,11 +1,20 @@ [package] name = "kvs-client" -version = { workspace = true } +version = { workspace = true } edition = "2021" -authors = { workspace = true } +authors = { workspace = true } +license.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] kvs = { workspace = true } -clap = { workspace = true } \ No newline at end of file +clap = { workspace = true } + +[dev-dependencies] +assert_cmd = "0.11" +criterion = "0.3" +predicates = "1.0.0" +rand = "0.6.5" +tempfile = "3.0.7" +walkdir = "2.2.7" \ No newline at end of file diff --git a/crates/kvs-client/src/main.rs b/crates/kvs-client/src/main.rs index aec7420..3ed202e 100644 --- a/crates/kvs-client/src/main.rs +++ b/crates/kvs-client/src/main.rs @@ -1,3 +1,18 @@ fn main() { println!("Hello, world! from kvs client"); + exit_program(0); +} +/// Non-zero exit code indicates a program error +fn exit_program(code: i32) -> ! { + std::process::exit(code) +} + +#[derive(Debug, clap::Parser)] +struct Cli { + #[arg(short, long)] + get: String, + #[arg(short, long)] + set: String, + #[arg(short, long)] + rm: String, } diff --git a/tests/cli.rs b/crates/kvs-client/tests/cli.rs similarity index 100% rename from tests/cli.rs rename to crates/kvs-client/tests/cli.rs diff --git a/lib/Cargo.toml b/lib/Cargo.toml new file mode 100644 index 0000000..18a505f --- /dev/null +++ b/lib/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "kvs" +authors.workspace = true +description.workspace = true +edition = { workspace = true } +version = { workspace = true } + +[[bin]] +name = "kvs" +path = "src/bin/main.rs" + +[dependencies] +clap = { version = "4.1.6", features = ["derive"] } +dotenv = "0.15.0" +env_logger = "0.10.0" +lazy_static = "1.4.0" +log = "0.4.20" +ron = "0.8.1" +serde = { version = "1.0.188", features = ["derive"] } +serde_json = "1.0.104" +thiserror = "1.0.38" + +[dev-dependencies] +assert_cmd = "0.11" +criterion = "0.3" +predicates = "1.0.0" +rand = "0.6.5" +tempfile = "3.0.7" +walkdir = "2.2.7" diff --git a/src/bin/main.rs b/lib/src/bin/main.rs similarity index 100% rename from src/bin/main.rs rename to lib/src/bin/main.rs diff --git a/src/cli.rs b/lib/src/cli.rs similarity index 100% rename from src/cli.rs rename to lib/src/cli.rs diff --git a/src/error.rs b/lib/src/error.rs similarity index 100% rename from src/error.rs rename to lib/src/error.rs diff --git a/src/lib.rs b/lib/src/lib.rs similarity index 100% rename from src/lib.rs rename to lib/src/lib.rs diff --git a/tests/kv_store.rs b/lib/tests/kv_store.rs similarity index 98% rename from tests/kv_store.rs rename to lib/tests/kv_store.rs index c4df2e6..8c8b4a9 100644 --- a/tests/kv_store.rs +++ b/lib/tests/kv_store.rs @@ -1,3 +1,5 @@ +#![allow(unused_mut)] + use kvs::{KvStore, KvsEngine, Result}; use tempfile::TempDir; use walkdir::WalkDir; @@ -82,6 +84,7 @@ fn remove_key() -> Result<()> { // Insert data until total size of the directory decreases. // Test data correctness after compaction. #[test] +#[ignore = "takes a while"] fn compaction() -> Result<()> { let temp_dir = TempDir::new().expect("unable to create temporary working directory"); let mut store = KvStore::open(temp_dir.path())?;