7a4d1fcf888bf6235b29d527257cd54061b57749
[feed/packages.git] / lang / rust / rust-values.mk
1 # SPDX-License-Identifier: GPL-2.0-only
2 #
3 # Copyright (C) 2023 Luca Barbato and Donald Hoskins
4
5 # Rust Environmental Vars
6 RUSTC_HOST_SUFFIX:=$(word 4, $(subst -, ,$(GNU_HOST_NAME)))
7 RUSTC_HOST_ARCH:=$(HOST_ARCH)-unknown-linux-$(RUSTC_HOST_SUFFIX)
8 CARGO_HOME:=$(DL_DIR)/cargo
9
10 ifeq ($(CONFIG_USE_MUSL),y)
11 # Force linking of the SSP library for musl
12 ifdef CONFIG_PKG_CC_STACKPROTECTOR_REGULAR
13 ifeq ($(strip $(PKG_SSP)),1)
14 RUSTC_LDFLAGS+=-lssp_nonshared
15 endif
16 endif
17 ifdef CONFIG_PKG_CC_STACKPROTECTOR_STRONG
18 ifeq ($(strip $(PKG_SSP)),1)
19 RUSTC_LDFLAGS+=-lssp_nonshared
20 endif
21 endif
22 endif
23
24 CARGO_RUSTFLAGS+=-Ctarget-feature=-crt-static $(RUSTC_LDFLAGS)
25
26 ifeq ($(HOST_OS),Darwin)
27 ifeq ($(HOST_ARCH),arm64)
28 RUSTC_HOST_ARCH:=aarch64-apple-darwin
29 endif
30 endif
31
32 # mips64 openwrt has a specific targed in rustc
33 ifeq ($(ARCH),mips64)
34 RUSTC_TARGET_ARCH:=$(REAL_GNU_TARGET_NAME)
35 else
36 RUSTC_TARGET_ARCH:=$(subst openwrt,unknown,$(REAL_GNU_TARGET_NAME))
37 endif
38
39 RUSTC_TARGET_ARCH:=$(subst muslgnueabi,musleabi,$(RUSTC_TARGET_ARCH))
40
41 ifeq ($(ARCH),i386)
42 RUSTC_TARGET_ARCH:=$(subst i486,i586,$(RUSTC_TARGET_ARCH))
43 else ifeq ($(ARCH),riscv64)
44 RUSTC_TARGET_ARCH:=$(subst riscv64,riscv64gc,$(RUSTC_TARGET_ARCH))
45 endif
46
47 # ARM Logic
48 ifeq ($(ARCH),arm)
49 ifeq ($(CONFIG_arm_v7),y)
50 RUSTC_TARGET_ARCH:=$(subst arm,armv7,$(RUSTC_TARGET_ARCH))
51 endif
52
53 ifeq ($(CONFIG_HAS_FPU),y)
54 RUSTC_TARGET_ARCH:=$(subst musleabi,musleabihf,$(RUSTC_TARGET_ARCH))
55 RUSTC_TARGET_ARCH:=$(subst gnueabi,gnueabihf,$(RUSTC_TARGET_ARCH))
56 endif
57 endif
58
59 ifeq ($(ARCH),aarch64)
60 RUSTC_CFLAGS:=-mno-outline-atomics
61 endif
62
63 # Support only a subset for now.
64 RUST_ARCH_DEPENDS:=@(aarch64||arm||i386||i686||mips||mipsel||mips64||mips64el||mipsel||powerpc64||riscv64||x86_64)
65
66 ifneq ($(CONFIG_RUST_SCCACHE),)
67 RUST_SCCACHE_DIR:=$(if $(call qstrip,$(CONFIG_RUST_SCCACHE_DIR)),$(call qstrip,$(CONFIG_RUST_SCCACHE_DIR)),$(TOPDIR)/.sccache)
68
69 RUST_SCCACHE_VARS:= \
70 CARGO_INCREMENTAL=0 \
71 RUSTC_WRAPPER=sccache \
72 SCCACHE_DIR=$(RUST_SCCACHE_DIR)
73 endif
74
75 CARGO_HOST_CONFIG_VARS= \
76 $(RUST_SCCACHE_VARS) \
77 CARGO_HOME=$(CARGO_HOME)
78
79 CARGO_HOST_PROFILE:=release
80
81 CARGO_PKG_CONFIG_VARS= \
82 $(RUST_SCCACHE_VARS) \
83 CARGO_BUILD_TARGET=$(RUSTC_TARGET_ARCH) \
84 CARGO_HOME=$(CARGO_HOME) \
85 CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1 \
86 CARGO_PROFILE_RELEASE_DEBUG=false \
87 CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS=false \
88 CARGO_PROFILE_RELEASE_LTO=true \
89 CARGO_PROFILE_RELEASE_OPT_LEVEL=z \
90 CARGO_PROFILE_RELEASE_OVERFLOW_CHECKS=true \
91 CARGO_PROFILE_RELEASE_PANIC=unwind \
92 CARGO_PROFILE_RELEASE_RPATH=false \
93 CARGO_TARGET_$(subst -,_,$(call toupper,$(RUSTC_TARGET_ARCH)))_LINKER=$(TARGET_CC_NOCACHE) \
94 RUSTFLAGS="$(CARGO_RUSTFLAGS)" \
95 TARGET_CC=$(TARGET_CC_NOCACHE) \
96 TARGET_CFLAGS="$(TARGET_CFLAGS) $(RUSTC_CFLAGS)"
97
98 CARGO_PKG_PROFILE:=$(if $(CONFIG_DEBUG),dev,release)