-
Notifications
You must be signed in to change notification settings - Fork 2
Log backend for rust frontend #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Log backend for rust frontend #1
Conversation
License Check Results🚀 The license check job ran with the Bazel command: bazel run //:license-check Status: Click to expand output
|
The created documentation from the pull request is available at: docu-html |
f5bf372
to
c63f846
Compare
c63f846
to
721f788
Compare
This is logger impl that bridges rust log frontend with C++ mw_log implementation Signed-off-by: Pawel Rutka <pawel.rutka.ext@qorix.ai>
721f788
to
5105b3a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good to me.
I was just wondering why we have the "mw" in namespace in Rust and C++.
src/mw_log_subscriber/src/lib.rs
Outdated
self, | ||
) -> MwLogger { | ||
let context_cstr = self.context.unwrap_or(CString::new("DFLT").unwrap()); | ||
let c_logger_ptr = unsafe { mw_log_create_logger(context_cstr.as_ptr() as *const _) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type could be specified:
let c_logger_ptr = unsafe { mw_log_create_logger(context_cstr.as_ptr() as *const _) }; | |
let c_logger_ptr = unsafe { mw_log_create_logger(context_cstr.as_ptr() as *const c_char) }; |
This is also recommended according to:
https://coding-guidelines.arewesafetycriticalyet.org/coding-guidelines/expressions.html#gui_HDnAZ7EZ4z6G
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
} | ||
|
||
/// Builds the MwLogger with the specified context and configuration and returns it. | ||
pub fn build<const SHOW_MODULE: bool, const SHOW_FILE: bool, const SHOW_LINE: bool>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From api user perspective I would prefer a builder with a more self-explanatory api signature:
pub fn build()
pub fn enable_log_file(mut self) -> MwLoggerBuilder
..
but I see the issue with the const and the that generics only support scalar types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be maybe doable via type state pattern, but for now, since this is just first version I would skip it.
|
||
# magic logging configuration | ||
common --@score-baselibs//score/mw/log/detail/flags:KUse_Stub_Implementation_Only=False | ||
common --@score-baselibs//score/mw/log/flags:KRemote_Logging=False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would we want to set this flag "globally" for anyone? Especially as remote logging is the standard way of logging ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand, currently this is not supported. The code does not compile without it and I copied it from other repos.
ERROR: no such package '@@score-baselibs+//score/mw/log/detail/data_router': BUILD file not found in directory 'score/mw/log/detail/data_router' of external repository @@score-baselibs+. Add a BUILD file to a directory to mark it as a package.
ERROR: /home/pawel/.cache/bazel/_bazel_pawel/d25adba3030c308deb575e8d3085ff8c/external/score-baselibs+/score/mw/log/detail/BUILD:45:11: no such package '@@score-baselibs+//score/mw/log/detail/data_router': BUILD file not found in directory 'score/mw/log/detail/data_router' of external repository @@score-baselibs+. Add a BUILD file to a directory to mark it as a package. and referenced by '@@score-baselibs+//score/mw/log/detail:recorder_config'
ERROR: Analysis of target '//src/mw_log_subscriber:example' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.484s, Critical Path: 0.00s
Maybe I am missing some knowledge here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, your right. I forgot about that. We just have to make sure, this get's changed once we provide the remote backend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was expecting a file name along the lines of rust_cpp_log_adapter.
I'm not happy with the current name as it repeats the module name "mw_log" needlessly and adds the "ffi" which does apply to all files in the module but make it seem this is not the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
extern "C" | ||
{ | ||
|
||
Logger *mw_log_create_logger(const char *context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest of the mw/log C++ codebase follows CamelCase notation for function names.
Does S-CORE have an alternating style guide?
Applies to all functions in the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the problem is that there is no released one? oding_guidelines.html#code-style
clang format files I found being used in the project:
eclipse-score/baselibs · score/language/futurecpp/.clang-format
eclipse-score/inc_feo · .clang-format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, this is not nice :(
We should at least (until overridden by overall project) decide on one for Logging.
Let's add it to the agenda of the CFT Meeting ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since Rust is snake_case, the FFI is snake case. Otherwise, major usage of ffi will mix camelCase and snake_case and will cause Rust warning needed to be supressed. I would not chnage it since its common practice in Rust.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its fine if this file (and this file only) has a different format for the reason you mentioned. I just wanted to make sure we align on the overall picture
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes in this file seem unrelated to rust log backend. Should be moved to individual PR (or at least individual commit)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they are related, to use new code in other repo You need them. I would not split this into seprate PR because it's direct consequence of adding a code and making it usable to other repos.
src/mw_log_subscriber/BUILD
Outdated
cc_library( | ||
name = "libmw_log_ffi", | ||
srcs = ["src/mw_log_ffi.cpp"], | ||
visibility = ["//visibility:public"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would the cpp mapper be public? I thought it needs only be seen by the rust backend? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, done
src/mw_log_subscriber/BUILD
Outdated
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library") | ||
|
||
cc_library( | ||
name = "libmw_log_ffi", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as on file. I'd advocate for a name along rust_cpp_log_mapper
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes in this file seem unrelated to rust log backend. Should be moved to individual PR (or at least individual commit)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they are related, to use new code in other repo You need them. I would not split this into seprate PR because it's direct consequence of adding a code and making it usable to other repos.
llvm.toolchain( | ||
cxx_standard = {"": "c++17"}, | ||
llvm_version = "19.1.0", | ||
gcc = use_extension("@score_toolchains_gcc//extentions:gcc.bzl", "gcc", dev_dependency = True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the toolchain fixed across S-CORE? I was expecting it fixed, as at some point the software has to be build using safety certified compiler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean a fixed version? This declared L47 like described in toolchain repo There is a newer version 0.6 available, but I don't know the version deployment/usage schema in the project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I mean in the end if an some entity want to put logging into a Vehicle under ISO26262 certification it needs to be compliable/linkable by a certified compiler. Typically those are older versions. Eg. for QNX7 Safety core it was GCC9. Hence a lot of brand new compiler goodies were not allowed to be used.
Here it seems you pull a very recent version, and I'm afraid it will break users who need to compile with the qualified compiler. Do you rely on any such brand new feature?
For the above reason, I thought all S-CORE Repos would have a common GCC = Version X.Y set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We dont rely on any, as You saw, usage is simple usage of baselib code. I think the compiler story, deps alignment and final checking is still not setup up finally in S-CORE. But I think the operational team is working on it. So for now I would skip this discussion here in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I mean in the end if an some entity want to put logging into a Vehicle under ISO26262 certification it needs to be compliable/linkable by a certified compiler. Typically those are older versions. Eg. for QNX7 Safety core it was GCC9. Hence a lot of brand new compiler goodies were not allowed to be used.
Here it seems you pull a very recent version, and I'm afraid it will break users who need to compile with the qualified compiler. Do you rely on any such brand new feature?
For the above reason, I thought all S-CORE Repos would have a common GCC = Version X.Y set.
So, to my understanding the s-core toolchain repo offers "fixed toolchains" which are versioned. In this PR we make already use of it ( https://github.com/eclipse-score/logging/pull/1/files#diff-6136fc12446089c3db7360e923203dd114b6a1466252e71667c6791c20fe6bdcR47 ).
What we should figure out, is which s-core gcc version shall be used at the moment e.g. 0.4 or the latest 0.6? But to me this is not a blocker, instead can be done later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We dont rely on any, as You saw, usage is simple usage of baselib code. I think the compiler story, deps alignment and final checking is still not setup up finally in S-CORE. But I think the operational team is working on it. So for now I would skip this discussion here in this PR.
Okay, then I might just not understand the change being introduced here. To me it looks as if we pull a very recent compiler version in that is out of line with what the rest of the S-core project is using.
If this is not the case and/or it is seen as tech debt with a clear roadmap of when and where to change to. Disregard my comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the work. The changes look good to me.
This is logger impl that bridges rust log frontend with C++ mw_log implementation.
This requires https://github.com/eclipse-score/baselibs/pull/18/files to be fully funcional (currently this PR is used in bazel override)
This is transfered from: eclipse-score/inc_mw_log#6