Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1161006lqd; Thu, 25 Apr 2024 07:38:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUfywLAQADM57uk8XrL8mq75nOQYHqPRMeBjP7+7OGECfZYHq+y81qg/KUD71VOZ5Mxr3NqmP9Ms/zDjQzWAjmReMkBZRjVKRW8+mx3NQ== X-Google-Smtp-Source: AGHT+IE/dtpp6rPOTntzB62On6Ozy4vFfglrfTq/ILcruavNLMSTDoJxv/+0+oPoqNOP9OqFfJj8 X-Received: by 2002:a05:6a20:9710:b0:1aa:58c9:6992 with SMTP id hr16-20020a056a20971000b001aa58c96992mr5542430pzc.42.1714055912142; Thu, 25 Apr 2024 07:38:32 -0700 (PDT) Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id bv189-20020a632ec6000000b005dc864bb6e6si13181662pgb.634.2024.04.25.07.38.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 07:38:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-158673-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@garyguo.net header.s=selector1 header.b=NWImHBuQ; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-158673-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158673-linux.lists.archive=gmail.com@vger.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id CEF7AB29FAA for ; Thu, 25 Apr 2024 14:15:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 44B4314A09A; Thu, 25 Apr 2024 14:15:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=garyguo.net header.i=@garyguo.net header.b="NWImHBuQ" Received: from GBR01-LO4-obe.outbound.protection.outlook.com (mail-lo4gbr01on2094.outbound.protection.outlook.com [40.107.122.94]) (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 453D61494BB; Thu, 25 Apr 2024 14:15:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.122.94 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714054539; cv=fail; b=n3qWgMSi9YXw6zeVsftyRkFS3nrAcO5G2aGWAIY6jJp0CnheGbvmu9aFgFFhdz7QiX/Sw08G6lnNTbv6HDJmu+n+Tup2vyKYrET7e2AFY+nGSfNgQ0vaUl1QkQLuS418JQp4qXZTw71sAv99lSl4W6Z9/u7BxYTJuVw4Owd61rM= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714054539; c=relaxed/simple; bh=Cu0nFxyTMNGkngcpZcLD5uAryF2daqLDA1gcv3Zice8=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=tu1WQtAzB8NwbrCTL8g/BkfiFNLH563cRT9suffSQ7TVjQFuEcIwKy0TTanABvlWLNel/Ip61XGhCsOoCowIclEHrPSzCAkvpePbnL/u4lT4qfGWJ1vdwuI0hnjoJ8s5WnugxoMoVtBHUfpp92wJserGh7P1FJ6lpv3yOvAJg50= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=garyguo.net; spf=pass smtp.mailfrom=garyguo.net; dkim=pass (1024-bit key) header.d=garyguo.net header.i=@garyguo.net header.b=NWImHBuQ; arc=fail smtp.client-ip=40.107.122.94 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=garyguo.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=garyguo.net ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KlgUKRxVjZLYA9dvQ4rCMu9AJX8Mb/v4Ypyy0IcvueAhAJz+xButxTFuriCzJrKXQEMCjsMcTh+agXkw8SzfVzMHKF4CxqZT2dJjqhimcB+FWRH8HrZ/qHwr+PIW/Tu9wArxGHi+3IelDu6taPLC9XXKHWsKyAaVpv/YsOeWnhc1LnRzJ99SwtrveRvOzFTLxf6gqzHht86eXwFwIXStMg1acxlrrOHRuTtoBeiKdUSV4ED3iIxJT2f594Jlnyu5MZiC6xAORSgMLl/r5BWivMlFX2tRtRf0hblv38GbLtS4F6zi3lG5aVPUvF3SvLGZ6NJnKfKLL0mpH2pCSIhtSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=aLDzXAsV8USwj6s+fuYV322QtDqxkGY6AlxzPxK6lF8=; b=e5RHmG5poBz/CsUnMCC3sxq1iLL/e+S5+dL4l0XoU2Lx59aR00VpUpZZgrgyQQPn3k+XF1DZX+xyzsu1keq1kKKMsjr2x5w4zoyNml/QXjSn45TScafp9zFYYmuauB0k9raur4HumV/PnthF1hRjacJSPIk6XrxnahUPIgO0QU+p6umLnchF5YcQba5qNzVFxJlphSjU4THiHs+73YR7oxXB4K2AE7fa9Hsikq5dCUCJJV5uy8CBF3yNAy/fGzadxPkeQnratQAYNoeQC1/dYh1U4WIQeeSVlRD7QXZh3MGHDlgtdZqHPapkSWcCwHfIhTnGweEzukc8Cao9Tvr3sA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=garyguo.net; dmarc=pass action=none header.from=garyguo.net; dkim=pass header.d=garyguo.net; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garyguo.net; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aLDzXAsV8USwj6s+fuYV322QtDqxkGY6AlxzPxK6lF8=; b=NWImHBuQ9vy7gtEaLWbA2cniICjPdKOAGk0jUfORDONRP4CaL1M265bzIuHol6qxxQaEabWJCq5jZt7385cu8d20zxpthGRpxdU5nT8g42BPq33TQvQyncUpTU23i8QzZO+c4zplf0ZBrT8AO3bW8iNpNbHuAmgqM/PB5fnbAaA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=garyguo.net; Received: from LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:253::10) by LO9P265MB7585.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:3a3::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Thu, 25 Apr 2024 14:15:34 +0000 Received: from LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM ([fe80::1818:a2bf:38a7:a1e7]) by LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM ([fe80::1818:a2bf:38a7:a1e7%4]) with mapi id 15.20.7472.044; Thu, 25 Apr 2024 14:15:34 +0000 Date: Thu, 25 Apr 2024 15:15:31 +0100 From: Gary Guo To: Miguel Ojeda Cc: Masahiro Yamada , Wedson Almeida Filho , Alex Gaynor , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Boqun Feng , =?UTF-8?B?QmrDtnJu?= Roy Baron , 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: Re: [PATCH] kbuild: rust: force `alloc` extern to allow "empty" Rust files Message-ID: <20240425151531.44df19f3@eugeo> In-Reply-To: <20240422090644.525520-1-ojeda@kernel.org> References: <20240422090644.525520-1-ojeda@kernel.org> X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO4P265CA0159.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2c7::9) To LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:253::10) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LO2P265MB5183:EE_|LO9P265MB7585:EE_ X-MS-Office365-Filtering-Correlation-Id: 056671b6-4ae9-4b32-b88a-08dc65322c10 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?imrpqDqbgxqz0DZ8LObg7a+gucafEi9JcaW81aqnn9v1lbCTOAy1NVJ9I9Qc?= =?us-ascii?Q?JzMWTLvCLw3qzfSzzDpc2LEB8PlcTxtEWnNh6cwuh3FmS+/zBhCHOdAxgtMM?= =?us-ascii?Q?TTgeCjbNKgDwZjKPHTe3QPjkBtXDyQoUY+HtA2B4PdVm8YAa6LseJbSEFZvy?= =?us-ascii?Q?YPjKYAtVe45lAFLNmrRpvUPNrb1L7/rCOQT+r4VwSuv0+NcoeP/+UW4nOjeD?= =?us-ascii?Q?/fx/Tb7RucilMkhdUHOiCvklkscrxPTmDZKT57WqYGB4rtZ4gP6uXjszlXih?= =?us-ascii?Q?91JTMQjZvuqphw52S2wE+PUOeM2tdJcsC8VCrM6WHa46fhiQpTc9YZ3AegAM?= =?us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WrC9JfzCgWlTNx6GVDqIrmlYUI?= =?us-ascii?Q?=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(376005)(7416005)(366007);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?vu0KFpJylnFkDyAw6xOoeXsimlAE7+XF5xWhBzN3j2ICX4jLD0r29Wiaaicp?= =?us-ascii?Q?+lXFx3ZNEctbuwS3ycelu7A9HR4+nHF7pyWpRb/yPdlocnIqRpn/iR/givCU?= =?us-ascii?Q?9ZcDSYvo2HY9iQQUA0kd6z8UiQhSohSQVcUXKjXfI2k8NIgCeTfCrR9GqBc5?= =?us-ascii?Q?w9hNrxjtD6E0BdCjTp+5WSj6u84AQvTK/5oCrTZvxaRs6fsUPxyxzaxSQFQy?= =?us-ascii?Q?n2cqp6mGKDYtvzTeNg9lFuK27foUL7zKT3+FIguINhs2NPocAXfk7lXZQo8B?= =?us-ascii?Q?z1bho1TuGy60fF+YBNsDRPXu9bp0XowSGf8atW2gUl4mUcxVfcJOPEBswC8C?= =?us-ascii?Q?CCdtYs4cehTcDLQeMzOb7JuKvBLXGum4c6XVGg8x+f8YPNPqwFr/G/RiNdB1?= =?us-ascii?Q?YmDgJy9IgiSzf//4+QsXUMKKJ+YnQT+OMlTdtvoAxmOnIl7y6WjYRA4FtspP?= =?us-ascii?Q?D0QeKOl+8JBozMrHW64t62Swxe4okj3eU3AkQE8UqRTXPNOxeV6TL1qW2ZoW?= =?us-ascii?Q?tHry8ve/ctwcdWFytEL/UoAQ4NqLPdVDpXfx+6i1ZTuB2o4f5w/gApJyvFdV?= =?us-ascii?Q?AvBCroBfZuDjUXFbQDPf98sSxNgXYnh+6PAG1SG4kVTQEYBYqrHgoB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eJh3gAZOoB3OS7igV1lDmWzCCQE84XY1rRvC/f?= =?us-ascii?Q?ORwM8Ixo+915MhMsQM22fjsAnpSxCQsttqSfZBjr?= X-OriginatorOrg: garyguo.net X-MS-Exchange-CrossTenant-Network-Message-Id: 056671b6-4ae9-4b32-b88a-08dc65322c10 X-MS-Exchange-CrossTenant-AuthSource: LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Apr 2024 14:15:34.3847 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bbc898ad-b10f-4e10-8552-d9377b823d45 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: TybCqmWHl8QgxAT2YhNMdgF8J0izvHBN7aBls2W+ZIEGvhcebpwHHZ7dX/owMAqRvCGlRLUmFEikULt+0HWzDg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LO9P265MB7585 On Mon, 22 Apr 2024 11:06:44 +0200 Miguel Ojeda wrote: > 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 > --- Reviewed-by: Gary Guo > 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