### this file is sourced not run
PKGVER=1.67.1
PKGBUILD=1
PKGARCH=x86_64

# BLFS author's note:
# -------------------
# This package is updated on a six-weekly release cycle.
# Because it is such a large and slow package to build, is at the moment
# only required by a few packages in this book, and particularly because
# newer versions tend to break older mozilla packages, the BLFS editors
# take the view that it should only be updated when that is necessary
# (either to fix problems, or to allow a new version of a package to build).
#
# As with many other programming languages, rustc (the rust compiler)
# needs a binary from which to bootstrap. It will download a stage0 binary
# at the start of the build, so you cannot compile it without an Internet connection.
# James note: in other words, the build is not reproducible and may not work again
# in the future. 

# source: BLFS 11.3
TARBALL=rustc-$PKGVER-src.tar.xz
MD5SUM=e5e47e53c52574ce89ea200e52819f81
SRC_URL=https://static.rust-lang.org/dist/$TARBALL
BUNDLE=

SLACKREQ='libssh2 llvm-clang'
SLACKDESC="rustc: rustc $PKGVER (Rust Compiler)
rustc: 
rustc: The Rust programming language is designed to be a safe, concurrent, 
rustc: practical language.
rustc: 
rustc: 
rustc: 
rustc: 
rustc: 
rustc: 
rustc: 
"

### default pkg_download
### default pkg_prepare
### default pkg_package
### build
pkg_build() {
	cd /tmp/rustc* &&

	# allow build to access internet
	echo nameserver 8.8.8.8 > /etc/resolv.conf &&
	
	# install into /opt/rustc
	mkdir -pv /opt/rustc-$PKGVER      &&
	ln -svfn rustc-$PKGVER /opt/rustc &&

	# create build config file
	cat << EOF > config.toml &&
# see config.toml.example for more possible options
# See the 8.4 book for an old example using shipped LLVM
# e.g. if not installing clang, or using a version before 13.0

# tell x.py to not keep printing an annoying warning
changelog-seen = 2

[llvm]
# by default, rust will build for a myriad of architectures
targets = "X86"

# When using system llvm prefer shared libraries
link-shared = true

[build]
# omit docs to save time and space (default is to build them)
docs = false

# install extended tools: cargo, clippy, etc
extended = true

# Do not query new versions of dependencies online.
locked-deps = true

# Specify which extended tools (those from the default install).
tools = ["cargo", "clippy", "rustfmt"]

# Use the source code shipped in the tarball for the dependencies.
# The combination of this and the "locked-deps" entry avoids downloading
# many crates from Internet, and makes the Rustc build more stable.
vendor = true

[install]
prefix = "/opt/rustc-$PKGVER"
docdir = "share/doc/rustc-$PKGVER"

[rust]
channel = "stable"
description = "for BLFS 11.3"

# BLFS used to not install the FileCheck executable from llvm,
# so disabled codegen tests.  The assembly tests rely on FileCheck
# and cannot easily be disabled, so those will anyway fail if
# FileCheck has not been installed.
#codegen-tests = false

[target.x86_64-unknown-linux-gnu]
# NB the output of llvm-config (i.e. help options) may be
# dumped to the screen when config.toml is parsed.
llvm-config = "/usr/bin/llvm-config"

[target.i686-unknown-linux-gnu]
# NB the output of llvm-config (i.e. help options) may be
# dumped to the screen when config.toml is parsed.
llvm-config = "/usr/bin/llvm-config"
EOF

	# and now build (notice the name: x.py)
	{ [ ! -e /usr/include/libssh2.h ] ||
	  export LIBSSH2_SYS_USE_PKG_CONFIG=1; } &&
	python3 ./x.py build &&

	# install
	python3 ./x.py install	&&

	# path setup etc
	cat > /etc/profile.d/rustc.sh << "EOF" &&
# Begin /etc/profile.d/rustc.sh

pathprepend /opt/rustc/bin           PATH

# Include /opt/rustc/man in the MANPATH variable to access manual pages
pathappend  /opt/rustc/share/man     MANPATH

# End /etc/profile.d/rustc.sh
EOF

	rm -f /etc/resolv.conf &&

	pkg_build_slackdesc
}
 

