mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Rust: Add crates-to-module adapter
This commit is contained in:
parent
7ee66ad219
commit
ba76c6ee65
@ -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
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
11
sys/rust_riotmodules/Cargo.toml
Normal file
11
sys/rust_riotmodules/Cargo.toml
Normal 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).
|
23
sys/rust_riotmodules/Kconfig
Normal file
23
sys/rust_riotmodules/Kconfig
Normal 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.
|
10
sys/rust_riotmodules/Makefile.dep
Normal file
10
sys/rust_riotmodules/Makefile.dep
Normal 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
|
6
sys/rust_riotmodules/Makefile.include
Normal file
6
sys/rust_riotmodules/Makefile.include
Normal 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
|
7
sys/rust_riotmodules/src/lib.rs
Normal file
7
sys/rust_riotmodules/src/lib.rs
Normal 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
BIN
sys/rust_riotmodules_standalone/Cargo.lock
generated
Normal file
Binary file not shown.
21
sys/rust_riotmodules_standalone/Cargo.toml
Normal file
21
sys/rust_riotmodules_standalone/Cargo.toml
Normal 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" }
|
12
sys/rust_riotmodules_standalone/Makefile
Normal file
12
sys/rust_riotmodules_standalone/Makefile
Normal 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
|
9
sys/rust_riotmodules_standalone/src/lib.rs
Normal file
9
sys/rust_riotmodules_standalone/src/lib.rs
Normal 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;
|
Loading…
Reference in New Issue
Block a user