Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp2099914rwo; Sun, 23 Jul 2023 07:36:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlE9HNp7PvdvbylHR04PmQibwBYqt/N3RP1/qEcgTXeTF8N/GFHJmxTYgA7Y5NSRDiJhMwMc X-Received: by 2002:a05:6a00:2e93:b0:668:83b7:fd02 with SMTP id fd19-20020a056a002e9300b0066883b7fd02mr5629725pfb.31.1690122974493; Sun, 23 Jul 2023 07:36:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690122974; cv=none; d=google.com; s=arc-20160816; b=u/VuRYYTaIXkoFN8CfGZqFJkCCYPZC8LudEvaTobGqDK+nem5LBlDNRbElWSCyIYp3 9CWqKhQdeB32+Yo+f/ABRpibLOI5ItYH1KyiSVgnnQFHEbCQSU5j9NSBKFKJH3FG8MHF w7RyEyNSr5uXnhiGcperboXukEVfQsEE1pEIf/rkUX7jay7SNDue3M7urzhJcu7oCnbt 1/yyV/3NNGJhtYZEbaMGVOothnpUSEyfoz5PoaDdeaYvgqi4SW/B+lr8mThUHkVJ+3LX 7EIjLqNetcY3u3HBUPpW5D/TkytaNC3Fnp//7ZkyvZXjMBbAaQRxYV4EG779JGAzpizb jaUA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=CLy7wwXz8GF5Pot688QURVk+eOypCHTBMHugUw+rCEQ=; fh=mKR6j7Vi7skgMbwTZDlFCcR7Y+6HRFNBbME2zORdlDg=; b=QbCVApYG330liFecJGKhL9XXUEr4+25pYd4QFIvSCdpEbt1Y+7RGO2lMW0wwr7QQCj XfT+j7liGlJIbLLRep/H0Nmu0lYvgK45FlyeuOdSqjSIiScJjCdQ5nm8oji1rONYF4or StXDmFQWTCssxIvffWY3zLHg2wXgEm2cZZQq07m6wfq8iSd6XLYBfBpOURIG0vjyxgpN XBMFHH49rRk3ovvynu83qD7kPMYdHvg6olq/WJXezlDe21ALfPzAbBtdpgaaTCA9Xbfv PAn8hsqI0Ic0b3SViEXU2d3+FcaWr8NcF1vP9TC3caiNtmPsUBGIw9UP3FVWb0mUpeYh vs/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Nf3VNf1V; 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 l23-20020a637017000000b00543a89c95c2si7434173pgc.207.2023.07.23.07.36.02; Sun, 23 Jul 2023 07:36:14 -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=Nf3VNf1V; 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 S229603AbjGWOVw (ORCPT + 99 others); Sun, 23 Jul 2023 10:21:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbjGWOVv (ORCPT ); Sun, 23 Jul 2023 10:21:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C910CB8; Sun, 23 Jul 2023 07:21:50 -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 66E5A60D36; Sun, 23 Jul 2023 14:21:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C4A3C433C8; Sun, 23 Jul 2023 14:21:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690122109; bh=P7IlLhixxEgKf7EpbN4DFFwoc1k1ZVIYZ+hvTtej5ok=; h=From:To:Cc:Subject:Date:From; b=Nf3VNf1VQPkyJzPRuDrzkcf1vm0BYDCgs5u38VttEdibhXOWuzQQSsD3WNFktN6xR ZgV4t4LN67chHoHXYej97xlQCGNic9iTMRBTL60pA1YBG14IARxvxa7fda8/4kxQK0 0/LBixFhlZKzcYZMAG1r5lA6FebXZvQZGDvoSO+/q2QVl7iJa4IeIhVJV3h/EbuIIy Ms1nownVv8FuDcm7l+X5tRzAUjtvWzYpdB4YG5OAjRhMGjIDXyZIU5DgUeuuhePlkb MEavIeV66nZVBoOYLSoc/bPX2f/BwWOdJdREhdEBcorsYvwzxyUZczqxsRtG7ijRo+ WrVow2dPnon/w== 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=20Roy=20Baron?= , 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 v2] kbuild: rust: avoid creating temporary files Date: Sun, 23 Jul 2023 16:21:28 +0200 Message-ID: <20230723142128.194339-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 `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. Similarly, do so for Rust host programs too. Reported-by: Raphael Nestler Closes: https://github.com/Rust-for-Linux/linux/issues/1015 Reported-by: Andrea Righi Tested-by: Raphael Nestler # non-hostprogs Tested-by: Andrea Righi # non-hostprogs Fixes: 295d8398c67e ("kbuild: specify output names separately for each emission type from rustc") Cc: stable@vger.kernel.org Signed-off-by: Miguel Ojeda --- v2: - Add fix for host programs too (Masahiro). scripts/Makefile.build | 5 ++++- scripts/Makefile.host | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) 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 diff --git a/scripts/Makefile.host b/scripts/Makefile.host index 7aea9005e497..8f7f842b54f9 100644 --- a/scripts/Makefile.host +++ b/scripts/Makefile.host @@ -86,7 +86,11 @@ hostc_flags = -Wp,-MMD,$(depfile) \ hostcxx_flags = -Wp,-MMD,$(depfile) \ $(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \ $(HOSTCXXFLAGS_$(target-stem).o) -hostrust_flags = --emit=dep-info=$(depfile) \ + +# `--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. +hostrust_flags = --out-dir $(dir $@) --emit=dep-info=$(depfile) \ $(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \ $(HOSTRUSTFLAGS_$(target-stem)) base-commit: 06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5 -- 2.41.0