#!/bin/mkpkg
# description: Rust programming language
# url: https://www.rust-lang.org/

name=rust
version=1.94.1
release=1
depends=(llvm)
makedeps=(cmake ninja python3 gcc-compat)
source=(
    https://static.rust-lang.org/dist/rustc-$version-src.tar.xz
    system.diff
    musl-no-crt-static.patch
)
sha256sums=(
    "62b67230754da642a264ca0cb9fc08820c54e2ed7b3baba0289876d4cdb48c08"
    "fdfd2b449aacd417921359db8bb3eb66944313485c72fde0a942230f2b19f55e"
    "8b7d3beb08cc22a4477b238eff22d91b249ea4c5344911f6fc3c279342538e35"
)
extract() {
    cp system.diff $SRC/
    cp musl-no-crt-static.patch $SRC/
    tar -xf $PKGMK_SOURCE_DIR/rustc-$version-src.tar.xz -C $SRC
}
build() {
    cd rustc-$version-src

    patch -p1 -i $SRC/system.diff
    patch -p1 -i $SRC/musl-no-crt-static.patch

    cat > bootstrap.toml <<EOF
change-id = 148795
[llvm]
link-shared = true
use-libcxx = true
static-libstdcpp = false
[build]
build = "x86_64-unknown-linux-musl"
host = ["x86_64-unknown-linux-musl"]
target = ["x86_64-unknown-linux-musl"]
rustc = "/usr/bin/rustc"
cargo = "/usr/bin/cargo"
docs = false
extended = true
tools = ["cargo", "rustfmt", "clippy", "rust-analyzer"]
vendor = true
[install]
prefix = "/usr"
[rust]
channel = "stable"
codegen-units = 1
lto = "thin"
llvm-libunwind = "system"
[target.x86_64-unknown-linux-musl]
llvm-config = "/usr/bin/llvm-config"
crt-static = false
cc = "clang"
cxx = "clang++"
ar = "llvm-ar"
ranlib = "llvm-ranlib"
linker = "clang"
rustflags = ["-C", "link-arg=-lunwind"]
EOF
    python3 x.py build
    DESTDIR=$PKG python3 x.py install

    rm -rf $PKG/usr/share/doc
    rm -f $PKG/usr/lib/rustlib/install.log
    rm -f $PKG/usr/lib/rustlib/uninstall.sh
    rm -f $PKG/usr/lib/rustlib/manifest-*
    rm -f $PKG/usr/lib/rustlib/components
    rm -f $PKG/usr/lib/rustlib/rust-installer-version
}

signify() {
    untrusted comment: public key
    RWTZ9IduCSQ/mL8337TEUinPwT92xFEUpD92hkS7IxcOnzTt9QdpohT3
}

# vim: filetype=sh

