Skip to content

Commit

Permalink
rust: Initial Commit Rust 1.50.0 lang toolchain
Browse files Browse the repository at this point in the history
Rust is a multi-paradigm 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 committed Mar 26, 2021
1 parent e236ffb commit cee25cd
Show file tree
Hide file tree
Showing 15 changed files with 691 additions and 0 deletions.
117 changes: 117 additions & 0 deletions lang/rust/Config.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Rust Language Options
menu "Compiler Options"
depends on 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 n

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
130 changes: 130 additions & 0 deletions lang/rust/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk

PKG_NAME:=rust
PKG_VERSION:=1.50.0
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-02-10
PKG_SOURCE_VERSION:=cb75ad5db02783e8b0222fee363c5f63f7e2cf5b
PKG_MIRROR_HASH:=747c6a9f26d143e0ef95f1be4c6ac814e2d5eead1811cba797b04e71f720df02
PKG_HOST_ONLY:=1

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

HOST_BUILD_DEPENDS:=ninja/host python3/host
PKG_BUILD_DEPENDS:=rust/host
CMAKE_INSTALL:=1

# These are environment variables that are used by other packages to
# define where rustc/cargo are kept.
CONFIG_HOST_SUFFIX:=$(shell cut -d"-" -f4 <<<"$(GNU_HOST_NAME)")
RUSTC_HOST_ARCH:=$(HOST_ARCH)-unknown-linux-$(CONFIG_HOST_SUFFIX)
RUSTC_TARGET_ARCH:=$(REAL_GNU_TARGET_NAME)
CARGO_HOME:=$(STAGING_DIR_HOSTPKG)

# Basic Configuration Args that are used across all builds.
# Other build arguments are found in ./rustc-config.mk
#
# Default CONFIGURE_ARGS introduces unknown options - Use this instead
CONFIGURE_ARGS = \
--host=$(RUSTC_HOST_ARCH) \
--build=$(RUSTC_HOST_ARCH) \
--target=$(RUSTC_TARGET_ARCH) \
--prefix=$(CARGO_HOME) \
--bindir=$(CARGO_HOME)/bin \
--libdir=$(CARGO_HOME)/lib \
--sysconfdir=$(CARGO_HOME)/etc \
--datadir=$(CARGO_HOME)/share \
--mandir=$(CARGO_HOME)/man \
--infodir=$(CARGO_HOME)/info \
--localstatedir=/var \
--release-channel=nightly \
--enable-lld

ifeq ($(CONFIG_USE_MUSL),y)
CONFIGURE_ARGS += \
--set=target.$(RUSTC_TARGET_ARCH).linker=$(TARGET_CC_NOCACHE) \
--set=target.$(RUSTC_TARGET_ARCH).cc=$(TARGET_CC_NOCACHE) \
--set=target.$(RUSTC_TARGET_ARCH).cxx=$(TARGET_CXX_NOCACHE) \
--set=target.$(RUSTC_TARGET_ARCH).ar=$(TARGET_AR) \
--set=target.$(RUSTC_TARGET_ARCH).ranlib=$(TARGET_RANLIB)
endif

# Because we override CONFIGURE_ARGS, this needs to go here.
include ./rustc-config.mk

RUST_TMP_DIR:=$(TMP_DIR)/rust-install
RUST_INSTALL_HOST_FILE_NAME:=$(PKG_NAME)-$(PKG_VERSION)-$(RUSTC_HOST_ARCH)-install.tar.xz
RUST_INSTALL_TARGET_FILE_NAME:=$(PKG_NAME)-$(PKG_VERSION)-$(RUSTC_TARGET_ARCH)-install.tar.xz

RUST_INSTALL_UNINSTALL:=$(CARGO_HOME)/lib/rustlib/uninstall.sh

RUST_INSTALL_HOST_BINARIES:=$(CURDIR)/install_binaries.sh $(RUST_TMP_DIR) $(DL_DIR)/$(RUST_INSTALL_HOST_FILE_NAME) $(CARGO_HOME)
RUST_INSTALL_TARGET_BINARIES:=$(CURDIR)/install_binaries.sh $(RUST_TMP_DIR) $(DL_DIR)/$(RUST_INSTALL_TARGET_FILE_NAME) $(CARGO_HOME)

RUST_HOST_BINARY:=$(or $(and $(wildcard $(DL_DIR)/$(RUST_INSTALL_HOST_FILE_NAME)),true),false)
RUST_TARGET_BINARY:=$(or $(and $(wildcard $(DL_DIR)/$(RUST_INSTALL_TARGET_FILE_NAME)),true),false)

# If the HOST Install doesn't exist, force building all the tools
ifeq ($(RUST_HOST_BINARY), false)
CONFIGURE_ARGS += \
--enable-full-tools
endif

define Host/Clean
$(call Host/Clean/Default)

[ -f $(RUST_INSTALL_UNINSTALL) ] && \
$(RUST_INSTALL_UNINSTALL) || echo No Uninstall Found

rm -rf $(BUILD_DIR_HOST)/rust
endef

define Host/Prepare
# Allows outside packages to call $$(BUILD_DIR_HOST)/rust as the dir
# rather than needing the version number.
[ -L $(BUILD_DIR_HOST)/rust ] || \
(cd $(BUILD_DIR_HOST); ln -s "$(PKG_NAME)-$(PKG_VERSION)" rust)

[ -d $(RUST_TMP_DIR) ] || \
mkdir -p $(RUST_TMP_DIR)

$(call Host/Prepare/Default)
endef

ifeq ($(RUST_TARGET_BINARY),true)
include ./rust_install.mk
else
include ./rust_compile.mk
endif

define Package/rust
SECTION:=lang
CATEGORY:=Languages
TITLE:=Rust Programming Language Compiler
URL:=https://www.rust-lang.org/
DEPENDS:=+python3 +ninja +pkg-config +libopenssl +libyaml \
+libyaml-cpp +libunwind +openssl-util +python3-yaml
endef

define Package/rust/description
Rust lang
endef

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

$(eval $(call HostBuild))
$(eval $(call BuildPackage,rust))
13 changes: 13 additions & 0 deletions lang/rust/install_binaries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
#
# Rust Langauge Host Installer
#
TMP_DIR=$1
RUST_INSTALL_FILE_NAME=$2
CARGO_HOME=$3

tar -C $TMP_DIR -xvJf $RUST_INSTALL_FILE_NAME

cd $TMP_DIR && \
find -iname "*.xz" -exec tar -v -x -J -f {} ";" && \
find ./* -type f -name install.sh -execdir sh {} --prefix=$CARGO_HOME --disable-ldconfig \;
11 changes: 11 additions & 0 deletions lang/rust/patches/00-default_dynamic_linking.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/compiler/rustc_target/src/spec/linux_musl_base.rs
+++ b/compiler/rustc_target/src/spec/linux_musl_base.rs
@@ -10,7 +10,7 @@
base.crt_objects_fallback = Some(CrtObjectsFallback::Musl);

// These targets statically link libc by default
- base.crt_static_default = true;
+ base.crt_static_default = false;

base
}
30 changes: 30 additions & 0 deletions lang/rust/patches/01-add_mips64_musl_support.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--- /dev/null
+++ b/compiler/rustc_target/src/spec/mips64_openwrt_linux_musl.rs
@@ -0,0 +1,16 @@
+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,+soft-float".to_string();
+ base.max_atomic_width = Some(64);
+ 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 { endian: "big".to_string(), mcount: "_mcount".to_string(), ..base },
+ }
+}
--- a/compiler/rustc_target/src/spec/mod.rs
+++ b/compiler/rustc_target/src/spec/mod.rs
@@ -662,6 +662,8 @@ supported_targets! {
("mipsel-sony-psp", mipsel_sony_psp),
("mipsel-unknown-none", mipsel_unknown_none),
("thumbv4t-none-eabi", thumbv4t_none_eabi),
+
+ ("mips64-openwrt-linux-musl", mips64_openwrt_linux_musl),
}

/// Everything `rustc` knows about how to compile for a specific target.
29 changes: 29 additions & 0 deletions lang/rust/patches/02-add_mips_musl_support.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--- /dev/null
+++ b/compiler/rustc_target/src/spec/mips_openwrt_linux_musl.rs
@@ -0,0 +1,16 @@
+use crate::spec::{Target, TargetOptions};
+
+pub fn target() -> Target {
+ let mut base = super::linux_musl_base::opts();
+ base.cpu = "mips32r2".to_string();
+ base.features = "+mips32r2,+soft-float".to_string();
+ base.max_atomic_width = Some(32);
+ base.crt_static_default = false;
+ Target {
+ llvm_target: "mips-unknown-linux-musl".to_string(),
+ pointer_width: 32,
+ data_layout: "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".to_string(),
+ arch: "mips".to_string(),
+ options: TargetOptions { endian: "big".to_string(), mcount: "_mcount".to_string(), ..base },
+ }
+}
--- a/compiler/rustc_target/src/spec/mod.rs
+++ b/compiler/rustc_target/src/spec/mod.rs
@@ -664,6 +664,7 @@ supported_targets! {
("thumbv4t-none-eabi", thumbv4t_none_eabi),

("mips64-openwrt-linux-musl", mips64_openwrt_linux_musl),
+ ("mips-openwrt-linux-musl", mips_openwrt_linux_musl),
}

/// Everything `rustc` knows about how to compile for a specific target.
32 changes: 32 additions & 0 deletions lang/rust/patches/03-add_x86_64_musl_support.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--- a/compiler/rustc_target/src/spec/mod.rs
+++ b/compiler/rustc_target/src/spec/mod.rs
@@ -665,6 +665,7 @@ supported_targets! {

("mips64-openwrt-linux-musl", mips64_openwrt_linux_musl),
("mips-openwrt-linux-musl", mips_openwrt_linux_musl),
+ ("x86_64-openwrt-linux-musl", x86_64_openwrt_linux_musl),
}

/// Everything `rustc` knows about how to compile for a specific target.
--- /dev/null
+++ b/compiler/rustc_target/src/spec/x86_64_openwrt_linux_musl.rs
@@ -0,0 +1,19 @@
+use crate::spec::{LinkerFlavor, Target};
+
+pub fn target() -> Target {
+ let mut base = super::linux_musl_base::opts();
+ base.cpu = "x86-64".to_string();
+ base.max_atomic_width = Some(64);
+ base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m64".to_string());
+ base.stack_probes = true;
+ base.static_position_independent_executables = true;
+
+ Target {
+ llvm_target: "x86_64-unknown-linux-musl".to_string(),
+ pointer_width: 64,
+ data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+ .to_string(),
+ arch: "x86_64".to_string(),
+ options: base,
+ }
+}
Loading

0 comments on commit cee25cd

Please sign in to comment.