linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Erik Schilling <erik.schilling@linaro.org>
To: Bartosz Golaszewski <brgl@bgdev.pl>,
	Linux-GPIO <linux-gpio@vger.kernel.org>
Cc: Viresh Kumar <viresh.kumar@linaro.org>,
	Manos Pitsidianakis <manos.pitsidianakis@linaro.org>,
	Kent Gibson <warthog618@gmail.com>,
	Erik Schilling <erik.schilling@linaro.org>
Subject: [libgpiod][PATCH 1/2] bindings: rust: feature gate unreleased features
Date: Fri, 06 Oct 2023 09:24:26 +0200	[thread overview]
Message-ID: <20231006-b4-bindings-old-version-fix-v1-1-a65f431afb97@linaro.org> (raw)
In-Reply-To: <20231006-b4-bindings-old-version-fix-v1-0-a65f431afb97@linaro.org>

`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>
---
 bindings/rust/libgpiod/Cargo.toml            |  3 +++
 bindings/rust/libgpiod/Makefile.am           |  2 +-
 bindings/rust/libgpiod/README.md             | 13 +++++++++++++
 bindings/rust/libgpiod/src/line_request.rs   |  2 ++
 bindings/rust/libgpiod/tests/line_request.rs |  1 +
 5 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/bindings/rust/libgpiod/Cargo.toml b/bindings/rust/libgpiod/Cargo.toml
index 3be4aa0..3fd1d74 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 92edbfc..619e36c 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 8d514e7..c86b06e 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 64ef05d..a7fe6d0 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 e0ae200..a936a1b 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();

-- 
2.41.0


  reply	other threads:[~2023-10-06  7:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-06  7:24 [libgpiod][PATCH 0/2] bindings: rust: feature gate unreleased features Erik Schilling
2023-10-06  7:24 ` Erik Schilling [this message]
2023-10-06  9:25   ` [libgpiod][PATCH 1/2] " Viresh Kumar
2023-10-06  7:24 ` [libgpiod][PATCH 2/2] DONOTMERGE: bindings: rust: simulate v2.1 release Erik Schilling
2023-10-09  8:58 ` [libgpiod][PATCH 0/2] bindings: rust: feature gate unreleased features Bartosz Golaszewski
2023-10-09 11:38   ` Erik Schilling
2023-10-09 12:43     ` Bartosz Golaszewski
2023-10-09 14:16       ` Erik Schilling
2023-10-09 14:32         ` Bartosz Golaszewski
2023-10-09 14:39           ` Manos Pitsidianakis
2023-10-09 15:21             ` Erik Schilling
2023-10-10  6:55               ` Bartosz Golaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231006-b4-bindings-old-version-fix-v1-1-a65f431afb97@linaro.org \
    --to=erik.schilling@linaro.org \
    --cc=brgl@bgdev.pl \
    --cc=linux-gpio@vger.kernel.org \
    --cc=manos.pitsidianakis@linaro.org \
    --cc=viresh.kumar@linaro.org \
    --cc=warthog618@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).