Skip to content

Commit 6aad19e

Browse files
committed
rust: build with PGO
1 parent 076480b commit 6aad19e

File tree

1 file changed

+44
-38
lines changed

1 file changed

+44
-38
lines changed

mingw-w64-rust/PKGBUILD

+44-38
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}"
1717
$([[ ${CARCH} == i686 ]] || echo "${MINGW_PACKAGE_PREFIX}-rust-wasm")
1818
"${MINGW_PACKAGE_PREFIX}-rust-src")
1919
pkgver=1.83.0
20-
pkgrel=3
20+
pkgrel=4
2121
pkgdesc="Systems programming language focused on safety, speed and concurrency (mingw-w64)"
2222
arch=('any')
2323
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
@@ -86,15 +86,15 @@ apply_patch_with_msg() {
8686
# =========================================== #
8787

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

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

9697
# 0008-disable-self-contained-for-gnu-targets.patch allows self-contained for non-windows-gnu targets
97-
cd ${_realname}c-${pkgver}-src
9898
apply_patch_with_msg \
9999
0001-rustc-llvm-fix-libs.patch \
100100
0008-disable-self-contained-for-gnu-targets.patch
@@ -109,7 +109,15 @@ prepare() {
109109
}
110110

111111
build() {
112-
mkdir -p "${MSYSTEM}" && cd "${MSYSTEM}"
112+
cd "${MSYSTEM}/${_realname}c-${pkgver}-src"
113+
114+
if [[ $MINGW_PACKAGE_PREFIX == *-clang-* ]]; then
115+
# We have to do the following because rust doesn't count x86_64-w64-mingw32 as a target triple
116+
export OSTYPE="$CARCH-pc-windows-gnullvm"
117+
else
118+
# We have to do the following because rust doesn't count x86_64-w64-mingw32 as a target triple
119+
export OSTYPE="$CARCH-pc-windows-gnu"
120+
fi
113121

114122
# hack to inject the bootstrap compiler
115123
if [[ $_bootstrapping != "no" && $MINGW_PACKAGE_PREFIX == *-clang-aarch64 ]]; then
@@ -118,14 +126,9 @@ build() {
118126
"${srcdir}/rust-std-${_stage0version}-dev-aarch64-pc-windows-gnullvm.tar.xz" \
119127
"${srcdir}/rustc-${_stage0version}-dev-aarch64-pc-windows-gnullvm.tar.xz" \
120128
"build/cache/${_stage0date}/"
121-
fi
122-
123-
if [[ $MINGW_PACKAGE_PREFIX == *-clang-* ]]; then
124-
# We have to do the following because rust doesn't count x86_64-w64-mingw32 as a target triple
125-
export OSTYPE="$CARCH-pc-windows-gnullvm"
126-
else
127-
# We have to do the following because rust doesn't count x86_64-w64-mingw32 as a target triple
128-
export OSTYPE="$CARCH-pc-windows-gnu"
129+
elif [[ $_bootstrapping == "no" ]]; then
130+
mkdir -p "build/stage0/$OSTYPE/bin"
131+
cp -f "${MINGW_PREFIX}"/bin/{cargo,rustc}.exe "build/stage0/$OSTYPE/bin"
129132
fi
130133

131134
if [[ $MINGW_PACKAGE_PREFIX != *-clang-aarch64 ]]; then
@@ -153,31 +156,36 @@ build() {
153156
export MSYS2_ENV_CONV_EXCL='INSTALL_PREFIX'
154157
export INSTALL_PREFIX="${MINGW_PREFIX}"
155158
export PKGREL="${pkgrel}"
156-
envsubst < ../config.toml > "../${_realname}c-${pkgver}-src/config.toml"
159+
envsubst < "${srcdir}/config.toml" > config.toml
157160

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

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

171-
# Building out of tree is not officially supported so we have to workaround some things like vendored deps
172-
cp -r ../${_realname}c-${pkgver}-src/.cargo .
173-
sed -i "s|directory = \"vendor\"|directory = \"../${_realname}c-${pkgver}-src/vendor\"|" .cargo/config.toml
174-
175-
local -a _rust_build=()
176-
_rust_build+=("--stage" "2")
177-
#_rust_build+=("--verbose")
178-
179-
# create the install at a temporary directory
180-
DESTDIR="$PWD"/dest-rust python ../${_realname}c-${pkgver}-src/x.py install "${_rust_build[@]}"
174+
if [[ ${CARCH} == x86_64 ]]; then
175+
# build opt-dist tool which manages PGO build
176+
python x.py build opt-dist --target="$OSTYPE"
177+
178+
# run opt-dist to get rustc optimized with PGO
179+
./build/$OSTYPE/stage0-tools-bin/opt-dist local \
180+
--target-triple="$OSTYPE" \
181+
--checkout-dir="$PWD" \
182+
--llvm-dir="${MINGW_PREFIX}" \
183+
--python="${MINGW_PREFIX}/bin/python.exe" -- \
184+
DESTDIR="$PWD"/dest-rust python x.py install --stage 2
185+
else
186+
# create the install at a temporary directory
187+
DESTDIR="$PWD"/dest-rust python x.py install --stage 2
188+
fi
181189

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

194202
check() {
195-
cd "${MSYSTEM}"
196-
python ../${_realname}c-${pkgver}-src/x.py test --stage 2 --exclude src/test/debuginfo
203+
cd "${MSYSTEM}/${_realname}c-${pkgver}-src"
204+
python x.py test --stage 2 --exclude src/test/debuginfo
197205
}
198206

199207
package_rust() {
@@ -208,7 +216,7 @@ package_rust() {
208216
conflicts=("${MINGW_PACKAGE_PREFIX}-rust-docs")
209217
replaces=("${MINGW_PACKAGE_PREFIX}-rust-docs")
210218

211-
cd "${MSYSTEM}"
219+
cd "${MSYSTEM}/${_realname}c-${pkgver}-src"
212220

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

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

236-
cd "${MSYSTEM}"
244+
cd "${MSYSTEM}/${_realname}c-${pkgver}-src"
237245

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

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

247-
cd "${MSYSTEM}"
254+
cd "${MSYSTEM}/${_realname}c-${pkgver}-src"
248255

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

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

0 commit comments

Comments
 (0)