2023-02-08 14:18:41 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
#
|
|
|
|
# Copyright (C) 2023 Luca Barbato and Donald Hoskins
|
|
|
|
|
2023-12-31 05:36:26 +00:00
|
|
|
# Clear environment variables which should be handled internally,
|
|
|
|
# as users might configure their own env on the host
|
|
|
|
|
|
|
|
# CCache
|
|
|
|
unexport RUSTC_WRAPPER
|
|
|
|
|
2023-02-08 14:18:41 +00:00
|
|
|
# Rust Environmental Vars
|
rust: Set rustflags by environment variable
In order to use $(RUSTC_TARGET_ARCH) in HOST_BUILD_DIR, the line to
include rust-values.mk in the Rust makefile was moved in
f489e019ac4a15e974518d9928ef913a157d135a, causing it to be included
before package.mk is included.
This had the side effect of preventing "-lssp_nonshared" from being
added to RUSTC_LDFLAGS, because PKG_SSP is indirectly set by package.mk
(package.mk includes hardening.mk, hardening.mk sets PKG_SSP).
There is a deeper issue; it is the Rust package's PKG_SSP value that
causes RUSTC_LDFLAGS to be set and written to the Cargo config file. For
packages that use Rust to build, their PKG_SSP value does not affect the
linker flag.
This sets rustflags with the RUSTFLAGS environment variable, instead of
writing the value to the Cargo config file, allowing PKG_SSP from the
package being built to be used and for the package being built to modify
the rustflags used.
This also:
* Fix "-lssp_nonshared" being added to TARGET_CFLAGS instead of
RUSTC_LDFLAGS, when CONFIG_PKG_CC_STACKPROTECTOR_STRONG is set.
* Remove the use of $(RUSTC_TARGET_ARCH) in HOST_BUILD_DIR and move the
include line for rust-values.mk back to after package.mk.
Since the host build directory was moved under the target build
directory in efdbac38dc8b649ca26b49fac27abeb5cf76cd28, it is no longer
necessary to separate build directories with RUSTC_TARGET_ARCH;
$(BUILD_DIR) already separates build directories by target.
* Add BUILDONLY:=1, as the Rust package does not build a target package.
* Install the Cargo config file as "config.toml" instead of "config", as
this is the preferred form[1].
* Rename RUST_CFLAGS to RUSTC_CFLAGS and CONFIG_HOST_SUFFIX to
RUSTC_HOST_SUFFIX, for consistency.
* Allow CARGO_VARS to be set before rust-values.mk is included.
[1]: https://doc.rust-lang.org/cargo/reference/config.html#hierarchical-structure
Fixes: f489e019ac4a ("rust: compile host package per target")
Fixes: 83785a7ce016 ("rust-lang: Add the rust language support")
Fixes: https://github.com/openwrt/packages/issues/22133
Signed-off-by: Jeffery To <jeffery.to@gmail.com>
2023-09-18 01:30:56 +00:00
|
|
|
RUSTC_HOST_SUFFIX:=$(word 4, $(subst -, ,$(GNU_HOST_NAME)))
|
|
|
|
RUSTC_HOST_ARCH:=$(HOST_ARCH)-unknown-linux-$(RUSTC_HOST_SUFFIX)
|
2023-09-22 16:26:20 +00:00
|
|
|
CARGO_HOME:=$(DL_DIR)/cargo
|
2023-02-08 14:18:41 +00:00
|
|
|
|
2023-03-19 18:08:00 +00:00
|
|
|
ifeq ($(CONFIG_USE_MUSL),y)
|
rust: Set rustflags by environment variable
In order to use $(RUSTC_TARGET_ARCH) in HOST_BUILD_DIR, the line to
include rust-values.mk in the Rust makefile was moved in
f489e019ac4a15e974518d9928ef913a157d135a, causing it to be included
before package.mk is included.
This had the side effect of preventing "-lssp_nonshared" from being
added to RUSTC_LDFLAGS, because PKG_SSP is indirectly set by package.mk
(package.mk includes hardening.mk, hardening.mk sets PKG_SSP).
There is a deeper issue; it is the Rust package's PKG_SSP value that
causes RUSTC_LDFLAGS to be set and written to the Cargo config file. For
packages that use Rust to build, their PKG_SSP value does not affect the
linker flag.
This sets rustflags with the RUSTFLAGS environment variable, instead of
writing the value to the Cargo config file, allowing PKG_SSP from the
package being built to be used and for the package being built to modify
the rustflags used.
This also:
* Fix "-lssp_nonshared" being added to TARGET_CFLAGS instead of
RUSTC_LDFLAGS, when CONFIG_PKG_CC_STACKPROTECTOR_STRONG is set.
* Remove the use of $(RUSTC_TARGET_ARCH) in HOST_BUILD_DIR and move the
include line for rust-values.mk back to after package.mk.
Since the host build directory was moved under the target build
directory in efdbac38dc8b649ca26b49fac27abeb5cf76cd28, it is no longer
necessary to separate build directories with RUSTC_TARGET_ARCH;
$(BUILD_DIR) already separates build directories by target.
* Add BUILDONLY:=1, as the Rust package does not build a target package.
* Install the Cargo config file as "config.toml" instead of "config", as
this is the preferred form[1].
* Rename RUST_CFLAGS to RUSTC_CFLAGS and CONFIG_HOST_SUFFIX to
RUSTC_HOST_SUFFIX, for consistency.
* Allow CARGO_VARS to be set before rust-values.mk is included.
[1]: https://doc.rust-lang.org/cargo/reference/config.html#hierarchical-structure
Fixes: f489e019ac4a ("rust: compile host package per target")
Fixes: 83785a7ce016 ("rust-lang: Add the rust language support")
Fixes: https://github.com/openwrt/packages/issues/22133
Signed-off-by: Jeffery To <jeffery.to@gmail.com>
2023-09-18 01:30:56 +00:00
|
|
|
# Force linking of the SSP library for musl
|
|
|
|
ifdef CONFIG_PKG_CC_STACKPROTECTOR_REGULAR
|
|
|
|
ifeq ($(strip $(PKG_SSP)),1)
|
|
|
|
RUSTC_LDFLAGS+=-lssp_nonshared
|
|
|
|
endif
|
2023-02-08 14:18:41 +00:00
|
|
|
endif
|
rust: Set rustflags by environment variable
In order to use $(RUSTC_TARGET_ARCH) in HOST_BUILD_DIR, the line to
include rust-values.mk in the Rust makefile was moved in
f489e019ac4a15e974518d9928ef913a157d135a, causing it to be included
before package.mk is included.
This had the side effect of preventing "-lssp_nonshared" from being
added to RUSTC_LDFLAGS, because PKG_SSP is indirectly set by package.mk
(package.mk includes hardening.mk, hardening.mk sets PKG_SSP).
There is a deeper issue; it is the Rust package's PKG_SSP value that
causes RUSTC_LDFLAGS to be set and written to the Cargo config file. For
packages that use Rust to build, their PKG_SSP value does not affect the
linker flag.
This sets rustflags with the RUSTFLAGS environment variable, instead of
writing the value to the Cargo config file, allowing PKG_SSP from the
package being built to be used and for the package being built to modify
the rustflags used.
This also:
* Fix "-lssp_nonshared" being added to TARGET_CFLAGS instead of
RUSTC_LDFLAGS, when CONFIG_PKG_CC_STACKPROTECTOR_STRONG is set.
* Remove the use of $(RUSTC_TARGET_ARCH) in HOST_BUILD_DIR and move the
include line for rust-values.mk back to after package.mk.
Since the host build directory was moved under the target build
directory in efdbac38dc8b649ca26b49fac27abeb5cf76cd28, it is no longer
necessary to separate build directories with RUSTC_TARGET_ARCH;
$(BUILD_DIR) already separates build directories by target.
* Add BUILDONLY:=1, as the Rust package does not build a target package.
* Install the Cargo config file as "config.toml" instead of "config", as
this is the preferred form[1].
* Rename RUST_CFLAGS to RUSTC_CFLAGS and CONFIG_HOST_SUFFIX to
RUSTC_HOST_SUFFIX, for consistency.
* Allow CARGO_VARS to be set before rust-values.mk is included.
[1]: https://doc.rust-lang.org/cargo/reference/config.html#hierarchical-structure
Fixes: f489e019ac4a ("rust: compile host package per target")
Fixes: 83785a7ce016 ("rust-lang: Add the rust language support")
Fixes: https://github.com/openwrt/packages/issues/22133
Signed-off-by: Jeffery To <jeffery.to@gmail.com>
2023-09-18 01:30:56 +00:00
|
|
|
ifdef CONFIG_PKG_CC_STACKPROTECTOR_STRONG
|
|
|
|
ifeq ($(strip $(PKG_SSP)),1)
|
|
|
|
RUSTC_LDFLAGS+=-lssp_nonshared
|
|
|
|
endif
|
2023-02-08 14:18:41 +00:00
|
|
|
endif
|
|
|
|
endif
|
rust: Set rustflags by environment variable
In order to use $(RUSTC_TARGET_ARCH) in HOST_BUILD_DIR, the line to
include rust-values.mk in the Rust makefile was moved in
f489e019ac4a15e974518d9928ef913a157d135a, causing it to be included
before package.mk is included.
This had the side effect of preventing "-lssp_nonshared" from being
added to RUSTC_LDFLAGS, because PKG_SSP is indirectly set by package.mk
(package.mk includes hardening.mk, hardening.mk sets PKG_SSP).
There is a deeper issue; it is the Rust package's PKG_SSP value that
causes RUSTC_LDFLAGS to be set and written to the Cargo config file. For
packages that use Rust to build, their PKG_SSP value does not affect the
linker flag.
This sets rustflags with the RUSTFLAGS environment variable, instead of
writing the value to the Cargo config file, allowing PKG_SSP from the
package being built to be used and for the package being built to modify
the rustflags used.
This also:
* Fix "-lssp_nonshared" being added to TARGET_CFLAGS instead of
RUSTC_LDFLAGS, when CONFIG_PKG_CC_STACKPROTECTOR_STRONG is set.
* Remove the use of $(RUSTC_TARGET_ARCH) in HOST_BUILD_DIR and move the
include line for rust-values.mk back to after package.mk.
Since the host build directory was moved under the target build
directory in efdbac38dc8b649ca26b49fac27abeb5cf76cd28, it is no longer
necessary to separate build directories with RUSTC_TARGET_ARCH;
$(BUILD_DIR) already separates build directories by target.
* Add BUILDONLY:=1, as the Rust package does not build a target package.
* Install the Cargo config file as "config.toml" instead of "config", as
this is the preferred form[1].
* Rename RUST_CFLAGS to RUSTC_CFLAGS and CONFIG_HOST_SUFFIX to
RUSTC_HOST_SUFFIX, for consistency.
* Allow CARGO_VARS to be set before rust-values.mk is included.
[1]: https://doc.rust-lang.org/cargo/reference/config.html#hierarchical-structure
Fixes: f489e019ac4a ("rust: compile host package per target")
Fixes: 83785a7ce016 ("rust-lang: Add the rust language support")
Fixes: https://github.com/openwrt/packages/issues/22133
Signed-off-by: Jeffery To <jeffery.to@gmail.com>
2023-09-18 01:30:56 +00:00
|
|
|
|
|
|
|
CARGO_RUSTFLAGS+=-Ctarget-feature=-crt-static $(RUSTC_LDFLAGS)
|
2023-02-08 14:18:41 +00:00
|
|
|
|
2023-08-16 07:25:50 +00:00
|
|
|
ifeq ($(HOST_OS),Darwin)
|
|
|
|
ifeq ($(HOST_ARCH),arm64)
|
2023-08-17 08:57:16 +00:00
|
|
|
RUSTC_HOST_ARCH:=aarch64-apple-darwin
|
2023-08-16 07:25:50 +00:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2023-02-08 14:18:41 +00:00
|
|
|
# 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))
|
2023-06-07 11:00:54 +00:00
|
|
|
else ifeq ($(ARCH),riscv64)
|
|
|
|
RUSTC_TARGET_ARCH:=$(subst riscv64,riscv64gc,$(RUSTC_TARGET_ARCH))
|
2023-02-08 14:18:41 +00:00
|
|
|
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))
|
2023-10-09 21:19:50 +00:00
|
|
|
RUSTC_TARGET_ARCH:=$(subst gnueabi,gnueabihf,$(RUSTC_TARGET_ARCH))
|
2023-02-08 14:18:41 +00:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(ARCH),aarch64)
|
rust: Set rustflags by environment variable
In order to use $(RUSTC_TARGET_ARCH) in HOST_BUILD_DIR, the line to
include rust-values.mk in the Rust makefile was moved in
f489e019ac4a15e974518d9928ef913a157d135a, causing it to be included
before package.mk is included.
This had the side effect of preventing "-lssp_nonshared" from being
added to RUSTC_LDFLAGS, because PKG_SSP is indirectly set by package.mk
(package.mk includes hardening.mk, hardening.mk sets PKG_SSP).
There is a deeper issue; it is the Rust package's PKG_SSP value that
causes RUSTC_LDFLAGS to be set and written to the Cargo config file. For
packages that use Rust to build, their PKG_SSP value does not affect the
linker flag.
This sets rustflags with the RUSTFLAGS environment variable, instead of
writing the value to the Cargo config file, allowing PKG_SSP from the
package being built to be used and for the package being built to modify
the rustflags used.
This also:
* Fix "-lssp_nonshared" being added to TARGET_CFLAGS instead of
RUSTC_LDFLAGS, when CONFIG_PKG_CC_STACKPROTECTOR_STRONG is set.
* Remove the use of $(RUSTC_TARGET_ARCH) in HOST_BUILD_DIR and move the
include line for rust-values.mk back to after package.mk.
Since the host build directory was moved under the target build
directory in efdbac38dc8b649ca26b49fac27abeb5cf76cd28, it is no longer
necessary to separate build directories with RUSTC_TARGET_ARCH;
$(BUILD_DIR) already separates build directories by target.
* Add BUILDONLY:=1, as the Rust package does not build a target package.
* Install the Cargo config file as "config.toml" instead of "config", as
this is the preferred form[1].
* Rename RUST_CFLAGS to RUSTC_CFLAGS and CONFIG_HOST_SUFFIX to
RUSTC_HOST_SUFFIX, for consistency.
* Allow CARGO_VARS to be set before rust-values.mk is included.
[1]: https://doc.rust-lang.org/cargo/reference/config.html#hierarchical-structure
Fixes: f489e019ac4a ("rust: compile host package per target")
Fixes: 83785a7ce016 ("rust-lang: Add the rust language support")
Fixes: https://github.com/openwrt/packages/issues/22133
Signed-off-by: Jeffery To <jeffery.to@gmail.com>
2023-09-18 01:30:56 +00:00
|
|
|
RUSTC_CFLAGS:=-mno-outline-atomics
|
2023-02-08 14:18:41 +00:00
|
|
|
endif
|
2023-09-12 20:27:11 +00:00
|
|
|
|
|
|
|
# Support only a subset for now.
|
|
|
|
RUST_ARCH_DEPENDS:=@(aarch64||arm||i386||i686||mips||mipsel||mips64||mips64el||mipsel||powerpc64||riscv64||x86_64)
|
2023-10-01 18:16:22 +00:00
|
|
|
|
2023-09-25 02:00:58 +00:00
|
|
|
ifneq ($(CONFIG_RUST_SCCACHE),)
|
|
|
|
RUST_SCCACHE_DIR:=$(if $(call qstrip,$(CONFIG_RUST_SCCACHE_DIR)),$(call qstrip,$(CONFIG_RUST_SCCACHE_DIR)),$(TOPDIR)/.sccache)
|
|
|
|
|
|
|
|
RUST_SCCACHE_VARS:= \
|
|
|
|
CARGO_INCREMENTAL=0 \
|
|
|
|
RUSTC_WRAPPER=sccache \
|
|
|
|
SCCACHE_DIR=$(RUST_SCCACHE_DIR)
|
|
|
|
endif
|
|
|
|
|
2023-09-25 03:58:12 +00:00
|
|
|
CARGO_HOST_CONFIG_VARS= \
|
2023-09-25 02:00:58 +00:00
|
|
|
$(RUST_SCCACHE_VARS) \
|
2023-09-25 03:58:12 +00:00
|
|
|
CARGO_HOME=$(CARGO_HOME)
|
|
|
|
|
2023-10-01 18:16:22 +00:00
|
|
|
CARGO_HOST_PROFILE:=release
|
|
|
|
|
2023-09-25 03:58:12 +00:00
|
|
|
CARGO_PKG_CONFIG_VARS= \
|
2023-09-25 02:00:58 +00:00
|
|
|
$(RUST_SCCACHE_VARS) \
|
2023-09-25 03:58:12 +00:00
|
|
|
CARGO_BUILD_TARGET=$(RUSTC_TARGET_ARCH) \
|
|
|
|
CARGO_HOME=$(CARGO_HOME) \
|
2023-09-30 05:57:43 +00:00
|
|
|
CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1 \
|
|
|
|
CARGO_PROFILE_RELEASE_DEBUG=false \
|
|
|
|
CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS=false \
|
|
|
|
CARGO_PROFILE_RELEASE_LTO=true \
|
|
|
|
CARGO_PROFILE_RELEASE_OPT_LEVEL=z \
|
|
|
|
CARGO_PROFILE_RELEASE_OVERFLOW_CHECKS=true \
|
|
|
|
CARGO_PROFILE_RELEASE_PANIC=unwind \
|
|
|
|
CARGO_PROFILE_RELEASE_RPATH=false \
|
2023-09-25 03:58:12 +00:00
|
|
|
CARGO_TARGET_$(subst -,_,$(call toupper,$(RUSTC_TARGET_ARCH)))_LINKER=$(TARGET_CC_NOCACHE) \
|
|
|
|
RUSTFLAGS="$(CARGO_RUSTFLAGS)" \
|
|
|
|
TARGET_CC=$(TARGET_CC_NOCACHE) \
|
|
|
|
TARGET_CFLAGS="$(TARGET_CFLAGS) $(RUSTC_CFLAGS)"
|
|
|
|
|
2023-10-01 18:16:22 +00:00
|
|
|
CARGO_PKG_PROFILE:=$(if $(CONFIG_DEBUG),dev,release)
|