diff --git a/cpu/cortexm_common/Kconfig b/cpu/cortexm_common/Kconfig index 76ffacab2b..c43c8ead87 100644 --- a/cpu/cortexm_common/Kconfig +++ b/cpu/cortexm_common/Kconfig @@ -80,6 +80,7 @@ config CPU_CORE_CORTEX_M3 bool select CPU_ARCH_ARMV7M select CPU_CORE_CORTEX_M + select HAS_RUST_TARGET config CPU_CORE_CORTEX_M33 bool @@ -90,12 +91,14 @@ config CPU_CORE_CORTEX_M4 bool select CPU_ARCH_ARMV7M select CPU_CORE_CORTEX_M + select HAS_RUST_TARGET config CPU_CORE_CORTEX_M4F bool select CPU_ARCH_ARMV7M select CPU_CORE_CORTEX_M select HAS_CORTEXM_FPU + select HAS_RUST_TARGET config CPU_CORE_CORTEX_M7 bool diff --git a/cpu/cortexm_common/Makefile.features b/cpu/cortexm_common/Makefile.features index aa667450f6..89ec714ed1 100644 --- a/cpu/cortexm_common/Makefile.features +++ b/cpu/cortexm_common/Makefile.features @@ -18,26 +18,38 @@ ifneq (,$(filter $(CPU_CORE),cortex-m4f cortex-m7)) endif # Set CPU_ARCH depending on the CPU_CORE +# +# RUST_TARGET is only used when building Rust code; any users need to require +# the `rust_target` feature to esnure things are checked properly. ifeq ($(CPU_CORE),cortex-m0) CPU_ARCH := armv6m + #RUST_TARGET = thumbv6m-none-eabi else ifeq ($(CPU_CORE),cortex-m0plus) CPU_ARCH := armv6m + #RUST_TARGET = thumbv6m-none-eabi else ifeq ($(CPU_CORE),cortex-m23) CPU_ARCH := armv8m else ifeq ($(CPU_CORE),cortex-m3) CPU_ARCH := armv7m + RUST_TARGET = thumbv7m-none-eabi else ifeq ($(CPU_CORE),cortex-m33) CPU_ARCH := armv8m else ifeq ($(CPU_CORE),cortex-m4) CPU_ARCH := armv7m + RUST_TARGET = thumbv7em-none-eabi else ifeq ($(CPU_CORE),cortex-m4f) CPU_ARCH := armv7m + RUST_TARGET = thumbv7em-none-eabihf else ifeq ($(CPU_CORE),cortex-m7) CPU_ARCH := armv7m else $(error Unkwnown cortexm core: $(CPU_CORE)) endif +ifneq (,$(RUST_TARGET)) + FEATURES_PROVIDED += rust_target +endif + FEATURES_PROVIDED += no_idle_thread # This configuration enables modules that are only available when using Kconfig diff --git a/cpu/native/Kconfig b/cpu/native/Kconfig index 4e9365a899..268185bd0a 100644 --- a/cpu/native/Kconfig +++ b/cpu/native/Kconfig @@ -62,6 +62,7 @@ config NATIVE_OS_LINUX select HAS_PERIPH_GPIO select HAS_PERIPH_GPIO_IRQ select HAS_PERIPH_SPI + select HAS_RUST_TARGET if "$(OS_ARCH)" = "x86_64" config NATIVE_OS_FREEBSD bool diff --git a/cpu/native/Makefile.features b/cpu/native/Makefile.features index 0e237bea44..14f89d59fb 100644 --- a/cpu/native/Makefile.features +++ b/cpu/native/Makefile.features @@ -18,6 +18,9 @@ FEATURES_PROVIDED += periph_hwrng FEATURES_PROVIDED += periph_pm FEATURES_PROVIDED += periph_pwm FEATURES_PROVIDED += periph_timer_periodic +ifeq ($(OS) $(OS_ARCH),Linux x86_64) + FEATURES_PROVIDED += rust_target +endif FEATURES_PROVIDED += ssp ifeq ($(OS),Linux) diff --git a/cpu/native/Makefile.include b/cpu/native/Makefile.include index 0dbbe715fb..279ff4f412 100644 --- a/cpu/native/Makefile.include +++ b/cpu/native/Makefile.include @@ -10,3 +10,8 @@ ifneq (,$(filter periph_can,$(USEMODULE))) endif TOOLCHAINS_SUPPORTED = gnu llvm afl + +# Platform triple as used by Rust +ifeq ($(OS) $(OS_ARCH),Linux x86_64) + RUST_TARGET = i686-unknown-linux-gnu +endif diff --git a/cpu/riscv_common/Kconfig b/cpu/riscv_common/Kconfig index 3a0c8d46fe..707cf33278 100644 --- a/cpu/riscv_common/Kconfig +++ b/cpu/riscv_common/Kconfig @@ -12,6 +12,7 @@ config CPU_ARCH_RISCV select HAS_NEWLIB select HAS_PERIPH_CORETIMER select HAS_PICOLIBC if '$(RIOT_CI_BUILD)' != '1' + #select HAS_RUST_TARGET select HAS_SSP select MODULE_MALLOC_THREAD_SAFE if TEST_KCONFIG diff --git a/cpu/riscv_common/Makefile.features b/cpu/riscv_common/Makefile.features index 30a1b8a5f6..39d2d1c083 100644 --- a/cpu/riscv_common/Makefile.features +++ b/cpu/riscv_common/Makefile.features @@ -8,6 +8,7 @@ FEATURES_PROVIDED += cpp FEATURES_PROVIDED += libstdcpp FEATURES_PROVIDED += newlib FEATURES_PROVIDED += periph_coretimer +#FEATURES_PROVIDED += rust_target FEATURES_PROVIDED += ssp # RISC-V toolchain on CI does not work properly with picolibc yet diff --git a/kconfigs/Kconfig.features b/kconfigs/Kconfig.features index ed995187e5..6743fae381 100644 --- a/kconfigs/Kconfig.features +++ b/kconfigs/Kconfig.features @@ -42,6 +42,11 @@ config HAS_BACKUP_RAM help Indicates that Backup RAM is supported. +config HAS_RUST_TARGET + bool + help + Indicates that a Rust target definition ("triple") is known. + config HAS_CPP bool help diff --git a/makefiles/arch/riscv.inc.mk b/makefiles/arch/riscv.inc.mk index 800e9460e2..557b376416 100644 --- a/makefiles/arch/riscv.inc.mk +++ b/makefiles/arch/riscv.inc.mk @@ -54,3 +54,8 @@ CFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) $(CFLAGS_OPT) $(CFLAGS_LINK) ASFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) # export linker flags LINKFLAGS += $(CFLAGS_CPU) $(CFLAGS_LINK) $(CFLAGS_DBG) $(CFLAGS_OPT) -nostartfiles -Wl,--gc-sections -static -lgcc + +# Platform triple as used by Rust +RUST_TARGET = riscv32imac-unknown-none-elf +# Workaround for https://github.com/rust-lang/rust-bindgen/issues/1555 +CARGO_EXTRACFLAGS += --target=riscv32 diff --git a/makefiles/info-global.inc.mk b/makefiles/info-global.inc.mk index 59150a34a6..68be99dab4 100644 --- a/makefiles/info-global.inc.mk +++ b/makefiles/info-global.inc.mk @@ -45,6 +45,7 @@ define board_unsatisfied_features undefine CPU_ARCH undefine CPU_CORE undefine CPU_FAM + undefine RUST_TARGET include $(RIOTBASE)/Makefile.features # always select provided architecture features diff --git a/makefiles/vars.inc.mk b/makefiles/vars.inc.mk index f7808cae23..720e473d9d 100644 --- a/makefiles/vars.inc.mk +++ b/makefiles/vars.inc.mk @@ -6,6 +6,7 @@ export QQ # as Q, but be more quiet export QUIET # The parameter to use whether to show verbose makefile commands or not. export OS # The operating system of the build host +export OS_ARCH # The build host's hardware architecture export APPLICATION # The application, set in the Makefile which is run by the user. export APPLICATION_MODULE # The application module name.