From ba76c6ee657bffb2dc803a9605a73faeb6b52c5f Mon Sep 17 00:00:00 2001 From: chrysn Date: Sat, 3 Apr 2021 17:33:14 +0200 Subject: [PATCH] Rust: Add crates-to-module adapter --- makefiles/cargo-settings.inc.mk | 6 ------ makefiles/cargo-targets.inc.mk | 13 ++++++++++++ makefiles/vars.inc.mk | 5 +++++ sys/Kconfig | 1 + sys/Makefile.dep | 4 ++++ sys/Makefile.include | 4 ++++ sys/rust_riotmodules/Cargo.toml | 11 ++++++++++ sys/rust_riotmodules/Kconfig | 23 +++++++++++++++++++++ sys/rust_riotmodules/Makefile.dep | 10 +++++++++ sys/rust_riotmodules/Makefile.include | 6 ++++++ sys/rust_riotmodules/src/lib.rs | 7 +++++++ sys/rust_riotmodules_standalone/Cargo.lock | Bin 0 -> 19776 bytes sys/rust_riotmodules_standalone/Cargo.toml | 21 +++++++++++++++++++ sys/rust_riotmodules_standalone/Makefile | 12 +++++++++++ sys/rust_riotmodules_standalone/src/lib.rs | 9 ++++++++ 15 files changed, 126 insertions(+), 6 deletions(-) create mode 100644 sys/rust_riotmodules/Cargo.toml create mode 100644 sys/rust_riotmodules/Kconfig create mode 100644 sys/rust_riotmodules/Makefile.dep create mode 100644 sys/rust_riotmodules/Makefile.include create mode 100644 sys/rust_riotmodules/src/lib.rs create mode 100644 sys/rust_riotmodules_standalone/Cargo.lock create mode 100644 sys/rust_riotmodules_standalone/Cargo.toml create mode 100644 sys/rust_riotmodules_standalone/Makefile create mode 100644 sys/rust_riotmodules_standalone/src/lib.rs diff --git a/makefiles/cargo-settings.inc.mk b/makefiles/cargo-settings.inc.mk index fa066dd5a6..983c2c1909 100644 --- a/makefiles/cargo-settings.inc.mk +++ b/makefiles/cargo-settings.inc.mk @@ -1,9 +1,3 @@ -# Rust's own version of the target triple / quadruple. -# -# This does not have a sane default, and needs to be set in the architecture -# files. -# RUST_TARGET = ... - # Setting anything other than "debug" or "release" will necessitate additional # -Z unstable-options as of 2021-03 nightlies. CARGO_PROFILE ?= release diff --git a/makefiles/cargo-targets.inc.mk b/makefiles/cargo-targets.inc.mk index 7b6628d8d8..0b4a0e35a2 100644 --- a/makefiles/cargo-targets.inc.mk +++ b/makefiles/cargo-targets.inc.mk @@ -1,6 +1,16 @@ CARGO_COMPILE_COMMANDS = $(BINDIR)/cargo-compile-commands.json CARGO_COMPILE_COMMANDS_FLAGS = --clang +# When an application crate is built, it has to use rust_riotmodules_standalone itself to +# pull in any Rust modules that might be enabled through RIOT's module system. +# (If the application fails to add the rust_riotmodules_standalone dependency, that will +# go unnoticed and work fine if none of the catchall-dispatched modules are +# active -- but if one is enabled, this also serves to ensure the application +# is not silently built without them, as the feature will not be available to +# Cargo). +# +# This list should eventually be autogenerated (but is currently empty) + # This is duplicating the compile-commands rule because unlike in the use case # when a $(RIOTBASE)/compile_commands.json is built, we *want* this to be # per-board and per-application. (The large mechanisms are shared anyway). @@ -64,3 +74,6 @@ $(APPLICATION_RUST_MODULE).module: $(CARGO_LIB) FORCE # (should they not exist), and also from re-building everything every time # because the .cargo inside is as ephemeral as the build container. $(shell mkdir -p ~/.cargo/git ~/.cargo/registry) + +FORCE: +.phony: FORCE diff --git a/makefiles/vars.inc.mk b/makefiles/vars.inc.mk index c0eaf7e614..980af62f6e 100644 --- a/makefiles/vars.inc.mk +++ b/makefiles/vars.inc.mk @@ -132,3 +132,8 @@ export AFL_FLAGS # Additional command-line flags passed to afl durin # LOG_LEVEL # Logging level as integer (NONE: 0, ERROR: 1, WARNING: 2, INFO: 3, DEBUG: 4, default: 3) # KCONFIG_ADD_CONFIG # List of .config files to be merged used by Boards and CPUs. See kconfig.mk # VERBOSE_ASSERT # Set to 1 to print the file and line of a failed assert when assertions blow + +export RUST_TARGET # Rust's own version of the target triple / quadruple. + # + # It is set by the architecture (and thus eventually the CPU), and exported to + # be available when building Rust modules. diff --git a/sys/Kconfig b/sys/Kconfig index 37943f299b..2b1e75d678 100644 --- a/sys/Kconfig +++ b/sys/Kconfig @@ -79,6 +79,7 @@ rsource "progress_bar/Kconfig" rsource "ps/Kconfig" rsource "random/Kconfig" rsource "rtc_utils/Kconfig" +rsource "rust_riotmodules/Kconfig" rsource "saul_reg/Kconfig" rsource "schedstatistics/Kconfig" rsource "sema/Kconfig" diff --git a/sys/Makefile.dep b/sys/Makefile.dep index edd4619374..9980b81ced 100644 --- a/sys/Makefile.dep +++ b/sys/Makefile.dep @@ -956,4 +956,8 @@ ifneq (,$(filter fido2_ctap,$(USEMODULE))) USEMODULE += fido2 endif +ifneq (,$(filter rust_riotmodules,$(USEMODULE))) + include $(RIOTBASE)/sys/rust_riotmodules/Makefile.dep +endif + include $(RIOTBASE)/sys/test_utils/Makefile.dep diff --git a/sys/Makefile.include b/sys/Makefile.include index 64e51fae6e..659b7e1a23 100644 --- a/sys/Makefile.include +++ b/sys/Makefile.include @@ -159,3 +159,7 @@ endif ifneq (,$(filter shell_lock,$(USEMODULE))) include $(RIOTBASE)/sys/shell_lock/Makefile.include endif + +ifneq (,$(filter rust_riotmodules,$(USEMODULE))) + include $(RIOTBASE)/sys/rust_riotmodules/Makefile.include +endif diff --git a/sys/rust_riotmodules/Cargo.toml b/sys/rust_riotmodules/Cargo.toml new file mode 100644 index 0000000000..8db4b4b7b7 --- /dev/null +++ b/sys/rust_riotmodules/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "rust_riotmodules" +version = "0.1.0" +authors = ["Christian Amsüss "] +edition = "2021" +publish = false + + +[dependencies] +# The list contains all modules available in RIOT, and should eventually be +# autogenerated (or at least automatically checked for consistency). diff --git a/sys/rust_riotmodules/Kconfig b/sys/rust_riotmodules/Kconfig new file mode 100644 index 0000000000..4a8cf11638 --- /dev/null +++ b/sys/rust_riotmodules/Kconfig @@ -0,0 +1,23 @@ +# Copyright (c) 2022 HAW Hamburg +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. +# + +menuconfig MODULE_RUST_RIOTMODULES + bool "RUST RIOT modules" + depends on TEST_KCONFIG + depends on HAS_RUST_TARGET + help + This module is used when some module asks to have its code built + through rust_riotmodules. + +config MODULE_RUST_RIOTMODULES_STANDALONE + bool "RUST RIOT modules are standalone" + default y + depends on MODULE_RUST_RIOTMODULES + help + This module is used when rust_riotmodules is selected, and the main + application does not already contain Rust code through which the + rust_riotmodules are built. diff --git a/sys/rust_riotmodules/Makefile.dep b/sys/rust_riotmodules/Makefile.dep new file mode 100644 index 0000000000..d2b9b8a2cf --- /dev/null +++ b/sys/rust_riotmodules/Makefile.dep @@ -0,0 +1,10 @@ +# No check for the presence of any of any dependencies (were there none, this +# wouldn't have been pulled in), but only pull in building this in if the +# application does not already provide a crate -- in which case the +# CARGO_OPTIONS added depending on the pseudomodules are enabled in the regular +# cargo-targets. +ifeq (,${APPLICATION_RUST_MODULE}) + USEMODULE += rust_riotmodules_standalone +endif + +FEATURES_REQUIRED += rust_target diff --git a/sys/rust_riotmodules/Makefile.include b/sys/rust_riotmodules/Makefile.include new file mode 100644 index 0000000000..cb1013b039 --- /dev/null +++ b/sys/rust_riotmodules/Makefile.include @@ -0,0 +1,6 @@ +## This module is used when some module asking to have its code built +# through rust_riotmodules. Whether that happens through actually enabling the +# rust_riotmodules_standalone module or by the application's crate was decided +# in ./Makefile.dep depending on whether a Rust application module is present +# or not. +PSEUDOMODULES += rust_riotmodules diff --git a/sys/rust_riotmodules/src/lib.rs b/sys/rust_riotmodules/src/lib.rs new file mode 100644 index 0000000000..0262141c92 --- /dev/null +++ b/sys/rust_riotmodules/src/lib.rs @@ -0,0 +1,7 @@ +#![no_std] + +// As we're pulling all crates in only for their side effects of having symbols (be that to place +// them in XFA symbols or to make them available for C) all these crates have to be extern-crate'd +// to be pulled in because they are not used on the laguage level. + +// This list should be as auto-generated / -maintained as the one in Cargo.toml diff --git a/sys/rust_riotmodules_standalone/Cargo.lock b/sys/rust_riotmodules_standalone/Cargo.lock new file mode 100644 index 0000000000000000000000000000000000000000..439acede226c603568cc869f2c2eaec7623dd868 GIT binary patch liter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-O0Vgq>dd=v8rTs*WQfp#pi(?EnGf zKZo3bn=nBrWOzYwmoe)iJT)_WH9`=VD_WTA6)9||0 z4QgK@!5}zE2?<7N)6nIxl?6})ZLT;088}RvU}Ghyk$tC`<`H+XOkfq7jsNI~m^lCC z>iuzw=rly~bA3fU^J^6FdX+P><4`KjG;$F!U4S>l@H=&W2*5N-A=3#bJe$U;!^u9R zciMDEuAPO1=WBTy#mLmPAz?)wXAGi~Ch`tbAZCEXu#2xDV1Gh9Y#E-p$7;as7}`+S z>+rO6=6>ClgwJo&Vg1vKA3b#KEb|@Y8^ z+Kz6?0hB&Wsnj|23w{R$?QCh}`}1k4(?BLIcI7}gJ4l~Fe#8|%HAzO+C?qFNupvXC za3Vfoa2)QEJT}2NXy%n9G6JRn&u;Z&{wy}rkG?)eHYKMt=>+10&(cZTz4MkOBP@6CVajO5kkJ zZ2$39S!*UphWra%PSC)o^W;l@4_-UW%=M-j=`xwA-bN+Op zfA*qzynUR3qfggy03Un#FrUJrsqt$VhzP*`)WFI79vD^xKWvWBB88tV0-|Uz+5ZES Cix#Z_ literal 0 HcmV?d00001 diff --git a/sys/rust_riotmodules_standalone/Cargo.toml b/sys/rust_riotmodules_standalone/Cargo.toml new file mode 100644 index 0000000000..f1a7c50344 --- /dev/null +++ b/sys/rust_riotmodules_standalone/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "rust_riotmodules_standalone" +version = "0.1.0" +authors = ["Christian Amsüss "] +edition = "2021" +publish = false + +[lib] +crate-type = [ "staticlib" ] + +[profile.release] +lto = true +opt-level = "s" +debug = true +panic = "abort" +codegen-units = 1 + +[dependencies] +riot-wrappers = { version = "0.7", default-features = false, features = [ "set_panic_handler" ] } + +rust_riotmodules = { path = "../rust_riotmodules" } diff --git a/sys/rust_riotmodules_standalone/Makefile b/sys/rust_riotmodules_standalone/Makefile new file mode 100644 index 0000000000..a7a4a980b7 --- /dev/null +++ b/sys/rust_riotmodules_standalone/Makefile @@ -0,0 +1,12 @@ +include $(RIOTBASE)/Makefile.base + +include $(RIOTMAKE)/cargo-settings.inc.mk + +APPLICATION_RUST_MODULE = rust_riotmodules_standalone + +# No need to set the Cargo features enabled through the general pseudomodules: +# They're added to the crate in cargo-targets.inc.mk no matter whether it's +# building the rust_riotmodules_standalone top level crate or an application +# crate. + +include $(RIOTMAKE)/cargo-targets.inc.mk diff --git a/sys/rust_riotmodules_standalone/src/lib.rs b/sys/rust_riotmodules_standalone/src/lib.rs new file mode 100644 index 0000000000..3f27a514f2 --- /dev/null +++ b/sys/rust_riotmodules_standalone/src/lib.rs @@ -0,0 +1,9 @@ +#![no_std] + +// As we're pulling all crates in only for their side effects of having symbols (they are required +// on the Rust side like riot_wrappers' panic_handler, and rust_riotmodules does that on its own +// too) all these crates have to be extern-crate'd to be pulled in because they are not used on the +// language level. + +extern crate riot_wrappers; +extern crate rust_riotmodules;