Re: [libgpiod][PATCH 1/2] bindings: rust: feature gate unreleased features

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 06-10-23, 09:24, Erik Schilling wrote:
> `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@xxxxxxxxxx>
> ---
>  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@xxxxxxxxxx>
>  
> +#[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();

Acked-by: Viresh Kumar <viresh.kumar@xxxxxxxxxx>

-- 
viresh



[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux