While the compiled binaries are intended to run on the host system, the rust/host package does include the target matching the configured OpenWrt target. If using (for example) ./scripts/env to switch between different OpenWrt configurations, this will cause issues if the different configuration is for a different target. In such case there will be a mismatch between the available Rust target and OpenWrt target and the following error will be printed: > error[E0463]: can't find crate for `core` > note: the `XXX` target may not be installed This fix will add the RUSTC_TARGET_ARCH as HOST_BUILD_DIR and CARGO_HOME suffix, such that rust/host will be compiled in case an OpenWrt configuration change causes the RUSTC_TARGET_ARCH to change. Fixes: #21530 Signed-off-by: Orne Brocaar <info@brocaar.com> [Applied Jeffery To's suggestion for build and install path] Signed-off-by: Tianling Shen <cnsztl@immortalwrt.org>
53 lines
1.4 KiB
Makefile
53 lines
1.4 KiB
Makefile
# SPDX-License-Identifier: GPL-2.0-only
|
|
#
|
|
# Copyright (C) 2023 Luca Barbato and Donald Hoskins
|
|
|
|
# Rust Environmental Vars
|
|
CONFIG_HOST_SUFFIX:=$(word 4, $(subst -, ,$(GNU_HOST_NAME)))
|
|
RUSTC_HOST_ARCH:=$(HOST_ARCH)-unknown-linux-$(CONFIG_HOST_SUFFIX)
|
|
CARGO_HOME:=$(STAGING_DIR)/host/cargo
|
|
CARGO_VARS:=
|
|
|
|
ifeq ($(CONFIG_USE_MUSL),y)
|
|
# Force linking of the SSP library for musl
|
|
ifdef CONFIG_PKG_CC_STACKPROTECTOR_REGULAR
|
|
ifeq ($(strip $(PKG_SSP)),1)
|
|
RUSTC_LDFLAGS += -lssp_nonshared
|
|
endif
|
|
endif
|
|
ifdef CONFIG_PKG_CC_STACKPROTECTOR_STRONG
|
|
ifeq ($(strip $(PKG_SSP)),1)
|
|
TARGET_CFLAGS += -lssp_nonshared
|
|
endif
|
|
endif
|
|
endif
|
|
|
|
# mips64 openwrt has a specific targed in rustc
|
|
ifeq ($(ARCH),mips64)
|
|
RUSTC_TARGET_ARCH:=$(REAL_GNU_TARGET_NAME)
|
|
else
|
|
RUSTC_TARGET_ARCH:=$(subst openwrt,unknown,$(REAL_GNU_TARGET_NAME))
|
|
endif
|
|
|
|
RUSTC_TARGET_ARCH:=$(subst muslgnueabi,musleabi,$(RUSTC_TARGET_ARCH))
|
|
|
|
ifeq ($(ARCH),i386)
|
|
RUSTC_TARGET_ARCH:=$(subst i486,i586,$(RUSTC_TARGET_ARCH))
|
|
else ifeq ($(ARCH),riscv64)
|
|
RUSTC_TARGET_ARCH:=$(subst riscv64,riscv64gc,$(RUSTC_TARGET_ARCH))
|
|
endif
|
|
|
|
# ARM Logic
|
|
ifeq ($(ARCH),arm)
|
|
ifeq ($(CONFIG_arm_v7),y)
|
|
RUSTC_TARGET_ARCH:=$(subst arm,armv7,$(RUSTC_TARGET_ARCH))
|
|
endif
|
|
|
|
ifeq ($(CONFIG_HAS_FPU),y)
|
|
RUSTC_TARGET_ARCH:=$(subst musleabi,musleabihf,$(RUSTC_TARGET_ARCH))
|
|
endif
|
|
endif
|
|
|
|
ifeq ($(ARCH),aarch64)
|
|
RUST_CFLAGS:=-mno-outline-atomics
|
|
endif
|