NAME="rustc"
DESC="Rust programming language"
VERSION="1.76.0"

FILES=("https://static.rust-lang.org/dist/rustc-${VERSION}-src.tar.xz")
HASHES=("14a8ac688b461a3127090cad513aee05")

DEPENDS=("curl" "libssh2")
BUILD=("cmake")

PACKAGE() {
  tar xf "${NAME}-${VERSION}-src.tar.xz"
  cd "${NAME}-${VERSION}-src"

  cat > config.toml << EOF
change-id = 118703

[llvm]
targets = "X86"
link-shared = true

[build]
docs = false
extended = true
locked-deps = true
tools = ["cargo", "clippy", "rustdoc", "rustfmt"]
vendor = true

[install]
prefix = "/usr"
docdir = "share/doc/rustc-${VERSION}"

[rust]
channel = "stable"
description = "for MatterLinux"

lto = "thin"
codegen-units = 1

[target.x86_64-unknown-linux-gnu]
llvm-config = "/usr/bin/llvm-config"

[target.i686-unknown-linux-gnu]
llvm-config = "/usr/bin/llvm-config"
EOF

  install -Ddm755 "${ROOTDIR}/usr/share/doc"
  python3 ./x.py build
  DESTDIR="${ROOTDIR}" python3 ./x.py install
  find "${ROOTDIR}/usr" -name "*.old" -delete

  cd .. && rm -r "${NAME}-${VERSION}-src"
}
