Install Rust in docker image, add Rust library and build rules (#41)
* Install Rust in docker image * Also install thumbv7em-none-eabi target * Install Rust in docker image * Also install thumbv7em-none-eabi target * Add Rust example * Link to the Rust example * Call function from the Rust lib * Move PROJECT_DIR to the 'paths' section * Fix target_f1 build * Link to the Rust library in target_f1 * Generate cbindgen bindings * Add forgotten dependency line * Use panic=abort instead of eh_personality lang item * Install Rust in docker image * Also install thumbv7em-none-eabi target * Add Rust example * Link to the Rust example * Call function from the Rust lib * Move PROJECT_DIR to the 'paths' section * Link to the Rust library in target_f1 * Generate cbindgen bindings * Add forgotten dependency line * Use panic=abort instead of eh_personality lang item * add rust call test Co-authored-by: aanper <mail@s3f.ru>
This commit is contained in:
@@ -28,6 +28,7 @@ OPT = -Og
|
||||
#######################################
|
||||
# paths
|
||||
#######################################
|
||||
PROJECT_DIR = $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
|
||||
# Build path
|
||||
BUILD_DIR = build
|
||||
|
||||
@@ -134,6 +135,10 @@ endif
|
||||
|
||||
# Add C_SOURCES +=, C_DEFS += or CPP_SOURCES += here
|
||||
|
||||
C_SOURCES += ../applications/tests/furiac_test.c
|
||||
C_SOURCES += ../applications/tests/furi_record_test.c
|
||||
C_SOURCES += ../applications/tests/test_index.c
|
||||
|
||||
#######################################
|
||||
# binaries
|
||||
#######################################
|
||||
@@ -155,7 +160,26 @@ SZ = $(PREFIX)size
|
||||
endif
|
||||
HEX = $(CP) -O ihex
|
||||
BIN = $(CP) -O binary -S
|
||||
|
||||
|
||||
|
||||
#######################################
|
||||
# Rust library
|
||||
#######################################
|
||||
|
||||
RUST_LIB_SRC = $(realpath $(PROJECT_DIR)/../core-rs)
|
||||
RUST_LIB_NAME = flipper_core
|
||||
RUST_LIB_TARGET = thumbv7em-none-eabihf
|
||||
RUST_LIB_FLAGS = --target=$(RUST_LIB_TARGET)
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
RUST_LIB_PATH = $(RUST_LIB_SRC)/target/$(RUST_LIB_TARGET)/debug
|
||||
else
|
||||
RUST_LIB_FLAGS += --release
|
||||
RUST_LIB_PATH = $(RUST_LIB_SRC)/target/$(RUST_LIB_TARGET)/release
|
||||
endif
|
||||
|
||||
RUST_LIB_CMD = cd $(RUST_LIB_SRC) && cargo build $(RUST_LIB_FLAGS)
|
||||
|
||||
#######################################
|
||||
# CFLAGS
|
||||
#######################################
|
||||
@@ -193,7 +217,8 @@ C_INCLUDES = \
|
||||
-IDrivers/CMSIS/Device/ST/STM32L4xx/Include \
|
||||
-IDrivers/CMSIS/Include \
|
||||
-IMiddlewares/ST/STM32_USB_Device_Library/Core/Inc \
|
||||
-IMiddlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc
|
||||
-IMiddlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc \
|
||||
-I../core-rs/bindings
|
||||
|
||||
|
||||
# compile gcc flags
|
||||
@@ -218,8 +243,8 @@ CPPFLAGS = -fno-threadsafe-statics
|
||||
LDSCRIPT = STM32L476RGTx_FLASH.ld
|
||||
|
||||
# libraries
|
||||
LIBS = -lc -lm -lnosys
|
||||
LIBDIR =
|
||||
LIBS = -lc -lm -lnosys -l$(RUST_LIB_NAME)
|
||||
LIBDIR = -L$(RUST_LIB_PATH)
|
||||
LDFLAGS = $(MCU) -specs=nano.specs -specs=nosys.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
|
||||
|
||||
# default action: build all
|
||||
@@ -258,7 +283,10 @@ $(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
|
||||
$(BUILD_DIR)/%.pb.c $(BUILD_DIR)/%.pb.h: ../flipper_proto/%.proto
|
||||
$(PROTOC) $(PROTOC_OPTS) --nanopb_out=$(BUILD_DIR) $<
|
||||
|
||||
$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
|
||||
$(RUST_LIB_PATH)/lib$(RUST_LIB_NAME).a:
|
||||
$(RUST_LIB_CMD)
|
||||
|
||||
$(BUILD_DIR)/$(TARGET).elf: $(RUST_LIB_PATH)/lib$(RUST_LIB_NAME).a $(OBJECTS) Makefile
|
||||
$(CPP) $(OBJECTS) $(LDFLAGS) -o $@
|
||||
$(SZ) $@
|
||||
|
||||
@@ -276,10 +304,12 @@ $(BUILD_DIR):
|
||||
#######################################
|
||||
clean:
|
||||
-rm -fR $(BUILD_DIR)
|
||||
cd $(RUST_LIB_SRC) && cargo clean
|
||||
|
||||
#######################################
|
||||
# dependencies
|
||||
#######################################
|
||||
-include $(wildcard $(BUILD_DIR)/*.d)
|
||||
-include $(wildcard $(RUST_LIB_PATH)/*.d)
|
||||
|
||||
# *** EOF ***
|
||||
|
Reference in New Issue
Block a user