linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Erik Schilling <erik.schilling@linaro.org>
To: Linux-GPIO <linux-gpio@vger.kernel.org>
Cc: "Bartosz Golaszewski" <bartosz.golaszewski@linaro.org>,
	"Viresh Kumar" <viresh.kumar@linaro.org>,
	"Manos Pitsidianakis" <manos.pitsidianakis@linaro.org>,
	"Alex Bennée" <alex.bennee@linaro.org>
Subject: Re: [PATCH libgpiod RFC 3/3] bindings: rust: build against pkg-config info
Date: Wed, 24 May 2023 07:01:28 +0200	[thread overview]
Message-ID: <880592b3-a83d-00d5-e980-fc4758797cf1@linaro.org> (raw)
In-Reply-To: <20230522-crates-io-v1-3-42eeee775eb6@linaro.org>



On 5/23/23 13:25, Erik Schilling wrote:
> This change replaces building against "bundled" headers by always
> building agains system headers (while following standard conventions to
> allow users to specify the version to build against).
> 
> Reasoning:
> 
> Previously, the code generated the bindings based on the headers, but
> then links against `-lgpiod` without further specifying where that is
> coming from.
> 
> This results in some challenges and problems:
> 
> 1. Packaging a Rust crate with `cargo package` requires the folder
>     containing the Cargo.toml to be self-contained. Essentially, a tar
>     ball with all the sources of that folder is created. Building against
>     that tar ball fails, since the headers files passed to bindgen are
>     a relative path pointing outside of that folder.
> 
> 2. While, for example, the cxx bindings are built AND linked against
>     the build results, the packaging situation for C++ libraries is a
>     bit different compared to Rust libs. The C++ libs will likely get
>     built as part of the larger libgpiod build and published together
>     with the C variant.
> 
>     In Rust, the vast majority of people will want to build the glue-code
>     during the compilation of the applications that consume this lib.
> 
>     This may lead to inconsistencies between the bundled headers and the
>     libraries shipped by the user's distro. While ABI should hopefully
>     be forward-compatible within the same MAJOR number of the .so,
>     using too new headers will likely quickly lead to mismatches with
>     symbols defined in the lib.
> 
> 3. Trying to build the core lib as part of the Rust build quickly runs
>     into similar packaging issues as the existing solution. The source
>     code of the C lib would need to become part of some package
>     (often people opt to pull it in as a submodule under their -sys crate
>     or even create a separate -src package [1]). This clearly does not
>     work well with the current setup...
> 
> Since building against system libs is probably? what 90%+ of the people
> want, this change hopefully addresses the problems above. The
> system-deps dependency honors pkg-config conventions, but also allows
> users flexible ways to override the defaults [2]. Overall, this keeps
> things simple while still allowing maximum flexibility.
> 
> Since the pkg-config interface is just telling us which include paths to
> use, we switch back to a wrapper.h file that includes the real gpiod.h.
> 
> Once Rust bindings require a lower version floor, the version metadata
> can also be updated to help telling users that their system library is
> too old.
> 
> Drawback:
> 
> People hacking on the Rust bindings, need to either have a reasonably
> up-to-date system lib, previously install the lib to some folder and
> specify PKG_CONFIG_PATH or set the relevant SYSTEM_DEPS_* environment
> variables. Instructions for developers are documented in the README.
> 
> [1] https://github.com/alexcrichton/openssl-src-rs
> [2] https://docs.rs/system-deps/latest/system_deps/#overriding-build-flags
> 
> Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
> ---
>   README                                | 13 +++++++++++-
>   bindings/rust/libgpiod-sys/Cargo.toml |  4 ++++
>   bindings/rust/libgpiod-sys/build.rs   | 40 +++++++++++++++++++++++------------
>   3 files changed, 42 insertions(+), 15 deletions(-)

Viresh told me on IRC that I forgot the wrapper.h:

diff --git a/bindings/rust/libgpiod-sys/wrapper.h 
b/bindings/rust/libgpiod-sys/wrapper.h
new file mode 100644
index 0000000..8a8bd41
--- /dev/null
+++ b/bindings/rust/libgpiod-sys/wrapper.h
@@ -0,0 +1 @@
+#include <gpiod.h>

  reply	other threads:[~2023-05-24  5:01 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-23 11:25 [PATCH libgpiod RFC 0/3] bindings: rust: allow packaging of libgpiod-sys Erik Schilling
2023-05-23 11:25 ` [PATCH libgpiod RFC 1/3] bindings: rust: drop legacy extern crate syntax Erik Schilling
2023-05-24  4:36   ` Viresh Kumar
2023-05-23 11:25 ` [PATCH libgpiod RFC 2/3] bindings: rust: remove unneeded cc dependency Erik Schilling
2023-05-24  4:36   ` Viresh Kumar
2023-05-23 11:25 ` [PATCH libgpiod RFC 3/3] bindings: rust: build against pkg-config info Erik Schilling
2023-05-24  5:01   ` Erik Schilling [this message]
2023-05-24  6:03 ` [PATCH libgpiod RFC 0/3] bindings: rust: allow packaging of libgpiod-sys Viresh Kumar
2023-05-24  8:09   ` Erik Schilling
2023-05-24  8:14     ` Viresh Kumar
2023-05-24 10:53       ` Erik Schilling
2023-05-26  8:30         ` Erik Schilling
2023-05-26  8:36           ` Bartosz Golaszewski
2023-05-26  8:59             ` Erik Schilling
2023-05-26  9:31               ` Viresh Kumar
2023-05-26  9:44                 ` Erik Schilling
2023-05-24  9:17 ` Bartosz Golaszewski
2023-05-26  9:45   ` Erik Schilling

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=880592b3-a83d-00d5-e980-fc4758797cf1@linaro.org \
    --to=erik.schilling@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=bartosz.golaszewski@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=manos.pitsidianakis@linaro.org \
    --cc=viresh.kumar@linaro.org \
    /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).