Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp10560477rwl; Wed, 11 Jan 2023 22:48:03 -0800 (PST) X-Google-Smtp-Source: AMrXdXuOGXhm6N3IgJ1zqOG7sgcKDxWE/e1EdpFusGy+x+PzmqmOd0tGH3sLu2SD9F88oiA4QDE0 X-Received: by 2002:a17:907:2a06:b0:84d:12db:fd23 with SMTP id fd6-20020a1709072a0600b0084d12dbfd23mr17211442ejc.71.1673506082921; Wed, 11 Jan 2023 22:48:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673506082; cv=none; d=google.com; s=arc-20160816; b=D8Awrg6z3WnjSrWchCdE8zIDemxKcybJGacQI5gCJm7blVNiKfe5cy3W+JpZkn5rvo P7IIhWv28nwMF7UIS0GEu8yC5a0EC7u0hdBgnPwXfNdXiHJsHLE1oMEsVUnCTC854lzg nIaghfxWn/ndfTMw6GZMFWtauJmzqaoEYc+afxfO0cNOgpW52B7uevGlxtYUm9Rs8e6C R/FanHc85NE/4yS6YJzKfgzX9IF3rXAsCRjumSXrAMGAAicjInZrowQuoCVY8tgbynn9 66u1V2ywOml3ogJBnVzBTPPnSAGbkz/NEmP8g9FF3sR+no59UIYfxJEy8nGDP+AZzgqw lK2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=MXPuuGvYre+qj3COJ8lWbz8MyupglRxp7Fwke1njLSk=; b=BsvEmaswRDZChWMSaypTwabLIwS8yt5wiZf7ga2+0Xy93AAii/mnJx6ey1PqpIYXl8 ZZVqr3qGZTC6kUH7RLlw24HYH+RJdCq5Kzk5xtLNNk3ocv5oNPZkcj1ZsFCmMvhW4RJV +xLc8srzQxVhdo1mByEATupomnjtdRBz9d4dPjX1qDQ6DpZ7WkApDgmJHky68bWZXJUs EVppOlw2zmeCYhX5NDoIQHP5vC+IN6cIE9qezrRvUThpBEPfmGeKFvDiw7mnWarTenT4 kbrdr0mH/ZME9bCdcDvhWfd7Zei5+sR6PEskQ22uXdmHk4Y4dpWnuzJbAZfb6a+HNVeo lidQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tjfdD0GG; 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 hd41-20020a17090796a900b007c0c0d7c4c8si17532011ejc.44.2023.01.11.22.47.49; Wed, 11 Jan 2023 22:48:02 -0800 (PST) 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=tjfdD0GG; 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 S235881AbjALF3U (ORCPT + 51 others); Thu, 12 Jan 2023 00:29:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231268AbjALF3R (ORCPT ); Thu, 12 Jan 2023 00:29:17 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 419E11B9F9; Wed, 11 Jan 2023 21:29:16 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id EAA48B81DCF; Thu, 12 Jan 2023 05:29:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9904DC433F1; Thu, 12 Jan 2023 05:29:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673501353; bh=NIDeF0qr5dTfp6q3dFL1NSocIKxhkjUOWkIF2RxNI90=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=tjfdD0GGQqh3mHroEoMk0jBfLGyj+vGhPLBwXwDJAlSgG+WtOMJtNd8X3Di012NpT ywCQ0wUqyU6zBYOYkAOHHaxAfJt6SDWWPJN7UQnfY5nNDofJkbPTzx3+0RKSSH4XX4 me0NScf4zyV0+gwM4DpHNAmbsm2LeXV5awASpwQBHq1kSeGjiXmtqCcdlmfFfnu5r5 5bfJOPQukomdQEW09Ocb1VB+r44MZn0BBHOuU25c5RujHL0L9V+/TuF4jTY6zPwqw+ 4aMvOIdAfn2pil+zbhzeSOl77lJ+97mpiYTo1o+JJbOwAKfm2GI6cGVtn7cN+qLQOe LZ//3R+TzK3aQ== Received: by mail-ot1-f53.google.com with SMTP id r2-20020a9d7cc2000000b006718a7f7fbaso10041177otn.2; Wed, 11 Jan 2023 21:29:13 -0800 (PST) X-Gm-Message-State: AFqh2krAoR2emqALr+2xstj1xgh5o+Jewp+FZ6wN8ZSmQmkqTepMp67m kUoDV0njXP2HnsPvPx+N+lpKoMf+NtbUX2eHLyY= X-Received: by 2002:a05:6830:31a8:b0:684:c0c2:59c6 with SMTP id q8-20020a05683031a800b00684c0c259c6mr124477ots.343.1673501352782; Wed, 11 Jan 2023 21:29:12 -0800 (PST) MIME-Version: 1.0 References: <20230109204520.539080-1-ojeda@kernel.org> <20230109204520.539080-4-ojeda@kernel.org> In-Reply-To: <20230109204520.539080-4-ojeda@kernel.org> From: Masahiro Yamada Date: Thu, 12 Jan 2023 14:28:36 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 4/6] kbuild: rust_is_available: check if the script was invoked from Kbuild To: Miguel Ojeda Cc: linux-kbuild@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= Content-Type: text/plain; charset="UTF-8" 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 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 Tue, Jan 10, 2023 at 5:46 AM Miguel Ojeda wrote: > > Sometimes [1] users may attempt to setup the Rust support by > checking what Kbuild does and they end up finding out about > `scripts/rust_is_available.sh`. Inevitably, they run the script > directly, but unless they setup the required variables, > the result of the script is not meaningful. > > We could add some defaults to the variables, but that could be > confusing for those that may override the defaults (compared > to their kernel builds), and `$CC` would not be a simple default > in any case. > > Therefore, instead, print a warning when the script detects > the user may be invoking it, by testing `$MAKEFLAGS`. > > Link: https://lore.kernel.org/oe-kbuild-all/Y6r4mXz5NS0+HVXo@zn.tnic/ [1] > Signed-off-by: Miguel Ojeda > --- > scripts/rust_is_available.sh | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh > index cd87729ca3bf..0c082a248f15 100755 > --- a/scripts/rust_is_available.sh > +++ b/scripts/rust_is_available.sh > @@ -35,6 +35,16 @@ print_docs_reference() > warning=0 > trap 'if [ $? -ne 0 ] || [ $warning -ne 0 ]; then print_docs_reference; fi' EXIT > > +# Check whether the script was invoked from Kbuild. > +if [ -z "${MAKEFLAGS+x}" ]; then > + echo >&2 "***" > + echo >&2 "*** This script is intended to be called from Kbuild." > + echo >&2 "*** Please use the 'rustavailable' target to call it instead." > + echo >&2 "*** Otherwise, the results may not be meaningful." > + echo >&2 "***" > + warning=1 > +fi I do not like this. We do not need to cater to every oddity. Checking MAKEFLAGS is too much. You can check RUSTC/BINDGEN/CC if you persist in this. diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh index a6f84dd2f71c..524aee03384a 100755 --- a/scripts/rust_is_available.sh +++ b/scripts/rust_is_available.sh @@ -34,7 +34,7 @@ warning=0 trap 'if [ $? -ne 0 ] || [ $warning -ne 0 ]; then print_docs_reference; fi' EXIT # Check that the Rust compiler exists. -if ! command -v "$RUSTC" >/dev/null; then +if ! command -v "${RUSTC:?RUSTC is not set}" >/dev/null; then echo >&2 "***" echo >&2 "*** Rust compiler '$RUSTC' could not be found." echo >&2 "***" @@ -42,7 +42,7 @@ if ! command -v "$RUSTC" >/dev/null; then fi # Check that the Rust bindings generator exists. -if ! command -v "$BINDGEN" >/dev/null; then +if ! command -v "${BINDGEN:?BINDGEN is not set}" >/dev/null; then echo >&2 "***" echo >&2 "*** Rust bindings generator '$BINDGEN' could not be found." echo >&2 "***" @@ -150,7 +150,7 @@ fi # # In the future, we might be able to perform a full version check, see # https://github.com/rust-lang/rust-bindgen/issues/2138. -cc_name=$($(dirname $0)/cc-version.sh "$CC" | cut -f1 -d' ') +cc_name=$($(dirname $0)/cc-version.sh ${CC:?CC is not set} | cut -f1 -d' ') if [ "$cc_name" = Clang ]; then clang_version=$( \ LC_ALL=C "$CC" --version 2>/dev/null \ -- Best Regards Masahiro Yamada