Skip to content

Commit

Permalink
rust: Initial commit for rust-lang
Browse files Browse the repository at this point in the history
Signed-off-by: Donald Hoskins <grommish@gmail.com>
  • Loading branch information
Grommish committed Mar 18, 2021
1 parent 0f566e4 commit 8d4b80f
Show file tree
Hide file tree
Showing 14 changed files with 694 additions and 0 deletions.
121 changes: 121 additions & 0 deletions lang/rust/Config.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# 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 y

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
bool "Build optimized rust code (--enable-optimize)"
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 y

endmenu
111 changes: 111 additions & 0 deletions lang/rust/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# 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.49.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:=2020-11-11
PKG_SOURCE_VERSION:=fa55f668e5ea5388ec98b9340969527252239151
PKG_MIRROR_HASH:=e7c3fefe77ee8c15b49fac4c89c9f7025c57e8f6ff3079d905e51a96bda3042d
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
include ./rustc-triple.mk

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

# 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 \
--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)

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

RUST_TMP_DIR:=$(TMP_DIR)/rust-install
RUST_INSTALL_FILE_NAME:=$(PKG_NAME)-$(PKG_VERSION)-$(RUSTC_HOST_ARCH)_$(RUSTC_TARGET_ARCH)-install.tar.xz
RUST_INSTALL_FILE_VERIFY:=$(call check_hash,$(RUST_INSTALL_FILE_NAME),$(RUST_INSTALL_FILE_HASH),RUST_INSTALL_FILE_HASH)
RUST_INSTALL_UNINSTALL:=$(CARGO_HOME)/lib/rustlib/uninstall.sh
RUST_INSTALL_BINARIES:=$(CURDIR)/install_binaries.sh $(RUST_TMP_DIR) $(DL_DIR)/$(RUST_INSTALL_FILE_NAME) $(CARGO_HOME)
RUST_INSTALL_FILE_HASH:=skip

RUST_BINARY=$(or $(and $(wildcard $(DL_DIR)/$(RUST_INSTALL_FILE_NAME)),true),false)

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_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,
+ }
+}
37 changes: 37 additions & 0 deletions lang/rust/patches/04-add_arm_muslgnuabi_support.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
--- /dev/null
+++ b/compiler/rustc_target/src/spec/arm_openwrt_linux_muslgnueabi.rs
@@ -0,0 +1,24 @@
+use crate::spec::{Target, TargetOptions};
+
+pub fn target() -> Target {
+ let mut base = super::linux_musl_base::opts();
+
+ // Most of these settings are copied from the arm_unknown_linux_gnueabi
+ // target.
+ base.features = "+strict-align,+v6".to_string();
+ base.max_atomic_width = Some(64);
+ Target {
+ // It's important we use "gnueabi" and not "musleabi" here. LLVM uses it
+ // to determine the calling convention and float ABI, and it doesn't
+ // support the "musleabi" value.
+ llvm_target: "arm-unknown-linux-gnueabi".to_string(),
+ pointer_width: 32,
+ data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(),
+ arch: "arm".to_string(),
+ options: TargetOptions {
+ unsupported_abis: super::arm_base::unsupported_abis(),
+ mcount: "\u{1}mcount".to_string(),
+ ..base
+ },
+ }
+}
--- a/compiler/rustc_target/src/spec/mod.rs
+++ b/compiler/rustc_target/src/spec/mod.rs
@@ -666,6 +666,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),
+ ("arm-openwrt-linux-muslgnueabi", arm_openwrt_linux_muslgnueabi),
}

/// Everything `rustc` knows about how to compile for a specific target.
Loading

0 comments on commit 8d4b80f

Please sign in to comment.