mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-03-09 15:40:03 +00:00
Add Rust language
This commit is contained in:
parent
4296ac92e9
commit
d07ccb47ff
7 changed files with 350 additions and 0 deletions
104
rust/Makefile
Normal file
104
rust/Makefile
Normal file
|
@ -0,0 +1,104 @@
|
|||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
#
|
||||
# Copyright (C) 2023 Luca Barbato and Donald Hoskins
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
include ./rust-values.mk
|
||||
|
||||
PKG_NAME:=rust
|
||||
PKG_VERSION:=1.71.1
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_SOURCE:=rustc-$(PKG_VERSION)-src.tar.gz
|
||||
PKG_SOURCE_URL:=https://static.rust-lang.org/dist/
|
||||
PKG_HASH:=6fa90d50d1d529a75f6cc349784de57d7ec0ba2419b09bde7d335c25bd4e472e
|
||||
HOST_BUILD_DIR:=$(BUILD_DIR)/host/rust-$(RUSTC_TARGET_ARCH)/rustc-$(PKG_VERSION)-src
|
||||
|
||||
PKG_MAINTAINER:=Luca Barbato <lu_zero@luminem.org>
|
||||
PKG_LICENSE:=Apache-2.0 MIT
|
||||
PKG_LICENSE_FILES:=LICENSE-APACHE LICENSE-MIT
|
||||
|
||||
HOST_BUILD_DEPENDS:=python3/host
|
||||
PKG_HOST_ONLY:=1
|
||||
|
||||
include $(INCLUDE_DIR)/host-build.mk
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/rust
|
||||
SECTION:=lang
|
||||
CATEGORY:=Languages
|
||||
SUBMENU:=Rust
|
||||
TITLE:=Rust Programming Language Compiler
|
||||
URL:=https://www.rust-lang.org/
|
||||
DEPENDS:=$(RUST_ARCH_DEPENDS)
|
||||
endef
|
||||
|
||||
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
|
||||
|
||||
# Rust-lang has an uninstall script
|
||||
RUST_UNINSTALL:=$(CARGO_HOME)/lib/rustlib/uninstall.sh
|
||||
|
||||
# Target Flags
|
||||
TARGET_CONFIGURE_ARGS = \
|
||||
--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) \
|
||||
--set=target.$(RUSTC_TARGET_ARCH).ranlib=$(TARGET_RANLIB) \
|
||||
$(if $(CONFIG_USE_MUSL),--set=target.$(RUSTC_TARGET_ARCH).musl-root=$(TOOLCHAIN_DIR))
|
||||
|
||||
# CARGO_HOME is an environmental
|
||||
HOST_CONFIGURE_OPTS += CARGO_HOME="$(CARGO_HOME)"
|
||||
|
||||
# Rust Configuration Arguments
|
||||
HOST_CONFIGURE_ARGS = \
|
||||
--build=$(RUSTC_HOST_ARCH) \
|
||||
--target=$(RUSTC_TARGET_ARCH),$(RUSTC_HOST_ARCH) \
|
||||
--host=$(RUSTC_HOST_ARCH) \
|
||||
--prefix=$(CARGO_HOME) \
|
||||
--bindir=$(CARGO_HOME)/bin \
|
||||
--libdir=$(CARGO_HOME)/lib \
|
||||
--sysconfdir=$(CARGO_HOME)/etc \
|
||||
--datadir=$(CARGO_HOME)/share \
|
||||
--mandir=$(CARGO_HOME)/man \
|
||||
--dist-compression-formats=xz \
|
||||
--enable-missing-tools \
|
||||
--disable-sanitizers \
|
||||
--release-channel=stable \
|
||||
--enable-cargo-native-static \
|
||||
--set=llvm.download-ci-llvm=true \
|
||||
$(TARGET_CONFIGURE_ARGS)
|
||||
|
||||
define Host/Uninstall
|
||||
# Call the Uninstall script
|
||||
[ -f $(RUST_UNINSTALL) ] && \
|
||||
$(BASH) $(RUST_UNINSTALL) || echo No Uninstall
|
||||
endef
|
||||
|
||||
define Host/Compile
|
||||
( \
|
||||
cd $(HOST_BUILD_DIR) ; \
|
||||
$(PYTHON) x.py --config ./config.toml dist build-manifest cargo llvm-tools \
|
||||
rustc rust-std rust-src ; \
|
||||
)
|
||||
endef
|
||||
|
||||
define Host/Install
|
||||
( \
|
||||
cd $(HOST_BUILD_DIR)/build/dist ; \
|
||||
find -iname "*.xz" -exec tar -xJf {} \; ; \
|
||||
find ./* -type f -name install.sh -execdir sh {} --prefix=$(CARGO_HOME) --disable-ldconfig \; ; \
|
||||
\
|
||||
sed -e 's|@RUSTC_TARGET_ARCH@|$(RUSTC_TARGET_ARCH)|g' \
|
||||
-e 's|@TARGET_CC_NOCACHE@|$(TARGET_CC_NOCACHE)|g' \
|
||||
-e 's|@RUSTC_LDFLAGS@|$(RUSTC_LDFLAGS)|g' \
|
||||
$(CURDIR)/files/cargo-config > $(CARGO_HOME)/config ; \
|
||||
)
|
||||
endef
|
||||
|
||||
$(eval $(call HostBuild))
|
||||
$(eval $(call BuildPackage,rust))
|
8
rust/files/cargo-config
Normal file
8
rust/files/cargo-config
Normal file
|
@ -0,0 +1,8 @@
|
|||
[target.@RUSTC_TARGET_ARCH@]
|
||||
linker = "@TARGET_CC_NOCACHE@"
|
||||
rustflags = ["-Ctarget-feature=-crt-static", "-Clink-args=@RUSTC_LDFLAGS@"]
|
||||
|
||||
[profile.stripped]
|
||||
inherits = "release"
|
||||
opt-level = "s"
|
||||
strip = true
|
48
rust/patches/0001-Update-xz2-and-use-it-static.patch
Normal file
48
rust/patches/0001-Update-xz2-and-use-it-static.patch
Normal file
|
@ -0,0 +1,48 @@
|
|||
From d3000458501d339ea2043006924d431ead18769e Mon Sep 17 00:00:00 2001
|
||||
From: Luca Barbato <lu_zero@gentoo.org>
|
||||
Date: Sun, 4 Jun 2023 19:32:28 +0000
|
||||
Subject: [PATCH] Update xz2 and use it static
|
||||
|
||||
---
|
||||
Cargo.lock | 8 ++++----
|
||||
src/bootstrap/Cargo.lock | 8 ++++----
|
||||
src/bootstrap/Cargo.toml | 2 +-
|
||||
3 files changed, 9 insertions(+), 9 deletions(-)
|
||||
|
||||
--- a/src/bootstrap/Cargo.lock
|
||||
+++ b/src/bootstrap/Cargo.lock
|
||||
@@ -443,9 +443,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "lzma-sys"
|
||||
-version = "0.1.17"
|
||||
+version = "0.1.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
-checksum = "bdb4b7c3eddad11d3af9e86c487607d2d2442d185d848575365c4856ba96d619"
|
||||
+checksum = "5fda04ab3764e6cde78b9974eec4f779acaba7c4e84b36eca3cf77c581b85d27"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
@@ -912,9 +912,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "xz2"
|
||||
-version = "0.1.6"
|
||||
+version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
-checksum = "c179869f34fc7c01830d3ce7ea2086bc3a07e0d35289b667d0a8bf910258926c"
|
||||
+checksum = "388c44dc09d76f1536602ead6d325eb532f5c122f17782bd57fb47baeeb767e2"
|
||||
dependencies = [
|
||||
"lzma-sys",
|
||||
]
|
||||
--- a/src/bootstrap/Cargo.toml
|
||||
+++ b/src/bootstrap/Cargo.toml
|
||||
@@ -50,7 +50,7 @@ toml = "0.5"
|
||||
ignore = "0.4.10"
|
||||
opener = "0.5"
|
||||
once_cell = "1.7.2"
|
||||
-xz2 = "0.1"
|
||||
+xz2 = { version = "0.1", features = ["static"] }
|
||||
walkdir = "2"
|
||||
|
||||
# Dependencies needed by the build-metrics feature
|
35
rust/patches/0002-Bumped-libc-version.patch
Normal file
35
rust/patches/0002-Bumped-libc-version.patch
Normal file
|
@ -0,0 +1,35 @@
|
|||
From 032857e7e403f654129c45dc7e6718a9ad49e377 Mon Sep 17 00:00:00 2001
|
||||
From: Nikolay Arhipov <n@arhipov.net>
|
||||
Date: Tue, 6 Jun 2023 16:09:05 +0300
|
||||
Subject: [PATCH] Bumped libc version
|
||||
|
||||
---
|
||||
Cargo.lock | 4 ++--
|
||||
library/std/Cargo.toml | 2 +-
|
||||
2 files changed, 3 insertions(+), 3 deletions(-)
|
||||
|
||||
--- a/Cargo.lock
|
||||
+++ b/Cargo.lock
|
||||
@@ -1988,9 +1988,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0e
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
-version = "0.2.143"
|
||||
+version = "0.2.146"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
-checksum = "edc207893e85c5d6be840e969b496b53d94cec8be2d501b214f50daa97fa8024"
|
||||
+checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b"
|
||||
dependencies = [
|
||||
"rustc-std-workspace-core",
|
||||
]
|
||||
--- a/library/std/Cargo.toml
|
||||
+++ b/library/std/Cargo.toml
|
||||
@@ -15,7 +15,7 @@ cfg-if = { version = "1.0", features = [
|
||||
panic_unwind = { path = "../panic_unwind", optional = true }
|
||||
panic_abort = { path = "../panic_abort" }
|
||||
core = { path = "../core" }
|
||||
-libc = { version = "0.2.143", default-features = false, features = ['rustc-dep-of-std'] }
|
||||
+libc = { version = "0.2.146", default-features = false, features = ['rustc-dep-of-std'] }
|
||||
compiler_builtins = { version = "0.1.92" }
|
||||
profiler_builtins = { path = "../profiler_builtins", optional = true }
|
||||
unwind = { path = "../unwind" }
|
45
rust/rust-host-build.mk
Normal file
45
rust/rust-host-build.mk
Normal file
|
@ -0,0 +1,45 @@
|
|||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
#
|
||||
# Copyright (C) 2023 Luca Barbato and Donald Hoskins
|
||||
|
||||
ifeq ($(origin RUST_INCLUDE_DIR),undefined)
|
||||
RUST_INCLUDE_DIR:=$(dir $(lastword $(MAKEFILE_LIST)))
|
||||
endif
|
||||
include $(RUST_INCLUDE_DIR)/rust-values.mk
|
||||
|
||||
# $(1) path to the package (optional)
|
||||
# $(2) additional arguments to cargo (optional)
|
||||
define Host/Compile/Cargo
|
||||
( \
|
||||
cd $(HOST_BUILD_DIR) ; \
|
||||
export PATH="$(CARGO_HOME)/bin:$(PATH)" ; \
|
||||
CARGO_HOME=$(CARGO_HOME) \
|
||||
CC=$(HOSTCC_NOCACHE) \
|
||||
cargo install -v \
|
||||
--profile stripped \
|
||||
$(if $(RUST_PKG_FEATURES),--features "$(RUST_PKG_FEATURES)") \
|
||||
--root $(HOST_INSTALL_DIR) \
|
||||
--path "$(if $(strip $(1)),$(strip $(1)),.)" $(2) ; \
|
||||
)
|
||||
endef
|
||||
|
||||
define Host/Uninstall/Cargo
|
||||
( \
|
||||
cd $(HOST_BUILD_DIR) ; \
|
||||
export PATH="$(CARGO_HOME)/bin:$(PATH)" ; \
|
||||
CARGO_HOME=$(CARGO_HOME) \
|
||||
CC=$(HOSTCC_NOCACHE) \
|
||||
cargo uninstall -v \
|
||||
--root $(HOST_INSTALL_DIR) || true ; \
|
||||
)
|
||||
endef
|
||||
|
||||
define RustBinHostBuild
|
||||
define Host/Install
|
||||
$(INSTALL_DIR) $(STAGING_DIR_HOSTPKG)/bin
|
||||
$(INSTALL_BIN) $(HOST_INSTALL_DIR)/bin/* $(STAGING_DIR_HOSTPKG)/bin/
|
||||
endef
|
||||
endef
|
||||
|
||||
Host/Compile=$(call Host/Compile/Cargo)
|
||||
Host/Uninstall=$(call Host/Uninstall/Cargo)
|
51
rust/rust-package.mk
Normal file
51
rust/rust-package.mk
Normal file
|
@ -0,0 +1,51 @@
|
|||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
#
|
||||
# Copyright (C) 2023 Luca Barbato and Donald Hoskins
|
||||
|
||||
# Variables (all optional) to be set in package Makefiles:
|
||||
#
|
||||
# RUST_PKG_FEATURES - list of options, default empty
|
||||
#
|
||||
# Space or comma separated list of features to activate
|
||||
#
|
||||
# e.g. RUST_PKG_FEATURES:=enable-foo,with-bar
|
||||
|
||||
ifeq ($(origin RUST_INCLUDE_DIR),undefined)
|
||||
RUST_INCLUDE_DIR:=$(dir $(lastword $(MAKEFILE_LIST)))
|
||||
endif
|
||||
include $(RUST_INCLUDE_DIR)/rust-values.mk
|
||||
|
||||
# Support only a subset for now.
|
||||
RUST_ARCH_DEPENDS:=@(aarch64||arm||i386||i686||mips||mipsel||mips64||mips64el||mipsel||powerpc64||riscv64||x86_64)
|
||||
|
||||
# $(1) path to the package (optional)
|
||||
# $(2) additional arguments to cargo (optional)
|
||||
define Build/Compile/Cargo
|
||||
( \
|
||||
cd $(PKG_BUILD_DIR) ; \
|
||||
export PATH="$(CARGO_HOME)/bin:$(PATH)" ; \
|
||||
CARGO_HOME=$(CARGO_HOME) \
|
||||
TARGET_CFLAGS="$(TARGET_CFLAGS) $(RUST_CFLAGS)" \
|
||||
TARGET_CC=$(TARGET_CC_NOCACHE) \
|
||||
CC=$(HOSTCC_NOCACHE) \
|
||||
$(CARGO_VARS) \
|
||||
cargo install -v \
|
||||
--profile stripped \
|
||||
--target $(RUSTC_TARGET_ARCH) \
|
||||
$(if $(strip $(RUST_PKG_FEATURES)),--features "$(strip $(RUST_PKG_FEATURES))") \
|
||||
--root $(PKG_INSTALL_DIR) \
|
||||
--path "$(if $(strip $(1)),$(strip $(1)),.)" \
|
||||
$(2) ; \
|
||||
)
|
||||
endef
|
||||
|
||||
define RustBinPackage
|
||||
ifndef Package/$(1)/install
|
||||
define Package/$(1)/install
|
||||
$$(INSTALL_DIR) $$(1)/usr/bin/
|
||||
$$(INSTALL_BIN) $$(PKG_INSTALL_DIR)/bin/* $$(1)/usr/bin/
|
||||
endef
|
||||
endif
|
||||
endef
|
||||
|
||||
Build/Compile=$(call Build/Compile/Cargo)
|
59
rust/rust-values.mk
Normal file
59
rust/rust-values.mk
Normal file
|
@ -0,0 +1,59 @@
|
|||
# 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
|
||||
|
||||
ifeq ($(HOST_OS),Darwin)
|
||||
ifeq ($(HOST_ARCH),arm64)
|
||||
RUSTC_HOST_ARCH:=aarch64-apple-darwin
|
||||
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
|
Loading…
Add table
Add a link
Reference in a new issue