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

Build Rust from source instead of using Rustup #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
65 changes: 48 additions & 17 deletions rust-lang/Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=rust-lang
PKG_VERSION:=1.25.1
PKG_VERSION:=1.63.0
PKG_RELEASE:=1

PKG_SOURCE:=rustup-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/rust-lang/rustup/tar.gz/$(PKG_VERSION)?
PKG_HASH:=4d062c77b08309bd212f22dd7da1957c1882509c478e57762f34ec4fb2884c9a
HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/rustup-$(PKG_VERSION)
PKG_SOURCE:=rustc-$(PKG_VERSION)-src.tar.gz
PKG_SOURCE_URL:=https://static.rust-lang.org/dist/
PKG_HASH:=1f9580295642ef5da7e475a8da2397d65153d3f2cb92849dbd08ed0effca99d0
HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/rustc-$(PKG_VERSION)-src

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

PKG_HOST_ONLY:=1
HOST_BUILD_PARALLEL:=1

HOST_BUILD_DEPENDS:=\
ninja/host \
python3/host

include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/host-build.mk
include ./files/rust-env.mk
Expand All @@ -29,26 +33,53 @@ define Package/rust-lang
BUILDONLY:=1
endef

define BUILD_CONFIG_TOML
changelog-seen = 2

[llvm]
targets = "AArch64;ARM;Mips;PowerPC;RISCV;WebAssembly;X86"

[rust]
channel = "stable"

[build]
target = [
"$(subst pc,unknown,$(GNU_HOST_NAME))",
"$(RUST_TARGET)",
]
docs = false
extended = true
tools = ["cargo", "src"]

[target.$(RUST_TARGET)]
musl-root = "$(TOOLCHAIN_DIR)"

[install]
prefix = "$(STAGING_DIR_HOST)"
sysconfdir = "etc"
endef

export BUILD_CONFIG_TOML

define Host/Configure
echo "$$$$BUILD_CONFIG_TOML" > $(HOST_BUILD_DIR)/config.toml
endef

define Host/Compile
sh $(HOST_BUILD_DIR)/rustup-init.sh -y \
--default-toolchain 1.60.0 \
--target $(RUST_TARGET) \
--profile minimal \
--no-modify-path
cd $(HOST_BUILD_DIR) && ./x.py build
endef

define Host/Install
ln -s $(CARGO_BIN)/cargo $(STAGING_DIR_HOST)/bin/
ln -s $(CARGO_BIN)/rustc $(STAGING_DIR_HOST)/bin/
ln -s $(CARGO_BIN)/rustup $(STAGING_DIR_HOST)/bin/
cd $(HOST_BUILD_DIR) && ./x.py install
endef

define Host/Clean
(\
if [ -f $(STAGING_DIR_HOST)/lib/rustlib/uninstall.sh ]; then \
$(STAGING_DIR_HOST)/lib/rustlib/uninstall.sh; \
fi \
)
$(call Host/Clean/Default)
-rm $(STAGING_DIR_HOST)/bin/cargo
-rm $(STAGING_DIR_HOST)/bin/rustc
-rm $(STAGING_DIR_HOST)/bin/rustup
-rm -rf $(RUSTUP_HOME) $(CARGO_HOME)
endef

$(eval $(call BuildPackage,rust-lang))
Expand Down
12 changes: 5 additions & 7 deletions rust-lang/files/rust-env.mk
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
export RUSTUP_HOME:=$(STAGING_DIR_HOST)/lib/rustup
export CARGO_HOME:=$(STAGING_DIR_HOST)/lib/cargo

CARGO_BIN:=$(CARGO_HOME)/bin

# NOTE: The Rust target triplet does not always match the target triplet used
# by OpenWrt. You can add exceptions for your device here.

RUST_TARGET_LDFLAGS := $(TARGET_LDFLAGS)

# Turris MOX
ifneq ($(findstring aarch64,$(CONFIG_ARCH)),)
RUST_TARGET := aarch64-unknown-linux-musl
Expand All @@ -14,7 +11,8 @@ else ifneq ($(findstring arm,$(CONFIG_ARCH)),)
RUST_TARGET := armv7-unknown-linux-musleabihf
# Turris 1.x
else ifneq ($(findstring powerpc,$(CONFIG_ARCH)),)
RUST_TARGET := powerpc_unknown_linux_muslspe
RUST_TARGET := powerpc-unknown-linux-muslspe
RUST_TARGET_LDFLAGS += -lssp_nonshared
else
RUST_TARGET := $(shell echo $(CONFIG_ARCH)-unknown-linux-$(CONFIG_TARGET_SUFFIX))
endif
Expand All @@ -24,7 +22,7 @@ define CARGO_CONFIG
ar = "$(TARGET_AR)"
linker = "$(TARGET_CC)"
rustflags = [
"-C", "link-args=$(TARGET_LDFLAGS)",
"-C", "link-args=$(RUST_TARGET_LDFLAGS)",
"-C", "target-feature=-crt-static",
]
endef
Expand Down
67 changes: 67 additions & 0 deletions rust-lang/patches/0001-add-powerpc-unknown-linux-muslspe.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
From fd9502e7c6b358cf7eb04c2824c0aa8a0a9b7ca0 Mon Sep 17 00:00:00 2001
From: Ondrej Perutka <[email protected]>
Date: Mon, 22 Aug 2022 15:12:30 +0200
Subject: [PATCH] Add powerpc-unknown-linux-muslspe target

Co-authored-by: Josef Schlehofer <[email protected]>
---
compiler/rustc_target/src/spec/mod.rs | 1 +
.../src/spec/powerpc_unknown_linux_muslspe.rs | 21 +++++++++++++++++++
src/doc/rustc/src/platform-support.md | 1 +
3 files changed, 23 insertions(+)
create mode 100644 compiler/rustc_target/src/spec/powerpc_unknown_linux_muslspe.rs

diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs
index da0589cdd20..46bfd6c4ba2 100644
--- a/compiler/rustc_target/src/spec/mod.rs
+++ b/compiler/rustc_target/src/spec/mod.rs
@@ -831,6 +831,7 @@ fn $module() {
("powerpc-unknown-linux-gnu", powerpc_unknown_linux_gnu),
("powerpc-unknown-linux-gnuspe", powerpc_unknown_linux_gnuspe),
("powerpc-unknown-linux-musl", powerpc_unknown_linux_musl),
+ ("powerpc-unknown-linux-muslspe", powerpc_unknown_linux_muslspe),
("powerpc64-unknown-linux-gnu", powerpc64_unknown_linux_gnu),
("powerpc64-unknown-linux-musl", powerpc64_unknown_linux_musl),
("powerpc64le-unknown-linux-gnu", powerpc64le_unknown_linux_gnu),
diff --git a/compiler/rustc_target/src/spec/powerpc_unknown_linux_muslspe.rs b/compiler/rustc_target/src/spec/powerpc_unknown_linux_muslspe.rs
new file mode 100644
index 00000000000..44557a3bd70
--- /dev/null
+++ b/compiler/rustc_target/src/spec/powerpc_unknown_linux_muslspe.rs
@@ -0,0 +1,21 @@
+use crate::abi::Endian;
+use crate::spec::{LinkerFlavor, Target, TargetOptions};
+
+pub fn target() -> Target {
+ let mut base = super::linux_musl_base::opts();
+ base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-mspe".into());
+ base.max_atomic_width = Some(32);
+
+ Target {
+ llvm_target: "powerpc-unknown-linux-muslspe".into(),
+ pointer_width: 32,
+ data_layout: "E-m:e-p:32:32-i64:64-n32".into(),
+ arch: "powerpc".into(),
+ options: TargetOptions {
+ abi: "spe".into(),
+ endian: Endian::Big,
+ mcount: "_mcount".into(),
+ ..base
+ },
+ }
+}
diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md
index eb985803266..281080971c1 100644
--- a/src/doc/rustc/src/platform-support.md
+++ b/src/doc/rustc/src/platform-support.md
@@ -265,6 +265,7 @@ target | std | host | notes
`msp430-none-elf` | * | | 16-bit MSP430 microcontrollers
`powerpc-unknown-linux-gnuspe` | ✓ | | PowerPC SPE Linux
`powerpc-unknown-linux-musl` | ? | |
+`powerpc-unknown-linux-muslspe` | ? | | PowerPC SPE Linux
`powerpc-unknown-netbsd` | ✓ | ✓ |
`powerpc-unknown-openbsd` | ? | |
`powerpc-wrs-vxworks-spe` | ? | |
--
2.37.2