OpenBSD: add sensor structure and related constants - #5510
Conversation
|
Some changes occurred in an OpenBSD module cc @semarie |
e4b9467 to
ad7c2d5
Compare
|
|
||
| s! { | ||
| pub struct sensor { | ||
| pub desc: [u8; 32], |
There was a problem hiding this comment.
use the C type please. for example by using c_char instead of u8. it is important as not all architectures supported has the same signess.
| pub desc: [u8; 32], | ||
| pub timeval: timeval, | ||
| pub value: i64, | ||
| pub type_: c_int, |
There was a problem hiding this comment.
type and status are C enum (see c_enum! macro).
|
I updated based on your remarks, and I declared the sensors module that I forgot the first time. |
| } | ||
| } | ||
|
|
||
| pub const sensor_type_s: [&'static str; SENSOR_MAX_TYPES as usize + 1] = [ |
There was a problem hiding this comment.
&str couldn't be used here. If I understood the error of the CI (local CI on OpenBSD), it is not FFI compatible: it means that the Rust layout for it is not the same than C, and so can't be used.
I am unsure how to resolv it. maybe just not export sensor_type_s.
else maybe @tgross35 will have some tips
There was a problem hiding this comment.
Would this be better?
pub const sensor_type_s: [*const c_char; SENSOR_MAX_TYPES as usize + 1] = [
cstr(b"temp\0"),
cstr(b"fan\0"),
/* ... */
];There was a problem hiding this comment.
I think that definition should work, but I wouldn't bother adding it unless there's a usecase
There was a problem hiding this comment.
I work on an i3 status bar project (which motivated this PR), and I use the sensor struct and the constants, but to be honest I don't use this one. I ported it because it was part of the sensor ecosystem in the header. I will remove it.
There was a problem hiding this comment.
LGTM but would also like @semarie's approval. Please squash also
|
@tgross35 I will ping you once it is fine on my side. For now I have CI issues that I need to look at (if related to these changes or not). Thanks. |
There was a problem hiding this comment.
After running the CI on it, there are several points to address.
And outside the commentaries, libc-test/build/main.rs should also be adapted:
- include
sys/sensors.hin the headers included for testing the C values - register the field rename for
sensor->type_ - declare the enums
For this part, I have the following diff you could reuse:
diff --git a/libc-test/build/main.rs b/libc-test/build/main.rs
index 6a2ff1252..bb0e47ee1 100755
--- a/libc-test/build/main.rs
+++ b/libc-test/build/main.rs
@@ -411,6 +411,7 @@ fn test_openbsd(t: &Target) {
"wchar.h",
"ctype.h",
"dirent.h",
+ "sys/sensors.h",
"sys/socket.h",
(x86_64, "machine/fpu.h"),
"net/if.h",
@@ -506,6 +507,10 @@ fn test_openbsd(t: &Target) {
"sa_sigaction" if struct_ == "sigaction" => "sa_handler".to_string(),
+ // Field is named `type` in C but that is a Rust keyword,
+ // so these fields are translated to `type_` in the bindings.
+ "type_" if struct_ == "sensor" => "type".to_string(),
+
_ => return None,
};
Some(replacement)
@@ -526,6 +531,13 @@ fn test_openbsd(t: &Target) {
cfg.rename_struct_ty(|ty| ty.ends_with("_t").then_some(ty.to_string()));
cfg.rename_union_ty(|ty| ty.ends_with("_t").then_some(ty.to_string()));
+ cfg.alias_is_c_enum(move |ty| {
+ match ty {
+ "sensor_type" | "sensor_status" => true,
+ _ => false,
+ }
+ });
+
cfg.skip_struct(move |struct_| {
match struct_.ident() {
// Extern types| SENSOR_STATUS_UNKNOWN | ||
| SENSOR_STATUS_UNSPEC | ||
| SENSOR_STATUS_WARN | ||
| SENSOR_TYPE_ACCEL |
There was a problem hiding this comment.
it is not the exported name: SENSOR_ACCEL is the right one.
same for all SENSOR_TYPE_* names.
| SENSOR_FINVALID | ||
| SENSOR_FUNKNOWN | ||
| SENSOR_MAX_TYPES | ||
| SENSOR_STATUS_CRIT |
There was a problem hiding this comment.
it is not the exported name: SENSOR_S_CRIT is the right one.
same for all SENSOR_STATUS_* names.
| SENSOR_TYPE_TEMP | ||
| SENSOR_TYPE_TIMEDELTA | ||
| SENSOR_TYPE_VELOCITY | ||
| SENSOR_TYPE_VOLTSAC |
There was a problem hiding this comment.
SENSOR_TYPE_VOLTSAC -> SENSOR_VOLTS_AC
| SENSOR_TYPE_TIMEDELTA | ||
| SENSOR_TYPE_VELOCITY | ||
| SENSOR_TYPE_VOLTSAC | ||
| SENSOR_TYPE_VOLTSDC |
There was a problem hiding this comment.
SENSOR_TYPE_VOLTSDC -> SENSOR_VOLTS_DC
|
Most issues came from when I moved the constants to enums, I should have been more careful, sorry. Thank you for the main.rs patch. |
|
The CI fails without any info, the error seems to be empty. Am I missing something? |
|
it is failing due to style check: https://github.com/rust-lang/libc/actions/runs/34332816559/job/102405155919?pr=5510 |
|
I discovered the script |
There was a problem hiding this comment.
LGTM but please squash the commits
Cc @tgross35
The structure sensor and the SENSOR_* constants have been added, as well as the sensor_status and sensor_type enumerations. Ref: https://github.com/openbsd/src/blob/e8afce5b5b9d68772098e66f10777f7b6abb530d/sys/sys/sensors.h
74cde7d to
b4769f4
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
Commits have been squashed. Thanks for your support in this PR. |
Description
Add the structure sensor from sys/sensors.h and related SENSOR_* constants.
Source
https://github.com/openbsd/src/blob/e8afce5b5b9d68772098e66f10777f7b6abb530d/sys/sys/sensors.h
@rustbot label +stable-nominated