Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust: Initial commit - rust lang #13916

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

132 changes: 132 additions & 0 deletions lang/rust/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# 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.62.0
PKG_RELEASE:=1

PKG_LICENSE:=Apache-2.0 MIT
PKG_LICENSE_FILES:=LICENSE-APACHE LICENSE-MIT
Grommish marked this conversation as resolved.
Show resolved Hide resolved

PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/rust-lang/rust.git
PKG_SOURCE_DATE:=2022-06-29
PKG_SOURCE_VERSION:=a8314ef7d0ec7b75c336af2c9857bfaf43002bfc
PKG_MIRROR_HASH:=09f933ee7a449751bc6d7ad6364dd44163439f029061daf158d7bfaf3a726184

HOST_BUILD_PARALLEL:=1
HOST_USE_NINJA:=1
PKG_HOST_ONLY:=1
HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/rust-$(PKG_VERSION)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this already default?


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

HOST_STAMP_PREPARED=$(HOST_BUILD_DIR)/.prepared_$(RUSTC_TARGET_ARCH)
HOST_STAMP_BUILT=$(HOST_BUILD_DIR)/.built_$(RUSTC_TARGET_ARCH)
HOST_STAMP_CONFIGURED=$(HOST_BUILD_DIR)/.configured_$(RUSTC_TARGET_ARCH)
HOST_STAMP_INSTALLED=$(CARGO_HOME)/.rust_$(RUSTC_TARGET_ARCH)_installed

# Requires Python3 to build
HOST_BUILD_DEPENDS:=python3/host rust_host/host

# Use External rust-lang specific LLVM
RUST_UNINSTALL:=$(STAGING_DIR_HOST)/lib/rustlib/uninstall.sh
RUST_TMP_DIR:=$(TMP_DIR)/rust-install

# Set Configure Environmentals
HOST_CONFIGURE_OPTS += CARGO_HOME="$(CARGO_HOME)"

# The Flags are Common between HOST and TARGET
RUST_COMMON_ARGS := \
--build=$(RUSTC_HOST_ARCH) \
--host=$(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 \
--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 \
--set=build.extended=true \
--llvm-root=$(LLVM_DIR) \
--set=target.$(RUSTC_TARGET_ARCH).llvm-config=$(LLVM_DIR)/bin/llvm-config

# MUSL Targets need additional flags
MUSL_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)

##
# 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) \
${RUST_COMMON_ARGS} \
$(MUSL_ARGS) \
--set=build.cargo=$(STAGING_DIR_HOST)/bin/cargo \
--set=build.rustc=$(STAGING_DIR_HOST)/bin/rustc
Copy link
Contributor

@predators46 predators46 Sep 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this throws an error while building rust
--set=build.rustc=$(STAGING_DIR_HOST)/bin/rustc

error: attributes starting with `rustc` are reserved for use by the `rustc` compiler --> library/core/src/lib.rs:87:4


HOST_CXXFLAGS += -DLLVM_RUSTLLVM

define Host/Uninstall
rm -rf $(HOST_STAMP_INSTALLED)
endef

# Installation is done via Host/Compile
define Host/Install
endef

define Host/Compile
cd $(HOST_BUILD_DIR) && \
CARGO_HOME='$(CARGO_HOME)' \
CXXFLAGS='$(HOST_CXXFLAGS)' \
LD_LIBRARY_PATH=$(LLVM_DIR)/lib:$(STAGING_DIR_HOST)/lib \
$(PYTHON) x.py install --config ./config.toml --stage 1 library/std
endef

define Package/rust
TITLE:=Rust programming language
CATEGORY:=Languages
SECTION:=lang
DEPENDS:=
endef

define Package/rust/description
Rust Programming Language
endef

define Package/rust/install
true
endef

$(eval $(call HostBuild))
$(eval $(call BuildPackage,rust))
30 changes: 30 additions & 0 deletions lang/rust/patches/03-add_mips.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--- a/compiler/rustc_target/src/spec/mod.rs
+++ b/compiler/rustc_target/src/spec/mod.rs
@@ -1016,6 +1016,7 @@
("x86_64-unknown-none", x86_64_unknown_none),

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

/// Warnings encountered when parsing the target `json`.
--- /dev/null
+++ b/compiler/rustc_target/src/spec/mips_openwrt_linux_musl.rs
@@ -0,0 +1,17 @@
+use crate::abi::Endian;
+use crate::spec::{Target, TargetOptions};
+
+pub fn target() -> Target {
+ let mut base = super::linux_musl_base::opts();
+ base.cpu = "mips32r2".into();
+ base.features = "+mips32r2,+soft-float".into();
+ base.max_atomic_width = Some(32);
+ base.crt_static_default = false;
+ Target {
+ llvm_target: "mips-unknown-linux-musl".into(),
+ pointer_width: 32,
+ data_layout: "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".into(),
+ arch: "mips".into(),
+ options: TargetOptions { endian: Endian::Big, mcount: "_mcount".into(), ..base },
+ }
+}
29 changes: 29 additions & 0 deletions lang/rust/patches/04-add_mipsel.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--- /dev/null
+++ b/compiler/rustc_target/src/spec/mipsel_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".into();
+ base.features = "+mips32r2,+soft-float".into();
+ base.max_atomic_width = Some(32);
+ base.crt_static_default = false;
+ Target {
+ llvm_target: "mipsel-unknown-linux-musl".into(),
+ pointer_width: 32,
+ data_layout: "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".into(),
+ arch: "mips".into(),
+ options: TargetOptions { mcount: "_mcount".into(), ..base },
+ }
+}
--- a/compiler/rustc_target/src/spec/mod.rs
+++ b/compiler/rustc_target/src/spec/mod.rs
@@ -1015,6 +1015,7 @@

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

/// Warnings encountered when parsing the target `json`.
27 changes: 27 additions & 0 deletions lang/rust/patches/05-add_aarch64.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--- /dev/null
+++ b/compiler/rustc_target/src/spec/aarch64_openwrt_linux_musl.rs
@@ -0,0 +1,14 @@
+use crate::spec::{Target, TargetOptions};
+
+pub fn target() -> Target {
+ let mut base = super::linux_musl_base::opts();
+ base.max_atomic_width = Some(128);
+
+ Target {
+ llvm_target: "aarch64-unknown-linux-musl".into(),
+ pointer_width: 64,
+ data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(),
+ arch: "aarch64".into(),
+ options: TargetOptions { mcount: "\u{1}_mcount".into(), ..base },
+ }
+}
--- a/compiler/rustc_target/src/spec/mod.rs
+++ b/compiler/rustc_target/src/spec/mod.rs
@@ -1016,6 +1016,7 @@
("mips64-openwrt-linux-musl", mips64_openwrt_linux_musl),
("mips-openwrt-linux-musl", mips_openwrt_linux_musl),
("mipsel-openwrt-linux-musl", mipsel_openwrt_linux_musl),
+ ("aarch64-openwrt-linux-musl", aarch64_openwrt_linux_musl),
}

/// Warnings encountered when parsing the target `json`.
38 changes: 38 additions & 0 deletions lang/rust/patches/06-add_armv7.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--- /dev/null
+++ b/compiler/rustc_target/src/spec/armv7_openwrt_linux_muslgnueabi.rs
@@ -0,0 +1,25 @@
+use crate::spec::{Target, TargetOptions};
+
+// This target is for musl Linux on ARMv7 without thumb-mode, NEON or
+// hardfloat.
+
+pub fn target() -> Target {
+ // Most of these settings are copied from the armv7_unknown_linux_gnueabi
+ // target.
+ 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: "armv7-unknown-linux-gnueabi".into(),
+ pointer_width: 32,
+ data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(),
+ arch: "arm".into(),
+
+ options: TargetOptions {
+ abi: "eabi".into(),
+ max_atomic_width: Some(64),
+ mcount: "\u{1}mcount".into(),
+ ..super::linux_musl_base::opts()
+ },
+ }
+}
--- a/compiler/rustc_target/src/spec/mod.rs
+++ b/compiler/rustc_target/src/spec/mod.rs
@@ -1017,6 +1017,7 @@
("mips-openwrt-linux-musl", mips_openwrt_linux_musl),
("mipsel-openwrt-linux-musl", mipsel_openwrt_linux_musl),
("aarch64-openwrt-linux-musl", aarch64_openwrt_linux_musl),
+ ("armv7-openwrt-linux-muslgnueabi", armv7_openwrt_linux_muslgnueabi),
}

/// Warnings encountered when parsing the target `json`.
Loading