From patchwork Fri Jun 16 00:16:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 108765 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp997264vqr; Thu, 15 Jun 2023 17:19:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4w0rwjVvqF8Earyzd8/zygKZlm9dxu5ll0rzDpfS5S38GvWBS7DZRBE3Zg/VjkTU1uScbx X-Received: by 2002:a05:6359:b94:b0:129:bddf:7960 with SMTP id gf20-20020a0563590b9400b00129bddf7960mr214656rwb.16.1686874792627; Thu, 15 Jun 2023 17:19:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686874792; cv=none; d=google.com; s=arc-20160816; b=FwXg2gx92TuXbTOKHI8fGpZj2TuI/fAbmvnV+NcEwWFXiv6dU/crM9QG6gWPB00W6q H0lfZVT38XxsXGO0gwiwHQOmQtsx0FvY3bg8xCGFy401W3qtoZpSIt9IzzZbRRe1phl7 hHgkcfqINLeDHXihB8PeADnCa3gqOSYtHYnyoBqy+TO5UjlA8Ys7Xa5E1lRHxs8uErSx fsxjlcy6imJU/aMq3Izduxukh8W4qOtFHRf/Q8D/JHhtUQXLESnAOibdMUDjHpliGhAW 6qALuSI36zBEDierC1bTlS9KJ+6mIMH8AQMksmam45ptCoBB62Upk7xY6UlFm5loJ8xb ipQw== 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=5tKhJX70/mdfyVDfmSS7y6+B7F4tSzhpuATTAt9iitc=; b=k2EwCCTSV71OG2P3mC8WuuRZ4YQh/0sFWeOCfBgxl4OKw5jwy6i/sOlN2PMWrF5c3N rFnG9VvLi1RJXEaAHb0EMCp2M+24dU7FlJDERzlSXnYjAI66ObI1w9aX3FAkTQ8IdUrS 4aEdPQPyuRKd4LUTbUPHqxTjwlfTC6iroOfd91xeKQJUPkiA5y20ew8adQyYACi8XDux EpMvmP3JpSFPVrXcv/Z3osYHusZkC63czVcHq/CIG9mL9X78kXVbAv3XZZHAzfWDcEe7 rLLfMgfIEUNa2iSQZGzg4+JoR1WFQSbA0OTL0ujUrc/OePZm3HCj6Q4SlRMgx61flA0f aKyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=j798rhKk; 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 v10-20020a63610a000000b0054fd8d57b1esi4223677pgb.668.2023.06.15.17.19.38; Thu, 15 Jun 2023 17:19:52 -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=j798rhKk; 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 S240130AbjFPARE (ORCPT + 99 others); Thu, 15 Jun 2023 20:17:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239804AbjFPAQ7 (ORCPT ); Thu, 15 Jun 2023 20:16:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9114A273C; Thu, 15 Jun 2023 17:16:58 -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 27AF061C81; Fri, 16 Jun 2023 00:16:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6EA06C433CA; Fri, 16 Jun 2023 00:16:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686874617; bh=1TOdHb4awwmt33Y2juISrDKX0ZSbj4m/jNHG4AXa3h0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j798rhKkKHglydpWr9mK5/3UgZ1jtvcRUJ8DYg1uYFDFdaU1lNH+fUmtvVad8FEsz 3VA805uGEmWh6nfTBIXxQgULRenQCk4GEFymOXp6MVDNoPrqA6INQy+mqpBpafABdc bqWF2jYWHl/UBgnsloxtvGdzJbRt10rdKS2Z2+Bd2CX2ryJUxp3AQ6iBYOOPCg3EOg atOm+PjM2xmvAmhVUCbIEdq0Pr6QLpRxYQSCDuhLvjFWAUurQNmWVWJv47vhkCYSEp ok8uB/GPf95kXba80olVD9sNWbds36FgouqhHkN6UwkDHq+hEr7ks0EsUo9gf3nRpv 3ZfGZDSIJS0cQ== 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 Subject: [PATCH v2 01/11] kbuild: rust_is_available: remove -v option Date: Fri, 16 Jun 2023 02:16:21 +0200 Message-ID: <20230616001631.463536-2-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,URIBL_BLOCKED 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?1768816422584708824?= X-GMAIL-MSGID: =?utf-8?q?1768816422584708824?= From: Masahiro Yamada The -v option is passed when this script is invoked from Makefile, but not when invoked from Kconfig. As you can see in scripts/Kconfig.include, the 'success' macro suppresses stdout and stderr anyway, so this script does not need to be quiet. Signed-off-by: Masahiro Yamada Reviewed-by: Miguel Ojeda Tested-by: Miguel Ojeda Reviewed-by: Nathan Chancellor Link: https://lore.kernel.org/r/20230109061436.3146442-1-masahiroy@kernel.org [ Reworded prefix to match the others in the patch series. ] Signed-off-by: Miguel Ojeda Reviewed-by: Martin Rodriguez Reboredo --- Makefile | 4 +- scripts/rust_is_available.sh | 96 +++++++++++++++--------------------- 2 files changed, 42 insertions(+), 58 deletions(-) diff --git a/Makefile b/Makefile index 0d3a9d3e73c1..f0c50c7bd6d2 100644 --- a/Makefile +++ b/Makefile @@ -1289,7 +1289,7 @@ prepare0: archprepare # All the preparing.. prepare: prepare0 ifdef CONFIG_RUST - $(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh -v + $(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh $(Q)$(MAKE) $(build)=rust endif @@ -1823,7 +1823,7 @@ $(DOC_TARGETS): # "Is Rust available?" target PHONY += rustavailable rustavailable: - $(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh -v && echo "Rust is available!" + $(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh && echo "Rust is available!" # Documentation target # diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh index aebbf1913970..f43a010eaf30 100755 --- a/scripts/rust_is_available.sh +++ b/scripts/rust_is_available.sh @@ -2,8 +2,6 @@ # SPDX-License-Identifier: GPL-2.0 # # Tests whether a suitable Rust toolchain is available. -# -# Pass `-v` for human output and more checks (as warnings). set -e @@ -23,21 +21,17 @@ get_canonical_version() # Check that the Rust compiler exists. if ! command -v "$RUSTC" >/dev/null; then - if [ "$1" = -v ]; then - echo >&2 "***" - echo >&2 "*** Rust compiler '$RUSTC' could not be found." - echo >&2 "***" - fi + echo >&2 "***" + echo >&2 "*** Rust compiler '$RUSTC' could not be found." + echo >&2 "***" exit 1 fi # Check that the Rust bindings generator exists. if ! command -v "$BINDGEN" >/dev/null; then - if [ "$1" = -v ]; then - echo >&2 "***" - echo >&2 "*** Rust bindings generator '$BINDGEN' could not be found." - echo >&2 "***" - fi + echo >&2 "***" + echo >&2 "*** Rust bindings generator '$BINDGEN' could not be found." + echo >&2 "***" exit 1 fi @@ -53,16 +47,14 @@ rust_compiler_min_version=$($min_tool_version rustc) rust_compiler_cversion=$(get_canonical_version $rust_compiler_version) rust_compiler_min_cversion=$(get_canonical_version $rust_compiler_min_version) if [ "$rust_compiler_cversion" -lt "$rust_compiler_min_cversion" ]; then - if [ "$1" = -v ]; then - echo >&2 "***" - echo >&2 "*** Rust compiler '$RUSTC' is too old." - echo >&2 "*** Your version: $rust_compiler_version" - echo >&2 "*** Minimum version: $rust_compiler_min_version" - echo >&2 "***" - fi + echo >&2 "***" + echo >&2 "*** Rust compiler '$RUSTC' is too old." + echo >&2 "*** Your version: $rust_compiler_version" + echo >&2 "*** Minimum version: $rust_compiler_min_version" + echo >&2 "***" exit 1 fi -if [ "$1" = -v ] && [ "$rust_compiler_cversion" -gt "$rust_compiler_min_cversion" ]; then +if [ "$rust_compiler_cversion" -gt "$rust_compiler_min_cversion" ]; then echo >&2 "***" echo >&2 "*** Rust compiler '$RUSTC' is too new. This may or may not work." echo >&2 "*** Your version: $rust_compiler_version" @@ -82,16 +74,14 @@ rust_bindings_generator_min_version=$($min_tool_version bindgen) rust_bindings_generator_cversion=$(get_canonical_version $rust_bindings_generator_version) rust_bindings_generator_min_cversion=$(get_canonical_version $rust_bindings_generator_min_version) if [ "$rust_bindings_generator_cversion" -lt "$rust_bindings_generator_min_cversion" ]; then - if [ "$1" = -v ]; then - echo >&2 "***" - echo >&2 "*** Rust bindings generator '$BINDGEN' is too old." - echo >&2 "*** Your version: $rust_bindings_generator_version" - echo >&2 "*** Minimum version: $rust_bindings_generator_min_version" - echo >&2 "***" - fi + echo >&2 "***" + echo >&2 "*** Rust bindings generator '$BINDGEN' is too old." + echo >&2 "*** Your version: $rust_bindings_generator_version" + echo >&2 "*** Minimum version: $rust_bindings_generator_min_version" + echo >&2 "***" exit 1 fi -if [ "$1" = -v ] && [ "$rust_bindings_generator_cversion" -gt "$rust_bindings_generator_min_cversion" ]; then +if [ "$rust_bindings_generator_cversion" -gt "$rust_bindings_generator_min_cversion" ]; then echo >&2 "***" echo >&2 "*** Rust bindings generator '$BINDGEN' is too new. This may or may not work." echo >&2 "*** Your version: $rust_bindings_generator_version" @@ -110,13 +100,11 @@ bindgen_libclang_min_version=$($min_tool_version llvm) bindgen_libclang_cversion=$(get_canonical_version $bindgen_libclang_version) bindgen_libclang_min_cversion=$(get_canonical_version $bindgen_libclang_min_version) if [ "$bindgen_libclang_cversion" -lt "$bindgen_libclang_min_cversion" ]; then - if [ "$1" = -v ]; then - echo >&2 "***" - echo >&2 "*** libclang (used by the Rust bindings generator '$BINDGEN') is too old." - echo >&2 "*** Your version: $bindgen_libclang_version" - echo >&2 "*** Minimum version: $bindgen_libclang_min_version" - echo >&2 "***" - fi + echo >&2 "***" + echo >&2 "*** libclang (used by the Rust bindings generator '$BINDGEN') is too old." + echo >&2 "*** Your version: $bindgen_libclang_version" + echo >&2 "*** Minimum version: $bindgen_libclang_min_version" + echo >&2 "***" exit 1 fi @@ -125,21 +113,19 @@ fi # # In the future, we might be able to perform a full version check, see # https://github.com/rust-lang/rust-bindgen/issues/2138. -if [ "$1" = -v ]; then - cc_name=$($(dirname $0)/cc-version.sh "$CC" | cut -f1 -d' ') - if [ "$cc_name" = Clang ]; then - clang_version=$( \ - LC_ALL=C "$CC" --version 2>/dev/null \ - | sed -nE '1s:.*version ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p' - ) - if [ "$clang_version" != "$bindgen_libclang_version" ]; then - echo >&2 "***" - echo >&2 "*** libclang (used by the Rust bindings generator '$BINDGEN')" - echo >&2 "*** version does not match Clang's. This may be a problem." - echo >&2 "*** libclang version: $bindgen_libclang_version" - echo >&2 "*** Clang version: $clang_version" - echo >&2 "***" - fi +cc_name=$($(dirname $0)/cc-version.sh "$CC" | cut -f1 -d' ') +if [ "$cc_name" = Clang ]; then + clang_version=$( \ + LC_ALL=C "$CC" --version 2>/dev/null \ + | sed -nE '1s:.*version ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p' + ) + if [ "$clang_version" != "$bindgen_libclang_version" ]; then + echo >&2 "***" + echo >&2 "*** libclang (used by the Rust bindings generator '$BINDGEN')" + echo >&2 "*** version does not match Clang's. This may be a problem." + echo >&2 "*** libclang version: $bindgen_libclang_version" + echo >&2 "*** Clang version: $clang_version" + echo >&2 "***" fi fi @@ -150,11 +136,9 @@ rustc_sysroot=$("$RUSTC" $KRUSTFLAGS --print sysroot) rustc_src=${RUST_LIB_SRC:-"$rustc_sysroot/lib/rustlib/src/rust/library"} rustc_src_core="$rustc_src/core/src/lib.rs" if [ ! -e "$rustc_src_core" ]; then - if [ "$1" = -v ]; then - echo >&2 "***" - echo >&2 "*** Source code for the 'core' standard library could not be found" - echo >&2 "*** at '$rustc_src_core'." - echo >&2 "***" - fi + echo >&2 "***" + echo >&2 "*** Source code for the 'core' standard library could not be found" + echo >&2 "*** at '$rustc_src_core'." + echo >&2 "***" exit 1 fi From patchwork Fri Jun 16 00:16:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 108766 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp997277vqr; Thu, 15 Jun 2023 17:19:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ531T40VRxcHqd3LKnrgg0XoYGzToWt1uwIMvY87FNHKqg1xIYAMnDiOaUCG1HVrRjQ0y8d X-Received: by 2002:a05:6808:d51:b0:399:8529:6726 with SMTP id w17-20020a0568080d5100b0039985296726mr814206oik.51.1686874794430; Thu, 15 Jun 2023 17:19:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686874794; cv=none; d=google.com; s=arc-20160816; b=cqmxZh+uifNYYvM+GzOEL+TL71IjHI3LovDSYKJd2XC7krXoke5AcB3Cbwomg8SiHt vQiR3ISUbrjT+u4F5J+u9Bv0jJPNYzJa+fvtnLNKc8SiJActVRv2yAbEWhC2kTGM7vnT ijowQmMyTQ0lqnyKcD+r2Guy4WNmXuov3yj0Ugx8PvN+9niuCKBmMg35KoMolGzxTJMK ugZ4zprdzI23W1fxWCBi++BpF9K8DaMzKaWnKVJVgLB9e0vCGYoYvRuhcw+oFaGWBvWf CjndtXabIOqFlHqpqVXkb5OJxboV+HqjBIW6kqnRB7FS5fLQ3UlK/yNTCNfcRcb9rfMH YO2w== 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=vpfxxwHJe3W9VZYIkDAYgzuz9DA/FTw6maxjX+yv1i0=; b=yPnk3CYcy8TyqCwQY09EOIzWiJKnAMvkScy/BLJoHtGyF0XHDjGiiXvaFxHyUxSdFs dnqD66O+gI/TCDB6ogAuKuf+RbrGPgUgnbig9EcBsWC8/WEhKLs1dkTNVHZ3xKwjLJyL xjOXF2hwNuekso9kO5zA0WvVO5vmsqmStALw+1+15fW9sNM+P36hwSIc8jdz/jfa4aMG Y0pbcxZZeZUoTi2i4sLAhUF9LhT0ehEFnIwO2sXzC6J3eooEuugZaJS7iH71YvbLnXDd gtaoq643EwltPsxBd/jQAX6rjCGPI6i1h/I7Sk180DxOmqMSKasR4OeVzSoirZkUXFmt I6bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lR3gCslZ; 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 k189-20020a633dc6000000b0053eedcd4d81si13916306pga.101.2023.06.15.17.19.39; Thu, 15 Jun 2023 17:19: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=lR3gCslZ; 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 S240563AbjFPARH (ORCPT + 99 others); Thu, 15 Jun 2023 20:17:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240508AbjFPARE (ORCPT ); Thu, 15 Jun 2023 20:17:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 610F22944; Thu, 15 Jun 2023 17:17:03 -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 E8F6061CDB; Fri, 16 Jun 2023 00:17:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E47CCC433C8; Fri, 16 Jun 2023 00:16:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686874622; bh=CG+nA737Ne3Ravt2rZwGSjf5nReCzoy15WvmtU+wHWo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lR3gCslZ4vHZLbRAmDnKtb5u2/yufUzYTAGEMOQQW/VbICIINE5k6cxPy6LY/3egY 9r+Ferze24Bqk9vhbg3jE95QIJ+CZ+hQI/zMUSaQzcPHbfLgUMZCkOqjwbkgX8DxcK s4WTNY3jEJiBpZGXkIpLy+xOcMzDqNR026Sr6M0VzRBKga6OCq67RAUbsh+rfXXAC3 oms90zuaeA92CdqYFWQeVp77+B6WxjolQHGLJg8QsYO+OWtCqwYiIReG/3EKYAn/uz g5P27JmMgNQMOgnSqaXia+I5jM1Mi2dE38CkrrACVxjaC52vQeZZnxkroIzzvxomBD WRif/mxmxdNZw== 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, Russell Currey Subject: [PATCH v2 02/11] kbuild: rust_is_available: fix version check when CC has multiple arguments Date: Fri, 16 Jun 2023 02:16:22 +0200 Message-ID: <20230616001631.463536-3-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,URIBL_BLOCKED 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?1768816424415555880?= X-GMAIL-MSGID: =?utf-8?q?1768816424415555880?= From: Russell Currey rust_is_available.sh uses cc-version.sh to identify which C compiler is in use, as scripts/Kconfig.include does. cc-version.sh isn't designed to be able to handle multiple arguments in one variable, i.e. "ccache clang". Its invocation in rust_is_available.sh quotes "$CC", which makes $1 == "ccache clang" instead of the intended $1 == ccache & $2 == clang. cc-version.sh could also be changed to handle having "ccache clang" as one argument, but it only has the one consumer upstream, making it simpler to fix the caller here. Signed-off-by: Russell Currey Fixes: 78521f3399ab ("scripts: add `rust_is_available.sh`") Link: https://github.com/Rust-for-Linux/linux/pull/873 [ Reworded title prefix and reflow line to 75 columns. ] Signed-off-by: Miguel Ojeda Reviewed-by: Martin Rodriguez Reboredo Reviewed-by: Nathan Chancellor --- scripts/rust_is_available.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh index f43a010eaf30..0c9be438e4cd 100755 --- a/scripts/rust_is_available.sh +++ b/scripts/rust_is_available.sh @@ -113,10 +113,10 @@ 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 | cut -f1 -d' ') if [ "$cc_name" = Clang ]; then clang_version=$( \ - LC_ALL=C "$CC" --version 2>/dev/null \ + LC_ALL=C $CC --version 2>/dev/null \ | sed -nE '1s:.*version ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p' ) if [ "$clang_version" != "$bindgen_libclang_version" ]; then From patchwork Fri Jun 16 00:16:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 108775 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1014725vqr; Thu, 15 Jun 2023 18:06:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ71K8ZxTH+hAVfDEzk/8sIB09f/0fJztzK3pbeNxpyp9iwVrebSKwQTH3/9ivqPT07i5Mqu X-Received: by 2002:a92:d7d2:0:b0:335:542b:aa48 with SMTP id g18-20020a92d7d2000000b00335542baa48mr1131487ilq.19.1686877590488; Thu, 15 Jun 2023 18:06:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686877590; cv=none; d=google.com; s=arc-20160816; b=L+vfe8fq+palnFrf7bpwbEYLIBJ/yPjdAw78p2KdpXiWrJPe+YIWrXgS1eT4zjEv9d WWIKM+B4iAfMQuSWqfVoIhntkDoBXtg2nH4LpJf090SmgU5mMS6bq43FLs6GNhTU0sy1 nm04YdIYwqJ8lwnYNFCbzSWatJQeMua7sYlwkJB23Y/0/UgcqaufdzKCnUov/cPvLuea ahvqVwfeGjaEOjiieY16asIsuHqLxXw9eAKWlaRJbc2BESwaQG4Tt6qN9c5r0DuJGxoy iDe3G3A0pXjYWP4OleFZMlqoSpBTRSLZcUjFhVK0ZyRk/pSE8+aX3GjKkaDgTCqmKYKV SONA== 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=M+5v9diAp8b0yNGRLW7Tlt4A1WqNagR0koI16JPqzvU=; b=VUTn0rfsNpZsCPbips8jTU1K6JUlILs5kEswFesRMLrP6k3ebtLgFWOX3mGtKSG+34 g34uIQpEdqetPJUQcAxgdAAh17a0pOHTfrmZSReARJNfy8KNJiuJTc1OrshxC+YU9ZVC yjRSPyXfKOP9UBsXCccNqbiOl4By8wCjruouBJ9d0FK1+QsnS2Yn+tvjMP5fO58tzjn3 DqodXkn8s/O5mbrEy1cn9I+RUzgOmTw1pul7mr0/Kq99FjjBPO+6Ys61YqtqCdBEmOCx aRjn0pdnnRvpYka9KfqAY1V41ERD8iG1V8BSp8N80FbdotkyZl8wduSTeE5cjBJjRGp2 SRSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sAANV7Aa; 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 v10-20020a63610a000000b0053eedcc504esi4242288pgb.373.2023.06.15.18.06.12; Thu, 15 Jun 2023 18:06:30 -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=sAANV7Aa; 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 S239840AbjFPARP (ORCPT + 99 others); Thu, 15 Jun 2023 20:17:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240648AbjFPARN (ORCPT ); Thu, 15 Jun 2023 20:17:13 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08129295B; Thu, 15 Jun 2023 17:17:07 -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 5422C61C11; Fri, 16 Jun 2023 00:17:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9BE0AC433CD; Fri, 16 Jun 2023 00:17:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686874626; bh=i3yIt3pkJh1+yUPFZ2G1YGSS4ROB0KkdEUSk4yxp0Ss=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sAANV7AatCJDD5oIOQhzC31TL4IJzbcwCNNtTfHTXGsc3Voolri0GhPM7HWCvwQry GQP8dhHnA592zxKc/Mw4DxvACL9NdTytHbD24ZCRu3HAXOvucHC2fFpW7xyPC8e7M7 iksHH4m0blCrS0TicmOHejS6oghpsFXYr6DIWtuw6nu6BLqvkiyOAT7n+VHRMO21Ei TqqM1BRaYTvx9a13Lh57duNLrOOeuIkNbCSpWMyQbaRGWCuNLRVG0vRLdpPcVPv+QF qzYPXGfSoWL9l96/1MXpVS9f+PaW18l/tpp4EJnu0/sO25exf/ALSGcOM45pA4juWK 9yHEVMxa8Ujhg== 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 Subject: [PATCH v2 03/11] docs: rust: add paragraph about finding a suitable `libclang` Date: Fri, 16 Jun 2023 02:16:23 +0200 Message-ID: <20230616001631.463536-4-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,URIBL_BLOCKED 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?1768819356246527190?= X-GMAIL-MSGID: =?utf-8?q?1768819356246527190?= Sometimes users need to tweak the finding process of `libclang` for `bindgen` via the `clang-sys`-provided environment variables. Thus add a paragraph to the setting up guide, including a reference to `clang-sys`'s relevant documentation. Link: https://lore.kernel.org/rust-for-linux/CAKwvOdm5JT4wbdQQYuW+RT07rCi6whGBM2iUAyg8A1CmLXG6Nw@mail.gmail.com/ Reviewed-by: Nick Desaulniers Signed-off-by: Miguel Ojeda Reviewed-by: Martin Rodriguez Reboredo Reviewed-by: Nathan Chancellor --- Documentation/rust/quick-start.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Documentation/rust/quick-start.rst b/Documentation/rust/quick-start.rst index 13b7744b1e27..a635be69e062 100644 --- a/Documentation/rust/quick-start.rst +++ b/Documentation/rust/quick-start.rst @@ -100,6 +100,23 @@ Install it via (note that this will download and build the tool from source):: cargo install --locked --version $(scripts/min-tool-version.sh bindgen) bindgen +``bindgen`` needs to find a suitable ``libclang`` in order to work. If it is +not found (or a different ``libclang`` than the one found should be used), +the process can be tweaked using the environment variables understood by +``clang-sys`` (the Rust bindings crate that ``bindgen`` uses to access +``libclang``): + +* ``LLVM_CONFIG_PATH`` can be pointed to an ``llvm-config`` executable. + +* Or ``LIBCLANG_PATH`` can be pointed to a ``libclang`` shared library + or to the directory containing it. + +* Or ``CLANG_PATH`` can be pointed to a ``clang`` executable. + +For details, please see ``clang-sys``'s documentation at: + + https://github.com/KyleMayes/clang-sys#environment-variables + Requirements: Developing ------------------------ From patchwork Fri Jun 16 00:16:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 108772 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1001632vqr; Thu, 15 Jun 2023 17:31:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4VK2pgiyS7NiSzPFWic4d2gsq6cT8D/zloz6HdM9S8YEZqcfho5BKcjVp3E7lI5PDwjxZ/ X-Received: by 2002:a05:6359:63a7:b0:129:c6d1:2176 with SMTP id sg39-20020a05635963a700b00129c6d12176mr235850rwb.15.1686875483274; Thu, 15 Jun 2023 17:31:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686875483; cv=none; d=google.com; s=arc-20160816; b=svYoNuG6A/HW/D3x0+NEXdvlGldbYuP0e/lheu/HZLNYZviNj/8So7TaUglNGjRvVN La5G5K+gOalEmJ/aW+1zD86Q7o+WTrNlrXL3VeIt5ORiDRY2gRtGC/6pItyp9fzvy8Fl /eF7hCi3JizExOdjofY+i6W0fRbSEoe9buoU6q9S8oqUKkmihohhUxpfm1WHTf8VqAnS UTsZzjqaxxLN7a+jTK6GuC4Qklsoo5zfpHw58k63HB9/uTM6WRgAK8XXiVMa0gInGRI1 MypCd1p4o/SpGeBueAVLvtJGXlrT8qFRTi5YmqXzEm1gngd+4wmwvlSq8dHADP0UbxjN RwOQ== 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=eRC6Jjp/XETjXZBw+sdrxc+zYNeCbZjRXXN6LACJX34=; b=1BKEOqKJpmrwFeIRxBdun/v8Mmyz+UwjXlBGA811NfVVBf7IuuJfhK9/8t/l3K3UAP 15/uH+Fxr4JA6nOaVAx5U+bCqx8OruCxX5TfHJW+XNeC3KXrS+Is+PtyL7b6OYDVEX3X paDRkka8WfmRedjeamGxHtPVknaMcpriocZpO3lhVqObGUz14r9k/y4fmEmRWpORDmC2 s+4T79LKr17tnOJrlHdWwT/bf3c0TeqMsjKTCYJ6kpuDSyUbJiG+FGUXVNXuYdQnnGxD xIUIa03fHveTVsTP5+M1kE7UhJtdOiOP7GSzIN/B2ju2+/ETyDQF7GkcPMhQX4VgcQHJ nT6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uy2ENEAr; 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 s198-20020a6377cf000000b0054ff3c2b9a9si2523396pgc.821.2023.06.15.17.31.09; Thu, 15 Jun 2023 17:31:23 -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=uy2ENEAr; 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 S240696AbjFPARW (ORCPT + 99 others); Thu, 15 Jun 2023 20:17:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229581AbjFPARS (ORCPT ); Thu, 15 Jun 2023 20:17:18 -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 D17BC2D6D; Thu, 15 Jun 2023 17:17:12 -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 0ACEC61C11; Fri, 16 Jun 2023 00:17:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20220C433C9; Fri, 16 Jun 2023 00:17:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686874631; bh=cgdU9EGPRg6prCiiXBlnJGZt5RUNOs2rhZy64y+yRgQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uy2ENEAr/f8o6ANqBrRm6AEU4+yZtU9A/j7+UT5Sff8RLmebqkp0vQSBp/eCF15pH s8aCj7Lb/siKDnQcXqOUVMYMZ34TOxSKP4Ym2WRFR7/jirD+RxVoXilgirqxD7/J50 519N1mXDhUGFqXTasW+85yF03Y68AQ4DABOrhWgJDxX2Te5l8AFKO6OR/2GS7q5BkD xwjRKGVE/obw9oQARJYlZPdA050EWfOse9LiMn/ORztl6jmTnbSu67EIV0Ye/nzrmV DXdD3uVIsUCusggpYa9EZ3KT5T6axCUYzxFVk7ICTXBtZKa0LMaBWlQMtnJF9N+wTp u8zjvh7D4hECQ== 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, Finn Behrens Subject: [PATCH v2 04/11] kbuild: rust_is_available: print docs reference Date: Fri, 16 Jun 2023 02:16:24 +0200 Message-ID: <20230616001631.463536-5-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=-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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768817146925006560?= X-GMAIL-MSGID: =?utf-8?q?1768817146925006560?= People trying out the Rust support in the kernel may get warnings and errors from `scripts/rust_is_available.sh` from the `rustavailable` target or the build step. Some of those users may be following the Quick Start guide, but others may not (likely those getting warnings from the build step instead of the target). While the messages are fairly clear on what the problem is, it may not be clear how to solve the particular issue, especially for those not aware of the documentation. We could add all sorts of details on the script for each one, but it is better to point users to the documentation instead, where it is easily readable in different formats. It also avoids duplication. Thus add a reference to the documentation whenever the script fails or there is at least a warning. Reviewed-by: Finn Behrens Signed-off-by: Miguel Ojeda Reviewed-by: Martin Rodriguez Reboredo Reviewed-by: Nathan Chancellor Reviewed-by: Masahiro Yamada --- scripts/rust_is_available.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh index 0c9be438e4cd..6b8131d5b547 100755 --- a/scripts/rust_is_available.sh +++ b/scripts/rust_is_available.sh @@ -19,6 +19,20 @@ get_canonical_version() echo $((100000 * $1 + 100 * $2 + $3)) } +# Print a reference to the Quick Start guide in the documentation. +print_docs_reference() +{ + echo >&2 "***" + echo >&2 "*** Please see Documentation/rust/quick-start.rst for details" + echo >&2 "*** on how to set up the Rust support." + echo >&2 "***" +} + +# If the script fails for any reason, or if there was any warning, then +# print a reference to the documentation on exit. +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 echo >&2 "***" @@ -60,6 +74,7 @@ if [ "$rust_compiler_cversion" -gt "$rust_compiler_min_cversion" ]; then echo >&2 "*** Your version: $rust_compiler_version" echo >&2 "*** Expected version: $rust_compiler_min_version" echo >&2 "***" + warning=1 fi # Check that the Rust bindings generator is suitable. @@ -87,6 +102,7 @@ if [ "$rust_bindings_generator_cversion" -gt "$rust_bindings_generator_min_cvers echo >&2 "*** Your version: $rust_bindings_generator_version" echo >&2 "*** Expected version: $rust_bindings_generator_min_version" echo >&2 "***" + warning=1 fi # Check that the `libclang` used by the Rust bindings generator is suitable. @@ -126,6 +142,7 @@ if [ "$cc_name" = Clang ]; then echo >&2 "*** libclang version: $bindgen_libclang_version" echo >&2 "*** Clang version: $clang_version" echo >&2 "***" + warning=1 fi fi 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 \ From patchwork Fri Jun 16 00:16:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 108771 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp999793vqr; Thu, 15 Jun 2023 17:26:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5CzoEvitgSdPtZjtnPpmKairbo6JHnxSn5SrcLt2FkKEYw1SGY6Sbg76VNJUWMgpBp/ZIY X-Received: by 2002:a17:903:25c9:b0:1b5:694:b1a9 with SMTP id jc9-20020a17090325c900b001b50694b1a9mr500596plb.32.1686875186663; Thu, 15 Jun 2023 17:26:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686875186; cv=none; d=google.com; s=arc-20160816; b=pmxwvsWtulc3I6REvuLSjc9N50ezMJHKtZnJHq4JF6DP51tKMIQ/jHtplL5a0kOFiy SXY43iPfcMiGjvDQKcIZEEDvsLBntRVbO2zfdooOqT2AVYt44Kh6woz3SXA+pLKzLXqv 5J6TVz73GGVg3pmPTjmzH7Wn3HfOQZsYG5td7MQiP/0lJt7sNPP7aZ5hDLkSPKN9PO9g 2RyZNnojU4CMMHobq7MizPkOKBdLyhD+j/a+Ox8cku/Gdx6J4CLNoiO6RCaMUme6QRO+ aHefeYiQfdf+2p6BbmNeAzDlgfsrwgkEtZH7Ja6m9RkkhE+JyZpfYzeJqGOApMxic+vD UB/Q== 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=/PdUvf9y38LlACR4AVgv6c3lD3R0OxFrRRNbyeSS3zs=; b=K4bMpU68HRwr6lHsud1Yexah22d5DqyO08EZluOg6wI2QOQvjFghdCTqRQuOkafNp8 OcQ8ZOM7RFJkrp17CAa+jQI6c5TscAV5XtLPfHfiY2HPRJaucFEubG4E7+rAnZ6N6Z/P LLSw/vGd4JQOck5uRJlWy3xIkruX2a6N8sbT1iTWhtmABzNofmaAL9MSQ8OYvCr1IKOI hgdWy1wS5eRGaA2v1YWS8M/Gawm/lWs1DOXhrWAxAHa8/1c1HPMXO76+DSbjPbXxfJIa Y0SllG9Wevx3U/kcQpcZ2fpJ3Stu77LHmgHqkjr31qZX37seFwSLeJUVpzym0ZQdBvK7 iyBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="XFjIS/ya"; 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 i13-20020a17090332cd00b001addf547a59si10367418plr.0.2023.06.15.17.26.13; Thu, 15 Jun 2023 17:26:26 -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="XFjIS/ya"; 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 S240673AbjFPARm (ORCPT + 99 others); Thu, 15 Jun 2023 20:17:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239772AbjFPARk (ORCPT ); Thu, 15 Jun 2023 20:17:40 -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 68CF72D68; Thu, 15 Jun 2023 17:17:22 -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 8806261C11; Fri, 16 Jun 2023 00:17:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E332BC433C8; Fri, 16 Jun 2023 00:17:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686874640; bh=aBzh/Fxzic0miW7yv3POPGW0A64Wwiniim+c1dkYLiY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XFjIS/yatBcC0vfZLDmGR7QeKsj8ZbBxd2HTcqyKH23qvQNMdnvuB2gh+r4kUPNUk 4/7k93BSX25IIwWtbQtq7AXQZMsXp86kDjEZqYXgO4QnCzgSossGvhPlCZS5rmfrC5 GDqpOAAo8ueR03U93/O3j5mEiVDAZgkocmWWw5x+WDmgxa6te+mBI3A1l5f2iOSbIU b0TuST7+0xT8+kzNQ578ITVzRQg8qayrqXgmEOyItmjaSaPg2nLntH3uyV/mXLZsC6 VOj9mzgHU1iT3MlVcgRkLobHnDjp+UDFN4+hlxcP3+7h88Y0PkdbYbWl9GbGkiK90y JsLznxCiKIGWw== 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 Subject: [PATCH v2 06/11] kbuild: rust_is_available: check that environment variables are set Date: Fri, 16 Jun 2023 02:16:26 +0200 Message-ID: <20230616001631.463536-7-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=-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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768816835708565893?= X-GMAIL-MSGID: =?utf-8?q?1768816835708565893?= 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, explicitly check whether the expected variables are set (`$RUSTC`, `$BINDGEN` and `$CC`). If not, print an explanation about the fact that the script is meant to be called from Kbuild, since that is the most likely cause for the variables not being set. Link: https://lore.kernel.org/oe-kbuild-all/Y6r4mXz5NS0+HVXo@zn.tnic/ [1] Signed-off-by: Miguel Ojeda Reviewed-by: Martin Rodriguez Reboredo Reviewed-by: Nathan Chancellor --- scripts/rust_is_available.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh index 1bdff4472cbe..7e0368babe64 100755 --- a/scripts/rust_is_available.sh +++ b/scripts/rust_is_available.sh @@ -28,11 +28,40 @@ print_docs_reference() echo >&2 "***" } +# Print an explanation about the fact that the script is meant to be called from Kbuild. +print_kbuild_explanation() +{ + 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." + exit 1 +} + # If the script fails for any reason, or if there was any warning, then # print a reference to the documentation on exit. warning=0 trap 'if [ $? -ne 0 ] || [ $warning -ne 0 ]; then print_docs_reference; fi' EXIT +# Check that the expected environment variables are set. +if [ -z "${RUSTC+x}" ]; then + echo >&2 "***" + echo >&2 "*** Environment variable 'RUSTC' is not set." + print_kbuild_explanation +fi + +if [ -z "${BINDGEN+x}" ]; then + echo >&2 "***" + echo >&2 "*** Environment variable 'BINDGEN' is not set." + print_kbuild_explanation +fi + +if [ -z "${CC+x}" ]; then + echo >&2 "***" + echo >&2 "*** Environment variable 'CC' is not set." + print_kbuild_explanation +fi + # Check that the Rust compiler exists. if ! command -v "$RUSTC" >/dev/null; then echo >&2 "***" From patchwork Fri Jun 16 00:16:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 108767 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp997484vqr; Thu, 15 Jun 2023 17:20:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5UeB4oGiHD0bkHnXwT2BfVwQ+SH0i/RbHOjMMgOwAP+0Q8DRXLUcQ5bbCdKF+vAM5aCS+Y X-Received: by 2002:a05:6808:201f:b0:389:4f86:205e with SMTP id q31-20020a056808201f00b003894f86205emr858414oiw.9.1686874823456; Thu, 15 Jun 2023 17:20:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686874823; cv=none; d=google.com; s=arc-20160816; b=NpDH/1rdcwxPYvB8lMzuVgbzL52JdmR1AkKRVBoGxc/Xk5lxIRANoVbDNu71G/t2VJ tbmyncKx4VV+yM2NJZUd9NV3zQPn8H8G+VbKn4w/LEkWYdNqfW9QztvQIa3Xo0+U0K/5 xpPRieRWEakEyrwIP6KD4evpwOGngNZ8KhtxLiz5yhwqOilr8zMmM/DJ9cP0DTTGVqfl 672q/hunZLzOm22QlildUvqTkdfwxLgltlGkpAmEWX5/K3MXzIqOa49aXh787LpHp4RB 4Dg98y5anevxgu96b6gpCzwjmnBt9HZEWbmrYYzTELgb0b5FJVtabfnVKBvJTikTcCXp vdrQ== 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=NdtpJtYFCTu/84JIYYvMCTFbbiCu0IdBQTnOe3VRi58=; b=SWPulmV84uEVsSS/bBn+e70VqBi2JhZUokp0ZS9VjHr7enSefsk6gD95hNxUiHNGoV y5vN5Z4Z9o6igODecdCrxVylLzAAVzUxUl5YxCEVyuw60T6rzfX0/IW1baY8Z6j9EK4A 1DQPgWCey5NBME1et2GwyNl9spZTLLK1jHv1s0Z2rRE4u0OnQEVvyp8R1PrH/jaoQKWk xRJDEOkgBTDQuta5rGLRQfIPXsm7olgk4rETsmzLWTgUCmozx3F+i07oPH383U4Ir5hm 5RCqOo3FlJYXnqmDjPZmOo7YOv2ecdYJootVnUWSNNoEwYZRjQzafg1eJtGn+yhNEv8I cg8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="L6/+ClNP"; 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 p12-20020a17090a348c00b0025ea380f868si487962pjb.2.2023.06.15.17.20.10; Thu, 15 Jun 2023 17:20:23 -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="L6/+ClNP"; 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 S240269AbjFPASZ (ORCPT + 99 others); Thu, 15 Jun 2023 20:18:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240813AbjFPAR7 (ORCPT ); Thu, 15 Jun 2023 20:17:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97F882D42; Thu, 15 Jun 2023 17:17:29 -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 BF672625AC; Fri, 16 Jun 2023 00:17:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 642A7C433CC; Fri, 16 Jun 2023 00:17:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686874646; bh=nRivV3zrCLYT47fKlzn6TTMrDbuRNBwLfZj2lP+tctE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L6/+ClNPTjQGAFtca0C1JEL2tzhvY36Ml/gV0PQp/e6aZGgVXadUjX/adcFLlq3Ya RX5p03CQEwY06y1FIlRj0MFG1HtVJ4427ppqq9bscXtvMKQ2YnETnBebAX0QjLDliV ySY3hvsxDKTXJ6rM/Wc37aqXnwi43VVUZuGdaQUgWwWGCv+RX2ITV+nNxlyLjygRhz fqk7IZWBevcdIgF9Y7f9z+l/6qZWxuDlWMopaMaxExeyxL35sAHFd8JZOTzzaZX+IT to/zrLflCo50kkIqx6ZQuZ7azDdY4QUyQgxUFfvCL2vrbk01TTdyhmnjUsgUPMNN4S jy1g13fpMqmKA== 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, Jordan Isaacs , "Ethan D . Twardy" , Tiago Lam Subject: [PATCH v2 07/11] kbuild: rust_is_available: fix confusion when a version appears in the path Date: Fri, 16 Jun 2023 02:16:27 +0200 Message-ID: <20230616001631.463536-8-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?1768816455107829283?= X-GMAIL-MSGID: =?utf-8?q?1768816455107829283?= `bindgen`'s output for `libclang`'s version check contains paths, which in turn may contain strings that look like version numbers [1][2]: .../6.1.0-dev/.../rust_is_available_bindgen_libclang.h:2:9: warning: clang version 11.1.0 [-W#pragma-messages], err: false which the script will pick up as the version instead of the latter. It is also the case that versions may appear after the actual version (e.g. distribution's version text), which was the reason behind `head` [3]: .../rust-is-available-bindgen-libclang.h:2:9: warning: clang version 13.0.0 (Fedora 13.0.0-3.fc35) [-W#pragma-messages], err: false Thus instead ask for a match after the `clang version` string. Reported-by: Jordan Isaacs Closes: https://github.com/Rust-for-Linux/linux/issues/942 [1] Reported-by: Ethan D. Twardy Closes: https://lore.kernel.org/rust-for-linux/20230528131802.6390-2-ethan.twardy@gmail.com/ [2] Reported-by: Tiago Lam Closes: https://github.com/Rust-for-Linux/linux/pull/789 [3] Fixes: 78521f3399ab ("scripts: add `rust_is_available.sh`") Signed-off-by: Miguel Ojeda Reviewed-by: Martin Rodriguez Reboredo Reviewed-by: Nathan Chancellor Reviewed-By: Ethan Twardy Tested-By: Ethan Twardy --- scripts/rust_is_available.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh index 7e0368babe64..810691af66eb 100755 --- a/scripts/rust_is_available.sh +++ b/scripts/rust_is_available.sh @@ -157,9 +157,7 @@ fi # of the `libclang` found by the Rust bindings generator is suitable. bindgen_libclang_version=$( \ echo "$bindgen_libclang_output" \ - | grep -F 'clang version ' \ - | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' \ - | head -n 1 \ + | sed -nE 's:.*clang version ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p' ) bindgen_libclang_min_version=$($min_tool_version llvm) bindgen_libclang_cversion=$(get_canonical_version $bindgen_libclang_version) From patchwork Fri Jun 16 00:16:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 108769 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp997708vqr; Thu, 15 Jun 2023 17:20:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4aDcyzDx9AKnRqjNkBpVpI8TvTHnl5mc/M7QUUjdhXo7PEtlnK4N616sj7Oq+ABpkLPLE6 X-Received: by 2002:a05:6a00:398f:b0:64f:aea5:7b49 with SMTP id fi15-20020a056a00398f00b0064faea57b49mr609680pfb.17.1686874854544; Thu, 15 Jun 2023 17:20:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686874854; cv=none; d=google.com; s=arc-20160816; b=Dlu5p56TyK4O3omRV9tLtJxFh9j2vV0bPh0hQxu3+foecSAn/4uz1nIqdSn4h6uv2n nH7ATetzwxrRIwPcawX+OBnx4Pwi3UX9oq+qRuVZt+dgHBnlns+G0CzfZl8PCIA9rICp ZnS9g711TPOkUGXDa2EgK1XKAkC8TcFOVXABSl7OrWTBJGtT78Mn5cSHQbR4JcqNl46i 59e3Uxp716p21QocoSEOcLWg6CZQ61RtjASQxyoFw9ssmbkjwQ5HboLLaN6oSiQO4djC Cfc8QTGw2BziVOaSow4DoP/3dK0KcsbdqLyv+c2bBCAf2OiXgLUYBxARiVGPLBNsORB0 Fh/Q== 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=MfRyuQ32BoUJRgW35m44bHQZNmbc1lA7wKNEsVFmKCc=; b=zLKYakCcwPhsfLw6lMXnTd1qnVak6YEFXgR+mtnZo46yzWQfVblT7HVoa1hC7yDLip QFY2GmQGdMLVdBQEPSTpm7O16Oi/pjjR08qpWyKNgTjeL46CELUc/UucvWZVe5zNP5hv r0QC2XvmYceUV/0rZt/28RjTtz4ydCcdPjIJMA6U6jSREvxdyCR6M3ix4YKzM1iE0wxj 3L88yL1oHQWSqcXShWp6CwB+jmfLAf19G2SQ1bqc0TsjHnAgKuERkTKUPJR/hwjxn/Jo SyRZjbuwGRmjHz1VZ5nZLVY92mpmaMCCTyn5JzbznHysRbzIPU2qqMrHsVSRpVWgVpcf 3K/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=U4pjlbre; 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 o25-20020a637e59000000b0054fef4ea777si2867250pgn.853.2023.06.15.17.20.40; Thu, 15 Jun 2023 17:20: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=U4pjlbre; 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 S239085AbjFPATB (ORCPT + 99 others); Thu, 15 Jun 2023 20:19:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240744AbjFPAS3 (ORCPT ); Thu, 15 Jun 2023 20:18:29 -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 EB83F30E2; Thu, 15 Jun 2023 17:17:54 -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 2DB1361C41; Fri, 16 Jun 2023 00:17:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87B9EC433CD; Fri, 16 Jun 2023 00:17:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686874650; bh=cWinNtrRNqE72MtzHUXpxkJuCIniJrJ/uXuToYRgE8M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U4pjlbreSJh9xy6s1BVW1nZNWwe/mqd4ae8t1KeqbwB3Ysvqq1EGaav9keNOgmjsP ovdjamLawMDqyYPc60zbyVGqeE6ksaaCP0+QsqurNC3ln7zmMY3453C1HjzVqF6jg7 4Dn/mw1QLIjnJ52Xp9kyOq15f6CPoYYu///mZ7jnEP+8Jf42Y78bqCwJ6YIDcCDr9Q V64YSPbKv0IeJLlbaqJxfbXUknmCoGJ0CtfQlCn1y86nX7FobYO2NgY21J5VBtbrEp Sj/WTRvG7JKTfCXw06IkuhgXSJf1K3J4coLC6kmuh4qwjKcL2atUexEQ3Wif7z7ydl 50hQVfO2T/qEg== 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 Subject: [PATCH v2 08/11] kbuild: rust_is_available: normalize version matching Date: Fri, 16 Jun 2023 02:16:28 +0200 Message-ID: <20230616001631.463536-9-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=-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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768816487782050276?= X-GMAIL-MSGID: =?utf-8?q?1768816487782050276?= In order to match the version string, `sed` is used in a couple cases, and `grep` and `head` in a couple others. Make the script more consistent and easier to understand by using the same method, `sed`, for all of them. This makes the version matching also a bit more strict for the changed cases, since the strings `rustc ` and `bindgen ` will now be required, which should be fine since `rustc` complains if one attempts to call it with another program name, and `bindgen` uses a hardcoded string. In addition, clarify why one of the existing `sed` commands does not provide an address like the others. Signed-off-by: Miguel Ojeda Reviewed-by: Martin Rodriguez Reboredo Reviewed-by: Nathan Chancellor Reviewed-by: Masahiro Yamada --- scripts/rust_is_available.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh index 810691af66eb..b7e0781fdea9 100755 --- a/scripts/rust_is_available.sh +++ b/scripts/rust_is_available.sh @@ -83,8 +83,7 @@ fi # Non-stable and distributions' versions may have a version suffix, e.g. `-dev`. rust_compiler_version=$( \ LC_ALL=C "$RUSTC" --version 2>/dev/null \ - | head -n 1 \ - | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' \ + | sed -nE '1s:.*rustc ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p' ) rust_compiler_min_version=$($min_tool_version rustc) rust_compiler_cversion=$(get_canonical_version $rust_compiler_version) @@ -111,8 +110,7 @@ fi # Non-stable and distributions' versions may have a version suffix, e.g. `-dev`. rust_bindings_generator_version=$( \ LC_ALL=C "$BINDGEN" --version 2>/dev/null \ - | head -n 1 \ - | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' \ + | sed -nE '1s:.*bindgen ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p' ) rust_bindings_generator_min_version=$($min_tool_version bindgen) rust_bindings_generator_cversion=$(get_canonical_version $rust_bindings_generator_version) @@ -155,6 +153,9 @@ fi # `bindgen` returned successfully, thus use the output to check that the version # of the `libclang` found by the Rust bindings generator is suitable. +# +# Unlike other version checks, note that this one does not necessarily appear +# in the first line of the output, thus no `sed` address is provided. bindgen_libclang_version=$( \ echo "$bindgen_libclang_output" \ | sed -nE 's:.*clang version ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p' From patchwork Fri Jun 16 00:16:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 108776 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1014724vqr; Thu, 15 Jun 2023 18:06:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6OB+3KI8gnO+NpeSVCePY2uLHVM/Tr2Hx9rzWwSwJJVFV2gZxWJTJmBH2S/h+tF1RrOvKm X-Received: by 2002:ad4:4ee9:0:b0:626:199e:1b96 with SMTP id dv9-20020ad44ee9000000b00626199e1b96mr639089qvb.64.1686877590501; Thu, 15 Jun 2023 18:06:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686877590; cv=none; d=google.com; s=arc-20160816; b=iUzWWI6LNEeRzu+EGQYyRKyMoeYjPbZij3W4cH/UR7psGgBqYL5qezuxWRmt+TfZvU /Fto5pqVeBlbVjRTTZp80dqSubui17oZThpMxLdfPec8Adv+42Fuk6UhrKW6kyvSS0Dn nOyEuFgUhd1KmSvgReL78AfN2kkMjzVUwxxzC08/Kh/wLM4Ev1NjaYsYhngRLTG6oLSz D53oEkgyUBZ54lY2M16RAYf8OKOLozWw+tb+TwOjQ7fK/jS+AuklA8Cesu6EntL+CE+p htwFs4gR7gfrRNmKTNB82SQeo9Yy14LwGmHg7EHCHQeKu1rZ6WZtJtetMxPY6Yaf4nk4 htaQ== 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=AEKl23U6D8iZUiMGbnFeXiLZouURaclE6xOG8ePhz7s=; b=Dekj5QHwEdqRDXlAVF1vd0JvEFIPjL3pv5kDdnp+ox1etyp91lfatPT/9TZDzVGHla UaFL1dY9jnbITMHhcOY3XPMRa/hLzQtRIcHZAfKdc2GvfRkuTabfKvP51GkUx7P9OpBB WNaE05nqMRPJgIv7Xkh99f9rXTb/iTVNxJVv01fshqOIX9CQS9Egx0wsnCzBiPhEsdPj rebewCfO9hCwmeFV/o+7FSkUjkDvJ72OkzmSlwi7s4okr/QgprbpM0YVPbQGV+FuAlBV w9zBuswXW/x+HXJy/PaFgwpKUAxhk3uQAX9YgVWvsmFBh0MntuhnlC8P24KHZ4JSoWUz OnjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ES+EVWrn; 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 az9-20020a056a02004900b0053fbb2ddb4csi14353532pgb.36.2023.06.15.18.06.07; Thu, 15 Jun 2023 18:06:30 -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=ES+EVWrn; 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 S240791AbjFPASa (ORCPT + 99 others); Thu, 15 Jun 2023 20:18:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241119AbjFPASR (ORCPT ); Thu, 15 Jun 2023 20:18:17 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10B8D2962; Thu, 15 Jun 2023 17:17:48 -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 A3F09628A3; Fri, 16 Jun 2023 00:17:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09FCCC433C8; Fri, 16 Jun 2023 00:17:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686874655; bh=iTX/Tcy5uIzvUJfO9A3D/AYRTPs+VCsc4/kXRmaB9Ro=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ES+EVWrnknZ8OqSaMlle32nh0KsO+2uIP/IbiHmnD26SD+GiR3e+Wdj8GR4bpY6qo 73zdhxQnNdXZQ5c0LP+uNPrmmtzvdv4WaMSm8JDgtvADsd25Oti6RG/snw/jsZWgvt GKBMINCiQejkb45HlZOx8nJWAtu9DtYuORZtGmw39ucs4n36oBViwy3LSif1dorT/S 36R5eSs77I38dH5TDQB8sWljzsUuii/2PNGIET5KwWaVnhQ6aWM+BscB8gKAyaMKIb 1/oKQvA4oUyaiYl1UT/KdrhqXp4NNWriCZfdx4iQbudYn4av2t4TJEwMeZuy1GxTk/ lJhZK59GaknWw== 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 Subject: [PATCH v2 09/11] kbuild: rust_is_available: handle failures calling `$RUSTC`/`$BINDGEN` Date: Fri, 16 Jun 2023 02:16:29 +0200 Message-ID: <20230616001631.463536-10-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?1768819355992772799?= X-GMAIL-MSGID: =?utf-8?q?1768819355992772799?= The script already checks if `$RUSTC` and `$BINDGEN` exists via `command`, but the environment variables may point to a non-executable file, or the programs may fail for some other reason. While the script successfully exits with a failure as it should, the error given can be quite confusing depending on the shell and the behavior of its `command`. For instance, with `dash`: $ RUSTC=./mm BINDGEN=bindgen CC=clang scripts/rust_is_available.sh scripts/rust_is_available.sh: 19: arithmetic expression: expecting primary: "100000 * + 100 * + " Thus detect failure exit codes when calling `$RUSTC` and `$BINDGEN` and print a better message, in a similar way to what we do when extracting the `libclang` version found by `bindgen`. Link: https://lore.kernel.org/rust-for-linux/CAK7LNAQYk6s11MASRHW6oxtkqF00EJVqhHOP=5rynWt-QDUsXw@mail.gmail.com/ Signed-off-by: Miguel Ojeda Reviewed-by: Martin Rodriguez Reboredo Reviewed-by: Nathan Chancellor --- scripts/rust_is_available.sh | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh index b7e0781fdea9..da8296cd9b8d 100755 --- a/scripts/rust_is_available.sh +++ b/scripts/rust_is_available.sh @@ -81,8 +81,20 @@ fi # Check that the Rust compiler version is suitable. # # Non-stable and distributions' versions may have a version suffix, e.g. `-dev`. +rust_compiler_output=$( \ + LC_ALL=C "$RUSTC" --version 2>/dev/null +) || rust_compiler_code=$? +if [ -n "$rust_compiler_code" ]; then + echo >&2 "***" + echo >&2 "*** Running '$RUSTC' to check the Rust compiler version failed with" + echo >&2 "*** code $rust_compiler_code. See output and docs below for details:" + echo >&2 "***" + echo >&2 "$rust_compiler_output" + echo >&2 "***" + exit 1 +fi rust_compiler_version=$( \ - LC_ALL=C "$RUSTC" --version 2>/dev/null \ + echo "$rust_compiler_output" \ | sed -nE '1s:.*rustc ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p' ) rust_compiler_min_version=$($min_tool_version rustc) @@ -108,8 +120,20 @@ fi # Check that the Rust bindings generator is suitable. # # Non-stable and distributions' versions may have a version suffix, e.g. `-dev`. +rust_bindings_generator_output=$( \ + LC_ALL=C "$BINDGEN" --version 2>/dev/null +) || rust_bindings_generator_code=$? +if [ -n "$rust_bindings_generator_code" ]; then + echo >&2 "***" + echo >&2 "*** Running '$BINDGEN' to check the Rust bindings generator version failed with" + echo >&2 "*** code $rust_bindings_generator_code. See output and docs below for details:" + echo >&2 "***" + echo >&2 "$rust_bindings_generator_output" + echo >&2 "***" + exit 1 +fi rust_bindings_generator_version=$( \ - LC_ALL=C "$BINDGEN" --version 2>/dev/null \ + echo "$rust_bindings_generator_output" \ | sed -nE '1s:.*bindgen ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p' ) rust_bindings_generator_min_version=$($min_tool_version bindgen) From patchwork Fri Jun 16 00:16:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 108768 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp997547vqr; Thu, 15 Jun 2023 17:20:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7RlR4uk8uZSp1rRlebkonigo7YbNJVg+lgcjFM6UUSnhtBXse6orqLlF32vBqgWtdRYqtt X-Received: by 2002:a05:6a20:a10b:b0:11d:9307:8acb with SMTP id q11-20020a056a20a10b00b0011d93078acbmr1018215pzk.45.1686874835601; Thu, 15 Jun 2023 17:20:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686874835; cv=none; d=google.com; s=arc-20160816; b=bd92FuWwy9aMQOVKqrbI6ZVlaFDBaU6JV/GM+XVm9hivxKIfY/F7aBLgyKc4DwWSNM +94Kr5XHul9D3a/gzLJIZskKkblGUtJvRprYJViqRjJO3rDOLil0sjLUyapIlLL89MgX 2cFtGDhvEGuiAsjZpqc1NA0g9bGsPEGhGnLcgJGFRuTdtQZ8g7fkd8etnISc3v+UfNPa nhCdVxejIGUOKJLnlGVxLJhUBRvw0aaVMvcJg6FExwaiy8iaJJ2dJ69Y4A1HKE1szT5O 4MLezU+fGWtqQNMLUQUqnZTVOuPGgv5RWzZC5/sid/vRBH2OAH+f76Ww27Mu/avm+dA7 TpGQ== 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=ZVsDlNWjJoBJQASi6kWL9UKJd/XScm4a0XXTcBPj11w=; b=h3+dcAybOQgHictkyOi8i+naWEvF50A1qkvTejXteSDCBpuczJ2CM+mENtYJIfCplO +rIz4fzdsqj7pPArgIUF0vdD5O1yA+lPaWtTBs7eSFKZEran1V0eGxxabpGJnHaKHRzx xTTfWYRIRsxH5SKr68DmDdbkbL8bGW1xHtGviqPxSiarytG6SVOi7alu9p3oQKKoIUAr Z7XBIwDoU6eVwIirG4OM4lEsuzO6edlbH3OY4rzIPM3X+XnbA7H+PG+vVmkSeRR30EoW Z5WKXGuTQZHwd7kr95epRFSzMKuXhdb06WVVxR91yfu7Gj0o3/UUkMm/+Bh3Ko/v0zbB MWHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GP+1tsVw; 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 k189-20020a633dc6000000b0053eedcd4d81si13916306pga.101.2023.06.15.17.20.20; Thu, 15 Jun 2023 17:20:35 -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=GP+1tsVw; 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 S240736AbjFPAS5 (ORCPT + 99 others); Thu, 15 Jun 2023 20:18:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239209AbjFPASW (ORCPT ); Thu, 15 Jun 2023 20:18:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8442030DB; Thu, 15 Jun 2023 17:17:52 -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 384A361CF2; Fri, 16 Jun 2023 00:17:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 829CCC433C0; Fri, 16 Jun 2023 00:17:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686874659; bh=ZOoiskACd1/vXGOYvayiPERAILLvpXavPq6Glrg++uA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GP+1tsVwBh5mcRHiNI5An8ChLve9xO1BdD2bzyC/23Ch3DVUUiG1JKhE8HYRKvSCg YV2dlGjlO/VmOUaUPV1E7Rc8PsHNnO/Fgy7Ca+YPGmlJ2QbdtcgLwkTi54uEVaj3kV rqNjgVp1TlxkqbbrpFYSkuxXT7446WpwD01ShZJrOKd28OyPRPmjfZaNSJQXHKchnr MQDMaaHpqJcnBfX89ysrwQ+iSTZGvbyzZkRoeBJI1kYOfjzmykglvpW+v7Iw0hXKMP 7N1QLfSrvN2FbLhuD5uwUfYutqSV71NWWLpQe4klVWglHxLU4bAq34k+1pVKOv6AXv DI7ok7tmxavmw== 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 Subject: [PATCH v2 10/11] kbuild: rust_is_available: check that output looks as expected Date: Fri, 16 Jun 2023 02:16:30 +0200 Message-ID: <20230616001631.463536-11-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?1768816467931812568?= X-GMAIL-MSGID: =?utf-8?q?1768816467931812568?= The script already checks for `$RUSTC` and `$BINDGEN` existing and exiting without failure. However, one may still pass an unexpected binary that does not output what the later parsing expects. The script still successfully reports a failure as expected, but the error is confusing. For instance: $ RUSTC=true BINDGEN=bindgen CC=clang scripts/rust_is_available.sh scripts/rust_is_available.sh: 19: arithmetic expression: expecting primary: "100000 * + 100 * + " *** *** Please see Documentation/rust/quick-start.rst for details *** on how to set up the Rust support. *** Thus add an explicit check and a proper message for unexpected output from the called command. Similarly, do so for the `libclang` version parsing, too. Link: https://lore.kernel.org/rust-for-linux/CAK7LNAQYk6s11MASRHW6oxtkqF00EJVqhHOP=5rynWt-QDUsXw@mail.gmail.com/ Signed-off-by: Miguel Ojeda Reviewed-by: Martin Rodriguez Reboredo Reviewed-by: Nathan Chancellor --- scripts/rust_is_available.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh index da8296cd9b8d..117018946b57 100755 --- a/scripts/rust_is_available.sh +++ b/scripts/rust_is_available.sh @@ -97,6 +97,15 @@ rust_compiler_version=$( \ echo "$rust_compiler_output" \ | sed -nE '1s:.*rustc ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p' ) +if [ -z "$rust_compiler_version" ]; then + echo >&2 "***" + echo >&2 "*** Running '$RUSTC' to check the Rust compiler version did not return" + echo >&2 "*** an expected output. See output and docs below for details:" + echo >&2 "***" + echo >&2 "$rust_compiler_output" + echo >&2 "***" + exit 1 +fi rust_compiler_min_version=$($min_tool_version rustc) rust_compiler_cversion=$(get_canonical_version $rust_compiler_version) rust_compiler_min_cversion=$(get_canonical_version $rust_compiler_min_version) @@ -136,6 +145,15 @@ rust_bindings_generator_version=$( \ echo "$rust_bindings_generator_output" \ | sed -nE '1s:.*bindgen ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p' ) +if [ -z "$rust_bindings_generator_version" ]; then + echo >&2 "***" + echo >&2 "*** Running '$BINDGEN' to check the bindings generator version did not return" + echo >&2 "*** an expected output. See output and docs below for details:" + echo >&2 "***" + echo >&2 "$rust_bindings_generator_output" + echo >&2 "***" + exit 1 +fi rust_bindings_generator_min_version=$($min_tool_version bindgen) rust_bindings_generator_cversion=$(get_canonical_version $rust_bindings_generator_version) rust_bindings_generator_min_cversion=$(get_canonical_version $rust_bindings_generator_min_version) @@ -184,6 +202,16 @@ bindgen_libclang_version=$( \ echo "$bindgen_libclang_output" \ | sed -nE 's:.*clang version ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p' ) +if [ -z "$bindgen_libclang_version" ]; then + echo >&2 "***" + echo >&2 "*** Running '$BINDGEN' to check the libclang version (used by the Rust" + echo >&2 "*** bindings generator) did not return an expected output. See output" + echo >&2 "*** and docs below for details:" + echo >&2 "***" + echo >&2 "$bindgen_libclang_output" + echo >&2 "***" + exit 1 +fi bindgen_libclang_min_version=$($min_tool_version llvm) bindgen_libclang_cversion=$(get_canonical_version $bindgen_libclang_version) bindgen_libclang_min_cversion=$(get_canonical_version $bindgen_libclang_min_version) From patchwork Fri Jun 16 00:16:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 108773 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1001865vqr; Thu, 15 Jun 2023 17:31:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6vuL077+wxGMzC+XOhy7mHn65EjnTjbF0el2vL1ZXqCMgkp8NFam+eup08R3UDtj7RTKN5 X-Received: by 2002:a92:c60a:0:b0:340:9132:f99 with SMTP id p10-20020a92c60a000000b0034091320f99mr1015260ilm.22.1686875519325; Thu, 15 Jun 2023 17:31:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686875519; cv=none; d=google.com; s=arc-20160816; b=tsph8hu0AYjgjIEQBXrSIjDG6btLOmw12hTgglt8DtwGGB+JXCev7G2OPCKfc9QVbq E835UG600cEDF1FvM+sEkQLOO0Z5nVhSwAouwhkNQ+LJp3UnXGutBqof/P7lOray2+1+ vhNWq5LG5+MgX2GEsbfEOV1ITXJv49JABU5Y6Vz8cJKj43NEUrXlhgFjLmV0O8hjU8DB Hm9wB1VeJtcVEYxxvR1HYCcPFSw6/4sIeQ4asXYDQ+R/LPsyQic4WeIv9rDEkofA9MSG UGFXNB9pidxsXlQ7djpYePyG1Mli7MzYmAJGh7yWgyPnFbygmoQe92qUiRMO7MUykwhq YYmg== 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=5TuRdP6GF7nXebSF2QUR7zjN8SN4Ncf/5gduXNsYm28=; b=ozPT3yRwU6OpAchDNUcgjfEN5qcr+xwOHR00Jolf6assTka9SyxfXPpyq0M5CbxV1s l6qIU5DQtw5dWlVvkKDnJbUM+oWMMoRk9APh9t2ybkT/vJDelUnLKGL+5hfRUB7JOCln 6rsEr6K0M4437FbBHDXFVqHu40/Uiok6Yp8XfEfnm2fZry3SOVJhJxGI562LRQhuKk8N T+YRDjNNy4MYWEtthYi01jo3FCEO30PSvJTVjZFXNeJTz/+uFyXeai6hsjl4yq5FuqNS ckZaVcOfe6SIKhneczKh704IX8oNZOs79i6bVqO85eP3u92sIJKP4WcCeorUxSoOXqmz 8yoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tNJBImjs; 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 t6-20020a63b706000000b0054fe2dfaab0si3442023pgf.893.2023.06.15.17.31.23; Thu, 15 Jun 2023 17:31:59 -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=tNJBImjs; 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 S241037AbjFPATE (ORCPT + 99 others); Thu, 15 Jun 2023 20:19:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240805AbjFPASb (ORCPT ); Thu, 15 Jun 2023 20:18:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5716D30E3; Thu, 15 Jun 2023 17:17:55 -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 AF49861D01; Fri, 16 Jun 2023 00:17:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 031BCC433C9; Fri, 16 Jun 2023 00:17:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686874664; bh=xHunRCQV08b7YqnNyvJhKOHNEj806DUbJVOw7kJtKXc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tNJBImjsgSviIoN9LojD1t+9dbBZ1ZLir+Cn7KEcAoyIJYYCEpKGlrgRdf/Gzk7Dm tGC9iK0ye48EDcZc1K/JSM2FmhVokwDViNlCH/zi8hTnbI7isdl1hKQOTrWiIAqAzd MyS1jc5WgNHqhKp9YIGARxdTcSiD2tHETp5IPjwmh85rs7IXDtdojuj90W3eeVecaz iEyWXm6Tb9lDUozYs9mn9kFx17if7Ll6T2X7RJJtFu7hlAtpv6i4iSDw7Lu9Hzrm6s orlfZfS7b2AzLFa8MDsE4HpxeEtlrJaIVQuwDj/6R4FgjDv2CKjFKxGYSqCaJemKGc g7Z7JzEL/UHkg== 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 Subject: [PATCH v2 11/11] kbuild: rust_is_available: add test suite Date: Fri, 16 Jun 2023 02:16:31 +0200 Message-ID: <20230616001631.463536-12-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,URIBL_BLOCKED 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?1768817184701416003?= X-GMAIL-MSGID: =?utf-8?q?1768817184701416003?= The `rust_is_available.sh` script runs for everybody compiling the kernel, even if not using Rust. Therefore, it is important to ensure that the script is correct to avoid breaking people's compilation. In addition, the script needs to be able to handle a set of subtle cases, including parsing version strings of different tools. Therefore, maintenance of this script can be greatly eased with a set of tests. Thus add a test suite to cover hopefully most of the setups that the script may encounter in the wild. Extra setups can be easily added later on if missing. The script currently covers all the branches of the shell script, including several ways in which they may be entered. Python is used for this script, since the script under test does not depend on Rust, thus hopefully making it easier for others to use if the need arises. Signed-off-by: Miguel Ojeda Reviewed-by: Martin Rodriguez Reboredo --- scripts/rust_is_available_test.py | 346 ++++++++++++++++++++++++++++++ 1 file changed, 346 insertions(+) create mode 100755 scripts/rust_is_available_test.py diff --git a/scripts/rust_is_available_test.py b/scripts/rust_is_available_test.py new file mode 100755 index 000000000000..57613fe5ed75 --- /dev/null +++ b/scripts/rust_is_available_test.py @@ -0,0 +1,346 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +"""Tests the `rust_is_available.sh` script. + +Some of the tests require the real programs to be available in `$PATH` +under their canonical name (and with the expected versions). +""" + +import enum +import os +import pathlib +import stat +import subprocess +import tempfile +import unittest + +class TestRustIsAvailable(unittest.TestCase): + @enum.unique + class Expected(enum.Enum): + SUCCESS = enum.auto() + SUCCESS_WITH_WARNINGS = enum.auto() + SUCCESS_WITH_EXTRA_OUTPUT = enum.auto() + FAILURE = enum.auto() + + @classmethod + def generate_executable(cls, content): + path = pathlib.Path(cls.tempdir.name) + name = str(len(tuple(path.iterdir()))) + path = path / name + with open(path, "w") as file_: + file_.write(content) + os.chmod(path, os.stat(path).st_mode | stat.S_IXUSR) + return path + + @classmethod + def generate_clang(cls, stdout): + return cls.generate_executable(f"""#!/usr/bin/env python3 +import sys +if "-E" in " ".join(sys.argv): + print({repr("Clang " + " ".join(cls.llvm_default_version.split(" ")))}) +else: + print({repr(stdout)}) +""") + + @classmethod + def generate_rustc(cls, stdout): + return cls.generate_executable(f"""#!/usr/bin/env python3 +import sys +if "--print sysroot" in " ".join(sys.argv): + print({repr(cls.rust_default_sysroot)}) +else: + print({repr(stdout)}) +""") + + @classmethod + def generate_bindgen(cls, version_stdout, libclang_stderr): + return cls.generate_executable(f"""#!/usr/bin/env python3 +import sys +if "rust_is_available_bindgen_libclang.h" in " ".join(sys.argv): + print({repr(libclang_stderr)}, file=sys.stderr) +else: + print({repr(version_stdout)}) +""") + + @classmethod + def generate_bindgen_version(cls, stdout): + return cls.generate_bindgen(stdout, cls.bindgen_default_bindgen_libclang_stderr) + + @classmethod + def generate_bindgen_libclang(cls, stderr): + return cls.generate_bindgen(cls.bindgen_default_bindgen_version_stdout, stderr) + + @classmethod + def setUpClass(cls): + cls.tempdir = tempfile.TemporaryDirectory() + + cls.missing = pathlib.Path(cls.tempdir.name) / "missing" + + cls.nonexecutable = pathlib.Path(cls.tempdir.name) / "nonexecutable" + with open(cls.nonexecutable, "w") as file_: + file_.write("nonexecutable") + + cls.unexpected_binary = "true" + + cls.rustc_default_version = subprocess.check_output(("scripts/min-tool-version.sh", "rustc")).decode().strip() + cls.bindgen_default_version = subprocess.check_output(("scripts/min-tool-version.sh", "bindgen")).decode().strip() + cls.llvm_default_version = subprocess.check_output(("scripts/min-tool-version.sh", "llvm")).decode().strip() + cls.rust_default_sysroot = subprocess.check_output(("rustc", "--print", "sysroot")).decode().strip() + + cls.bindgen_default_bindgen_version_stdout = f"bindgen {cls.bindgen_default_version}" + cls.bindgen_default_bindgen_libclang_stderr = f"scripts/rust_is_available_bindgen_libclang.h:2:9: warning: clang version {cls.llvm_default_version} [-W#pragma-messages], err: false" + + cls.default_rustc = cls.generate_rustc(f"rustc {cls.rustc_default_version}") + cls.default_bindgen = cls.generate_bindgen(cls.bindgen_default_bindgen_version_stdout, cls.bindgen_default_bindgen_libclang_stderr) + cls.default_cc = cls.generate_clang(f"clang version {cls.llvm_default_version}") + + def run_script(self, expected, override_env): + env = { + "RUSTC": self.default_rustc, + "BINDGEN": self.default_bindgen, + "CC": self.default_cc, + } + + for key, value in override_env.items(): + if value is None: + del env[key] + continue + env[key] = value + + result = subprocess.run("scripts/rust_is_available.sh", env=env, capture_output=True) + + # The script should never output anything to `stdout`. + self.assertEqual(result.stdout, b"") + + if expected == self.Expected.SUCCESS: + # When expecting a success, the script should return 0 + # and it should not output anything to `stderr`. + self.assertEqual(result.returncode, 0) + self.assertEqual(result.stderr, b"") + elif expected == self.Expected.SUCCESS_WITH_EXTRA_OUTPUT: + # When expecting a success with extra output (that is not warnings, + # which is the common case), the script should return 0 and it + # should output at least something to `stderr` (the output should + # be checked further by the test). + self.assertEqual(result.returncode, 0) + self.assertNotEqual(result.stderr, b"") + elif expected == self.Expected.SUCCESS_WITH_WARNINGS: + # When expecting a success with warnings, the script should return 0 + # and it should output at least the instructions to `stderr`. + self.assertEqual(result.returncode, 0) + self.assertIn(b"Please see Documentation/rust/quick-start.rst for details", result.stderr) + else: + # When expecting a failure, the script should return non-0 + # and it should output at least the instructions to `stderr`. + self.assertNotEqual(result.returncode, 0) + self.assertIn(b"Please see Documentation/rust/quick-start.rst for details", result.stderr) + + # The output will generally be UTF-8 (i.e. unless the user has + # put strange values in the environment). + result.stderr = result.stderr.decode() + + return result + + def test_rustc_unset(self): + result = self.run_script(self.Expected.FAILURE, { "RUSTC": None }) + self.assertIn("Environment variable 'RUSTC' is not set.", result.stderr) + self.assertIn("This script is intended to be called from Kbuild.", result.stderr) + + def test_bindgen_unset(self): + result = self.run_script(self.Expected.FAILURE, { "BINDGEN": None }) + self.assertIn("Environment variable 'BINDGEN' is not set.", result.stderr) + self.assertIn("This script is intended to be called from Kbuild.", result.stderr) + + def test_cc_unset(self): + result = self.run_script(self.Expected.FAILURE, { "CC": None }) + self.assertIn("Environment variable 'CC' is not set.", result.stderr) + self.assertIn("This script is intended to be called from Kbuild.", result.stderr) + + def test_rustc_missing(self): + result = self.run_script(self.Expected.FAILURE, { "RUSTC": self.missing }) + self.assertIn(f"Rust compiler '{self.missing}' could not be found.", result.stderr) + + def test_bindgen_missing(self): + result = self.run_script(self.Expected.FAILURE, { "BINDGEN": self.missing }) + self.assertIn(f"Rust bindings generator '{self.missing}' could not be found.", result.stderr) + + def test_rustc_nonexecutable(self): + result = self.run_script(self.Expected.FAILURE, { "RUSTC": self.nonexecutable }) + self.assertIn(f"Running '{self.nonexecutable}' to check the Rust compiler version failed with", result.stderr) + + def test_rustc_unexpected_binary(self): + result = self.run_script(self.Expected.FAILURE, { "RUSTC": self.unexpected_binary }) + self.assertIn(f"Running '{self.unexpected_binary}' to check the Rust compiler version did not return", result.stderr) + + def test_rustc_unexpected_name(self): + rustc = self.generate_rustc(f"unexpected {self.rustc_default_version} (a8314ef7d 2022-06-27)") + result = self.run_script(self.Expected.FAILURE, { "RUSTC": rustc }) + self.assertIn(f"Running '{rustc}' to check the Rust compiler version did not return", result.stderr) + + def test_rustc_unexpected_version(self): + rustc = self.generate_rustc("rustc unexpected (a8314ef7d 2022-06-27)") + result = self.run_script(self.Expected.FAILURE, { "RUSTC": rustc }) + self.assertIn(f"Running '{rustc}' to check the Rust compiler version did not return", result.stderr) + + def test_rustc_no_minor(self): + rustc = self.generate_rustc(f"rustc {'.'.join(self.rustc_default_version.split('.')[:2])} (a8314ef7d 2022-06-27)") + result = self.run_script(self.Expected.FAILURE, { "RUSTC": rustc }) + self.assertIn(f"Running '{rustc}' to check the Rust compiler version did not return", result.stderr) + + def test_rustc_old_version(self): + rustc = self.generate_rustc("rustc 1.60.0 (a8314ef7d 2022-06-27)") + result = self.run_script(self.Expected.FAILURE, { "RUSTC": rustc }) + self.assertIn(f"Rust compiler '{rustc}' is too old.", result.stderr) + + def test_rustc_new_version(self): + rustc = self.generate_rustc("rustc 1.999.0 (a8314ef7d 2099-06-27)") + result = self.run_script(self.Expected.SUCCESS_WITH_WARNINGS, { "RUSTC": rustc }) + self.assertIn(f"Rust compiler '{rustc}' is too new. This may or may not work.", result.stderr) + + def test_bindgen_nonexecutable(self): + result = self.run_script(self.Expected.FAILURE, { "BINDGEN": self.nonexecutable }) + self.assertIn(f"Running '{self.nonexecutable}' to check the Rust bindings generator version failed with", result.stderr) + + def test_bindgen_unexpected_binary(self): + result = self.run_script(self.Expected.FAILURE, { "BINDGEN": self.unexpected_binary }) + self.assertIn(f"Running '{self.unexpected_binary}' to check the bindings generator version did not return", result.stderr) + + def test_bindgen_unexpected_name(self): + bindgen = self.generate_bindgen_version(f"unexpected {self.bindgen_default_version}") + result = self.run_script(self.Expected.FAILURE, { "BINDGEN": bindgen }) + self.assertIn(f"Running '{bindgen}' to check the bindings generator version did not return", result.stderr) + + def test_bindgen_unexpected_version(self): + bindgen = self.generate_bindgen_version("bindgen unexpected") + result = self.run_script(self.Expected.FAILURE, { "BINDGEN": bindgen }) + self.assertIn(f"Running '{bindgen}' to check the bindings generator version did not return", result.stderr) + + def test_bindgen_no_minor(self): + bindgen = self.generate_bindgen_version(f"bindgen {'.'.join(self.bindgen_default_version.split('.')[:2])}") + result = self.run_script(self.Expected.FAILURE, { "BINDGEN": bindgen }) + self.assertIn(f"Running '{bindgen}' to check the bindings generator version did not return", result.stderr) + + def test_bindgen_old_version(self): + bindgen = self.generate_bindgen_version("bindgen 0.50.0") + result = self.run_script(self.Expected.FAILURE, { "BINDGEN": bindgen }) + self.assertIn(f"Rust bindings generator '{bindgen}' is too old.", result.stderr) + + def test_bindgen_new_version(self): + bindgen = self.generate_bindgen_version("bindgen 0.999.0") + result = self.run_script(self.Expected.SUCCESS_WITH_WARNINGS, { "BINDGEN": bindgen }) + self.assertIn(f"Rust bindings generator '{bindgen}' is too new. This may or may not work.", result.stderr) + + def test_bindgen_libclang_failure(self): + for env in ( + { "LLVM_CONFIG_PATH": self.missing }, + { "LIBCLANG_PATH": self.missing }, + { "CLANG_PATH": self.missing }, + ): + with self.subTest(env=env): + result = self.run_script(self.Expected.FAILURE, env | { "PATH": os.environ["PATH"], "BINDGEN": "bindgen" }) + self.assertIn("Running 'bindgen' to check the libclang version (used by the Rust", result.stderr) + self.assertIn("bindings generator) failed with code ", result.stderr) + + def test_bindgen_libclang_unexpected_version(self): + bindgen = self.generate_bindgen_libclang("scripts/rust_is_available_bindgen_libclang.h:2:9: warning: clang version unexpected [-W#pragma-messages], err: false") + result = self.run_script(self.Expected.FAILURE, { "BINDGEN": bindgen }) + self.assertIn(f"Running '{bindgen}' to check the libclang version (used by the Rust", result.stderr) + self.assertIn("bindings generator) did not return an expected output. See output", result.stderr) + + def test_bindgen_libclang_old_version(self): + bindgen = self.generate_bindgen_libclang("scripts/rust_is_available_bindgen_libclang.h:2:9: warning: clang version 10.0.0 [-W#pragma-messages], err: false") + result = self.run_script(self.Expected.FAILURE, { "BINDGEN": bindgen }) + self.assertIn(f"libclang (used by the Rust bindings generator '{bindgen}') is too old.", result.stderr) + + def test_clang_matches_bindgen_libclang_different_bindgen(self): + bindgen = self.generate_bindgen_libclang("scripts/rust_is_available_bindgen_libclang.h:2:9: warning: clang version 999.0.0 [-W#pragma-messages], err: false") + result = self.run_script(self.Expected.SUCCESS_WITH_WARNINGS, { "BINDGEN": bindgen }) + self.assertIn("version does not match Clang's. This may be a problem.", result.stderr) + + def test_clang_matches_bindgen_libclang_different_clang(self): + cc = self.generate_clang("clang version 999.0.0") + result = self.run_script(self.Expected.SUCCESS_WITH_WARNINGS, { "CC": cc }) + self.assertIn("version does not match Clang's. This may be a problem.", result.stderr) + + def test_rustc_src_core_krustflags(self): + result = self.run_script(self.Expected.FAILURE, { "PATH": os.environ["PATH"], "RUSTC": "rustc", "KRUSTFLAGS": f"--sysroot={self.missing}" }) + self.assertIn("Source code for the 'core' standard library could not be found", result.stderr) + + def test_rustc_src_core_rustlibsrc(self): + result = self.run_script(self.Expected.FAILURE, { "RUST_LIB_SRC": self.missing }) + self.assertIn("Source code for the 'core' standard library could not be found", result.stderr) + + def test_success_cc_unknown(self): + result = self.run_script(self.Expected.SUCCESS_WITH_EXTRA_OUTPUT, { "CC": self.missing }) + self.assertIn("unknown C compiler", result.stderr) + + def test_success_cc_multiple_arguments_ccache(self): + clang = self.generate_clang(f"""Ubuntu clang version {self.llvm_default_version}-1ubuntu1 +Target: x86_64-pc-linux-gnu +Thread model: posix +InstalledDir: /usr/bin +""") + result = self.run_script(self.Expected.SUCCESS, { "CC": f"{clang} clang" }) + + def test_success_rustc_version(self): + for rustc_stdout in ( + f"rustc {self.rustc_default_version} (a8314ef7d 2022-06-27)", + f"rustc {self.rustc_default_version}-dev (a8314ef7d 2022-06-27)", + f"rustc {self.rustc_default_version}-1.60.0 (a8314ef7d 2022-06-27)", + ): + with self.subTest(rustc_stdout=rustc_stdout): + rustc = self.generate_rustc(rustc_stdout) + result = self.run_script(self.Expected.SUCCESS, { "RUSTC": rustc }) + + def test_success_bindgen_version(self): + for bindgen_stdout in ( + f"bindgen {self.bindgen_default_version}", + f"bindgen {self.bindgen_default_version}-dev", + f"bindgen {self.bindgen_default_version}-0.999.0", + ): + with self.subTest(bindgen_stdout=bindgen_stdout): + bindgen = self.generate_bindgen_version(bindgen_stdout) + result = self.run_script(self.Expected.SUCCESS, { "BINDGEN": bindgen }) + + def test_success_bindgen_libclang(self): + for stderr in ( + f"scripts/rust_is_available_bindgen_libclang.h:2:9: warning: clang version {self.llvm_default_version} (https://github.com/llvm/llvm-project.git 4a2c05b05ed07f1f620e94f6524a8b4b2760a0b1) [-W#pragma-messages], err: false", + f"/home/jd/Documents/dev/kernel-module-flake/linux-6.1/outputs/dev/lib/modules/6.1.0-development/source/scripts/rust_is_available_bindgen_libclang.h:2:9: warning: clang version {self.llvm_default_version} [-W#pragma-messages], err: false", + f"scripts/rust_is_available_bindgen_libclang.h:2:9: warning: clang version {self.llvm_default_version} (Fedora 13.0.0-3.fc35) [-W#pragma-messages], err: false", + f""" +/nix/store/dsd5gz46hdbdk2rfdimqddhq6m8m8fqs-bash-5.1-p16/bin/bash: warning: setlocale: LC_ALL: cannot change locale (c) +scripts/rust_is_available_bindgen_libclang.h:2:9: warning: clang version {self.llvm_default_version} [-W#pragma-messages], err: false +""", + f""" +/nix/store/dsd5gz46hdbdk2rfdimqddhq6m8m8fqs-bash-5.1.0-p16/bin/bash: warning: setlocale: LC_ALL: cannot change locale (c) +/home/jd/Documents/dev/kernel-module-flake/linux-6.1/outputs/dev/lib/modules/6.1.0-development/source/scripts/rust_is_available_bindgen_libclang.h:2:9: warning: clang version {self.llvm_default_version} (Fedora 13.0.0-3.fc35) [-W#pragma-messages], err: false +""" + ): + with self.subTest(stderr=stderr): + bindgen = self.generate_bindgen_libclang(stderr) + result = self.run_script(self.Expected.SUCCESS, { "BINDGEN": bindgen }) + + def test_success_clang_version(self): + for clang_stdout in ( + f"clang version {self.llvm_default_version} (https://github.com/llvm/llvm-project.git 4a2c05b05ed07f1f620e94f6524a8b4b2760a0b1)", + f"clang version {self.llvm_default_version}-dev", + f"clang version {self.llvm_default_version}-2~ubuntu20.04.1", + f"Ubuntu clang version {self.llvm_default_version}-2~ubuntu20.04.1", + ): + with self.subTest(clang_stdout=clang_stdout): + clang = self.generate_clang(clang_stdout) + result = self.run_script(self.Expected.SUCCESS, { "CC": clang }) + + def test_success_real_programs(self): + for cc in ["gcc", "clang"]: + with self.subTest(cc=cc): + result = self.run_script(self.Expected.SUCCESS, { + "PATH": os.environ["PATH"], + "RUSTC": "rustc", + "BINDGEN": "bindgen", + "CC": cc, + }) + +if __name__ == "__main__": + unittest.main()