1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-28 23:49:47 +01:00

Rust: Add crates-to-module adapter

This commit is contained in:
chrysn 2021-04-03 17:33:14 +02:00
parent 7ee66ad219
commit ba76c6ee65
15 changed files with 126 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,11 @@
[package]
name = "rust_riotmodules"
version = "0.1.0"
authors = ["Christian Amsüss <chrysn@fsfe.org>"]
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).

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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

BIN
sys/rust_riotmodules_standalone/Cargo.lock generated Normal file

Binary file not shown.

View File

@ -0,0 +1,21 @@
[package]
name = "rust_riotmodules_standalone"
version = "0.1.0"
authors = ["Christian Amsüss <chrysn@fsfe.org>"]
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" }

View File

@ -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

View File

@ -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;