From: Daniel Gomez <da.gomez@samsung.com>
To: Tamir Duberstein <tamird@gmail.com>, <rust-for-linux@vger.kernel.org>
Cc: "Fiona Behrens" <me@kloenk.dev>,
"Masahiro Yamada" <masahiroy@kernel.org>,
"Nathan Chancellor" <nathan@kernel.org>,
"Nicolas Schier" <nicolas@fjasle.eu>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"David S. Miller" <davem@davemloft.net>,
"Kris Van Hees" <kris.van.hees@oracle.com>,
"Íñigo Huguet" <ihuguet@redhat.com>,
"Thomas Weißschuh" <linux@weissschuh.net>,
"Vegard Nossum" <vegard.nossum@oracle.com>,
"Laurent Pinchart" <laurent.pinchart@ideasonboard.com>,
linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org
Subject: Re: [PATCH] rust: query the compiler for dylib path
Date: Thu, 10 Oct 2024 10:08:26 +0200 [thread overview]
Message-ID: <D4RZ0TWSGGPX.3M4FKLTO3WPZ7@samsung.com> (raw)
In-Reply-To: <20241008224810.84024-1-tamird@gmail.com>
On Wed Oct 9, 2024 at 12:48 AM CEST, Tamir Duberstein wrote:
> Rust proc-macro crates are loaded by the compiler at compile-time, so
> are always dynamic libraries; on macOS, these artifacts get a .dylib
> extension rather than .so.
>
> Replace hardcoded paths ending in .so with paths obtained from the
> compiler.
>
> Signed-off-by: Fiona Behrens <me@kloenk.dev>
> Signed-off-by: Tamir Duberstein <tamird@gmail.com>
> ---
> .gitignore | 1 +
> Makefile | 2 +-
> rust/Makefile | 21 ++++++++++++---------
> scripts/generate_rust_analyzer.py | 16 ++++++++++++----
> 4 files changed, 26 insertions(+), 14 deletions(-)
>
> diff --git a/.gitignore b/.gitignore
> index 56972adb5031..7cfe4f70b39a 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -22,6 +22,7 @@
> *.dtb.S
> *.dtbo.S
> *.dwo
> +*.dylib
> *.elf
> *.gcno
> *.gcda
> diff --git a/Makefile b/Makefile
> index c5493c0c0ca1..3808869fb95b 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1506,7 +1506,7 @@ MRPROPER_FILES += include/config include/generated \
> certs/x509.genkey \
> vmlinux-gdb.py \
> rpmbuild \
> - rust/libmacros.so
> + rust/libmacros.so rust/libmacros.dylib
>
> # clean - Delete most, but leave enough to build external modules
> #
> diff --git a/rust/Makefile b/rust/Makefile
> index b5e0a73b78f3..a185a4d05b08 100644
> --- a/rust/Makefile
> +++ b/rust/Makefile
> @@ -11,9 +11,6 @@ always-$(CONFIG_RUST) += exports_core_generated.h
> obj-$(CONFIG_RUST) += helpers/helpers.o
> CFLAGS_REMOVE_helpers/helpers.o = -Wmissing-prototypes -Wmissing-declarations
>
> -always-$(CONFIG_RUST) += libmacros.so
> -no-clean-files += libmacros.so
> -
> always-$(CONFIG_RUST) += bindings/bindings_generated.rs bindings/bindings_helpers_generated.rs
> obj-$(CONFIG_RUST) += alloc.o bindings.o kernel.o
> always-$(CONFIG_RUST) += exports_alloc_generated.h exports_helpers_generated.h \
> @@ -36,9 +33,15 @@ always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated_kunit.c
> obj-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated.o
> obj-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated_kunit.o
>
> -# Avoids running `$(RUSTC)` for the sysroot when it may not be available.
> +# Avoids running `$(RUSTC)` when it may not be available.
> ifdef CONFIG_RUST
>
> +libmacros_name := $($(RUSTC) --print file-names --crate-name macros --crate-type proc-macro - < /dev/null)
> +libmacros_extension := $(patsubst libmacros.%,%,$(libmacros_name))
> +
> +always-$(CONFIG_RUST) += $(libmacros_name)
> +no-clean-files += $(libmacros_name)
> +
> # `$(rust_flags)` is passed in case the user added `--sysroot`.
> rustc_sysroot := $(shell MAKEFLAGS= $(RUSTC) $(rust_flags) --print sysroot)
> rustc_host_target := $(shell $(RUSTC) --version --verbose | grep -F 'host: ' | cut -d' ' -f2)
> @@ -115,10 +118,10 @@ rustdoc-alloc: $(RUST_LIB_SRC)/alloc/src/lib.rs rustdoc-core rustdoc-compiler_bu
> +$(call if_changed,rustdoc)
>
> rustdoc-kernel: private rustc_target_flags = --extern alloc \
> - --extern build_error --extern macros=$(objtree)/$(obj)/libmacros.so \
> + --extern build_error --extern macros=$(objtree)/$(obj)/$(libmacros_name) \
> --extern bindings --extern uapi
> rustdoc-kernel: $(src)/kernel/lib.rs rustdoc-core rustdoc-macros \
> - rustdoc-compiler_builtins rustdoc-alloc $(obj)/libmacros.so \
> + rustdoc-compiler_builtins rustdoc-alloc $(obj)/$(libmacros_name) \
> $(obj)/bindings.o FORCE
> +$(call if_changed,rustdoc)
>
> @@ -339,10 +342,10 @@ quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
> -Clink-args='$(call escsq,$(KBUILD_HOSTLDFLAGS))' \
> --emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \
> --crate-type proc-macro \
> - --crate-name $(patsubst lib%.so,%,$(notdir $@)) $<
> + --crate-name $(patsubst lib%.$(libmacros_extension),%,$(notdir $@)) $<
>
> # Procedural macros can only be used with the `rustc` that compiled it.
> -$(obj)/libmacros.so: $(src)/macros/lib.rs FORCE
> +$(obj)/$(libmacros_name): $(src)/macros/lib.rs FORCE
> +$(call if_changed_dep,rustc_procmacro)
>
> quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L $@
> @@ -421,7 +424,7 @@ $(obj)/uapi.o: $(src)/uapi/lib.rs \
> $(obj)/kernel.o: private rustc_target_flags = --extern alloc \
> --extern build_error --extern macros --extern bindings --extern uapi
> $(obj)/kernel.o: $(src)/kernel/lib.rs $(obj)/alloc.o $(obj)/build_error.o \
> - $(obj)/libmacros.so $(obj)/bindings.o $(obj)/uapi.o FORCE
> + $(obj)/$(libmacros_name) $(obj)/bindings.o $(obj)/uapi.o FORCE
> +$(call if_changed_rule,rustc_library)
>
> endif # CONFIG_RUST
> diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
> index d2bc63cde8c6..3834ab0eea9d 100755
> --- a/scripts/generate_rust_analyzer.py
> +++ b/scripts/generate_rust_analyzer.py
> @@ -9,6 +9,8 @@ import logging
> import os
> import pathlib
> import sys
> +import os
> +import subprocess
import os is duplicated.
>
> def args_crates_cfgs(cfgs):
> crates_cfgs = {}
> @@ -35,8 +37,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs):
> crates_cfgs = args_crates_cfgs(cfgs)
>
> def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False):
> - crates_indexes[display_name] = len(crates)
> - crates.append({
> + crate = {
> "display_name": display_name,
> "root_module": str(root_module),
> "is_workspace_member": is_workspace_member,
> @@ -47,7 +48,15 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs):
> "env": {
> "RUST_MODFILE": "This is only for rust-analyzer"
> }
> - })
> + }
> + if is_proc_macro:
> + proc_macro_dylib_name = subprocess.check_output(
> + [os.environ["RUSTC"], "--print", "file-names", "--crate-name", display_name, "--crate-type", "proc-macro", "-"],
> + stdin=subprocess.DEVNULL,
> + ).decode('utf-8')
> + crate["proc_macro_dylib_path"] = f"{objtree}/rust/{proc_macro_dylib_name}"
> + crates_indexes[display_name] = len(crates)
> + crates.append(crate)
>
> # First, the ones in `rust/` since they are a bit special.
> append_crate(
> @@ -77,7 +86,6 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs):
> [],
> is_proc_macro=True,
> )
> - crates[-1]["proc_macro_dylib_path"] = f"{objtree}/rust/libmacros.so"
>
> append_crate(
> "build_error",
prev parent reply other threads:[~2024-10-10 8:08 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20241010080828eucas1p1a1fbd99e5f7bb1c454f14ba4fa19a3e1@eucas1p1.samsung.com>
2024-10-08 22:48 ` [PATCH] rust: query the compiler for dylib path Tamir Duberstein
2024-10-09 12:42 ` Miguel Ojeda
2024-10-09 12:56 ` Tamir Duberstein
2024-10-09 13:12 ` Miguel Ojeda
2024-10-09 13:18 ` Tamir Duberstein
2024-10-09 14:07 ` [PATCH v3] " Tamir Duberstein
2024-10-09 14:28 ` Miguel Ojeda
2024-10-09 14:33 ` [PATCH v4] " Tamir Duberstein
2024-10-09 14:20 ` [PATCH] " Miguel Ojeda
2024-10-09 14:47 ` Tamir Duberstein
2024-10-12 13:17 ` Miguel Ojeda
2024-10-10 8:31 ` Daniel Gomez
2024-10-10 14:28 ` [PATCH v5] " Tamir Duberstein
2024-10-14 18:44 ` Masahiro Yamada
2024-10-12 13:41 ` [PATCH] " Miguel Ojeda
2024-10-12 14:25 ` Tamir Duberstein
2024-10-12 23:37 ` Miguel Ojeda
2024-10-12 23:52 ` Tamir Duberstein
2024-10-14 18:45 ` Masahiro Yamada
2024-10-14 19:08 ` Miguel Ojeda
2024-10-15 1:10 ` Tamir Duberstein
2024-10-15 10:33 ` Miguel Ojeda
2024-10-15 15:05 ` Tamir Duberstein
2024-10-15 15:30 ` Miguel Ojeda
2024-10-15 15:53 ` Tamir Duberstein
2024-10-16 1:35 ` Masahiro Yamada
2024-10-15 9:10 ` Miguel Ojeda
2024-10-10 8:08 ` Daniel Gomez [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=D4RZ0TWSGGPX.3M4FKLTO3WPZ7@samsung.com \
--to=da.gomez@samsung.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=davem@davemloft.net \
--cc=gary@garyguo.net \
--cc=ihuguet@redhat.com \
--cc=kris.van.hees@oracle.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=masahiroy@kernel.org \
--cc=me@kloenk.dev \
--cc=nathan@kernel.org \
--cc=nicolas@fjasle.eu \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@gmail.com \
--cc=tmgross@umich.edu \
--cc=vegard.nossum@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox