Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7271900rwd; Mon, 19 Jun 2023 21:54:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4bS9CDKHiKCZnNvZljm50PhzinqRVkQioigMDRSNZT9vvKC39Yyx6DU5MoOfNju4c/BfXn X-Received: by 2002:a17:902:ce87:b0:1b5:6312:4c5b with SMTP id f7-20020a170902ce8700b001b563124c5bmr3744353plg.63.1687236858589; Mon, 19 Jun 2023 21:54:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687236858; cv=none; d=google.com; s=arc-20160816; b=PWEZHh0VcUvUWOw+orvIRNzPUAbFGpg8R429hvvK7A4awzmjduI/+BuGoz1wFqXIjX Szze5P4ZBFrwCdTcqwDJyjIGvkt/WVn/W38OBicKgskDaXOctmTLHtlyxVCnnxxSnIL5 VIqADpX0y23rRuz35IWMRQ6FHADy5fC2N3h3ica+yZLYBWDlAUuXRxgdQcF30xbHM5iA q8j2j/7IGHtgufz8cVcZiHPFStGnQEO7tZ+zT4505ZEuy9odvHTP3dTG0sp0QArRNIjZ WWT3ByB1c3msIZHAFhrTWj1r0NlPaHJ+GrTsYZE0q9JZNjYWqbp7Aj2vT4hYLHsuADR3 OC0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Iy4BgSehtsUlOBQZXXuGX3Pra+njVZOqgCYDRzGNhGg=; b=LBhdVcJDTrDJkiNd1LvU6sbziyL99SnNqnNjqtwTgLQhIhdDZ9ol2/TmaHD/GTJCd/ yG01uQScp4KTx62NQOGpHWs0dRnwaXAYSSKb2dVASCUqYAYWYCYks7G/qAE3V2Jfci33 pAoNUzAQN0YIPBdeyl1m7L7n7As89CMqgHlWgvf6Op7cB9EXkPqrGV2zASpm3sn7KE7b D1ZFz0ALLXFQLihuY87cRTH2jvQ/C4Je41tkwY7QBRzmxLoCIY+lhfCbvvaxj9F+IOUJ SBpt7ZsuQjk9lTISifZs82F+Pj22PyDx02sltfeRp3foGQrREGkEJo8bHu53deCH7w+l vlNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fhi4PMPD; 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 lf14-20020a170902fb4e00b001a95d336558si1073401plb.594.2023.06.19.21.54.06; Mon, 19 Jun 2023 21:54:18 -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=fhi4PMPD; 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 S230051AbjFTElc (ORCPT + 99 others); Tue, 20 Jun 2023 00:41:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229506AbjFTEla (ORCPT ); Tue, 20 Jun 2023 00:41:30 -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 0001D10C8; Mon, 19 Jun 2023 21:41:28 -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 8811E60FB6; Tue, 20 Jun 2023 04:41:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DCDC0C433C9; Tue, 20 Jun 2023 04:41:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687236087; bh=/tNS/QGR44nW36zshBiU7IiaxE+ykcQcF4Z0lFSXucQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=fhi4PMPDDVROsI6GO5TEwBwwIkMegERJHu37VzUaipq80PVe1amXKO3e3warDe5yV 3rh7xLu+Y8XM3zAVaepeathtsIfDavAcGr2Noh+C3XTdaoEwyZzERrBEgBPHPKUB8V tmw3T2YsLKN/nLV+cqDcLiTFUb5SxYFhiXaiaM5qzBLcTbDqg+fj42Fv+IxQ9rx+YK kGrBzKpb8Vg+JTL46TNfldBk0fpsCy5p0G86aKdKHsuOY/fDUx6xM4gZkwQtr8d0Bl 851yPqrqsw3pVmkoz+Lfj/9KmeEw1vfRUM96dc3pZ5PY6NqHtx+MZ4jDC5+TX4KM2i t0jUjyoIJPckg== Received: by mail-oo1-f54.google.com with SMTP id 006d021491bc7-55e4b840858so1209618eaf.1; Mon, 19 Jun 2023 21:41:27 -0700 (PDT) X-Gm-Message-State: AC+VfDzqUzMM7FXTNAVBFZmJglLMGkoqjtBjnz8u+PTOcOaIlY+m4Sjp JVQKuSTCA0R8pMqnUVDoqLaYX7PWa4/TOwnj9o8= X-Received: by 2002:a05:6808:1524:b0:39e:c806:5889 with SMTP id u36-20020a056808152400b0039ec8065889mr8808160oiw.28.1687236087177; Mon, 19 Jun 2023 21:41:27 -0700 (PDT) MIME-Version: 1.0 References: <20230616001631.463536-1-ojeda@kernel.org> <20230616001631.463536-6-ojeda@kernel.org> In-Reply-To: <20230616001631.463536-6-ojeda@kernel.org> From: Masahiro Yamada Date: Tue, 20 Jun 2023 13:40:50 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 05/11] kbuild: rust_is_available: add check for `bindgen` invocation To: Miguel Ojeda Cc: Wedson Almeida Filho , Alex Gaynor , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 9:17=E2=80=AFAM Miguel Ojeda wro= te: > > `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+RT07rCi= 6whGBM2iUAyg8A1CmLXG6Nw@mail.gmail.com/ > Reported-by: Fran=C3=A7ois 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-d= ev@mattleach.net/ > Fixes: 78521f3399ab ("scripts: add `rust_is_available.sh`") > Signed-off-by: Miguel Ojeda > --- 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 suita= ble. > +# > +# In order to do that, first invoke `bindgen` to get the `libclang` vers= ion > +# found by `bindgen`. This step may already fail if, for instance, `libc= lang` > +# is not found, thus inform the user in such a case. > +bindgen_libclang_output=3D$( \ > + LC_ALL=3DC "$BINDGEN" $(dirname $0)/rust_is_available_bindgen_lib= clang.h 2>&1 >/dev/null Nit. To avoid shellcheck warnings, you can quote as follows: "$(dirname "$0")/rust_is_available_bindgen_libclang.h" You can do shellcheck scanning to avoid new warnings. (Of course, 02/11 intentionally unquote $CC, though) > +) || bindgen_libclang_code=3D$? > +if [ -n "$bindgen_libclang_code" ]; then > + echo >&2 "***" > + echo >&2 "*** Running '$BINDGEN' to check the libclang version (u= sed by the Rust" > + echo >&2 "*** bindings generator) failed with code $bindgen_libcl= ang_code. This may be caused by" > + echo >&2 "*** a failure to locate libclang. See output and docs b= elow 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=3D$( \ > - LC_ALL=3DC "$BINDGEN" $(dirname $0)/rust_is_available_bindgen_lib= clang.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 > --=20 Best Regards Masahiro Yamada