Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2127997lqt; Mon, 22 Apr 2024 02:09:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVFXfu63a9qMDoU2o651vGl4FCdW0s8TuRAOeoDkXcgqqyYB06OSPGD6fHDRmYXs47TpmkVAzXKgHvt4jv+0yax969CuNfkDsrWae//7w== X-Google-Smtp-Source: AGHT+IGVILCGjWeOmSjshVyKor98maMMZ7N6pZ817frjjLn1UIK7O0ct1jQeyNVb/glMjeiquiy9 X-Received: by 2002:ae9:f00d:0:b0:78e:fd3c:b6 with SMTP id l13-20020ae9f00d000000b0078efd3c00b6mr9834078qkg.40.1713776966891; Mon, 22 Apr 2024 02:09:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713776966; cv=pass; d=google.com; s=arc-20160816; b=TxvqaY/0Bw03cV67UZo0OKT63TMPHO6UsYKAOpKA8WT3TQR0TQNuZx+N3vhB9X9bFe ++tVZ85OXrRVW3vhQch9nJpIAAX+m2yNiNEvQTbd5RbXR6Rri12cGf6CxJVD185KRd+V B42JwcEeUkzPeWlY0BoQ3+I5KcM6X1ARulaWmLxFAW+8nGNiH5mBwPwnIWsXRqm9fakZ 5Can3lUk2LXMb+B8NTpFfCY4zeSQvbAnV9x8j+wq2lkH46anjmlWi4yqKvv9hOaSoA+M ZL0xuYlr0oVpdPHWNbG82h7baQyNGkLH5jpZWCkzqyBLfqvKPuDBCMB5JTY764E71ZrE cYPg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=7egbxtEsa+pAfbOTBEvWhYQu/eusMYIzakJBZ/3bIwM=; fh=dQ8pA3ex66+aize+HrCJC0qlezwft/0YKBYMg5cqZu4=; b=YTUlWreNfTE4MCuV4gHLFv3euMJ5KLgNIY4iVsnYioFe2r1dH/6Hwx3uLoHxVwhtIg 8CcOKP0m1GtViAqa7gneLTK58jYIMPRJoD0czUr+QlBJzdISh2KvvhXwX+cDS8350lhd w2Ro7QpHo8o9FFb1AOebo+LkvpQs23I0WagVazIp9II4Ky+fcBLkm4CG/VZ95/ROelew vmdC16e2BdIlat74I1eL8q2Sh6BvBpzyVpGjHFs8lW+JItL0Bven51zOUzo20aTGOWOR rPYdmMF4C4lFsYfcMWJATuMJkMuOYyOVC5dDdXNDnSJko0VQNlThOSFZtctApKJgqVm0 6TBQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="f/vWRz1/"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-153060-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153060-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id v3-20020ae9e303000000b007905cfc3a5asi6279972qkf.6.2024.04.22.02.09.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 02:09:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-153060-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="f/vWRz1/"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-153060-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153060-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 76D1A1C20A8E for ; Mon, 22 Apr 2024 09:09:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B57A313CA93; Mon, 22 Apr 2024 09:08:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="f/vWRz1/" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C353F56B62; Mon, 22 Apr 2024 09:08:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713776893; cv=none; b=St8aI6tvmqBgmHKq66hFH2PzL7QPjFHDxWsiV6WrGjdV+U6PjJlrZmnqvs9Ht8gkHn0zKL0ya7dHKJ4wTkmQ5b9eprnN0ZyWEzJJ3uI9aR4ta7V8gC4lFtGRHg+4Yod61RQbZ7zsfazlMaXiEKUf3rbbNNOwyVsGCUbNBIdLYJE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713776893; c=relaxed/simple; bh=nLmuYu0vjDSSPfnTZYanrd2ZE6KNz5H4Gy9hK4smJew=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=tX9PzLz9UubyHdIL3m8/yrYpOve8eb3Y7yKq1AvPw1hvygq2wup7zZDdxPOelyTlp37D/31mWXvT3ueMnliB0zXJxEHDGbrx9dJLIKorkJkYzhhNPKPgvpUdJqVdcRZabMKKU8iudP1YfunDWaB/8phYpTXCiBkcjdQD/m/Zgyc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=f/vWRz1/; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E509CC2BD11; Mon, 22 Apr 2024 09:08:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713776893; bh=nLmuYu0vjDSSPfnTZYanrd2ZE6KNz5H4Gy9hK4smJew=; h=From:To:Cc:Subject:Date:From; b=f/vWRz1/H6RXhOhaIZGUNLX/n8qb9XAR7xOna0+LcmYCPgZjinz83E8Vtio5GaKhn Nm4hZTOi24CKzp40peY24bICe/TcrJ111eJwPohJXcliwcsp69ocFNwcQMxNk53OKK 0bnVjrf9NpyB9yTm1yoyfKdPy5r8a40uYvCBnYenIzWd7WQnJNVSn77wguPWgsG98C zJPz9ZeRAcnrwVkE9obdd4a/RixaIcBNmx/zOcnPNlu8jAcCPc7nkKwbq4VhrUJcyU 84/7GOh0UOtsYz+4ASehvMM2Jat4Ac5CD1HC6kNCvo+2er+8ZbKkDR/ahRTzRc2yWz jMHQAxvBZlZpQ== 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 , Andreas Hindborg , Alice Ryhl , linux-kbuild@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, stable@vger.kernel.org, Daniel Almeida , Julian Stecklina Subject: [PATCH] kbuild: rust: force `alloc` extern to allow "empty" Rust files Date: Mon, 22 Apr 2024 11:06:44 +0200 Message-ID: <20240422090644.525520-1-ojeda@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit If one attempts to build an essentially empty file somewhere in the kernel tree, it leads to a build error because the compiler does not recognize the `new_uninit` unstable feature: error[E0635]: unknown feature `new_uninit` --> :1:9 | 1 | feature(new_uninit) | ^^^^^^^^^^ The reason is that we pass `-Zcrate-attr='feature(new_uninit)'` (together with `-Zallow-features=new_uninit`) to let non-`rust/` code use that unstable feature. However, the compiler only recognizes the feature if the `alloc` crate is resolved (the feature is an `alloc` one). `--extern alloc`, which we pass, is not enough to resolve the crate. Introducing a reference like `use alloc;` or `extern crate alloc;` solves the issue, thus this is not seen in normal files. For instance, `use`ing the `kernel` prelude introduces such a reference, since `alloc` is used inside. While normal use of the build system is not impacted by this, it can still be fairly confusing for kernel developers [1], thus use the unstable `force` option of `--extern` [2] (added in Rust 1.71 [3]) to force the compiler to resolve `alloc`. This new unstable feature is only needed meanwhile we use the other unstable feature, since then we will not need `-Zcrate-attr`. Cc: stable@vger.kernel.org # v6.6+ Reported-by: Daniel Almeida Reported-by: Julian Stecklina Closes: https://rust-for-linux.zulipchat.com/#narrow/stream/288089-General/topic/x/near/424096982 [1] Fixes: 2f7ab1267dc9 ("Kbuild: add Rust support") Link: https://github.com/rust-lang/rust/issues/111302 [2] Link: https://github.com/rust-lang/rust/pull/109421 [3] Signed-off-by: Miguel Ojeda --- scripts/Makefile.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index baf86c0880b6..533a7799fdfe 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -273,7 +273,7 @@ rust_common_cmd = \ -Zallow-features=$(rust_allowed_features) \ -Zcrate-attr=no_std \ -Zcrate-attr='feature($(rust_allowed_features))' \ - --extern alloc --extern kernel \ + -Zunstable-options --extern force:alloc --extern kernel \ --crate-type rlib -L $(objtree)/rust/ \ --crate-name $(basename $(notdir $@)) \ --sysroot=/dev/null \ base-commit: 4cece764965020c22cff7665b18a012006359095 -- 2.44.0