2023-02-08 15:18:41 +01:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
#
|
|
|
|
# Copyright (C) 2023 Luca Barbato and Donald Hoskins
|
|
|
|
|
|
|
|
include $(TOPDIR)/rules.mk
|
|
|
|
|
|
|
|
PKG_NAME:=rust
|
2024-05-04 12:39:44 +02:00
|
|
|
PKG_VERSION:=1.78.0
|
2024-05-13 12:37:18 +02:00
|
|
|
PKG_RELEASE:=2
|
2023-02-08 15:18:41 +01:00
|
|
|
|
2024-05-04 12:39:44 +02:00
|
|
|
PKG_SOURCE:=rustc-$(PKG_VERSION)-src.tar.gz
|
2023-02-08 15:18:41 +01:00
|
|
|
PKG_SOURCE_URL:=https://static.rust-lang.org/dist/
|
2024-05-04 12:39:44 +02:00
|
|
|
PKG_HASH:=ff544823a5cb27f2738128577f1e7e00ee8f4c83f2a348781ae4fc355e91d5a9
|
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 03:30:56 +02:00
|
|
|
HOST_BUILD_DIR:=$(BUILD_DIR)/host/rustc-$(PKG_VERSION)-src
|
2023-03-09 08:58:16 +01:00
|
|
|
|
2023-02-08 15:18:41 +01:00
|
|
|
PKG_MAINTAINER:=Luca Barbato <lu_zero@luminem.org>
|
2023-03-09 08:58:16 +01:00
|
|
|
PKG_LICENSE:=Apache-2.0 MIT
|
|
|
|
PKG_LICENSE_FILES:=LICENSE-APACHE LICENSE-MIT
|
2023-02-08 15:18:41 +01:00
|
|
|
|
|
|
|
PKG_HOST_ONLY:=1
|
2023-10-26 10:11:06 +02:00
|
|
|
PKG_BUILD_FLAGS:=no-mips16
|
2023-02-08 15:18:41 +01:00
|
|
|
|
2023-03-09 08:58:16 +01:00
|
|
|
include $(INCLUDE_DIR)/host-build.mk
|
2023-03-19 07:07:48 +01:00
|
|
|
include $(INCLUDE_DIR)/package.mk
|
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 03:30:56 +02:00
|
|
|
include ./rust-values.mk
|
2023-02-08 15:18:41 +01:00
|
|
|
|
2023-03-19 06:39:55 +01:00
|
|
|
define Package/rust
|
|
|
|
SECTION:=lang
|
|
|
|
CATEGORY:=Languages
|
|
|
|
SUBMENU:=Rust
|
|
|
|
TITLE:=Rust Programming Language Compiler
|
|
|
|
URL:=https://www.rust-lang.org/
|
2023-03-19 06:43:06 +01:00
|
|
|
DEPENDS:=$(RUST_ARCH_DEPENDS)
|
2023-03-19 06:39:55 +01:00
|
|
|
endef
|
2023-02-08 15:18:41 +01:00
|
|
|
|
2023-03-19 06:39:55 +01:00
|
|
|
define Package/rust/description
|
|
|
|
Rust is a multi-paradigm, general-purpose programming language designed for performance
|
|
|
|
and safety, especially safe concurrency. Rust is syntactically similar to C++, but can
|
|
|
|
guarantee memory safety by using a borrow checker to validate references.
|
|
|
|
endef
|
2023-02-08 15:18:41 +01:00
|
|
|
|
2023-09-25 04:00:58 +02:00
|
|
|
define Package/rust/config
|
|
|
|
source "$(SOURCE)/Config.in"
|
|
|
|
endef
|
|
|
|
|
2023-02-08 15:18:41 +01:00
|
|
|
# Rust-lang has an uninstall script
|
2023-09-22 18:02:01 +02:00
|
|
|
RUST_UNINSTALL:=$(STAGING_DIR)/host/lib/rustlib/uninstall.sh
|
2023-02-08 15:18:41 +01:00
|
|
|
|
|
|
|
# Target Flags
|
|
|
|
TARGET_CONFIGURE_ARGS = \
|
2023-03-09 08:58:16 +01:00
|
|
|
--set=target.$(RUSTC_TARGET_ARCH).ar=$(TARGET_AR) \
|
|
|
|
--set=target.$(RUSTC_TARGET_ARCH).cc=$(TARGET_CC_NOCACHE) \
|
|
|
|
--set=target.$(RUSTC_TARGET_ARCH).cxx=$(TARGET_CXX_NOCACHE) \
|
|
|
|
--set=target.$(RUSTC_TARGET_ARCH).linker=$(TARGET_CC_NOCACHE) \
|
2023-03-19 19:08:00 +01:00
|
|
|
--set=target.$(RUSTC_TARGET_ARCH).ranlib=$(TARGET_RANLIB) \
|
2023-10-12 15:24:31 +02:00
|
|
|
--set=target.$(RUSTC_TARGET_ARCH).crt-static=false \
|
2023-10-19 18:24:57 +02:00
|
|
|
$(if $(CONFIG_USE_MUSL),--set=target.$(RUSTC_TARGET_ARCH).musl-root=$(TOOLCHAIN_ROOT_DIR))
|
2023-02-08 15:18:41 +01:00
|
|
|
|
|
|
|
# CARGO_HOME is an environmental
|
2023-09-22 18:02:01 +02:00
|
|
|
HOST_CONFIGURE_VARS += CARGO_HOME="$(CARGO_HOME)"
|
2023-02-08 15:18:41 +01:00
|
|
|
|
|
|
|
# Rust Configuration Arguments
|
|
|
|
HOST_CONFIGURE_ARGS = \
|
2023-03-09 08:58:16 +01:00
|
|
|
--build=$(RUSTC_HOST_ARCH) \
|
|
|
|
--target=$(RUSTC_TARGET_ARCH),$(RUSTC_HOST_ARCH) \
|
|
|
|
--host=$(RUSTC_HOST_ARCH) \
|
2023-09-22 18:02:01 +02:00
|
|
|
--prefix=$(STAGING_DIR)/host \
|
|
|
|
--bindir=$(STAGING_DIR)/host/bin \
|
|
|
|
--libdir=$(STAGING_DIR)/host/lib \
|
|
|
|
--sysconfdir=$(STAGING_DIR)/host/etc \
|
|
|
|
--datadir=$(STAGING_DIR)/host/share \
|
|
|
|
--mandir=$(STAGING_DIR)/host/man \
|
2023-10-11 06:56:20 +02:00
|
|
|
--dist-compression-formats=gz \
|
2023-03-09 08:58:16 +01:00
|
|
|
--disable-sanitizers \
|
|
|
|
--release-channel=stable \
|
|
|
|
--enable-cargo-native-static \
|
2024-05-04 12:39:44 +02:00
|
|
|
--bootstrap-cache-path=$(DL_DIR)/rustc \
|
2023-03-19 07:20:40 +01:00
|
|
|
--set=llvm.download-ci-llvm=true \
|
2023-03-09 08:58:16 +01:00
|
|
|
$(TARGET_CONFIGURE_ARGS)
|
2023-02-08 15:18:41 +01:00
|
|
|
|
|
|
|
define Host/Uninstall
|
|
|
|
# Call the Uninstall script
|
|
|
|
[ -f $(RUST_UNINSTALL) ] && \
|
2023-03-19 06:39:55 +01:00
|
|
|
$(BASH) $(RUST_UNINSTALL) || echo No Uninstall
|
2023-02-08 15:18:41 +01:00
|
|
|
endef
|
|
|
|
|
|
|
|
define Host/Compile
|
2023-09-25 04:00:58 +02:00
|
|
|
$(RUST_SCCACHE_VARS) \
|
2023-09-23 14:24:37 +02:00
|
|
|
CARGO_HOME=$(CARGO_HOME) \
|
2023-10-26 10:11:06 +02:00
|
|
|
TARGET_CFLAGS="$(TARGET_CFLAGS)" \
|
2023-09-23 14:24:37 +02:00
|
|
|
$(PYTHON) $(HOST_BUILD_DIR)/x.py \
|
|
|
|
--build-dir $(HOST_BUILD_DIR)/build \
|
|
|
|
--config $(HOST_BUILD_DIR)/config.toml \
|
|
|
|
dist build-manifest cargo llvm-tools rustc rust-std rust-src
|
2023-02-08 15:18:41 +01:00
|
|
|
endef
|
|
|
|
|
|
|
|
define Host/Install
|
2023-03-09 08:58:16 +01:00
|
|
|
( \
|
|
|
|
cd $(HOST_BUILD_DIR)/build/dist ; \
|
2023-10-11 06:56:20 +02:00
|
|
|
for targz in *.tar.gz; do \
|
|
|
|
$(STAGING_DIR_HOST)/bin/libdeflate-gzip -dc "$$$$targz" | tar -xf - ; \
|
|
|
|
done ; \
|
|
|
|
find . -mindepth 2 -maxdepth 2 -type f -name install.sh \
|
2023-09-22 18:02:01 +02:00
|
|
|
-execdir bash '{}' --prefix=$(STAGING_DIR)/host --disable-ldconfig \; ; \
|
2023-03-09 08:58:16 +01:00
|
|
|
)
|
2023-02-08 15:18:41 +01:00
|
|
|
endef
|
|
|
|
|
|
|
|
$(eval $(call HostBuild))
|
|
|
|
$(eval $(call BuildPackage,rust))
|