From patchwork Fri Jun 16 00:16:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 108770 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp999759vqr; Thu, 15 Jun 2023 17:26:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6sHJ7XbQGMjkH6lBjCy5Q9+mICyXTjZQPIHG6xX/T0+8PWt0n1nS2AUsPQKOW1poUZSts1 X-Received: by 2002:a17:90a:c905:b0:25c:19e:9424 with SMTP id v5-20020a17090ac90500b0025c019e9424mr433311pjt.10.1686875182670; Thu, 15 Jun 2023 17:26:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686875182; cv=none; d=google.com; s=arc-20160816; b=xGv2GVtYKjOGfUyrW01gX5q5Yjb9b2ybcZiFNIAkLBhEfhZYdoNeBkS1QTMvnHpK9z 37zsJfwJw5ynMc7jsbSD25jw/+cU5KYqwFbB/8xDcW9FhP1HJpIwHw9A2KFxWgMgX71P iEPImY+e8x67EWAkO56ryYgUdnCS/6J98j8AwapSiDLESdu64aTmMeQKFLHEoYH50XdU NTe97gbzYA5ybtdFO+LI5n8fhcOt5ir3thebHLiFdmzPhQsjVaV5kZAYRubvhQHl4Zjq ry90DPBjq1oPQM8cydgGXpRcdAq/t6WNRnCGSEEwiweZQ0XzYcf03W7xU4nRRbEg82LD ZCcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pPMce/fltVMIKUXG9RRXpYY3maI1nv2lAqeanzYUUJc=; b=IG5/cd6LD1x/K7GbE79wgylEfOydOtVXrvpNlbHTbvoJGxcPRyMOTKHk51KlA1ddp2 gPwS103mRE8/MCpvhf5GDVWzVg4ZndW5kL1HIntIEqutlRy4tKRBD32hrUZU0XD7GN8k teO6pd75YgPfKjVE2scSxw3ammn+/wJgsodFd3Gty+U0EuWz3XbnnAGpoBNLDI8OJtHC Ou68KxYozrjhrjZh+K70+CjdU4YqePRjkJh46CcYDBS15pZVqlOUUNU3vye/M+fDHTY4 vlbElSRM3MbWbIlj8Rpk88yq4QrHtHlngP4uM8fKwxQ2af6421Pl3RrTTRsKrGjgPnzN 7e6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MPhNZmP4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gq18-20020a17090b105200b0025c1f1b7527si474668pjb.11.2023.06.15.17.26.08; Thu, 15 Jun 2023 17:26:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MPhNZmP4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230090AbjFPARb (ORCPT + 99 others); Thu, 15 Jun 2023 20:17:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230427AbjFPAR2 (ORCPT ); Thu, 15 Jun 2023 20:17:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E40A2D54; Thu, 15 Jun 2023 17:17:17 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1562E61C81; Fri, 16 Jun 2023 00:17:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC274C433C0; Fri, 16 Jun 2023 00:17:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686874636; bh=7JYfaB5YdtedAdhpVlS2QsZ4lLvtcfQUiWPkYmJeGc8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MPhNZmP4ycgQtFC7ZZp2oX5p+P2KUHrheWE2WSgDrt/qV6o2HVQBMeL276GUbxQyW 6XlDLgh9HcS9PXinRFmzZ7YftUzQc5Y08CkQf5dlz3UsYq4uzGrBR23rU1wm/k2Jk0 ccW8SNDUF2HavEw23umrFV5YzKPGfASXl4OkUD/HRwMRONqPO+NOxDLj5exL1VU7H1 D3XaorM2UgHs/tqdrrn32PwdKradxuGT72TS0WwwhcLvwfN3dAiIF/lt0aCLr36a3l WCvAgbDiOGVyfrZk+4K4RtHa3fb511xMzkpiHByRDfEiX+WG1JESi96AaGxDFOdpal bCX5sctGc8mdg== From: Miguel Ojeda To: Masahiro Yamada , Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor Cc: Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Andreas Hindborg , linux-kbuild@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, =?utf-8?q?Fran=C3=A7ois_Valenduc?= , Alexandru Radovici , Matthew Leach Subject: [PATCH v2 05/11] kbuild: rust_is_available: add check for `bindgen` invocation Date: Fri, 16 Jun 2023 02:16:25 +0200 Message-ID: <20230616001631.463536-6-ojeda@kernel.org> In-Reply-To: <20230616001631.463536-1-ojeda@kernel.org> References: <20230616001631.463536-1-ojeda@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768816831836656706?= X-GMAIL-MSGID: =?utf-8?q?1768816831836656706?= `scripts/rust_is_available.sh` calls `bindgen` with a special header in order to check whether the `libclang` version in use is suitable. However, the invocation itself may fail if, for instance, `bindgen` cannot locate `libclang`. This is fine for Kconfig (since the script will still fail and therefore disable Rust as it should), but it is pretty confusing for users of the `rustavailable` target given the error will be unrelated: ./scripts/rust_is_available.sh: 21: arithmetic expression: expecting primary: "100000 * + 100 * + " make: *** [Makefile:1816: rustavailable] Error 2 Instead, run the `bindgen` invocation independently in a previous step, saving its output and return code. If it fails, then show the user a proper error message. Otherwise, continue as usual with the saved output. Since the previous patch we show a reference to the docs, and the docs now explain how `bindgen` looks for `libclang`, thus the error message can leverage the documentation, avoiding duplication here (and making users aware of the setup guide in the documentation). Reported-by: Nick Desaulniers Link: https://lore.kernel.org/rust-for-linux/CAKwvOdm5JT4wbdQQYuW+RT07rCi6whGBM2iUAyg8A1CmLXG6Nw@mail.gmail.com/ Reported-by: François Valenduc Closes: https://github.com/Rust-for-Linux/linux/issues/934 Reported-by: Alexandru Radovici Closes: https://github.com/Rust-for-Linux/linux/pull/921 Reported-by: Matthew Leach Closes: https://lore.kernel.org/rust-for-linux/20230507084116.1099067-1-dev@mattleach.net/ Fixes: 78521f3399ab ("scripts: add `rust_is_available.sh`") Signed-off-by: Miguel Ojeda Reviewed-by: Martin Rodriguez Reboredo Reviewed-by: Nathan Chancellor Reviewed-by: Masahiro Yamada --- scripts/rust_is_available.sh | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh index 6b8131d5b547..1bdff4472cbe 100755 --- a/scripts/rust_is_available.sh +++ b/scripts/rust_is_available.sh @@ -106,8 +106,28 @@ if [ "$rust_bindings_generator_cversion" -gt "$rust_bindings_generator_min_cvers fi # Check that the `libclang` used by the Rust bindings generator is suitable. +# +# In order to do that, first invoke `bindgen` to get the `libclang` version +# found by `bindgen`. This step may already fail if, for instance, `libclang` +# is not found, thus inform the user in such a case. +bindgen_libclang_output=$( \ + LC_ALL=C "$BINDGEN" $(dirname $0)/rust_is_available_bindgen_libclang.h 2>&1 >/dev/null +) || bindgen_libclang_code=$? +if [ -n "$bindgen_libclang_code" ]; then + echo >&2 "***" + echo >&2 "*** Running '$BINDGEN' to check the libclang version (used by the Rust" + echo >&2 "*** bindings generator) failed with code $bindgen_libclang_code. This may be caused by" + echo >&2 "*** a failure to locate libclang. See output and docs below for details:" + echo >&2 "***" + echo >&2 "$bindgen_libclang_output" + echo >&2 "***" + exit 1 +fi + +# `bindgen` returned successfully, thus use the output to check that the version +# of the `libclang` found by the Rust bindings generator is suitable. bindgen_libclang_version=$( \ - LC_ALL=C "$BINDGEN" $(dirname $0)/rust_is_available_bindgen_libclang.h 2>&1 >/dev/null \ + echo "$bindgen_libclang_output" \ | grep -F 'clang version ' \ | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' \ | head -n 1 \