diff --git a/makefiles/cargo-settings.inc.mk b/makefiles/cargo-settings.inc.mk index 2553184551681..d90f679054a5c 100644 --- a/makefiles/cargo-settings.inc.mk +++ b/makefiles/cargo-settings.inc.mk @@ -2,7 +2,10 @@ # # This does not have a sane default, and needs to be set in the architecture # files. -# CARGO_TARGET = ... +# +# It is set by the architecture (and thus eventually the CPU), and exported to +# be available when building Rust modules. +export CARGO_TARGET # Flags that need to be added to the RIOT_CFLAGS passed to cargo in order to # make bindgen happy @@ -18,5 +21,5 @@ CARGO_PROFILE ?= release # here is to pick a particular nightly when something breaks. CARGO_CHANNEL ?= nightly -# The single Rust library to be built. +# The single Rust library to be built for the application CARGO_LIB = target/$(CARGO_TARGET)/${CARGO_PROFILE}/lib$(APPLICATION_RUST_MODULE).a diff --git a/sys/rust_lib_catchall/Cargo.toml b/sys/rust_lib_catchall/Cargo.toml new file mode 100644 index 0000000000000..c401d76cae575 --- /dev/null +++ b/sys/rust_lib_catchall/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "rust_lib_catchall" +version = "0.1.0" +authors = ["Christian Amsüss "] +edition = "2018" +resolver = "2" + +[lib] +crate-type = ["staticlib"] + +[dependencies] +# Provides the panic_handler +riot-wrappers = "0.7" + +riot-shell-commands = { git = "https://gitlab.com/etonomy/riot-module-examples", optional = true } diff --git a/sys/rust_lib_catchall/Makefile b/sys/rust_lib_catchall/Makefile new file mode 100644 index 0000000000000..d535c33005890 --- /dev/null +++ b/sys/rust_lib_catchall/Makefile @@ -0,0 +1,34 @@ +include $(RIOTBASE)/Makefile.base + +# FIXME: These are the defaults; I guess we'll need to pass down everything, and not just CARGO_TARGET +include ../../makefiles/cargo-settings.inc.mk + +# The single Rust library to be built collection modules +# Not placing this in $(BINDIR)/rust_lib_catchall/target/... as that'd mean +# that the find in _LINK can catch on to some .o files not intended to be found +CARGO_LIB_MODULES = $(BINDIR)/rust_lib_catchall-target/$(CARGO_TARGET)/${CARGO_PROFILE}/librust_lib_catchall.a + +# FIXME: This is the point where any RIOT modules written in Rust (which would +# be pseudomodules depending on this) are turned into a list of features to be +# enabled +CARGO_OPTIONS += --features riot-shell-commands + +$(CARGO_LIB_MODULES): $(RIOTBUILD_CONFIG_HEADER_C) $(BUILDDEPS) FORCE + $(Q)[ x"${CARGO_TARGET}" != x"" ] || (echo "Error: No CARGO_TARGET was set for this platform"; exit 1) + # differenct to standalone: this uses only CFLAGS and not + # CFLAGS_WITGH_MACROS, and then hacks the modules back from the + # exported USEMODULE variable (which may generally be a good idea until + # compile-commands are available) + $(Q)CC= CFLAGS= CPPFLAGS= CXXFLAGS= RIOT_CC="${CC}" RIOT_CFLAGS="$(CFLAGS) $(patsubst %,-DMODULE_%,$(USEMODULE)) $(INCLUDES) $(CARGO_EXTRACFLAGS)" cargo +$(CARGO_CHANNEL) build --target $(CARGO_TARGET) `if [ x$(CARGO_PROFILE) = xrelease ]; then echo --release; else if [ x$(CARGO_PROFILE) '!=' xdebug ]; then echo "--profile $(CARGO_PROFILE)"; fi; fi` $(CARGO_OPTIONS) --target-dir $(BINDIR)/rust_lib_catchall-target + +rust_lib_catchall.module: $(CARGO_LIB_MODULES) FORCE + $(Q)# Ensure no old object files persist. These would lead to duplicate + $(Q)# symbols, or worse, lingering behaivor of XFA entries. + $(Q)rm -rf $(BINDIR)/rust_lib_catchall/ + $(Q)mkdir -p $(BINDIR)/rust_lib_catchall/ + # difference to standalone: no PWD as it' an absolute path + $(Q)cd $(BINDIR)/rust_lib_catchall/ && $(AR) x $< + +FORCE: + +.PHONY: FORCE diff --git a/sys/rust_lib_catchall/src/lib.rs b/sys/rust_lib_catchall/src/lib.rs new file mode 100644 index 0000000000000..2d48825725780 --- /dev/null +++ b/sys/rust_lib_catchall/src/lib.rs @@ -0,0 +1,11 @@ +#![no_std] + +// As we're pulling all crates in only for their side effects of having symbols (be they required +// on the Rust side like riot_wrappers' panic_handler, or to be used by RIOT like the XFA symbols +// emittted by riot-shell-commands), all these crates have to be extern-crate'd to be pulled in +// even though they're note used on the language level. + +extern crate riot_wrappers; + +#[cfg(feature = "riot-shell-commands")] +extern crate riot_shell_commands;