Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@
load("@score_cr_checker//:cr_checker.bzl", "copyright_checker")
load("@score_dash_license_checker//:dash.bzl", "dash_license_checker")
load("@score_format_checker//:macros.bzl", "use_format_targets")
load("@score_starpls_lsp//:starpls.bzl", "setup_starpls")
load("//:project_config.bzl", "PROJECT_CONFIG")

setup_starpls(
name = "starpls_server",
visibility = ["//visibility:public"],
)

copyright_checker(
name = "copyright",
srcs = [
Expand Down
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ bazel_dep(name = "rules_cc", version = "0.1.1")

# LLVM Toolchains Rules - host configuration
bazel_dep(name = "toolchains_llvm", version = "1.2.0")
bazel_dep(name = "score_starpls_lsp", version = "0.1.0")

llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm")
llvm.toolchain(
Expand Down
198 changes: 198 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
# Key-Value-Storage

## License

```text
Copyright (c) 2025 Contributors to the Eclipse Foundation

See the NOTICE file(s) distributed with this work for additional
information regarding copyright ownership.

This program and the accompanying materials are made available under the
terms of the Apache License Version 2.0 which is available at
https://www.apache.org/licenses/LICENSE-2.0

SPDX-License-Identifier: Apache-2.0
```

## Setup

### System dependencies

```bash
sudo apt-get update
sudo apt-get install -y curl build-essential protobuf-compiler libclang-dev
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did You check those deps are relevant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I checked it out in docker

```

### Rust installation

[Install Rust using rustup](https://www.rust-lang.org/tools/install)

```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
```

### Bazel installation

[Install Bazel using Bazelisk](https://bazel.build/install/bazelisk)

```bash
curl --proto '=https' -sSfOL https://github.com/bazelbuild/bazelisk/releases/download/v1.26.0/bazelisk-amd64.deb
dpkg -i bazelisk-amd64.deb
rm bazelisk-amd64.deb
```

Correct Bazel version will be installed on first run, based on `bazelversion` file.

## Build

List all targets:

```bash
bazel query //...
```

Build selected target:

```bash
bazel build <TARGET_NAME>
```

Build all targets:

```bash
bazel build //...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this will work in this repo right now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs are the only that don't. But in general that command shall be always working. Created ticket - #52

```

## Run

List all rust library targets:

```bash
bazel query 'kind(rust_library, //src/...)'
```

Run selected target:

```bash
bazel run <TARGET_NAME>
```

## Test

List all test targets:

```bash
bazel query 'kind(rust_test, //...)'
```

Run all tests:

```bash
bazel test //...
```

Run Component Integration Tests (groupped into single Test Suite):

```bash
bazel test //src/rust/rust_kvs:cit
```

Run selected test target:

```bash
bazel test <TARGET_NAME>
```

## Cargo-based operations

Please use Bazel whenever possible.

### Build with Cargo

Build using `cargo` directly:

```bash
cargo build
```

### Run CLI tool with Cargo

```bash
cargo run --help
```

```text
---------------------------------------
KVS Tool - Command Line Interface
---------------------------------------

Version 0.1.0
Author: Joshua Licht, Continental Automotive Technologies GmbH - Contributors to the Eclipse Foundation

---------------------------------------

Options:
-h, --help Show this help message and exit
-o, --operation Specify the operation to perform (setkey, getkey, removekey, listkeys, reset, snapshotcount, snapshotmaxcount, snapshotrestore, getkvsfilename, gethashfilename, createtestdata)
-k, --key Specify the key to operate on (for key operations)
-p, --payload Specify the value to write (for set operations)
-t, --type Specify the value type for get operations (number, bool, string, null, array, object or first letter as a short form: n = number (except NULL))
-s, --snapshotid Specify the snapshot ID for Snapshot operations

---------------------------------------

Usage Examples:

Read a Key and show value:
kvs_tool -o getkey -k MyKey [optional: -t for type, if not specified, String is used. Panic if not correct type!]
kvs_tool -o getkey -k MyKey -t number (or -t n)
kvs_tool -o getkey -k MyKey -t bool (or -t b)
kvs_tool -o getkey -k MyKey -t array (or -t a)
kvs_tool -o getkey -k MyKey -t object (or -t o)
kvs_tool -o getkey -k MyKey -t string (or -t s or no type specification => string is default)
kvs_tool -o getkey -k MyKey -t null

Write a Key and use the <payload> as the data source:
kvs_tool -o setkey -k MyKey -p 'Hello World' (automatically detects following types: Number, Boolean, String, Null, Object, Array)
kvs_tool -o setkey -k MyKey -p 'true'
kvs_tool -o setkey -k MyKey -p 15
kvs_tool -o setkey -k MyKey -p '[456,false,"Second"]'
kvs_tool -o setkey -k MyKey -p '{"sub-number":789,"sub-string":"Third","sub-bool":true,"sub-array":[1246,false,"Fourth"],"sub-null":null}'

Delete a key:
kvs_tool -o removekey -k MyKey

List Keys:
kvs_tool -o listkeys

Reset KVS:
kvs_tool -o reset

Snapshot Count:
kvs_tool -o snapshotcount

Snapshot Restore:
kvs_tool -o snapshotrestore -s 1

Get KVS Filename:
kvs_tool -o getkvsfilename -s 1

Get Hash Filename:
kvs_tool -o gethashfilename -s 1

---------------------------------------

Create Test Data:
kvs_tool -o createtestdata (Creates Data provided by the example code in the KVS API)

---------------------------------------
```

### Run tests with Cargo

Using `cargo test`:

```bash
cargo test
```
68 changes: 66 additions & 2 deletions src/rust/rust_kvs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,77 @@
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************
load("@crates//:defs.bzl", "all_crate_deps")
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", "rust_test")
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")

rust_library(
name = "rust_kvs",
srcs = ["src/lib.rs"],
srcs = glob(["src/**/*.rs"]),
visibility = ["//visibility:public"],
deps = all_crate_deps(
normal = True,
),
)

__cit_deps = [
":rust_kvs",
] + all_crate_deps(
normal = True,
normal_dev = True,
)

__cit_tags = [
"cit",
"component_tests",
]

rust_test(
name = "cit_default_values",
srcs = ["tests/cit_default_values.rs"],
tags = __cit_tags,
deps = __cit_deps,
)

rust_test(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not fond of having a target for every file, but TBH couldn't find a way to do it better without breaking existing cargo test runs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

me too, so far the only way I found to group tests is by using test suite and I think this will be our way of running all component tests at once:
bazel test //src/rust/rust_kvs:cit

name = "cit_multiple_kvs",
srcs = ["tests/cit_multiple_kvs.rs"],
tags = __cit_tags,
deps = __cit_deps,
)

rust_test(
name = "cit_persistency",
srcs = [
"tests/cit_persistency.rs",
"tests/common.rs",
],
tags = __cit_tags,
deps = __cit_deps,
)

rust_test(
name = "cit_snapshots",
srcs = ["tests/cit_snapshots.rs"],
tags = __cit_tags,
deps = __cit_deps,
)

rust_test(
name = "cit_supported_datatypes",
srcs = [
"tests/cit_supported_datatypes.rs",
"tests/common.rs",
],
tags = __cit_tags,
deps = __cit_deps,
)

test_suite(
name = "cit",
tests = [
":cit_default_values",
":cit_multiple_kvs",
":cit_persistency",
":cit_snapshots",
":cit_supported_datatypes",
],
)
22 changes: 0 additions & 22 deletions src/rust/rust_kvs/tests/README.md

This file was deleted.

5 changes: 0 additions & 5 deletions src/rust/rust_kvs/tests/kvs_0_default.json

This file was deleted.