Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1859560rwd; Thu, 15 Jun 2023 17:20:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7U5oNN34Of7ya3CugXm5h5d2xCYKVT6JhXK5pXRNArBUJtwn2XGV9LSo1zdpAfLIZojXO2 X-Received: by 2002:a05:620a:944a:b0:75d:5642:2b7f with SMTP id sm10-20020a05620a944a00b0075d56422b7fmr225286qkn.0.1686874802419; Thu, 15 Jun 2023 17:20:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686874802; cv=none; d=google.com; s=arc-20160816; b=vIlgu9R6hbV0YDY1yiN02G1AjrroTOuoPMtOLKMEkLGVrq6335snO+eNz0Tyczr5eU 3IzBNIh0NDtrxx1Ho2RWU1KaTK/9kJ2r6+8jllDz4dXDr8ntkEZNLDG0eKaDx1XETEHa M/FibiZ3xy3Pc417iTpUS0mL+QfrjV+85r6elfNGhAHiwm3r96d3r075GXsqIbDZWWaB gaXyemfnvtcIaWAkjd6D/DITghAptzKFy8Dhwg6dF+tTemYQtJ1hZ3TkahSZGriD21n7 J1cxKnSjn6/ND6PJ0ybbGsktMgnOAx2JIlBlaCB9SIa/eidtBICQQuIpEzdiv9FMR6j0 gfBQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r13-20020a632b0d000000b0054fe295d487si3306024pgr.434.2023.06.15.17.19.49; Thu, 15 Jun 2023 17:20:02 -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 S229581AbjFPARa (ORCPT + 99 others); Thu, 15 Jun 2023 20:17:30 -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=20Roy=20Baron?= , 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=20Valenduc?= , 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 `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 --- 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 \ -- 2.41.0