# Maintainer: Maksim Bondarenkov # Maintainer: Alexey Pavlov # Contributor: Zion Nimchuk # Contributor: Mateusz MikuĊ‚a _bootstrapping=yes if [[ $MINGW_PACKAGE_PREFIX == *-clang-* ]]; then _bootstrapping=no fi if [[ $CARCH == x86_64 ]]; then _pgo=1 fi rust_dist_server=https://static.rust-lang.org/dist #rust_dist_server=https://dev-static.rust-lang.org/dist/2025-08-04 _realname=rust pkgbase=mingw-w64-${_realname} pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}" $([[ ${CARCH} == i686 ]] || echo \ "${MINGW_PACKAGE_PREFIX}-rust-wasm" \ "${MINGW_PACKAGE_PREFIX}-rust-emscripten" \ "${MINGW_PACKAGE_PREFIX}-rust-src")) pkgver=1.89.0 pkgrel=3 pkgdesc="Systems programming language focused on safety, speed and concurrency (mingw-w64)" arch=('any') mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64') url="https://www.rust-lang.org/" msys2_repository_url="https://github.com/rust-lang/rust" msys2_references=( 'anitya: 7635' 'archlinux: rust' "cpe: cpe:/a:rust-lang:rust" 'gentoo: dev-lang/rust' ) license=('spdx:Apache-2.0 AND MIT') makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-clang" "${MINGW_PACKAGE_PREFIX}-cmake" "${MINGW_PACKAGE_PREFIX}-curl" "${MINGW_PACKAGE_PREFIX}-libffi" "${MINGW_PACKAGE_PREFIX}-libgit2" "${MINGW_PACKAGE_PREFIX}-libssh2" "${MINGW_PACKAGE_PREFIX}-llvm" "${MINGW_PACKAGE_PREFIX}-ninja" "${MINGW_PACKAGE_PREFIX}-openssl" "${MINGW_PACKAGE_PREFIX}-pkgconf" "${MINGW_PACKAGE_PREFIX}-python" "${MINGW_PACKAGE_PREFIX}-sqlite3" $([[ "$_bootstrapping" == "no" ]] && echo "${MINGW_PACKAGE_PREFIX}-rust") "${MINGW_PACKAGE_PREFIX}-xz" "${MINGW_PACKAGE_PREFIX}-zstd" "${MINGW_PACKAGE_PREFIX}-zlib" $([[ ${CARCH} == i686 ]] || echo \ "${MINGW_PACKAGE_PREFIX}-emscripten" \ "${MINGW_PACKAGE_PREFIX}-wasi-libc" \ "${MINGW_PACKAGE_PREFIX}-wasm-component-ld") $((( _pgo )) && echo \ "${MINGW_PACKAGE_PREFIX}-compiler-rt" \ "${MINGW_PACKAGE_PREFIX}-lld") 'git') source=("${rust_dist_server}/${_realname}c-${pkgver}-src.tar.gz"{,.asc} "rustc-perf::git+https://github.com/rust-lang/rustc-perf.git#commit=6a70166b92a1b1560cb3cf056427b011b2a1f2bf" "bootstrap.toml" "0001-rustc-llvm-fix-libs.patch" "0004-compiler-Use-wasm-ld-for-wasm-targets.patch" "0008-disable-self-contained-for-gnu-targets.patch" "0014-rustc-perf-less-verbose.patch" # patches in case of doing PGO for LLVM with opt-dist #"0015-lesser-llvm-build.patch" #"https://patch-diff.githubusercontent.com/raw/rust-lang/rust/pull/143898.patch" # various backports. most of them to be removed after 1.90.0 update "https://patch-diff.githubusercontent.com/raw/rust-lang/rust/pull/143928.patch" "https://patch-diff.githubusercontent.com/raw/rust-lang/rust/pull/144159.patch" "https://patch-diff.githubusercontent.com/raw/rust-lang/rust/pull/144164.patch" "https://patch-diff.githubusercontent.com/raw/rust-lang/rust/pull/144254.patch") noextract=(${_realname}c-${pkgver}-src.tar.gz) sha256sums=('2576f9f440dd99b0151bd28f59aa0ac6102d5c4f3ed4ef8a810c8dd05057250d' 'SKIP' '549b63a9e2b460a02bafbb7f7fd4a101a067be6a02c6d2b0108ea2123aee0f3a' 'ebb90532e08fc1cb4ec8af6a3de66519fb6f168a2a4f075355082dea3be0ce60' '7cb1773c288ffb1c1e751edc49b1890c84bf9c362742bc5225d19d474edb73a0' '56882f1a0f1404c10c7726d6cc37444f2b343e72b969badfcb43760f80db0f32' '87b68c2dfbe996d3ef439278e1ac90997fc4ea192f449e8f00262360a551386a' '6a8d987186785901d8a6e347d6ec3bccd84c869c9fa1a57cb9a30c8f6a3ce3ac' 'd8dd34d2474aa550c1e2089dfb7d75b5cf63174bb673e9fb5b233598c53115a6' '6ba3bf8fa7b9196dc97f5e3c00718311471e3bbac0a7641e0ef88c190b830c7f' '191addeef0af122bc09ef0a6578d7eaa62afbb30080227cdd1baa75d4671686d' '8b81f31a3069f63694d375f7ece7bac5a711f10a9c06b803d9bca675dde33cf7') validpgpkeys=('108F66205EAEB0AAA8DD5E1C85AB96E6FA1BE5FE' # Rust Language (Tag and Release Signing Key) '474E22316ABF4785A88C6E8EA2C794A986419D8A' # Tom Stellard 'B6C8F98282B944E3B0D5C2530FC3042E345AD05D') # Hans Wennborg # =========================================== # # Helper macros to help make tasks easier # apply_patch_with_msg() { for _patch in "$@" do msg2 "Applying ${_patch}" patch -Nbp1 -i "${srcdir}/${_patch}" done } # =========================================== # # Make sure the duplication in rust-wasm is found COMPRESSZST+=(--long) prepare() { plain "Extracting ${_realname}c-${pkgver}-src.tar.gz" tar -xzf ${_realname}c-${pkgver}-src.tar.gz || true cd ${_realname}c-${pkgver}-src if (( ! _pgo )); then apply_patch_with_msg \ 0001-rustc-llvm-fix-libs.patch fi # 0008-disable-self-contained-for-gnu-targets.patch allows self-contained for non-windows-gnu targets apply_patch_with_msg \ 0008-disable-self-contained-for-gnu-targets.patch \ 0004-compiler-Use-wasm-ld-for-wasm-targets.patch \ 0014-rustc-perf-less-verbose.patch \ 143928.patch \ 144159.patch \ 144164.patch \ 144254.patch } build() { cd "${_realname}c-${pkgver}-src" # We have to do the following because rust doesn't count x86_64-w64-mingw32 as a target triple if [[ $MINGW_PACKAGE_PREFIX == *-clang-* ]]; then export OSTYPE="$CARCH-pc-windows-gnullvm" else export OSTYPE="$CARCH-pc-windows-gnu" fi if [[ $MINGW_PACKAGE_PREFIX != *-clang-aarch64 ]]; then # Use $CFLAGS for $OSTYPE only export CFLAGS_${OSTYPE//-/_}="$CFLAGS" # Remove unsupported options for target wasm32-* local _unsupported_options="-march=nocona -msahf" export CFLAGS="${CFLAGS#$_unsupported_options}" fi # For a faster build: # - add --disable-docs and --disable-compiler-docs # - compile only rustc by removing --enable-extended # - run makepkg-mingw with --nocheck # - remove --stage 2 export RUST_BACKTRACE=1 export RUST_LOG=info # force some system libraries export LIBSQLITE3_SYS_USE_PKG_CONFIG=1 export LIBSSH2_SYS_USE_PKG_CONFIG=1 # substitute the values in bootstrap.toml export MSYS2_ENV_CONV_EXCL='INSTALL_PREFIX' export INSTALL_PREFIX="${MINGW_PREFIX}" export PKGREL="${pkgrel}" envsubst < ../bootstrap.toml > bootstrap.toml if [ "${_bootstrapping}" = "no" ]; then sed -i '/^\[build\]/,/^$/ s|^#||g' bootstrap.toml fi # generate debuginfo only for non-i686 targets if check_option "debug" "y" && [ "${CARCH}" != i686 ]; then sed -i 's/^#debug/debug/g' bootstrap.toml fi # Add wasm32-* targets, tools and enable LTO for non-i686 if [[ ${CARCH} != i686 ]]; then sed -i -e '/target = \[/a\ "wasm32-unknown-unknown", "wasm32-unknown-emscripten", "wasm32-wasip1", "wasm32v1-none", "wasm32-wasip1-threads", "wasm32-wasip2",' \ -e '/tools = \[/a\ "clippy", "rustdoc", "rustfmt", "rust-analyzer-proc-macro-srv", "analysis", "src",' \ -e 's/#lto/lto/' bootstrap.toml fi if (( _pgo )); then sed -i 's/#use-lld/use-lld/' bootstrap.toml # LLVM must be build for GCC envs, otherwise lld fails to link our LLVM while profiling rustc if [[ ${MSYSTEM} != CLANG* ]]; then sed -i -e '/^\[llvm\]/,/^$/ s|^#||g' -e 's/llvm-config/#llvm-config/' bootstrap.toml fi # build opt-dist tool which manages PGO build python x.py build opt-dist --target="$OSTYPE" local _pgo_opts=(--target-triple="$OSTYPE" --checkout-dir="$PWD" --llvm-dir="${MINGW_PREFIX}" --llvm-shared=false --build-llvm=false --python="${MINGW_PREFIX}/bin/python.exe" --artifact-dir=opt-artifacts-${MSYSTEM} --build-dir=build-${MSYSTEM} --rustc-perf-checkout-dir="${srcdir}/rustc-perf") # CLANG* don't have prebuilt stage0 if [[ ${MSYSTEM} == CLANG* ]]; then _pgo_opts+=(--stage0-root="${MINGW_PREFIX}") fi # run opt-dist to get rustc optimized with PGO CXXFLAGS="$CXXFLAGS -fuse-ld=lld" \ DESTDIR="$PWD/build-$MSYSTEM/dest-rust" \ RUSTFLAGS="${RUSTFLAGS/+crt-static/-crt-static}" \ build-${MSYSTEM}/${OSTYPE}/stage0-tools-bin/opt-dist local ${_pgo_opts[@]} -- \ python x.py install else DESTDIR="$PWD/build-$MSYSTEM/dest-rust" python x.py install --stage 2 fi cd build-${MSYSTEM} if [[ ${CARCH} != i686 ]]; then # move wasm32-unknown-emscripten out of the way for splitting mkdir -p dest-emscripten${MINGW_PREFIX}/lib/rustlib mv dest-rust${MINGW_PREFIX}/lib/rustlib/wasm32-unknown-emscripten dest-emscripten${MINGW_PREFIX}/lib/rustlib # move other wasm targets out of the way for splitting mkdir -p dest-wasm${MINGW_PREFIX}/lib/rustlib mv dest-rust${MINGW_PREFIX}/lib/rustlib/wasm32{,v1}-* dest-wasm${MINGW_PREFIX}/lib/rustlib # move src out of the way for splitting mkdir -p dest-src${MINGW_PREFIX}/lib/rustlib mv dest-rust${MINGW_PREFIX}/lib/rustlib/src dest-src${MINGW_PREFIX}/lib/rustlib fi rm -f dest-rust${MINGW_PREFIX}/lib/rustlib/$OSTYPE/lib/self-contained/* } check() { cd "${_realname}c-${pkgver}-src" python x.py test --stage 2 --exclude src/test/debuginfo } package_rust() { depends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-libgit2" "${MINGW_PACKAGE_PREFIX}-libssh2" "${MINGW_PACKAGE_PREFIX}-sqlite3" "${MINGW_PACKAGE_PREFIX}-zlib") # these dependencies are linked with our LLVM library, which has more features enabled if [[ ${MSYSTEM} == CLANG* ]] || [[ ${CARCH} == i686 ]]; then depends+=("${MINGW_PACKAGE_PREFIX}-libxml2" "${MINGW_PACKAGE_PREFIX}-zstd") fi if [[ ${CARCH} != i686 ]]; then optdepends=("${MINGW_PACKAGE_PREFIX}-gdb: for rust-gdb script" "${MINGW_PACKAGE_PREFIX}-lldb: for rust-lldb script") fi conflicts=("${MINGW_PACKAGE_PREFIX}-rust-docs") replaces=("${MINGW_PACKAGE_PREFIX}-rust-docs") cd "${_realname}c-${pkgver}-src/build-${MSYSTEM}" cp -a dest-rust/* "${pkgdir}" # delete unnecessary files, e.g. components and manifest files only used for the uninstall script # and rust-{gdb{,gui},lldb} for i686 cd "${pkgdir}${MINGW_PREFIX}/lib/rustlib" rm components install.log manifest-* rust-installer-version uninstall.sh if [[ ${CARCH} == i686 ]]; then rm "${pkgdir}${MINGW_PREFIX}"/bin/rust-{gdb{,gui},lldb} fi install -d "${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions" mv "${pkgdir}${MINGW_PREFIX}/etc/bash_completion.d/cargo" \ "${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions/cargo" } package_rust-wasm() { pkgdesc="WebAssembly targets for Rust (mingw-w64)" depends=("${MINGW_PACKAGE_PREFIX}-lld" "${MINGW_PACKAGE_PREFIX}-rust" "${MINGW_PACKAGE_PREFIX}-wasm-component-ld") # strip wasm object files manually due to binutils' lack of support options=('!strip') cd "${_realname}c-${pkgver}-src/build-${MSYSTEM}" cp -a dest-wasm/* "${pkgdir}" pushd "${pkgdir}${MINGW_PREFIX}"/lib/rustlib llvm-strip --strip-debug wasm32*/lib/*.rlib popd install -Dm644 ../LICENSE-{APACHE,MIT} -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}-wasm" } package_rust-emscripten() { pkgdesc="Emscripten target for Rust (mingw-w64)" depends=("${MINGW_PACKAGE_PREFIX}-rust" "${MINGW_PACKAGE_PREFIX}-emscripten") options=('!strip') cd "${_realname}c-${pkgver}-src/build-${MSYSTEM}" cp -a dest-emscripten/* "${pkgdir}" pushd "${pkgdir}${MINGW_PREFIX}"/lib/rustlib llvm-strip --strip-debug wasm32-*/lib/*.rlib popd # manually add self-contained linkers to make emscripten target happy mkdir -p "${pkgdir}${MINGW_PREFIX}/lib/rustlib/$OSTYPE/bin/gcc-ld/" cp "${MINGW_PREFIX}"/bin/{ld{,64}.lld,lld-link,wasm-ld} \ "${pkgdir}${MINGW_PREFIX}/lib/rustlib/$OSTYPE/bin/gcc-ld/" install -Dm644 ../LICENSE-{APACHE,MIT} -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}-emscripten" } package_rust-src() { pkgdesc='Source code for the Rust standard library (mingw-w64)' depends=("${MINGW_PACKAGE_PREFIX}-rust") cd "${_realname}c-${pkgver}-src/build-${MSYSTEM}" cp -a dest-src/* "${pkgdir}" install -Dm644 ../LICENSE-{APACHE,MIT} -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}-src" } # template start; name=mingw-w64-splitpkg-wrappers; version=1.0; # vim: set ft=bash : # generate wrappers for _name in "${pkgname[@]}"; do _short="package_${_name#${MINGW_PACKAGE_PREFIX}-}" _func="$(declare -f "${_short}")" eval "${_func/#${_short}/package_${_name}}" done # template end;