Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3006804rwd; Fri, 16 Jun 2023 10:55:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ77/3lIPY27Ee6ujv9pdJFfbn9cJyECdtPTyzw8fRa6S/h7DEvCWQjBHhsuSEUPgtv8jvkb X-Received: by 2002:a05:6a20:938f:b0:10c:322:72d5 with SMTP id x15-20020a056a20938f00b0010c032272d5mr3323544pzh.23.1686938154877; Fri, 16 Jun 2023 10:55:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686938154; cv=none; d=google.com; s=arc-20160816; b=MikjYkSRicTNcCaHSgUjnvycq8A8kWacVwN+z9bAkNy/aFZtDYIzpIOHWsrYLDC1vi 0uU7zQiIXJFFHrqY8f9Kuuq4dckpbhUabENUWxcPEUIWKhP6cL8gRVZQZTEN8gHPSW+Q k9UQFVWYSZQJpUDMh7FbQ+/EfAqJNs8tMIgQzN8mEdWOqFFMye+PaCrXyeljyMcejrhR Jfw4QVbBWdStH3k4IRh1XOVLk1jAcdhWHp7084yen/qrAc5l/qGe/TeqLAZquhwDh8Db 9X+M3fuIhV6ugxW+dijOJ0qsf5C00t+Qubtp3JZ2aP4/WXTpMPNSM1oZhslUXfVxi1UK MqWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=hnqD4bg8q334VeMQYEmg+Yk5wmRdfqk2dFkTIcJmMNE=; b=g2+0P2uT2ENxe+vwC/WB7VS3YVDZTmcbXl/clJrHbRI+GoNK0HHUIRjvR1bRaOqnd9 5tEbIC/azA/lcqc8HDmse8npYpGSz/V4anOYn8zSmoAPMfdw2voX+NdD7fUI6FnE/zun YlMlAmggKNH76F3/VIB+PCoVeafzPtaRexDUiy9/gm+i0YE4pHKr9KYYA7kNm+8t5Ii6 EYYkbF6vXrqZuOjan120P7MbkPoFNmmV3IzqyCDkfP2loS5Pwg6tpP0gVeds6CUHjXWt 8YWNMO0zttifdLR/FBHqiTQVMC2oviF84GP/w5bNvZ8oxwNap8zabA0Iah0mHthwWv+o IYng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fvlJYYh9; 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 t12-20020a63954c000000b0053efcd20010si14880759pgn.423.2023.06.16.10.55.42; Fri, 16 Jun 2023 10:55:54 -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=fvlJYYh9; 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 S1345984AbjFPRMF (ORCPT + 99 others); Fri, 16 Jun 2023 13:12:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230327AbjFPRME (ORCPT ); Fri, 16 Jun 2023 13:12:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1A38C5; Fri, 16 Jun 2023 10:12:02 -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 7B896631A0; Fri, 16 Jun 2023 17:12:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CDC2AC433C8; Fri, 16 Jun 2023 17:12:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686935521; bh=L5y6zXF08tEbBhI51U9tyt9pakLlguN2cCvEZbd7tFo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=fvlJYYh9UqgtrtbfwEHUD6d5Cxn22isE9KJvEunCabqSPiC0DwxlpKh62jWvavSjV I2tvLb87GVwCfNDmbHdssss04W5FcmlKkru/Uicf4Hi8e4T3sRO8uQBYLb6ZDb1Z1f G+5EQcBxalrp4c6jNaavq//anhGDXesOZM1qAcidDomfBmNPPNRUMTwcX19Iv+vYXW 0F0hC2uhm0vMxWcP2YiVGuHr3KuUGfqoRT64oPXlcd5GSk5F1wEze/Ui2KIQeiVut8 IS+83Ev7P0h2wJc2e5hhqitfyge2zKiqBUkAR1s586XRPtpgIcLD1skUhnnKLxUq/o 2Rh3ix9zoIv5A== Date: Fri, 16 Jun 2023 10:11:59 -0700 From: Nathan Chancellor To: Miguel Ojeda Cc: Masahiro Yamada , Wedson Almeida Filho , Alex Gaynor , Nick Desaulniers , Nicolas Schier , Boqun Feng , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= 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, =?iso-8859-1?Q?Fran=E7ois?= Valenduc , Alexandru Radovici , Matthew Leach Subject: Re: [PATCH v2 05/11] kbuild: rust_is_available: add check for `bindgen` invocation Message-ID: <20230616171159.GD3474164@dev-arch.thelio-3990X> References: <20230616001631.463536-1-ojeda@kernel.org> <20230616001631.463536-6-ojeda@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230616001631.463536-6-ojeda@kernel.org> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 On Fri, Jun 16, 2023 at 02:16:25AM +0200, Miguel Ojeda wrote: > `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: Nathan Chancellor > --- > 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 >