Skip to content

Commit

Permalink
rust-lang: 1.58.1
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Donald Hoskins <grommish@gmail.com>
  • Loading branch information
Grommish authored and lu-zero committed Dec 25, 2022
1 parent 822d44e commit d652016
Show file tree
Hide file tree
Showing 12 changed files with 764 additions and 0 deletions.
118 changes: 118 additions & 0 deletions lang/rust/Config.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Rust Language Options
menu "Compiler Options"
visible if PACKAGE_rust

config RUST_DEBUG
bool "Enables Debugging Environment (--enable-debug)"
default n

config RUST_DOCS
bool "Build standard library documentation (--enable-docs)"
default n

config RUST_COMPILER_DOCS
bool "Build compiler documentation (--enable-compiler-docs)"
default n

config RUST_OPTIMIZE_TESTS
bool "Build tests with optimizations (--enable-optimized-tests)"
default n

config RUST_PARALLEL
bool "Build with multi-threaded support (--enable-parallel-compiler)"
default n

config RUST_VERBOSE_TESTS
bool "Enable verbose output when running tests (--enable-verbose-tests)"
default n

config RUST_CCACHE
bool "Build with ccache enabled (--enable-ccache)"
default n

config RUST_LLVM_STATIC
bool "Statically link to libstdc++ to LLVM (--enable-llvm-static-stdccp)"
default n

config RUST_LLVM_SHARED
bool "Prefer shared linking to LLVM (--enable-llvm-link-shared)"
default n

config RUST_CODEGEN_TESTS
bool "Run the src/test/codegen tests (--enable-codegen-tests)"
default n

config RUST_OPTION_CHECKING
bool "Complain about unrecognized options in this configure script (--enable-option-checking)"
default y

config RUST_ENABLE_NINJA
bool "Build LLVM using the Ninja generator (--enable-ninja)"
default y

config RUST_LOCKED_DEPS
bool "Force Cargo.lock to be up to date (--enable-locked-deps)"
default n

config RUST_VENDOR
bool "Enable usage of vendored Rust crates (--enable-vendor)"
default n

config RUST_SANITIZERS
bool "Build the sanitizer runtimes (asan, lsan, msan, tsan) (--enable-sanitizers)"
default n

config RUST_DIST_SRC
bool "When building tarballs enables building a source tarball (--enable-dist-src)"
default n

config RUST_CARGO_NATIVE_STATIC
bool "Build static native libraries in Cargo (--enable-cargo-native-static)"
default n

config RUST_PROFILER
bool "Build the profiler runtime (--enable-profiler)"
default n

config RUST_FULL_TOOLS
bool "Build all tools (--enable-full-tools)"
default n

config RUST_MISSING_TOOLS
bool "Allow failures when building tools (--enable-missing-tools)"
default y

config RUST_USE_LIBCXX
bool "Build LLVM with libc++ (--enable-use-libcxx)"
default n

config RUST_CONTROL_FLOW_GUARD
bool "Enable Control Flow Guard (--enable-control-flow-guard)"
default n

config RUST_OPTIMIZE_LLVM
bool "Build optimized LLVM (--enable-optimize-llvm)"
default y

config RUST_LLVM_ASSERTIONS
bool "Build LLVM with assertions (--enable-llvm-assertions)"
default n

config RUST_DEBUG_ASSERTIONS
bool "Build with debugging assertions (--enable-debug-assertions)"
default n

config RUST_LLVM_RELEASE_DEBUGINFO
bool "Build LLVM with debugger metadata (--enable-llvm-release-debuginfo)"
default n

config RUST_MANAGE_SUBMODULES
bool "Let the build manage the git submodules (--enable-manage-submodules)"
default y

config RUST_FULL_BOOTSTRAP
bool "Full Bootstrap - Build three compilers instead of two (--enable-full-bootstrap)"
default n

endmenu

184 changes: 184 additions & 0 deletions lang/rust/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
include $(TOPDIR)/rules.mk

PKG_NAME := rust
PKG_VERSION := 1.58.1
PKG_RELEASE := 1

PKG_LICENSE := Apache-2.0 MIT
PKG_LICENSE_FILES := LICENSE-APACHE LICENSE-MIT

PKG_SOURCE_PROTO := git
PKG_SOURCE_URL := https://github.com/rust-lang/rust.git
PKG_SOURCE_DATE := 2021-12-02
PKG_SOURCE_VERSION := db9d1b20bba1968c1ec1fc49616d4742c1725b4b
PKG_MIRROR_HASH := 7adf556f2be1de12fd4a500cc0fef501f2f9c0fa553128ee968ec78290ca8283

PKG_HOST_ONLY := 1
PKG_BUILD_PARALLEL := 1

HOST_USE_NINJA := 1
CMAKE_INSTALL := 1

include $(INCLUDE_DIR)/cmake.mk
include $(INCLUDE_DIR)/host-build.mk
include $(INCLUDE_DIR)/package.mk

# Requires Python3 to build
HOST_BUILD_DEPENDS:=python3/host

# rust environmental variables
include ./rust_environment.mk

# Rust Temp Directory
RUST_TMP_DIR:=$(TMP_DIR)/rust-install

RUST_INSTALL_HOST_FILENAME:=$(PKG_NAME)-$(PKG_VERSION)-$(RUSTC_HOST_ARCH)-install.tar.xz
RUST_INSTALL_TARGET_FILENAME:=$(PKG_NAME)-$(PKG_VERSION)-$(RUSTC_TARGET_ARCH)-install.tar.xz

# Rust-lang has an uninstall script
RUST_UNINSTALL:=$(CARGO_HOME)/lib/rustlib/uninstall.sh

# This checks to see if the dist installation already exists
IS_RUSTC_INSTALLED:=$(or $(and $(wildcard $(CARGO_HOME)/bin/rustc),true),false)
IS_CARGO_INSTALLED:=$(or $(and $(wildcard $(CARGO_HOME)/bin/cargo),true),false)

# MUSL Target Flags
MUSL_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).musl-root=$(TOOLCHAIN_DIR) \
--set=target.$(RUSTC_TARGET_ARCH).ranlib=$(TARGET_RANLIB)

# CARGO_HOME is an environmental
HOST_CONFIGURE_OPTS += CARGO_HOME="$(CARGO_HOME)"

# The Flags are Common between HOST and TARGET
RUST_COMMON_ARGS := \
--build=$(RUSTC_HOST_ARCH) \
--dist-compression-formats=xz \
--enable-llvm-link-shared \
--enable-llvm-plugins \
--enable-missing-tools \
--enable-ninja \
--enable-optimize \
--enable-optimize-llvm \
--enable-parallel-compiler \
--enable-sanitizers \
--release-channel=nightly \
${MUSL_CONFIGURE_ARGS}

##
# Because OpenWrt uses default configure flags that are not recognized
# we override the default and set our own.
#
# Rust HOST Configuration Arguments
HOST_CONFIGURE_ARGS = \
--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 \
${RUST_COMMON_ARGS}

# TODO: For future use
# Rust TARGET Configuration Args
#CONFIGURE_ARGS = \
# --target=$(RUSTC_TARGET_ARCH) \
# --host=$(RUSTC_TARGET_ARCH) \
# --prefix=$(CONFIGURE_PREFIX) \
# --bindir=$(CONFIGURE_PREFIX)/bin \
# --libdir=$(CONFIGURE_PREFIX)/lib \
# --sysconfdir=$(CONFIGURE_PREFIX)/etc \
# --datadir=$(CONFIGURE_PREFIX)/share \
# --mandir=$(CONFIGURE_PREFIX)/man \
# $(RUST_COMMOM_ARGS) \
# --set=llvm.cxxflags='$(RUST_LLVM_CXXFLAGS)'

# Add rust_config.mk Debug flags
#include ./rust_config.mk

define Host/Prepare
# Ensure rust temp directory
[ -d $(RUST_TMP_DIR) ] || \
mkdir -p $(RUST_TMP_DIR)

$(call Host/Prepare/Default)
endef

define Host/Uninstall
# Call the Uninstall script
[ -f $(RUST_UNINSTALL) ] && \
$(BASH) $(RUST_UNINSTALL) || echo No Uninstall

rm -rf $(RUST_TMP_DIR)
endef

# Makes and then packages the dist artifacts
define Host/Compile
cd $(HOST_BUILD_DIR) && \
$(PYTHON) x.py --config ./config.toml dist build-manifest cargo llvm-tools \
rustc rust-std rust-src

$(call Host/PackageDist)
endef

# Distribution Artifacts are packaged by Host/PackageDist
# We just need to extract and install
define Host/Install
$(TAR) -C $(RUST_TMP_DIR) -xJf $(DL_DIR)/$(RUST_INSTALL_HOST_FILENAME) && \
$(TAR) -C $(RUST_TMP_DIR) -xJf $(DL_DIR)/$(RUST_INSTALL_TARGET_FILENAME)

cd $(RUST_TMP_DIR) && \
find -iname "*.xz" -exec tar -xJf {} ";" && \
find ./* -type f -name install.sh -execdir sh {} --prefix=$(CARGO_HOME) --disable-ldconfig \;
endef

# Packages the Distribution Artifacts into HOST and TARGET bundles.
define Host/PackageDist
cd $(HOST_BUILD_DIR)/build/dist && \
$(TAR) -cJf $(DL_DIR)/$(RUST_INSTALL_TARGET_FILENAME) \
rust-*-$(RUSTC_TARGET_ARCH).tar.xz

cd $(HOST_BUILD_DIR)/build/dist && \
$(TAR) -cJf $(DL_DIR)/$(RUST_INSTALL_HOST_FILENAME) \
--exclude rust-*-$(RUSTC_TARGET_ARCH).tar.xz *.xz
endef

define Package/rust
SECTION:=lang
CATEGORY:=Languages
TITLE:=Rust Programming Language Compiler
URL:=https://www.rust-lang.org/
DEPENDS:=@(aarch64||arm||mips64||mips||mipsel||x86_64) \
+pkg-config +libunwind
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

define Package/rust/config
source "$(SOURCE)/Config.in"
endef

$(eval $(call HostBuild))
$(eval $(call BuildPackage,rust))
72 changes: 72 additions & 0 deletions lang/rust/patches/00-add_mips64.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
From 2e0f33744f8f67afeecdc4963bccc7942d20582d Mon Sep 17 00:00:00 2001
From: Donald Hoskins <grommish@gmail.com>
Date: Mon, 3 Jan 2022 02:48:02 -0500
Subject: [PATCH] rustc_target: mips64-openwrt-linux-musl - Add Tier 3 target

Tier 3 tuple for Mips64 OpenWrt toolchain.

Signed-off-by: Donald Hoskins <grommish@gmail.com>
---
.../src/spec/mips64_openwrt_linux_musl.rs | 26 +++++++++++++++++++
compiler/rustc_target/src/spec/mod.rs | 2 ++
src/doc/rustc/src/platform-support.md | 1 +
3 files changed, 29 insertions(+)
create mode 100644 compiler/rustc_target/src/spec/mips64_openwrt_linux_musl.rs

diff --git a/compiler/rustc_target/src/spec/mips64_openwrt_linux_musl.rs b/compiler/rustc_target/src/spec/mips64_openwrt_linux_musl.rs
new file mode 100644
index 0000000000000..1199ed44202f9
--- /dev/null
+++ b/compiler/rustc_target/src/spec/mips64_openwrt_linux_musl.rs
@@ -0,0 +1,26 @@
+/// A target tuple for OpenWrt MIPS64 targets
+///
+use crate::abi::Endian;
+use crate::spec::{Target, TargetOptions};
+
+pub fn target() -> Target {
+ let mut base = super::linux_musl_base::opts();
+ base.cpu = "mips64r2".to_string();
+ base.features = "+mips64r2".to_string();
+ base.max_atomic_width = Some(64);
+ base.crt_static_default = false;
+
+ Target {
+ // LLVM doesn't recognize "muslabi64" yet.
+ llvm_target: "mips64-unknown-linux-musl".to_string(),
+ pointer_width: 64,
+ data_layout: "E-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128".to_string(),
+ arch: "mips64".to_string(),
+ options: TargetOptions {
+ abi: "abi64".to_string(),
+ endian: Endian::Big,
+ mcount: "_mcount".to_string(),
+ ..base
+ },
+ }
+}
diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs
index 43913183694e0..fee40c4c6c95e 100644
--- a/compiler/rustc_target/src/spec/mod.rs
+++ b/compiler/rustc_target/src/spec/mod.rs
@@ -1014,6 +1014,8 @@ supported_targets! {
("armv7-unknown-linux-uclibceabihf", armv7_unknown_linux_uclibceabihf),

("x86_64-unknown-none", x86_64_unknown_none),
+
+ ("mips64-openwrt-linux-musl", mips64_openwrt_linux_musl),
}

/// Warnings encountered when parsing the target `json`.
diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md
index f4f659ffa273e..d225701087d4d 100644
--- a/src/doc/rustc/src/platform-support.md
+++ b/src/doc/rustc/src/platform-support.md
@@ -244,6 +244,7 @@ target | std | host | notes
`i686-wrs-vxworks` | ? | |
`m68k-unknown-linux-gnu` | ? | | Motorola 680x0 Linux
`mips-unknown-linux-uclibc` | ✓ | | MIPS Linux with uClibc
+`mips64-openwrt-linux-musl` | ? | | OpenWrt
`mipsel-sony-psp` | * | | MIPS (LE) Sony PlayStation Portable (PSP)
`mipsel-unknown-linux-uclibc` | ✓ | | MIPS (LE) Linux with uClibc
`mipsel-unknown-none` | * | | Bare MIPS (LE) softfloat
Loading

0 comments on commit d652016

Please sign in to comment.