Skip to content

Commit

Permalink
rust: Add patch to set dynamic linking, add mips64sf target, correct …
Browse files Browse the repository at this point in the history
…and update Makefiles

Signed-off-by: Donald Hoskins <grommish@gmail.com>
  • Loading branch information
Grommish committed Dec 12, 2020
1 parent 262649f commit 2000c04
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 66 deletions.
2 changes: 1 addition & 1 deletion lang/rust/Config.in
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ menu "Compiler Options"

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

config RUST_MISSING_TOOLS
bool "Allow failures when building tools (--enable-missing-tools)"
Expand Down
72 changes: 27 additions & 45 deletions lang/rust/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ PKG_SOURCE_VERSION:=5a6a41e7847ff5f85a31b87431ce2af29c567f1d
PKG_HASH:=skip
PKG_HOST_ONLY:=1

include $(INCLUDE_DIR)/download.mk
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
HOST_BUILD_DEPENDS:=rust/host ninja/host python3/host
CMAKE_INSTALL:=1
gen_sha256sum = $(shell mkhash sha256 $(DL_DIR)/$(1))

#gen_sha256sum=$(shell mkhash sha256 $(DL_DIR)/$(1))
#fixup_rust_hash=$(shell $(SCRIPT_DIR)/fixup-makefile.pl $(1) fix-hash $(2) $(3))

# Basic Configuration Args that are used across all builds.
# Other build arguments are found in ./rustc-config.mk
Expand Down Expand Up @@ -53,18 +55,14 @@ CONFIGURE_ARGS = \

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

RUST_TMP_DIR:=$(TMP_DIR)/rust-install
RUST_INSTALL_FILE_NAME:=$(PKG_NAME)-$(PKG_VERSION)-install.tar.xz
RUST_INSTALL_CALC_HASH:=$(call gen_sha256sum,$(RUST_INSTALL_FILE_NAME))
RUST_INSTALL_UNINSTALL=$(CARGO_HOME)/lib/rustlib/uninstall.sh
fixup_rust_hash:=$(SCRIPT_DIR)/fixup-makefile.pl $(CURDIR)/rustc-binaries.mk fix-hash RUST_INSTALL_FILE_HASH $(RUST_INSTALL_CALC_HASH)
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_FILE_HASH:=skip

# $(1): Temp extraction dir
# $(2): Path/to/file
# $(3): CARGO_HOME
install_rust:=$(CURDIR)/install_binaries.sh $(RUST_TMP_DIR) $(DL_DIR)/$(RUST_INSTALL_FILE_NAME) $(CARGO_HOME)
RUST_BINARY=$(or $(and $(wildcard $(DL_DIR)/$(RUST_INSTALL_FILE_NAME)),true),false)

define Host/Clean
$(info In Clean)
Expand All @@ -73,37 +71,23 @@ define Host/Clean
[ -f $(RUST_INSTALL_UNINSTALL) ] && \
$(RUST_INSTALL_UNINSTALL) || echo No Uninstall Found

rm -rf $(CARGO_HOME) $(RUSTUP_HOME) $(BUILD_DIR_HOST)/rust
endef

define Host/Prepare
$(info In Prepare)
# This is our CARGO_HOME, so make sure it's there to receive files
[ -d $(CARGO_HOME) ] || (mkdir -p $(CARGO_HOME))

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

[ -f $(DL_DIR)/$(RUST_INSTALL_FILE_NAME) ] && \
([ $(RUST_INSTALL_FILE_HASH) == $(RUST_INSTALL_CALC_HASH) ] && \
$(call install_rust) || rm $(DL_DIR)/$(RUST_INSTALL_FILE_NAME))) || \
$(call Host/Prepare/Default)
rm -rf $(BUILD_DIR_HOST)/rust
endef

define Host/Configure
$(info In Configure)
# Required because OpenWrt Default CONFIGURE_ARGS contain extra
# args that cause errors
cd $(HOST_BUILD_DIR) && \
[ $(RUST_BINARY) = true ] && true || \
cd $(HOST_BUILD_DIR) && \
RUST_BACKTRACE=full \
./configure $(CONFIGURE_ARGS)
endef

define Host/Compile
$(info In Compile)
cd $(HOST_BUILD_DIR) && \
[ $(RUST_BINARY) = true ] && true || \
cd $(HOST_BUILD_DIR) && \
RUST_BACKTRACE=full \
$(PYTHON) x.py --config ./config.toml dist cargo extended \
library/std llvm-tools miri rust-dev rustc-dev src \
Expand All @@ -117,29 +101,27 @@ define Host/CreateBinaries
$(RM) *.gz && \
$(call dl_tar_pack,$(DL_DIR)/$(RUST_INSTALL_FILE_NAME),.)

$(call fixup_rust_hash)
$(call fixup_rust_hash, $(CURDIR)/Makefile, \
RUST_INSTALL_FILE_HASH, \
$(call gen_sha256sum,$(RUST_INSTALL_FILE_NAME)))
endef

define Host/InstallBinaries
[ -d $(RUST_TMP_DIR) ] && \
rm -rf $(RUST_TMP_DIR)

mkdir -p $(RUST_TMP_DIR)

tar -C $(RUST_TMP_DIR) -xJf $(DL_DIR)/$(RUST_INSTALL_FILE_NAME)

define Host/Install
cd $(RUST_TMP_DIR) && \
find -iname "*.xz" -exec tar -x -J -f {} ";" && \
$(TAR) -xJf $(DL_DIR)/$(RUST_INSTALL_FILE_NAME) && \
find -iname "*.xz" -exec $(TAR) -x -J -f {} ";" && \
find ./* -type f -name install.sh -execdir sh {} --prefix=$(CARGO_HOME) --disable-ldconfig \;
$(RM) -rf $(RUST_TMP_DIR)
endef

define Host/Install
$(info In Install)
$(call install_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)

define Host/UninstallBinaries
$(shell $(RUST_INSTALL_UNINSTALL))
$(call Host/Prepare/Default)
endef

define Package/rust
Expand Down
11 changes: 3 additions & 8 deletions lang/rust/install_binaries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@
#
# Rust Langauge Host Installer
#
RUST_TMP_DIR=$1
TMP_DIR=$1
RUST_INSTALL_FILE_NAME=$2
CARGO_HOME=$3

[ -d $RUST_TMP_DIR ] && \
rm -rf $RUST_TMP_DIR
tar -C $TMP_DIR -xJf $RUST_INSTALL_FILE_NAME

mkdir -p $RUST_TMP_DIR

tar -C $RUST_TMP_DIR -xJf $RUST_INSTALL_FILE_NAME

cd $RUST_TMP_DIR && \
cd $TMP_DIR && \
find -iname "*.xz" -exec tar -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@
("mips64el-unknown-linux-muslabi64", mips64el_unknown_linux_muslabi64),
("hexagon-unknown-linux-musl", hexagon_unknown_linux_musl),

--- /dev/null 2020-11-11 20:50:49.703861051 -0500
--- /dev/null
+++ b/compiler/rustc_target/src/spec/mips64_unknown_linux_muslabi64sf.rs
@@ -0,0 +1,17 @@
@@ -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);
+ base.crt_static_default = false;
+ Target {
+ // LLVM doesn't recognize "muslabi64" yet.
+ llvm_target: "mips64-unknown-linux-musl".to_string(),
Expand Down
5 changes: 0 additions & 5 deletions lang/rust/rustc-binaries.mk

This file was deleted.

25 changes: 21 additions & 4 deletions lang/rust/rustc-triple.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,24 @@
# You will need to add --host=$(RUSTC_TARGET_ARCH) to your packages
# CONFIGURE_VARS to cross-compile for the target architecture

ifeq ($(CONFIG_arm_v7),y)
RUST_ARCH:=armv7
else
RUST_ARCH:=$(ARCH)
endif

CONFIG_HOST_SUFFIX:=$(shell cut -d"-" -f4 <<<"$(GNU_HOST_NAME)")

RUSTC_ARCH_TARGETS:= \
mips64-unknown-linux-gnuabi64 mips64-unknown-linux-muslabi64 \
mips64-unknown-linux-gnuabi64sf mips64-unknown-linux-muslabi64sf \
\
armv7-unknown-linux-gnueabi armv7-unknown-linux-gnueabihf \
armv7-unknown-linux-musleabi \
\
x86_64-unknown-linux-gnu x86_64-unknown-linux-musl

#RUSTC_ARCH_TARGETS:= \
aarch64-unknown-linux-gnu aarch64-unknown-linux-musl \
\
arm-unknown-linux-gnueabi arm-unknown-linux-gnueabihf \
Expand Down Expand Up @@ -56,7 +73,6 @@ thumbv7neon-unknown-linux-gnueabihf thumbv7neon-unknown-linux-musleabihf \
\
x86_64-unknown-linux-gnu x86_64-unknown-linux-musl

CONFIG_HOST_SUFFIX:=$(shell cut -d"-" -f4 <<<"$(GNU_HOST_NAME)")
RUSTC_HOST_ARCH:= \
$(strip $(foreach \
v, \
Expand All @@ -68,11 +84,13 @@ RUSTC_HOST_ARCH:= \
RUSTC_TARGET_ARCH_BASE:= \
$(strip $(foreach \
v, \
$(filter $(ARCH)-%, $(RUSTC_ARCH_TARGETS)), \
$(filter $(RUST_ARCH)-%, $(RUSTC_ARCH_TARGETS)), \
$(if $(findstring -$(CONFIG_TARGET_SUFFIX:"%"=%),$v),$v) \
) \
)

#$(info 1 Arch:$(ARCH) RustArch:$(RUST_ARCH) HSuffix:$(CONFIG_HOST_SUFFIX:"%"=%) TSuffix:$(CONFIG_TARGET_SUFFIX:"%"=%) RUSTC_HOST_ARCH:$(RUSTC_HOST_ARCH) RUSTC_TARGET_ARCH_BASE:$(RUSTC_TARGET_ARCH_BASE))

# Check to see if it's a soft-float target
ifeq ($(CONFIG_SOFT_FLOAT),y)
RUSTC_TARGET_ARCH:=$(strip $(filter %sf, $(RUSTC_TARGET_ARCH_BASE)))
Expand All @@ -90,5 +108,4 @@ endif

# These are environment variables that are used by other packages to
# define where rustc/cargo are kept.
CARGO_HOME:=$(BUILD_DIR_HOST)/.cargo
export PATH:=$(CARGO_HOME)/bin:$(PATH)
CARGO_HOME:=$(STAGING_DIR_HOSTPKG)

0 comments on commit 2000c04

Please sign in to comment.