Skip to content

Commit

Permalink
rust: build with PGO
Browse files Browse the repository at this point in the history
  • Loading branch information
ognevny committed Dec 11, 2024
1 parent 076480b commit c2edd29
Showing 1 changed file with 33 additions and 30 deletions.
63 changes: 33 additions & 30 deletions mingw-w64-rust/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}"
$([[ ${CARCH} == i686 ]] || echo "${MINGW_PACKAGE_PREFIX}-rust-wasm")
"${MINGW_PACKAGE_PREFIX}-rust-src")
pkgver=1.83.0
pkgrel=3
pkgrel=4
pkgdesc="Systems programming language focused on safety, speed and concurrency (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
Expand Down Expand Up @@ -86,15 +86,15 @@ apply_patch_with_msg() {
# =========================================== #

prepare() {
plain "Extracting ${_realname}c-${pkgver}-src.tar.gz"
tar -xzf ${_realname}c-${pkgver}-src.tar.gz || true
plain "Extracting ${_realname}c-${pkgver}-src.tar.gz to ${MSYSTEM} directory"
mkdir -p "${MSYSTEM}" && tar -xzf ${_realname}c-${pkgver}-src.tar.gz -C "${MSYSTEM}" || true
cd "${MSYSTEM}/${_realname}c-${pkgver}-src"

# use latest version of psm to fix arm4 build
rm -r ${_realname}c-${pkgver}-src/vendor/psm-0.1.23
mv psm-0.1.24 ${_realname}c-${pkgver}-src/vendor/psm-0.1.24
rm -r vendor/psm-0.1.23
mv ${srcdir}/psm-0.1.24 vendor/psm-0.1.24

# 0008-disable-self-contained-for-gnu-targets.patch allows self-contained for non-windows-gnu targets
cd ${_realname}c-${pkgver}-src
apply_patch_with_msg \
0001-rustc-llvm-fix-libs.patch \
0008-disable-self-contained-for-gnu-targets.patch
Expand All @@ -109,7 +109,7 @@ prepare() {
}

build() {
mkdir -p "${MSYSTEM}" && cd "${MSYSTEM}"
cd "${MSYSTEM}/${_realname}c-${pkgver}-src"

# hack to inject the bootstrap compiler
if [[ $_bootstrapping != "no" && $MINGW_PACKAGE_PREFIX == *-clang-aarch64 ]]; then
Expand Down Expand Up @@ -153,31 +153,36 @@ build() {
export MSYS2_ENV_CONV_EXCL='INSTALL_PREFIX'
export INSTALL_PREFIX="${MINGW_PREFIX}"
export PKGREL="${pkgrel}"
envsubst < ../config.toml > "../${_realname}c-${pkgver}-src/config.toml"
envsubst < "${srcdir}/config.toml" > config.toml

if [ "${_bootstrapping}" = "no" ]; then
sed -i '/^\[build\]/,/^$/ s|^#||g' "../${_realname}c-${pkgver}-src/config.toml"
sed -i '/^\[build\]/,/^$/ s|^#||g' config.toml
fi
# generate debuginfo only for non-i686 targets
if check_option "debug" "y" && [ "${CARCH}" != i686 ]; then
sed -i 's/^#debug/debug/g' "../${_realname}c-${pkgver}-src/config.toml"
sed -i 's/^#debug/debug/g' config.toml
fi

# Add target wasm32-*
if [[ ${CARCH} != i686 ]]; then
sed -i '/target = \[/a\ "wasm32-unknown-unknown", "wasm32-wasip1", "wasm32-wasip1-threads", "wasm32-wasip2",' "../${_realname}c-${pkgver}-src/config.toml"
sed -i '/target = \[/a\ "wasm32-unknown-unknown", "wasm32-wasip1", "wasm32-wasip1-threads", "wasm32-wasip2",' config.toml
fi

# Building out of tree is not officially supported so we have to workaround some things like vendored deps
cp -r ../${_realname}c-${pkgver}-src/.cargo .
sed -i "s|directory = \"vendor\"|directory = \"../${_realname}c-${pkgver}-src/vendor\"|" .cargo/config.toml

local -a _rust_build=()
_rust_build+=("--stage" "2")
#_rust_build+=("--verbose")

# create the install at a temporary directory
DESTDIR="$PWD"/dest-rust python ../${_realname}c-${pkgver}-src/x.py install "${_rust_build[@]}"
if [[ ${CARCH} == x86_64 ]]; then
# build opt-dist tool which manages PGO build
python x.py build opt-dist --target="$OSTYPE"

# run opt-dist to get rustc optimized with PGO
./build/$OSTYPE/stage0-tools-bin/opt-dist local \
--target-triple="$OSTYPE" \
--checkout-dir="$PWD" \
--llvm-dir="${MINGW_PREFIX}" \
--python="${MINGW_PREFIX}/bin/python.exe" -- \
DESTDIR="$PWD"/dest-rust python x.py install --stage 2
else
# create the install at a temporary directory
DESTDIR="$PWD"/dest-rust python x.py install --stage 2
fi

if [[ ${CARCH} != i686 ]]; then
# move wasm32-* targets out of the way for splitting
Expand All @@ -192,8 +197,8 @@ build() {
}

check() {
cd "${MSYSTEM}"
python ../${_realname}c-${pkgver}-src/x.py test --stage 2 --exclude src/test/debuginfo
cd "${MSYSTEM}/${_realname}c-${pkgver}-src"
python x.py test --stage 2 --exclude src/test/debuginfo
}

package_rust() {
Expand All @@ -208,7 +213,7 @@ package_rust() {
conflicts=("${MINGW_PACKAGE_PREFIX}-rust-docs")
replaces=("${MINGW_PACKAGE_PREFIX}-rust-docs")

cd "${MSYSTEM}"
cd "${MSYSTEM}/${_realname}c-${pkgver}-src"

cp -a dest-rust/* "${pkgdir}"

Expand All @@ -233,21 +238,19 @@ package_rust-wasm() {
# object files provided for wasm32-* targets can't be stripped with MSYS2 toolchain
options=('!strip')

cd "${MSYSTEM}"
cd "${MSYSTEM}/${_realname}c-${pkgver}-src"

cp -a dest-wasm/* "${pkgdir}"
install -Dm644 ../${_realname}c-${pkgver}-src/LICENSE-{APACHE,MIT} -t \
"${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}-wasm/"
install -Dm644 LICENSE-{APACHE,MIT} -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}-wasm/"
}

package_rust-src() {
pkgdesc='Source code for the Rust standard library (mingw-w64)'
depends=("${MINGW_PACKAGE_PREFIX}-rust")

cd "${MSYSTEM}"
cd "${MSYSTEM}/${_realname}c-${pkgver}-src"

install -Dm644 ../${_realname}c-${pkgver}-src/LICENSE-{APACHE,MIT} -t \
"${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}-src/"
install -Dm644 LICENSE-{APACHE,MIT} -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}-src/"

install -d "${pkgdir}${MINGW_PREFIX}/lib/rustlib/"
cp -a dest-src "${pkgdir}${MINGW_PREFIX}/lib/rustlib/src"
Expand Down

0 comments on commit c2edd29

Please sign in to comment.