From patchwork Tue May 23 11:25:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Erik Schilling X-Patchwork-Id: 685499 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 930F7C77B75 for ; Tue, 23 May 2023 11:26:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229889AbjEWL0a (ORCPT ); Tue, 23 May 2023 07:26:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233200AbjEWL00 (ORCPT ); Tue, 23 May 2023 07:26:26 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C38611A for ; Tue, 23 May 2023 04:26:22 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-50c8d87c775so1140530a12.3 for ; Tue, 23 May 2023 04:26:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684841181; x=1687433181; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=zSRh5YpJNZyKU79HfIsiaXhN0Nt28k1YrpgmzdCgZJM=; b=VgwXg+DxUPKzVaorm7wwxR5WwXectIFPoJ32mhgfBaMkpB93PI6uJKR9tmEEPoSGzF QGmpQ68mzRm7Yc9R2IsKsIjnHsY2cNKuQAQEB3DlAu0dtiNDZ0rCWm6siURs1G/J3jQ6 AN6xtZBBKovuOQfvn2bPnoWY9mprOm63riEIpsN5ZnERCJPjr0oMIfpV4oLEm0iVOuh7 /0yTYtBEkNN0RlcJexEJmsBfewSwGsMvrub6fYwGIsZsboLeYksvdQlfAPWxABkIIu1E m3qX17be1g5BSIlXHa/CAfRn/hZPqu9uVnWuVNRhaxZPsajvzVTEkqvkdcti3G880r6+ BGAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684841181; x=1687433181; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zSRh5YpJNZyKU79HfIsiaXhN0Nt28k1YrpgmzdCgZJM=; b=jS/gq4a5xHQHFiykJgnJvnawA+UGZKwToi7gLttMcwrUha+Y/6MnQs9hWX4LTRBNMP jLtlxDdrZsJU6EsZ85KFZ5IeoBMJproct46SZ+K6crbKpiXhSPZ7zpPxFhdm7EVbwGMi YyamgkfdNgK/X6q2O7P1Uxn4VQB3vsyl7mt4Y9GpoqlFgu7iT71Wcsz7ST8EibMPGMLq BGVyR2sYegxEeq3XE1ffMguvfLskkH6c0s0EGUrov8jeaa0e/muGXfbuc7RPaoXBhLYG Qy9btROHkhVk8YciqZNRvtuoAVJHRrAddc5E/j+wQ7ZP3RhA46GfVcRotYRx62PtlxRP NfNw== X-Gm-Message-State: AC+VfDxMWc4Bd5sLbNOb1xFSjdSMLGL4GRIbmjWmP6+m2wHqo+Wxo3AV FAHjcNyWreHMIzdEkcUey1Qynw== X-Google-Smtp-Source: ACHHUZ4wWgAxDpeqw8HC7wzzEE0golCb12CYPjdGues95vI6v2PASq06b6IvUIxdiGVaxduWlOqkBQ== X-Received: by 2002:a17:907:70a:b0:966:2123:e0c3 with SMTP id xb10-20020a170907070a00b009662123e0c3mr13159458ejb.15.1684841181041; Tue, 23 May 2023 04:26:21 -0700 (PDT) Received: from [192.168.1.149] (i5C7409D3.versanet.de. [92.116.9.211]) by smtp.gmail.com with ESMTPSA id gv3-20020a1709072bc300b0094f3b18044bsm4342911ejc.218.2023.05.23.04.26.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 04:26:20 -0700 (PDT) From: Erik Schilling Date: Tue, 23 May 2023 13:25:46 +0200 Subject: [PATCH libgpiod RFC 1/3] bindings: rust: drop legacy extern crate syntax MIME-Version: 1.0 Message-Id: <20230522-crates-io-v1-1-42eeee775eb6@linaro.org> References: <20230522-crates-io-v1-0-42eeee775eb6@linaro.org> In-Reply-To: <20230522-crates-io-v1-0-42eeee775eb6@linaro.org> To: Linux-GPIO Cc: Bartosz Golaszewski , Viresh Kumar , Manos Pitsidianakis , =?utf-8?q?Alex_Benn?= =?utf-8?q?=C3=A9e?= , Erik Schilling X-Mailer: b4 0.12.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1684841179; l=743; i=erik.schilling@linaro.org; s=20230523; h=from:subject:message-id; bh=PcWsfB5fQWns8QdVUTDMIWalHo+rM28xkDqyRS9wXmQ=; b=ogoCZFzLziKez78FWpeIVrQhZABukbHgHCCOeH5+v0faZXMitBpRhuA067tyBWPNAuNGB+rBq Pufsb2oWjAkCb3MSBk/3IpfdlnA4R+yaWySdK6qDe36HDnTURqxzmsZ X-Developer-Key: i=erik.schilling@linaro.org; a=ed25519; pk=/nNqy8/YOEdthj1epXl5FgwCTKEiVqTqqnVN1jVal7s= Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org This is a relict from old Rust standards and no longer requires [1]. [1] https://doc.rust-lang.org/edition-guide/rust-2018/path-changes.html#no-more-extern-crate Signed-off-by: Erik Schilling --- bindings/rust/libgpiod-sys/build.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/bindings/rust/libgpiod-sys/build.rs b/bindings/rust/libgpiod-sys/build.rs index e3ed04a..b1333f1 100644 --- a/bindings/rust/libgpiod-sys/build.rs +++ b/bindings/rust/libgpiod-sys/build.rs @@ -2,8 +2,6 @@ // SPDX-FileCopyrightText: 2022 Linaro Ltd. // SPDX-FileCopyrightTest: 2022 Viresh Kumar -extern crate bindgen; - use std::env; use std::path::PathBuf; From patchwork Tue May 23 11:25:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Erik Schilling X-Patchwork-Id: 685193 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06FC9C7EE2A for ; Tue, 23 May 2023 11:26:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236326AbjEWL0a (ORCPT ); Tue, 23 May 2023 07:26:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235695AbjEWL01 (ORCPT ); Tue, 23 May 2023 07:26:27 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 272F5121 for ; Tue, 23 May 2023 04:26:26 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-96fbe7fbdd4so534501866b.3 for ; Tue, 23 May 2023 04:26:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684841181; x=1687433181; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=od3SP5ky8Y9LxP+1XQ7PmGRAgzgjOHbNgHLzMDz2k38=; b=QG7KYGcA8AkGBnh6XlZeaTUIhqOXn8GAd0e3E45FyvgOGgE4IwMIGdEEgRzOoVFqAz /1I1d7g31Y1qK724Fl/hphs8Q8F4kqmQQBRU7fv6ZPkMYhDmNBGc1RxaJYdc+/MNr6fe MgDVT4zzRFtflixbIPhYD75HIKj+ntdU5sx8SLDZJZYkauO4dFm1ZkEWI8oCX3SyD6cD t/6gx6zLuttMjo+ep282MXaFZNXOjLbi9aRKc1mZBkq9dOU5aj5oCoRWqyh9lBqTKkHm P8OpE91PAFege+909eeulbCLsy41bIdT/vt3udZoiKkmNLW6mg0+DUqe25D80kFmV8yE RppA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684841181; x=1687433181; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=od3SP5ky8Y9LxP+1XQ7PmGRAgzgjOHbNgHLzMDz2k38=; b=cgOlRMigiTps1qGqSTUMIRjIEV+SS58XdDYla1HxnUkaIUKjsFM0563P9Fus0Ye1EQ FQr5/aPPTblMsMSIX7zoMGn/f72j3/3Zh/liXXvk3u/LHDB7nHwbUIwYip3ZG6zE2qxY XL8EllNWKtT0Q9BISS0LOxGSYzgn98YA0W7n8YMo3BIrhP2AV4PVyhNit4fbe+iALry9 2gB7BWXpm/7KfpeW9oGR41midg6fFs2rtIhsHS8LYBnl1kJO1w/+nGLbDXwdtW5elXKP NyZbvibrYeKF2vF8fS8Nb2RxoKDUM8UdUOugUWfBJg5hq1LoVLGUDWc+XAERsr7PNqz6 Xs8Q== X-Gm-Message-State: AC+VfDwWcNXjy/zcJfe8siYR5WUOCUsV/lb9H1IsXlxB44UaJEtZ3+4x IFucfeixbzaBvdkRwMGKlD6s2CPTgbaRXyH3Kn0= X-Google-Smtp-Source: ACHHUZ6+Sv5lckUHJ0RyTdvhH208cw5iZYv6gL7eOwgVMhg5dz+YG1L0xP75jZ/LFwHhzWOmlcK/XA== X-Received: by 2002:a17:906:6a0d:b0:96a:928c:d391 with SMTP id qw13-20020a1709066a0d00b0096a928cd391mr14399139ejc.4.1684841181694; Tue, 23 May 2023 04:26:21 -0700 (PDT) Received: from [192.168.1.149] (i5C7409D3.versanet.de. [92.116.9.211]) by smtp.gmail.com with ESMTPSA id gv3-20020a1709072bc300b0094f3b18044bsm4342911ejc.218.2023.05.23.04.26.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 04:26:21 -0700 (PDT) From: Erik Schilling Date: Tue, 23 May 2023 13:25:47 +0200 Subject: [PATCH libgpiod RFC 2/3] bindings: rust: remove unneeded cc dependency MIME-Version: 1.0 Message-Id: <20230522-crates-io-v1-2-42eeee775eb6@linaro.org> References: <20230522-crates-io-v1-0-42eeee775eb6@linaro.org> In-Reply-To: <20230522-crates-io-v1-0-42eeee775eb6@linaro.org> To: Linux-GPIO Cc: Bartosz Golaszewski , Viresh Kumar , Manos Pitsidianakis , =?utf-8?q?Alex_Benn?= =?utf-8?q?=C3=A9e?= , Erik Schilling X-Mailer: b4 0.12.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1684841179; l=663; i=erik.schilling@linaro.org; s=20230523; h=from:subject:message-id; bh=mH7k+DOE/0trTqK7DJ7T4IJFhqsFAqGTsXPFyu/Zb+E=; b=CMCUWMImpYwF2ES0kAeWe9ab9V3euSKaJHKRVNVdYc1pfXFS7/4uguC4GhQKUnQ10N4SlfMOJ b/V+JM5d717Al/7AKmOkLbx7lTAWKYZUe5ApR2cW8vewBEs8jK8ifau X-Developer-Key: i=erik.schilling@linaro.org; a=ed25519; pk=/nNqy8/YOEdthj1epXl5FgwCTKEiVqTqqnVN1jVal7s= Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org It was never used in upstream. The use was dropped during review [1], but this dependency did not get removed. [1] https://lore.kernel.org/r/cover.1659442066.git.viresh.kumar@linaro.org/ Signed-off-by: Erik Schilling --- bindings/rust/libgpiod-sys/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/bindings/rust/libgpiod-sys/Cargo.toml b/bindings/rust/libgpiod-sys/Cargo.toml index 3bc3525..cb8dc70 100644 --- a/bindings/rust/libgpiod-sys/Cargo.toml +++ b/bindings/rust/libgpiod-sys/Cargo.toml @@ -18,4 +18,3 @@ edition = "2021" [build-dependencies] bindgen = "0.63" -cc = "1.0.46" From patchwork Tue May 23 11:25:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Erik Schilling X-Patchwork-Id: 685498 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 206B5C7EE2E for ; Tue, 23 May 2023 11:26:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236216AbjEWL0a (ORCPT ); Tue, 23 May 2023 07:26:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235598AbjEWL01 (ORCPT ); Tue, 23 May 2023 07:26:27 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7074120 for ; Tue, 23 May 2023 04:26:23 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-96652cb7673so1143358266b.0 for ; Tue, 23 May 2023 04:26:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684841182; x=1687433182; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=sOy9xIiG8gh5AExeZkXTRpX85BoP9eilfC7RfJuFSrk=; b=PuAQV78w/Ee0iZeCcAtNBxf+DPmdevTI1d/IPb034oBCsw/6o4IO2Js8/npb8ftYhw 0RWzlYfHLC45cuqRv57xRBuMskiiiysxBuvEudwzCyWpSLI1oYsohrxlPPy1dniW3PB1 ZWYsF3ddU4+obrUMV9xZCcqk/WGB2NvNSPRTuenQnJnmbBU3iqODf1mvw2Z0BygfR+4H ixWYsZ0NLMpoUAoR7NeZCnln8dsFkDelm9XWlvtmT+T1Ic+U9vzfQ8CAeQyOcsyRrxy1 gHZXh/tC7PxXFPcI3xQKIw12R6pnMnNsqcS9pIgRV+hy5sXxEmX7zqHoIiPZ5iCGA3/y tS9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684841182; x=1687433182; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sOy9xIiG8gh5AExeZkXTRpX85BoP9eilfC7RfJuFSrk=; b=BCt2cD3E59IalpTEruUWDI3nRxuC3vcmVaLSckgqsPzMzWMqaVEwhunmcENt7Dg4nD dLEZAxYTWHoOBhYCbDYj6vCuQAl3djocBx7BpRzgsAcvfWkd7pvIjjh/aScjcIqTsimm qKRrD4z7p5K/4/Yw2wOaJxLMSuMqwnrc9DosG9B+yhlIrCshoO11TU2O4Y//ZDQ/WyCc n4ugfni7T/8u8LoKVQt8fiW52A9kSy7jKeZ9P3Xc4jFTpbrrvyO9q+ZpMHaM2Gu/4JSH RDxgAKNWqwY8gzl7Y/zn5CslB/Ch579w3WFQVPyF2riymAa3lsfqlhVp5K0a9Ku+0V7V xnZg== X-Gm-Message-State: AC+VfDzpo+YPAh1ezsyWL1oUIkpr5FWyg0uP2oL73fhsIANeUKVRQm6N xmUh82ySVL3UJj6ynxsgK6+3SQ== X-Google-Smtp-Source: ACHHUZ78IRd+3jzO5OTwlwgS9pTwsSeznXmTvFPNoYhbkDdQiN0SAcsI5Hb2iWiMDsTmjT4fv3vJOw== X-Received: by 2002:a17:907:6287:b0:965:d18b:f03a with SMTP id nd7-20020a170907628700b00965d18bf03amr13628252ejc.58.1684841182393; Tue, 23 May 2023 04:26:22 -0700 (PDT) Received: from [192.168.1.149] (i5C7409D3.versanet.de. [92.116.9.211]) by smtp.gmail.com with ESMTPSA id gv3-20020a1709072bc300b0094f3b18044bsm4342911ejc.218.2023.05.23.04.26.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 04:26:22 -0700 (PDT) From: Erik Schilling Date: Tue, 23 May 2023 13:25:48 +0200 Subject: [PATCH libgpiod RFC 3/3] bindings: rust: build against pkg-config info MIME-Version: 1.0 Message-Id: <20230522-crates-io-v1-3-42eeee775eb6@linaro.org> References: <20230522-crates-io-v1-0-42eeee775eb6@linaro.org> In-Reply-To: <20230522-crates-io-v1-0-42eeee775eb6@linaro.org> To: Linux-GPIO Cc: Bartosz Golaszewski , Viresh Kumar , Manos Pitsidianakis , =?utf-8?q?Alex_Benn?= =?utf-8?q?=C3=A9e?= , Erik Schilling X-Mailer: b4 0.12.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1684841179; l=7423; i=erik.schilling@linaro.org; s=20230523; h=from:subject:message-id; bh=+9qrdhsqceKESpwBJJaS5PqIz7cMrhRgMOWCKpGkbqY=; b=DMSlxTg9WJ9xqDofTztJKJLee/UfyVZ5WUVJFxVzxEePo5SBDfSiIbpZBfl1oBQfgx0htgwdL I6le+UiM3AbAiwCOl6T9plfI0oFyUhXBSIk1Um2gvEb2lM4utqpXyYs X-Developer-Key: i=erik.schilling@linaro.org; a=ed25519; pk=/nNqy8/YOEdthj1epXl5FgwCTKEiVqTqqnVN1jVal7s= Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org 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 --- README | 13 +++++++++++- bindings/rust/libgpiod-sys/Cargo.toml | 4 ++++ bindings/rust/libgpiod-sys/build.rs | 40 +++++++++++++++++++++++------------ 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/README b/README index b71739e..8780b09 100644 --- a/README +++ b/README @@ -218,7 +218,18 @@ the PYTHON_CPPFLAGS and PYTHON_LIBS variables in order to point the build system to the correct locations. During native builds, the configure script can auto-detect the location of the development files. -Rust bindings require cargo support. +Rust bindings require cargo support. Additionally, a compatible variant of the C +library needs to detectable using pkg-config. Alternatively, one can inform the +build system about the location of the libs and headers by setting environment +variables. For example, after building the C lib, one should be able to build +the bindings using: + + cd bindings/rust/libgpiod-sys/ + env SYSTEM_DEPS_LIBGPIOD_NO_PKG_CONFIG=1 \ + SYSTEM_DEPS_LIBGPIOD_SEARCH_NATIVE="../../../.libs/" \ + SYSTEM_DEPS_LIBGPIOD_LIB=gpiod \ + SYSTEM_DEPS_LIBGPIOD_INCLUDE="../../../include/" \ + cargo build TESTING ------- diff --git a/bindings/rust/libgpiod-sys/Cargo.toml b/bindings/rust/libgpiod-sys/Cargo.toml index cb8dc70..d945e02 100644 --- a/bindings/rust/libgpiod-sys/Cargo.toml +++ b/bindings/rust/libgpiod-sys/Cargo.toml @@ -18,3 +18,7 @@ edition = "2021" [build-dependencies] bindgen = "0.63" +system-deps = "2.0" + +[package.metadata.system-deps] +libgpiod = "2" diff --git a/bindings/rust/libgpiod-sys/build.rs b/bindings/rust/libgpiod-sys/build.rs index b1333f1..189a12a 100644 --- a/bindings/rust/libgpiod-sys/build.rs +++ b/bindings/rust/libgpiod-sys/build.rs @@ -1,25 +1,44 @@ // SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause -// SPDX-FileCopyrightText: 2022 Linaro Ltd. +// SPDX-FileCopyrightText: 2022-2023 Linaro Ltd. // SPDX-FileCopyrightTest: 2022 Viresh Kumar +// SPDX-FileCopyrightText: 2023 Erik Schilling use std::env; use std::path::PathBuf; -fn generate_bindings() { +fn main() { + // Probe dependency info based on the metadata from Cargo.toml + // (and potentially other sources like environment, pkg-config, ...) + // https://docs.rs/system-deps/latest/system_deps/#overriding-build-flags + let libs = system_deps::Config::new().probe().unwrap(); + // Tell cargo to invalidate the built crate whenever following files change - println!("cargo:rerun-if-changed=../../../include/gpiod.h"); + println!("cargo:rerun-if-changed=wrapper.h"); // The bindgen::Builder is the main entry point // to bindgen, and lets you build up options for // the resulting bindings. - let bindings = bindgen::Builder::default() + let mut builder = bindgen::Builder::default() // The input header we would like to generate // bindings for. - .header("../../../include/gpiod.h") + .header("wrapper.h") // Tell cargo to invalidate the built crate whenever any of the // included header files changed. - .parse_callbacks(Box::new(bindgen::CargoCallbacks)) - // Finish the builder and generate the bindings. + .parse_callbacks(Box::new(bindgen::CargoCallbacks)); + + // Inform bindgen about the include paths identified by system_deps. + for (_name, lib) in libs { + for include_path in lib.include_paths { + builder = builder.clang_arg("-I").clang_arg( + include_path + .to_str() + .expect("Failed to convert include_path to &str!"), + ); + } + } + + // Finish the builder and generate the bindings. + let bindings = builder .generate() // Unwrap the Result and panic on failure. .expect("Unable to generate bindings"); @@ -30,10 +49,3 @@ fn generate_bindings() { .write_to_file(out_path.join("bindings.rs")) .expect("Couldn't write bindings!"); } - -fn main() { - generate_bindings(); - - println!("cargo:rustc-link-search=./../../lib/.libs/"); - println!("cargo:rustc-link-lib=gpiod"); -}