Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp3880366rwb; Sat, 21 Jan 2023 01:57:55 -0800 (PST) X-Google-Smtp-Source: AMrXdXvubNOPa4Z7JRy0tdloEv5YGVYMckgRuANLFyGTRFg0HGF29z9ltp3fzKaxWkWvwhpF6Cbz X-Received: by 2002:a05:6402:448:b0:492:798:385e with SMTP id p8-20020a056402044800b004920798385emr30542417edw.33.1674295074924; Sat, 21 Jan 2023 01:57:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674295074; cv=none; d=google.com; s=arc-20160816; b=mE7bn5wiP35o5RxyWjXfuTytR0coMFuDeW1XK/6ALlwXSEFFj0xcql5jKVTxClWJFy iX+4xpBgb2gFTkpuF275g3mmGo0DZw07F3fr+uiFH5ueaPWVRskAv9t6kRHolnr6JOk8 c0Bhmim3nXovk7G4tkrj5/7ufdTFXIJZa4e+VNhtgLb0dXFOKrZQiudUtaFxZ7lV0W1Q TU3m1EGOqQ1MgkYN8BMFVgehsVJ8laTBz5TbCmFRRDJP1pNrtkkNp8etNvsvVPam/WrI twhvGN6d3BA6AM0geFpFkaFZPux3Df7CkyL3NVIIv8B3k03DI+18SjNXYHUp8kQrKCIZ bZYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=aowpnCRtenqvbx0ejFr6lUMTZot+giaS4EO5iybC5UI=; b=e+0t+D6a0V/tz2w7844nQklmURVwuhAJsNeWV0wb6/BpgSbQp68JbJgv24Kvzbw6+q Si4cUqt5TCBu+h059Yew5QsJDVKHgG0oQqR9k9a6v159+ZC5EZj+zSfJK1HqIePV01+m 8teB1Qx8HrUkvdKce7a3piqRGyf/m+JBXflkRmkFwKiAhDZap99rAsJ4sCT1YnPTSD+W N1vyrh4S4Iy2wTXR3LR9siXBLfmfhkfrdJMYMtkR+AtKuUebIyBiw2urHSGSmYyEsmoU XJoRcZWdHNjiFY0kwangKCtdBkL2tsOx9OJTC6kD2y1EjhIhX94bUbtJoGtNlCWKaXn3 aKrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bbQpInJV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dp15-20020a170906c14f00b008717c29397csi19035263ejc.55.2023.01.21.01.57.42; Sat, 21 Jan 2023 01:57:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bbQpInJV; 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 S229667AbjAUJSt (ORCPT + 52 others); Sat, 21 Jan 2023 04:18:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229575AbjAUJSn (ORCPT ); Sat, 21 Jan 2023 04:18:43 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBC4B4F84B; Sat, 21 Jan 2023 01:18:41 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 76E35B82841; Sat, 21 Jan 2023 09:18:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 25334C433A1; Sat, 21 Jan 2023 09:18:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674292719; bh=mA9ejibVRK+MNBY1BLKv1msYutJZL66f/w8OohSF5UU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=bbQpInJVCXxBiCnrM72P5EMfLfGcbmhmvXOsmiJdmga77QV2yGi9oWLmTVhnI0x9O 1v7fqVDQizG1y0GesYFU9VFKLlBai2uX9G0xDltEkECPyG+PEwiJ8p73cRe1Bji9Qs g8ylOuvB5sHzH7pFf5JuzutVQxOBzE7qw3jhIyDap6gOcxjwtiqkqhK4AzHcOef8Y5 kWTHcvQJLdq3asdkXONcq3NS02tHieofMCDkjgMBXeeabcaTq0TpOdKV3zXC3ZDZ9/ 7OZ7GRVJba5B/f7zBV0bJn5tzzX9ck22P/Z67Ol/l3i78bbzgBGBAPVXVMMzHblQ4y j+pOYkeF65MfA== Received: by mail-oi1-f178.google.com with SMTP id d188so6394669oia.3; Sat, 21 Jan 2023 01:18:39 -0800 (PST) X-Gm-Message-State: AFqh2kr3lBQDmQf2Ftyd5kDru+WrbwD3ii8ecdCSKmI5j2HE2leDCXEW tHKWWG1FJ4AfYI82UlgyOGnTkT31T6i+hUMciOw= X-Received: by 2002:a05:6808:1786:b0:35e:7c55:b015 with SMTP id bg6-20020a056808178600b0035e7c55b015mr1077897oib.287.1674292718293; Sat, 21 Jan 2023 01:18:38 -0800 (PST) MIME-Version: 1.0 References: <20230121052507.885734-1-varmavinaym@gmail.com> In-Reply-To: <20230121052507.885734-1-varmavinaym@gmail.com> From: Masahiro Yamada Date: Sat, 21 Jan 2023 18:18:01 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] scripts: `make rust-analyzer` for out-of-tree modules To: Vinay Varma Cc: alicef@alicef.me, Michal Marek , Nick Desaulniers , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,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 On Sat, Jan 21, 2023 at 2:25 PM Vinay Varma wrote: > > Adds support for out-of-tree rust modules to use the `rust-analyzer` > make target to generate the rust-project.json file. > > The change involves adding an optional parameter `external_src` to the > `generate_rust_analyzer.py` which expects the path to the out-of-tree > module's source directory. When this parameter is passed, I have chosen > not to add the non-core modules (samples and drivers) into the result > since these are not expected to be used in third party modules. Related > changes are also made to the Makefile and rust/Makefile allowing the > `rust-analyzer` target to be used for out-of-tree modules as well. > > Link: https://github.com/Rust-for-Linux/linux/pull/914 > Link: https://github.com/Rust-for-Linux/rust-out-of-tree-module/pull/2 > > Signed-off-by: Vinay Varma > --- > Makefile | 12 +++++++----- > rust/Makefile | 6 ++++-- > scripts/generate_rust_analyzer.py | 31 ++++++++++++++++++------------- > 3 files changed, 29 insertions(+), 20 deletions(-) > > diff --git a/Makefile b/Makefile > index f41ec8c8426b..a055a316d2a4 100644 > --- a/Makefile > +++ b/Makefile > @@ -1831,11 +1831,6 @@ rustfmt: > rustfmtcheck: rustfmt_flags = --check > rustfmtcheck: rustfmt > > -# IDE support targets > -PHONY += rust-analyzer > -rust-analyzer: > - $(Q)$(MAKE) $(build)=rust $@ > - > # Misc > # --------------------------------------------------------------------------- > > @@ -1888,6 +1883,7 @@ help: > @echo ' modules - default target, build the module(s)' > @echo ' modules_install - install the module' > @echo ' clean - remove generated files in module directory only' > + @echo ' rust-analyzer - generate rust-project.json rust-analyzer support file' > @echo '' > > endif # KBUILD_EXTMOD > @@ -2022,6 +2018,12 @@ quiet_cmd_tags = GEN $@ > tags TAGS cscope gtags: FORCE > $(call cmd,tags) > > +# IDE support targets > +PHONY += rust-analyzer > +rust-analyzer: > + $(Q)$(MAKE) $(build)=rust $@ > + > + Extra empty line. > # Script to generate missing namespace dependencies > # --------------------------------------------------------------------------- > > diff --git a/rust/Makefile b/rust/Makefile > index 8f598a904f38..41c1435cd8d4 100644 > --- a/rust/Makefile > +++ b/rust/Makefile > @@ -389,8 +389,10 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L > $(if $(rustc_objcopy),;$(OBJCOPY) $(rustc_objcopy) $@) > > rust-analyzer: > - $(Q)$(srctree)/scripts/generate_rust_analyzer.py $(srctree) $(objtree) \ > - $(RUST_LIB_SRC) > $(objtree)/rust-project.json > + $(Q)$(srctree)/scripts/generate_rust_analyzer.py \ > + $(abs_srctree) $(abs_objtree) \ > + $(RUST_LIB_SRC) $(KBUILD_EXTMOD) > \ > + $(if $(KBUILD_EXTMOD),$(extmod_prefix),$(objtree))/rust-project.json This is equivalent to: > $(extmod_prefix)/rust-project.json See the rule of 'compile_commands.json'. > $(obj)/core.o: private skip_clippy = 1 > $(obj)/core.o: private skip_flags = -Dunreachable_pub > diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py > index ecc7ea9a4dcf..1792f379ee4e 100755 > --- a/scripts/generate_rust_analyzer.py > +++ b/scripts/generate_rust_analyzer.py > @@ -6,10 +6,11 @@ > import argparse > import json > import logging > +import os > import pathlib > import sys > > -def generate_crates(srctree, objtree, sysroot_src): > +def generate_crates(srctree, objtree, sysroot_src, external_src): > # Generate the configuration list. > cfg = [] > with open(objtree / "include" / "generated" / "rustc_cfg") as fd: > @@ -65,7 +66,7 @@ def generate_crates(srctree, objtree, sysroot_src): > [], > is_proc_macro=True, > ) > - crates[-1]["proc_macro_dylib_path"] = "rust/libmacros.so" > + crates[-1]["proc_macro_dylib_path"] = f"{objtree}/rust/libmacros.so" > > append_crate( > "build_error", > @@ -95,25 +96,28 @@ def generate_crates(srctree, objtree, sysroot_src): > "exclude_dirs": [], > } > > + def is_root_crate(build_file, target): > + return os.path.exists(build_file) and target in open(build_file).read() > + > # Then, the rest outside of `rust/`. > # > # We explicitly mention the top-level folders we want to cover. Huh, not maintainable, unfortunately. > - for folder in ("samples", "drivers"): > + for folder in ("samples", "drivers") if external_src is None else [external_src]: > for path in (srctree / folder).rglob("*.rs"): It is odd to add 'srctree' prefix to external module sources. I think rust-project.json is a similar concept to compile_commands.json, but it was implemented in a different way. -- Best Regards Masahiro Yamada