Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2130057lqt; Mon, 22 Apr 2024 02:13:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW11mKneM14jcFUwe6qcxhFzmTjbH/w63/dTIvCXJs4dHclRVp5iBAuA3kvR3iN4vY8SKA3oGSUxGCbZ8ju/KDjh/lI/A8BV6w+vJPp0w== X-Google-Smtp-Source: AGHT+IGuREbeJPtyLe/MpOx2y5rGiG6To98biUvbAmV4t+NPol54N2U9cVUPWeOEM+1gy3bIo25x X-Received: by 2002:a50:bb08:0:b0:566:d333:45e8 with SMTP id y8-20020a50bb08000000b00566d33345e8mr7040954ede.20.1713777218569; Mon, 22 Apr 2024 02:13:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713777218; cv=pass; d=google.com; s=arc-20160816; b=zvpisOAc69fiQvZrgEsDBfD1d0fufijHMr2XYG5E0Vhl85cy8de6YSwHCq3USRC/Tw a4Yx2qQmX/Hbt0hvj0ZPzNkQ8WCJjY1YiJ8UJpr1dq7attMdtH6AWPSDZc8uTe07452U 2d5MbRwoC42qj4DfkISRQQAo41M3igSOwHpaPc29GSn0mxulLsloip4RnZzIud01w50r re6aAjTQlbvWM95c5I/RU/sKm/1NCn7IpHl/T50kdt3jFangkKO9joTLL32t/pl0igTz Rfwbq8e8G+qrp/gzXsE1Eji8ARnDAtNXxqiJxKfIXf6LL5OunQBiLykBft9Ww9ECTWQr RlmA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=QebkKGtK/XqpHpUc2nwxSwucxpv5AvI/DnU2unuULxo=; fh=EwM9mEzKOsuZWvhq61JfCHUUSnNUG5I0hFknXfRKDmY=; b=r8afpUq+4DUacRD8V0hdBAQBGF1nkoLY8Q2kGADRAj1XC7Ju1su0Jt+yVoWfHxLa2A l7DgCFFlYbdslmA050HNZ7IH32kn2A6u7Ht49hLTG8W3u3fp+3Zc/7V7EsKSSguB0Pi1 Ecni314Gei6hV00bs7Prt1rxXtbgqOfsOhW7o5uY5uecXlzZ+2gSE7UFS8BXuo4NQBCF 20aMAjxyuXmj2DpveY121QDU0dgjGOoh6HEOYG7nnkQu5ygee+EReZ378TI+PLuFlqfN Xs9JDlUYS8Lm1Q4cIwCinlQ2nDkQb2P2FU1Tnea+eRcjyvoZgQQiuPEePSAnzyQVXEGu iv5Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=YEMCdOJq; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-153070-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153070-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id s23-20020a50d497000000b00571b20a1400si5807827edi.472.2024.04.22.02.13.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 02:13:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-153070-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=YEMCdOJq; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-153070-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153070-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 4DFE21F247E1 for ; Mon, 22 Apr 2024 09:13:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B567153805; Mon, 22 Apr 2024 09:13:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YEMCdOJq" Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1336153E35 for ; Mon, 22 Apr 2024 09:13:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713777195; cv=none; b=Jx41iewgQ9tMf1kptBHaHot2xZsP4xC25dex7CtFFUTu5EJcAeue+M1mPXAX/lq9Uqt/jjDCiotKY8KV5h0dIGewfinIEbX4wC1j3Ii7CLwoAJfL6zwkk36HIwxBDlkA5nYmkRpJZ4WuK28L5Si6tmhy2TklHT85iAfu4LAZaEQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713777195; c=relaxed/simple; bh=7avuffUOa/Q3Pcy1DWsnTSzRKVAI1nDHdyVzBoGiFPY=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=qrzAfoY7cXNstsP91Y8Qjia1+pYywW+qc5gDoVyYgJFDPqapkmC6/rm3pMwdvzf8BcRM+rQhhuSBsz1K7awG3nEuMq4viz/bhHidczE1Ik7jE8UXKVRifT0gnyp5YyLZ3uU4+sI9NVsHyduXuGq6TEh6I+qsxgX2ofX5zs8leMY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=YEMCdOJq; arc=none smtp.client-ip=209.85.128.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-617f8a59a24so34575847b3.1 for ; Mon, 22 Apr 2024 02:13:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713777192; x=1714381992; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=QebkKGtK/XqpHpUc2nwxSwucxpv5AvI/DnU2unuULxo=; b=YEMCdOJqFCVsngC4v07lnoToCemqG7BSt5Y14OgqXeDCdjaXbQnlxZw4Rk6KO8J9du uyQn8Wt4I/5yNA1O74N+impKRlyjEH8qOfV6lceVpJtNACOls7Vh2JElChMkuJOVqrWO Q6r1yFGg3uh76GCXOEXMHJ7bfz1K+q23v4B7SLxHq03XgncbWY9Tvicoauau531ATH6c BpjgfziiGNyr0u3fdKoNX5mhFeN5AcGd/IJ3nOPhqVfimyqW+kuj+gE/He26t3KqD5vZ 7p/G3M0PZ2WzjMGv4beBfz1Exi/z0y6HsoNo4iKF3yYti/H6lcGHBQXCeI6qGZTKTUXS nhWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713777192; x=1714381992; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QebkKGtK/XqpHpUc2nwxSwucxpv5AvI/DnU2unuULxo=; b=X2dEtHkNcf42yvVgORU+QHaDGTst2Fzbfe60j5yRymRyz/Gj6tdhmOWg8OtitqgEXW XuP78uYDuMWD6uVusGi8v9n2eNMx6V6u7pbDMjpvw0dURDChWx8ORGl2Ez3RgVwCJG3i QAvAzYLT+UlSnX8YMKOP+AT82BfUVKW46wmV0XYN5E9M5gbqcb4R7PJzUFEnz/ZBZn/P 4vbxZSKn69wjhCsEGxHgQlX0yaXj/8iznsVWNXVzuvFblAu2v1thwPlnAJjrqUBEvtIK y1aeLZJwFA3zbBgiN/1ozYwkuPhE10Dzwic6Znvg/5yaZdvmmsm9agGDjVTknomTKIhF Ch8g== X-Forwarded-Encrypted: i=1; AJvYcCWX28Bdkyx2cgW4s9IJN4VPCt86br8fOi4WDB5DVBTqveaQCDo1rya/2pjhC3eRml/m2PEaJ2qEaFV02720SfhRjN0D5p1LZoYQSiqC X-Gm-Message-State: AOJu0YzCFpO/A84oWiEbm13q+j24VdR+ELtz8QYyTeZN9Kapjppz8ScH AS3FhBOE8rEq7ukVt2Uqs0BfkkTlPYOadj0UcDW2p+eNCRqPjaSqtWrDnaZ2nu0DO7o1Cx+84Wr 8dTC+dHf2XV4xf1lpkWE/i+qoUB+M2naP8ST7 X-Received: by 2002:a05:690c:b15:b0:618:8a27:f26 with SMTP id cj21-20020a05690c0b1500b006188a270f26mr8241721ywb.48.1713777191944; Mon, 22 Apr 2024 02:13:11 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240422090644.525520-1-ojeda@kernel.org> In-Reply-To: <20240422090644.525520-1-ojeda@kernel.org> From: Alice Ryhl Date: Mon, 22 Apr 2024 11:13:00 +0200 Message-ID: Subject: Re: [PATCH] kbuild: rust: force `alloc` extern to allow "empty" Rust files To: Miguel Ojeda Cc: Masahiro Yamada , Wedson Almeida Filho , Alex Gaynor , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Apr 22, 2024 at 11:08=E2=80=AFAM Miguel Ojeda wr= ote: > > 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=3D'feature(new_uninit)'` (togeth= er > with `-Zallow-features=3Dnew_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 stil= l > 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-Genera= l/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 Reviewed-by: Alice Ryhl