From patchwork Tue Jul 18 05:52:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 13316742 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18C70EB64DA for ; Tue, 18 Jul 2023 05:53:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229496AbjGRFxE (ORCPT ); Tue, 18 Jul 2023 01:53:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230496AbjGRFw7 (ORCPT ); Tue, 18 Jul 2023 01:52:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E64ADE56; Mon, 17 Jul 2023 22:52: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 84EB96145F; Tue, 18 Jul 2023 05:52:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40276C433C7; Tue, 18 Jul 2023 05:52:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689659577; bh=PlSlsqHDqw67L6N41kdBC8ML9MQoqYiPEiBjjydxhOg=; h=From:To:Cc:Subject:Date:From; b=bKhQPfEDuI1pDq4l9wyUuymLSoTsnxo1GvrG/Es/WawS5X4hE9bWy9pTJh4yA3Nj3 MxlVo6XX6Gj8/xnDHz2Y1Ci9vcWiEF6yrrf7zj0A/O6vSRnU+YUfpuxxTV4cyWbiO2 J7Vnz71dErFpjiDiYSwddt5vEsl5o/pyV/pJO6s5SYBb5VVZymmk4LTXqMHo4d8mCt 5qPlnoKxOUTnr9/2jYQsbrXI+BnP8M7CBgaucPTRkZlw80JmvS5k7fODlR4/RXA331 iFxBLNeqLscvckubTDjfnFkDez1N1FU+N5cnW/t/jOTILQgUsENboSXYOozQDoo1cx Z5Uqa6u1j1Ktg== 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, Raphael Nestler , Andrea Righi , stable@vger.kernel.org Subject: [PATCH] kbuild: rust: avoid creating temporary files Date: Tue, 18 Jul 2023 07:52:35 +0200 Message-ID: <20230718055235.1050223-1-ojeda@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org `rustc` outputs by default the temporary files (i.e. the ones saved by `-Csave-temps`, such as `*.rcgu*` files) in the current working directory when `-o` and `--out-dir` are not given (even if `--emit=x=path` is given, i.e. it does not use those for temporaries). Since out-of-tree modules are compiled from the `linux` tree, `rustc` then tries to create them there, which may not be accessible. Thus pass `--out-dir` explicitly, even if it is just for the temporary files. Reported-by: Raphael Nestler Closes: https://github.com/Rust-for-Linux/linux/issues/1015 Reported-by: Andrea Righi Tested-by: Raphael Nestler Tested-by: Andrea Righi Cc: stable@vger.kernel.org Signed-off-by: Miguel Ojeda Reviewed-by: Nathan Chancellor Reviewed-by: Martin Rodriguez Reboredo --- scripts/Makefile.build | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) base-commit: 06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5 diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 6413342a03f4..82e3fb19fdaf 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -264,6 +264,9 @@ $(obj)/%.lst: $(src)/%.c FORCE rust_allowed_features := new_uninit +# `--out-dir` is required to avoid temporaries being created by `rustc` in the +# current working directory, which may be not accessible in the out-of-tree +# modules case. rust_common_cmd = \ RUST_MODFILE=$(modfile) $(RUSTC_OR_CLIPPY) $(rust_flags) \ -Zallow-features=$(rust_allowed_features) \ @@ -272,7 +275,7 @@ rust_common_cmd = \ --extern alloc --extern kernel \ --crate-type rlib -L $(objtree)/rust/ \ --crate-name $(basename $(notdir $@)) \ - --emit=dep-info=$(depfile) + --out-dir $(dir $@) --emit=dep-info=$(depfile) # `--emit=obj`, `--emit=asm` and `--emit=llvm-ir` imply a single codegen unit # will be used. We explicitly request `-Ccodegen-units=1` in any case, and