aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Schilling <erik.schilling@linaro.org>2023-10-06 09:24:26 +0200
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>2023-10-10 08:55:07 +0200
commitacebcf2cbefb735eaddc06ee52eb1b1c85886d1b (patch)
treee8e68fda29274743833e9dabbba26545ad2d2a0a
parente7b02c2259d97c77107c77b68e3bc1664e6703c1 (diff)
downloadlibgpiod-acebcf2cbefb735eaddc06ee52eb1b1c85886d1b.tar.gz
bindings: rust: feature gate unreleased features
`gpiod_line_request_get_chip_name()` is not released yet. Still, libgpiod-sys will just happily generate bindings for it if it sees the definition in the header file. This guards the unreleased features behind an optional feature `vnext`. To sketch the process of what happens once these features get into an assumed "2.1" release: libgpiod-sys will get updated with a `v2_1` feature. That feature would then raise the minimum version that is attempted to query from pkg- config. An identical feature will then be introduced on the `libgpiod` crate and `vnext` guards will be changed to `v2_1` guards. The `vnext` feature will then be updated to require the new `v2_1` feature. Eventually, we will probably raise the minimum supported version for the rust bindings and drop all the version gates before that. Signed-off-by: Erik Schilling <erik.schilling@linaro.org> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
-rw-r--r--bindings/rust/libgpiod/Cargo.toml3
-rw-r--r--bindings/rust/libgpiod/Makefile.am2
-rw-r--r--bindings/rust/libgpiod/README.md13
-rw-r--r--bindings/rust/libgpiod/src/line_request.rs2
-rw-r--r--bindings/rust/libgpiod/tests/line_request.rs1
5 files changed, 20 insertions, 1 deletions
diff --git a/bindings/rust/libgpiod/Cargo.toml b/bindings/rust/libgpiod/Cargo.toml
index 3be4aa09..3fd1d741 100644
--- a/bindings/rust/libgpiod/Cargo.toml
+++ b/bindings/rust/libgpiod/Cargo.toml
@@ -18,6 +18,9 @@ exclude = [
"Makefile.am",
]
+[features]
+vnext = []
+
[dependencies]
errno = "0.2.8"
intmap = "2.0.0"
diff --git a/bindings/rust/libgpiod/Makefile.am b/bindings/rust/libgpiod/Makefile.am
index 92edbfc9..619e36ca 100644
--- a/bindings/rust/libgpiod/Makefile.am
+++ b/bindings/rust/libgpiod/Makefile.am
@@ -8,7 +8,7 @@ command = SYSTEM_DEPS_LIBGPIOD_NO_PKG_CONFIG=1 \
SYSTEM_DEPS_LIBGPIOD_SEARCH_NATIVE="${PWD}/../../../lib/.libs/" \
SYSTEM_DEPS_LIBGPIOD_LIB=gpiod \
SYSTEM_DEPS_LIBGPIOD_INCLUDE="${PWD}/../../../include/" \
- cargo build --release --lib
+ cargo build --features=vnext --release --lib
if WITH_TESTS
command += --tests
diff --git a/bindings/rust/libgpiod/README.md b/bindings/rust/libgpiod/README.md
index 8d514e71..c86b06eb 100644
--- a/bindings/rust/libgpiod/README.md
+++ b/bindings/rust/libgpiod/README.md
@@ -17,6 +17,19 @@ By default, `libgpiod-sys` builds against the libgpiod version identified via
`pkg-config`. See the `README.md` of `libgpiod-sys` for options to override
that.
+Currently at least libgpiod 2.0 is required with the default feature set.
+
+## Features
+
+The Rust bindings will usually be built against whatever libgpiod version a
+system provides. Hence, only the functionality of the oldest supported libgpiod
+C library will be exposed by default.
+
+Setting flags allows to increase the base version and export features of newer
+versions:
+
+- `vnext`: The upcoming, still unreleased version of the C lib
+
## License
This project is licensed under either of
diff --git a/bindings/rust/libgpiod/src/line_request.rs b/bindings/rust/libgpiod/src/line_request.rs
index 64ef05d4..a7fe6d06 100644
--- a/bindings/rust/libgpiod/src/line_request.rs
+++ b/bindings/rust/libgpiod/src/line_request.rs
@@ -2,6 +2,7 @@
// SPDX-FileCopyrightText: 2022 Linaro Ltd.
// SPDX-FileCopyrightText: 2022 Viresh Kumar <viresh.kumar@linaro.org>
+#[cfg(feature = "vnext")]
use std::ffi::CStr;
use std::os::unix::prelude::AsRawFd;
use std::time::Duration;
@@ -31,6 +32,7 @@ impl Request {
}
/// Get the name of the chip this request was made on.
+ #[cfg(feature = "vnext")]
pub fn chip_name(&self) -> Result<&str> {
// SAFETY: The `gpiod_line_request` is guaranteed to be live as long
// as `&self`
diff --git a/bindings/rust/libgpiod/tests/line_request.rs b/bindings/rust/libgpiod/tests/line_request.rs
index e0ae2004..a936a1b7 100644
--- a/bindings/rust/libgpiod/tests/line_request.rs
+++ b/bindings/rust/libgpiod/tests/line_request.rs
@@ -60,6 +60,7 @@ mod line_request {
use super::*;
#[test]
+ #[cfg(feature = "vnext")]
fn chip_name() {
const GPIO: Offset = 2;
let mut config = TestConfig::new(NGPIO).unwrap();