Skip to content

Commit

Permalink
[rust] Update build logic
Browse files Browse the repository at this point in the history
Split into compile and install

Signed-off-by: Donald Hoskins <grommish@gmail.com>
  • Loading branch information
Grommish committed Dec 14, 2020
1 parent f56c571 commit 868705e
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 69 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 y
default n

config RUST_MISSING_TOOLS
bool "Allow failures when building tools (--enable-missing-tools)"
Expand Down
67 changes: 27 additions & 40 deletions lang/rust/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/rust-lang/rust.git
PKG_SOURCE_DATE:=2020-11-11
#PKG_SOURCE_VERSION:=b2d115f6db5172c961dfeb50de15f35784dbc7c9
PKG_SOURCE_VERSION:=5a6a41e7847ff5f85a31b87431ce2af29c567f1d
#PKG_SOURCE_VERSION:=5a6a41e7847ff5f85a31b87431ce2af29c567f1d
PKG_SOURCE_VERSION:=fa55f668e5ea5388ec98b9340969527252239151
PKG_HASH:=skip
PKG_HOST_ONLY:=1

Expand Down Expand Up @@ -60,13 +61,12 @@ 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) $(RUST_INSTALL_FILE_NAME) $(CARGO_HOME)
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
$(info In Clean)
$(call Host/Clean/Default)

[ -f $(RUST_INSTALL_UNINSTALL) ] && \
Expand All @@ -75,58 +75,45 @@ define Host/Clean
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
[ $(RUST_BINARY) = true ] && \
( true ) || \
( cd $(HOST_BUILD_DIR) && \
RUST_BACKTRACE=full \
./configure $(CONFIGURE_ARGS) )
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

define Host/Compile
$(info In Compile)
ifeq ($(RUST_BINARY),true)
include ./rust_install.mk
else
include ./rust_compile.mk
endif

#define Host/InstallDev
# [ $(RUST_BINARY) = true ] && ( sh $(RUST_INSTALL_BINARIES) )
#endef

define Host/Compile-Bak
[ $(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 \
src/librustc src/lldb_batchmode.py src/tools/build-manifest ) && \
( $(RUST_INSTALL_BINARIES)))
src/librustc src/lldb_batchmode.py src/tools/build-manifest ))
endef

define Host/CreateBinaries
# This creates the installation binary in downloads
cd $(HOST_BUILD_DIR)/build/dist && \
$(RM) *.gz && \
$(call dl_tar_pack,$(DL_DIR)/$(RUST_INSTALL_FILE_NAME),.)

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


define Host/Install
cd $(RUST_TMP_DIR) && \
$(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/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)
$(call gen_sha256sum,$(RUST_INSTALL_FILE_NAME))))
endef

define Package/rust
Expand Down
4 changes: 2 additions & 2 deletions lang/rust/install_binaries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ TMP_DIR=$1
RUST_INSTALL_FILE_NAME=$2
CARGO_HOME=$3

tar -C $TMP_DIR -xJf $RUST_INSTALL_FILE_NAME
tar -C $TMP_DIR -xvJf $RUST_INSTALL_FILE_NAME

cd $TMP_DIR && \
find -iname "*.xz" -exec tar -x -J -f {} ";" && \
find -iname "*.xz" -exec tar -v -x -J -f {} ";" && \
find ./* -type f -name install.sh -execdir sh {} --prefix=$CARGO_HOME --disable-ldconfig \;
4 changes: 2 additions & 2 deletions lang/rust/patches/01-add-mips64-muslabi64-soft-float.patch
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
("mips-unknown-linux-musl", mips_unknown_linux_musl),
("mipsel-unknown-linux-musl", mipsel_unknown_linux_musl),
("mips64-unknown-linux-muslabi64", mips64_unknown_linux_muslabi64),
+ ("mips64-unknown-linux-muslabi64sf", mips64_unknown_linux_muslabi64sf),
+ ("mips64-openwrt-linux-musl", mips64_openwrt_linux_musl),
("mips64el-unknown-linux-muslabi64", mips64el_unknown_linux_muslabi64),
("hexagon-unknown-linux-musl", hexagon_unknown_linux_musl),

--- /dev/null
+++ b/compiler/rustc_target/src/spec/mips64_unknown_linux_muslabi64sf.rs
+++ b/compiler/rustc_target/src/spec/mips64_openwrt_linux_musl.rs
@@ -0,0 +1,16 @@
+use crate::spec::{Target, TargetOptions};
+
Expand Down
22 changes: 22 additions & 0 deletions lang/rust/rust_compile.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
define Host/Configure
# Required because OpenWrt Default CONFIGURE_ARGS contain extra
# args that cause errors
cd $(HOST_BUILD_DIR) && \
RUST_BACKTRACE=full ./configure $(CONFIGURE_ARGS)
endef

define Host/Compile
cd $(HOST_BUILD_DIR) && \
RUST_BACKTRACE=full $(PYTHON) x.py --config ./config.toml dist \
cargo
endef

define Host/Install
cd $(HOST_BUILD_DIR)/build/dist && \
$(RM) *.gz && \
$(call dl_tar_pack,$(DL_DIR)/$(RUST_INSTALL_FILE_NAME),.) && \
cd $(RUST_TMP_DIR) && \
$(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 \;
endef
11 changes: 11 additions & 0 deletions lang/rust/rust_install.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
define Host/Configure
true
endef

define Host/Compile
true
endef

define Host/Install
sh $(RUST_INSTALL_BINARIES)
endef
4 changes: 4 additions & 0 deletions lang/rust/rustc-config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ ifeq ($(CONFIG_RUST_VERBOSE_TESTS),y)
CONFIGURE_ARGS += --enable-verbose-tests
endif

ifeq ($(filter $(CONFIG_RUST_CCACHE) $(CCACHE),y),)
CONFIGURE_ARGS += --enable-ccache
endif

ifeq ($(CONFIG_RUST_CCACHE),y)
CONFIGURE_ARGS += --enable-ccache
endif
Expand Down
28 changes: 4 additions & 24 deletions lang/rust/rustc-triple.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ endif

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

RUSTC_ARCH_TARGETS:= \
#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:= \
RUSTC_ARCH_TARGETS:= \
aarch64-unknown-linux-gnu aarch64-unknown-linux-musl \
\
arm-unknown-linux-gnueabi arm-unknown-linux-gnueabihf \
Expand All @@ -44,7 +43,6 @@ i686-unknown-linux-gnu i686-unknown-linux-musl \
mips-unknown-linux-gnu mips-unknown-linux-musl mips-unknown-linux-uclibc \
\
mips64-unknown-linux-gnuabi64 mips64-unknown-linux-muslabi64 \
mips64-unknown-linux-gnuabi64sf mips64-unknown-linux-muslabi64sf \
\
mips64el-unknown-linux-gnuabi64 mips64el-unknown-linux-muslabi64 \
\
Expand Down Expand Up @@ -81,31 +79,13 @@ RUSTC_HOST_ARCH:= \
) \
)

RUSTC_TARGET_ARCH_BASE:= \
$(strip $(foreach \
v, \
$(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)))
else
RUSTC_TARGET_ARCH:=$(strip $(filter-out %sf, $(RUSTC_TARGET_ARCH_BASE)))
endif

# For Testing - Override
#RUSTC_TARGET_ARCH:=mips64-unknown-linux-muslabi64

# More than one triple-target remains.
ifneq ($(word 2, $(RUSTC_TARGET_ARCH)),)
$(error RUSTC ERROR: Unsupported or Unknown Target Triple: $(RUSTC_TARGET_ARCH))
endif

RUSTC_TARGET_ARCH:=$(REAL_GNU_TARGET_NAME)

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

0 comments on commit 868705e

Please sign in to comment.