Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp820138rdh; Thu, 26 Oct 2023 17:35:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFlLTwKd6JmDFG5CPIQ5xDXv/jjKNm7XOVtXH4kCih6dep92NTUFs4lZTemMtwIPiIEHCtb X-Received: by 2002:a81:d007:0:b0:5a8:5137:b5fb with SMTP id v7-20020a81d007000000b005a85137b5fbmr1298353ywi.47.1698366926843; Thu, 26 Oct 2023 17:35:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698366926; cv=none; d=google.com; s=arc-20160816; b=AAcQut+UJBTs20/tKb8zoz4huRn3C38L8QM74Llcs2qIKp+IKq3O3qesZEwN0n5X9z VRf33mhk9SuccUTX561ZD8N1JD5N7wNwMO9mMmUzr9I4W64PiwNcvetBMiAkQ3igFM6q u+MnyfL/HRrTZ8dq6i8XG+9ukT1NxOero2mNyNy5fmxIENdL2C/D0vyjnkCNAIP5qwmq azarp/2ahG5Djz31xeYkSslOZuRIxAB3rqF9nwyKySWc63na7ACl74e4OjWsPzvRanmX bmTbqgmsh3QGBc3LUCE+KKvn3/DfE6Aiyyd0CWx+zbeIDfEgx9v9zKpMJ0kY+t5fKYII O2Zg== 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=usbHaxcBxH3v5TUXsmVVZxNrcj87lpTiZe9iPVq/oHc=; fh=vk2En4JZf0Eii1UaCwHBWN9cLnpTYENKR+h9TvzU6vU=; b=EZmfNwkO5D06d+Sf/m69mq6YdnM1QP3KbZMTbZPI1hwYqTVM5Up50LEVZdf+JrgGZw FWe3lIVeCCk9UrEgCk62kclwYOur58NwQPtkSHN4532st9slvv5DO2YTtnPl1GQlklzM mNsj/jjCxtWEAtBf+h4FFmnUktPNUG7kuS6OZStcWZ3fCjAJfkYr8t2i22udI6nDAPZF yfYJ42bjDiZ21k+567xjny4EVaAHBQxgrN6a60ptWu/fBafdkrGlailaF9riDpc1r/he YDmFdowMPW8RvMwaB1p/ztyR4yFQ1yAQwJoC0w07D2GPiuAp1aDLh/DBg00Gk8cUQwe+ akpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="aRBYX/lB"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id i10-20020a816d0a000000b0059219587f24si668882ywc.388.2023.10.26.17.35.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 17:35:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="aRBYX/lB"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 30E3B8270DF0; Thu, 26 Oct 2023 17:35:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229831AbjJ0AfR (ORCPT + 99 others); Thu, 26 Oct 2023 20:35:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbjJ0AfQ (ORCPT ); Thu, 26 Oct 2023 20:35:16 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBB911B6; Thu, 26 Oct 2023 17:35:12 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6b9af7d41d2so1489807b3a.0; Thu, 26 Oct 2023 17:35:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698366912; x=1698971712; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=usbHaxcBxH3v5TUXsmVVZxNrcj87lpTiZe9iPVq/oHc=; b=aRBYX/lB+H0RHOWogdS8RKa99kEzBMZiDlD62iuK36d8oFDXCBpkGNTYjGU55rq/lU tsmL7mEu8hI0wfFPDfTr6FYIjmZbWswBFFIh1Za3wV9bX2NL8idm2gFtMI1RUU9SKW5b dQ4yutTa4uIcvzZVacDjVrzpZAEpgmcPKv/gufNpzwjJKjPj5pYvh2UEjgodrUo9XZGn nerU8QUYrLHC0vOQ4+0LlvtjATdCTVQBQtvMQj+Bi+xqdpHJfgQfYp0euGLrxiz/Ng7y MnZE4puqYICFPnhDFD+/739gBV8I0LfHHxInatCeqSjnMDytI6mHiAzGBoEOn0Hj4xB6 /yiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698366912; x=1698971712; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=usbHaxcBxH3v5TUXsmVVZxNrcj87lpTiZe9iPVq/oHc=; b=Jjgd5qTw8C8DmSKnaIo4eQXUZPG8nDoGrp8SkE6em4Gj/VrlfdzbqNBLW0dos5jBqL CcbzAXEUx5BgimILbYrxvyaNNa75eT8egPTAdF6gFYd7vwcX5JR8ZLwXhBVhU8YBSic8 z54P1+8FVww/XfsyMZl5E1fw+2Lu4hBccgn5Tp3+4s0Qb95+OjxcZqKQ8DRS93VRAw5d iGDk23c8jpq8y6k/lSPApKdsHhYaVm78a/X1pXBLZppcdmT9G8Tk12CV5UyX4zQLmDE8 0Xx4ajJaioaPxrR4C2PtyEx+TYJ/cR+UJSY8u7nC0prkNzaC2n7758IdvuYloXEMaGOm yjoA== X-Gm-Message-State: AOJu0YwYShrKfPixxRdL+sDqo+xZCDFbwCbQKk4Syd6Pjcn/sz7o0YFi dJ/Gpg2ebxHV8lmghhwCjgk= X-Received: by 2002:a05:6a00:1810:b0:68e:3bc8:17d1 with SMTP id y16-20020a056a00181000b0068e3bc817d1mr1467842pfa.29.1698366911825; Thu, 26 Oct 2023 17:35:11 -0700 (PDT) Received: from tx3000mach.io (static.220.238.itcsa.net. [190.15.220.238]) by smtp.gmail.com with ESMTPSA id g21-20020aa78755000000b006be683108cesm183096pfo.213.2023.10.26.17.35.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 17:35:11 -0700 (PDT) From: Martin Rodriguez Reboredo To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Subject: [RFC PATCH v2 0/2] rust: crates in other kernel directories Date: Thu, 26 Oct 2023 21:34:49 -0300 Message-ID: <20231027003504.146703-1-yakoyoku@gmail.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 26 Oct 2023 17:35:25 -0700 (PDT) This RFC provides makes possible to have bindings for kernel subsystems that are compiled as modules. Previously, if you wanted to have Rust bindings for a subsystem, like AMBA for example, you had to put it under `rust/kernel/` so it came part of the `kernel` crate, but this came with many downsides. Namely if you compiled said subsystem as a module you've a dependency on it from `kernel`, which is linked directly on `vmlinux`. So instead of overpopulating `kernel` with a gazillion modules that throws you into dire straits you should rather have the bindings in the same directory as the subsystem you want to bind with and link it to it. With this patch Rust sources can be compiled into libraries for them to be consumed. These libraries are ar archives that follow the `.rlib` structure, namely a libfoo.rlib thin archive with a foo.foo.o object and a libfoo.rmeta rustc metadata as members. Such Rust crates get their symbols exposed and the `bindings` crate is made available for them. Also included there's a sample usage of this in another patch, but it is not meant to be merged as it remains as an example. If you want to use a crate with your Rust module just add a `rust-libs` variable in your Makefile with a value of the relative directory of said crate plus its name, e.g. # Link with the foo crate rust-libs += ../path/to/foo Martin Rodriguez Reboredo (2): kbuild: Build Rust crates as libraries samples: rust: Add USB sample bindings .gitignore | 2 ++ Makefile | 4 +-- drivers/usb/core/Kconfig | 7 +++++ drivers/usb/core/Makefile | 3 ++ drivers/usb/core/usb.rs | 13 +++++++++ samples/rust/Kconfig | 10 +++++++ samples/rust/Makefile | 3 ++ samples/rust/rust_usb_simple.rs | 22 +++++++++++++++ scripts/Makefile.build | 49 ++++++++++++++++++++++++++++++--- scripts/Makefile.lib | 18 ++++++++++-- scripts/Makefile.modfinal | 7 ++++- 11 files changed, 128 insertions(+), 10 deletions(-) create mode 100644 drivers/usb/core/usb.rs create mode 100644 samples/rust/rust_usb_simple.rs -- 2.42.0