Skip to content

Commit 7f22bb6

Browse files
committed
impl: logging support
- Support for `mw_log` with C++ backend for Bazel. - Support for `log` for Cargo. - Add more logs. - Fix tests. - Disable `score-log` feature in CI check.
1 parent 96c8441 commit 7f22bb6

File tree

26 files changed

+461
-152
lines changed

26 files changed

+461
-152
lines changed

.bazelrc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ build --tool_java_language_version=17
2525
build --java_runtime_version=remotejdk_17
2626
build --tool_java_runtime_version=remotejdk_17
2727

28+
build --@score_baselibs_rust//src/log:safety_level=qm
2829
build --@score_baselibs//score/json:base_library=nlohmann
2930
build --@score_baselibs//score/mw/log/flags:KRemote_Logging=False
3031

31-
# ToDo: needed for "wrong" implicit dependencies
32-
build --@score-baselibs//score/json:base_library=nlohmann
33-
build --@score-baselibs//score/mw/log/flags:KRemote_Logging=False
32+
common --extra_toolchains=@gcc_toolchain//:host_gcc_12
3433

3534
# Clippy linting (enabled by default)
3635
build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect

.github/workflows/check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838

3939
- name: Cargo Clippy
4040
run: |
41-
cargo clippy --all-targets --all-features
41+
cargo clippy --all-targets --features logging -- -D warnings
4242
4343
- name: Cargo Fmt
4444
run: |

Cargo.lock

Lines changed: 106 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MODULE.bazel

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ bazel_dep(name = "score_rust_policies", version = "0.0.2", dev_dependency = True
4646
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust", dev_dependency = True)
4747
rust.toolchain(
4848
edition = "2021",
49-
versions = ["1.85.0"],
49+
versions = ["1.90.0"],
5050
)
5151

5252
# bazel cc rules
@@ -85,16 +85,19 @@ bazel_dep(name = "google_benchmark", version = "1.9.4", dev_dependency = True)
8585
bazel_dep(name = "platforms", version = "1.0.0")
8686

8787
## S-CORE bazel registry
88-
bazel_dep(name = "score_baselibs", version = "0.1.2")
89-
bazel_dep(name = "score_bazel_platforms", version = "0.0.2")
90-
bazel_dep(name = "score_docs_as_code", version = "2.2.0")
91-
bazel_dep(name = "score_platform", version = "0.5.0")
88+
bazel_dep(name = "score_baselibs", version = "0.2.2")
89+
bazel_dep(name = "score_baselibs_rust", version = "0.0.1")
90+
91+
# TODO: replace with stable version.
9292
git_override(
93-
module_name = "score_platform",
94-
commit = "9d30b718db22ad335cccbcfd72f96e5b37fa58f1", # obsolete by 0.5.1+
95-
remote = "https://github.com/eclipse-score/score.git",
93+
module_name = "score_baselibs_rust",
94+
commit = "18160f840f6623a38b0cb3cd58576cbaf0cf03f6",
95+
remote = "https://github.com/eclipse-score/baselibs_rust.git",
9696
)
9797

98+
bazel_dep(name = "score_bazel_platforms", version = "0.0.2")
99+
bazel_dep(name = "score_docs_as_code", version = "2.2.0")
100+
bazel_dep(name = "score_platform", version = "0.5.0")
98101
bazel_dep(name = "score_process", version = "1.3.2")
99102
bazel_dep(name = "score_python_basics", version = "0.3.4")
100103
bazel_dep(name = "score_tooling", version = "1.0.3")
@@ -107,6 +110,13 @@ git_override(
107110
remote = "https://github.com/eclipse-score/tooling.git",
108111
)
109112

113+
bazel_dep(name = "score_logging", version = "0.0.3")
114+
git_override(
115+
module_name = "score_logging",
116+
commit = "cd7528ce86c6eb5215a53dbbd3cdc761451e5a4b",
117+
remote = "https://github.com/eclipse-score/logging.git",
118+
)
119+
110120
# ToDo: implicit dependencies for score_tooling, but needed directly here??
111121
bazel_dep(name = "aspect_rules_lint", version = "1.10.2")
112122
bazel_dep(name = "buildifier_prebuilt", version = "8.2.0.2")
@@ -156,6 +166,22 @@ archive_override(
156166
],
157167
)
158168

169+
# TODO: remove once inherited properly from `score_logging`.
170+
bazel_dep(name = "trlc")
171+
git_override(
172+
module_name = "trlc",
173+
commit = "650b51a47264a4f232b3341f473527710fc32669", # trlc-2.0.2 release
174+
remote = "https://github.com/bmw-software-engineering/trlc.git",
175+
)
176+
177+
# TODO: remove once inherited properly from `score_logging`.
178+
bazel_dep(name = "score_communication", version = "0.1.2")
179+
git_override(
180+
module_name = "score_communication",
181+
commit = "5a70133dd8bd632f5c07f200a5ee4bc9f507c23b",
182+
remote = "https://github.com/eclipse-score/communication.git",
183+
)
184+
159185
# Registers the custom Rust toolchain wired to @qnx_rust
160186
register_toolchains(
161187
"@score_toolchains_rust//toolchains/aarch64-unknown-qnx8_0:toolchain_aarch64_qnx8_0",

src/rust/rust_kvs/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
1515
rust_library(
1616
name = "rust_kvs",
1717
srcs = glob(["src/**/*.rs"]),
18+
crate_features = ["score-log"],
1819
visibility = ["//visibility:public"],
1920
deps = [
21+
"@score_baselibs_rust//src/log/mw_log",
2022
"@score_crates//:adler32",
2123
"@score_crates//:tinyjson",
2224
],
@@ -25,6 +27,7 @@ rust_library(
2527
rust_test(
2628
name = "tests",
2729
crate = "rust_kvs",
30+
crate_features = ["score-log"],
2831
tags = [
2932
"unit_tests",
3033
"ut",

src/rust/rust_kvs/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ edition.workspace = true
77
[dependencies]
88
adler32.workspace = true
99
tinyjson.workspace = true
10+
log = { version = "0.4.29", optional = true }
11+
12+
13+
[features]
14+
default = ["logging"]
15+
score-log = []
16+
logging = ["log"]
1017

1118

1219
[dev-dependencies]

src/rust/rust_kvs/src/error_code.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111

1212
extern crate alloc;
1313

14+
use crate::log::error;
1415
use alloc::string::FromUtf8Error;
1516
use core::array::TryFromSliceError;
1617

1718
/// Runtime Error Codes
1819
#[derive(Debug, PartialEq)]
20+
#[cfg_attr(feature = "score-log", derive(mw_log::ScoreDebug))]
1921
pub enum ErrorCode {
2022
/// Error that was not yet mapped
2123
UnmappedError,
@@ -93,7 +95,7 @@ impl From<std::io::Error> for ErrorCode {
9395
match kind {
9496
std::io::ErrorKind::NotFound => ErrorCode::FileNotFound,
9597
_ => {
96-
eprintln!("error: unmapped error: {kind}");
98+
error!("Unmapped IO error: {:?}", kind.to_string());
9799
ErrorCode::UnmappedError
98100
}
99101
}
@@ -102,21 +104,21 @@ impl From<std::io::Error> for ErrorCode {
102104

103105
impl From<FromUtf8Error> for ErrorCode {
104106
fn from(cause: FromUtf8Error) -> Self {
105-
eprintln!("error: UTF-8 conversion failed: {cause:#?}");
107+
error!("Conversion from UTF-8 failed: {:#?}", cause);
106108
ErrorCode::ConversionFailed
107109
}
108110
}
109111

110112
impl From<TryFromSliceError> for ErrorCode {
111113
fn from(cause: TryFromSliceError) -> Self {
112-
eprintln!("error: try_into from slice failed: {cause:#?}");
114+
error!("Conversion from slice failed: {:#?}", cause);
113115
ErrorCode::ConversionFailed
114116
}
115117
}
116118

117119
impl From<Vec<u8>> for ErrorCode {
118120
fn from(cause: Vec<u8>) -> Self {
119-
eprintln!("error: try_into from u8 vector failed: {cause:#?}");
121+
error!("Conversion from vector of u8 failed: {:#?}", cause);
120122
ErrorCode::ConversionFailed
121123
}
122124
}

0 commit comments

Comments
 (0)