aboutsummaryrefslogtreecommitdiffstats
path: root/community/rust/APKBUILD
blob: 29e9680a59734b8c761c601ac656e87cb80a80a3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# Contributor: Rasmus Thomsen <oss@cogitri.dev>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Contributor: Shiz <hi@shiz.me>
# Contributor: Jeizsm <jeizsm@gmail.com>
# Contributor: Ariadne Conill <ariadne@dereferenced.org>
# Maintainer: Rasmus Thomsen <oss@cogitri.dev>
pkgname=rust
pkgver=1.52.1
_llvmver=11
_bootver=1.52.0
pkgrel=0
pkgdesc="The Rust Programming Language"
url="https://www.rust-lang.org"
arch="x86_64 armv7 armhf aarch64 x86 ppc64le"
license="Apache-2.0 AND MIT"

# gcc is needed at runtime just for linking. Someday rustc might invoke
# the linker directly, and then we'll only need binutils.
# See: https://github.com/rust-lang/rust/issues/11937
depends="$pkgname-stdlib=$pkgver-r$pkgrel gcc musl-dev"

_python=python3
# * Rust is self-hosted, so you need rustc (and cargo) to build rustc...
#   The last revision of this abuild that does not depend on itself (uses
#   prebuilt rustc and cargo) is 2e6769eb39eaff3029d8298fc02856623c563cd8.
makedepends_build="
	$_python
	file
	tar
	coreutils
	llvm$_llvmver-dev
	llvm$_llvmver-test-utils
	rust-bootstrap=>$_bootver
	cargo-bootstrap=>$_bootver
	curl-dev
	libgit2-dev
	openssl-dev
	zlib-dev
"
makedepends_host="
	curl-dev
	libgit2-dev
	openssl-dev
	llvm$_llvmver-dev
	zlib-dev
"

# XXX: This is a hack to allow this abuild to depend on itself. Adding "rust"
# to makedepends would not work, because abuild implicitly removes $pkgname
# and $subpackages from the abuild's dependencies.
provides="rust-bootstrap=$pkgver-r$pkgrel"
# This is needed for -src that contains some testing binaries.
# Disable tests for now, while we use foreign triplets
options="!archcheck !check"

subpackages="
	$pkgname-dbg
	$pkgname-stdlib
	$pkgname-analysis
	$pkgname-gdb::noarch
	$pkgname-lldb::noarch
	$pkgname-doc
	$pkgname-src::noarch
	cargo
	cargo-bash-completions:_cargo_bashcomp:noarch
	cargo-zsh-completion:_cargo_zshcomp:noarch
	cargo-doc:_cargo_doc:noarch
	"
source="https://static.rust-lang.org/dist/rustc-$pkgver-src.tar.gz
	musl-fix-linux_musl_base.patch
	need-rpath.patch
	need-ssp_nonshared.patch
	alpine-move-py-scripts-to-share.patch
	alpine-target.patch
	install-template-shebang.patch
	check-rustc
	link-musl-dynamically.patch
	0006-Prefer-libgcc_eh-over-libunwind-for-musl.patch
	0007-do-not-install-libunwind-source.patch
	mips-softfloat.patch
	"
builddir="$srcdir/rustc-$pkgver-src"

# secfixes:
#   1.51.0-r2:
#     - CVE-2020-36323
#     - CVE-2021-31162
#   1.34.2-r0:
#     - CVE-2019-12083
#   1.26.0-r0:
#     - CVE-2019-16760

# We have to add new arches in multiple steps:
# 1. Compile with the upstream triplets, compiling alpine's triplets in
# 2. Compile again, now with our triplets selected as build/target, now that
#    rustc knows about them
_build="$CBUILD"
_target="$CTARGET"

_rlibdir="usr/lib/rustlib/$_target/lib"
_sharedir="usr/share/rust"

ldpath="/$_rlibdir"

export RUST_BACKTRACE=1
# Don't use system libgit2 for now...
# https://github.com/rust-lang/rust/issues/63476
# Convince libgit2-sys to use the distro libgit2.
#export LIBGIT2_SYS_USE_PKG_CONFIG=1

# rust checksums files in vendor/, but we have to patch a few files...
_clear_vendor_checksums() {
	sed -i 's/\("files":{\)[^}]*/\1/' vendor/$1/.cargo-checksum.json
}

prepare() {
	default_prepare

	sed -i /LD_LIBRARY_PATH/d src/bootstrap/bootstrap.py

	# to dynamically link against musl
	_clear_vendor_checksums libc

	# Remove bundled dependencies.
	rm -Rf src/llvm-project/
}

build() {
	# Fails to compile libbacktrace-sys otherwise
	case "$CARCH" in
		x86)
			export CFLAGS="$CFLAGS -fno-stack-protector"
			;;
	esac
	if [ "$_build" != "$_target" ]; then
		export PKG_CONFIG_ALLOW_CROSS=1
	fi

	./configure \
		--build="$_build" \
		--host="$_target" \
		--target="$_target" \
		--prefix="/usr" \
		--release-channel="stable" \
		--enable-local-rust \
		--local-rust-root="/usr" \
		--llvm-root="/usr/lib/llvm$_llvmver" \
		--disable-docs \
		--enable-extended \
		--tools="analysis,cargo,src" \
		--enable-llvm-link-shared \
		--enable-option-checking \
		--enable-locked-deps \
		--enable-vendor \
		--python="$_python" \
		--set="rust.musl-root=/usr" \
		--set="rust.codegen-units=1" \
		--set="rust.codegen-units-std=1" \
		--set="rust.parallel-compiler=false" \
		--set="target.$_target.llvm-config=/usr/lib/llvm$_llvmver/bin/llvm-config" \
		--set="target.$_target.musl-root=/usr" \
		--set="target.$_target.crt-static=false" \
		--set="target.$_target.cc=${CROSS_COMPILE}gcc" \
		--set="target.$_target.cxx=${CROSS_COMPILE}c++" \
		--set="target.$_target.ar=${CROSS_COMPILE}ar" \
		--set="target.$_target.linker=${CROSS_COMPILE}gcc" \
		--set="target.$_build.musl-root=/usr" \
		--set="target.$_build.crt-static=false" \
		--set="target.$_build.cc=gcc" \
		--set="target.$_build.cxx=c++" \
		--set="target.$_build.ar=ar" \
		--set="target.$_build.linker=gcc"

	# Allow warnings instead of just aborting the build
	sed 's/#deny-warnings = .*/deny-warnings = false/' -i config.toml
	sed 's|deny(warnings,|deny(|' -i src/bootstrap/lib.rs

	$_python ./x.py dist -v --jobs ${JOBS:-2}
}

check() {
	# At this moment lib/rustlib/$CTARGET/lib does not contain a complete
	# copy of the .so libs from lib (they will be copied there during
	# 'x.py install'). Thus we must set LD_LIBRARY_PATH for tests to work.
	# This is related to change-rpath-to-rustlib.patch.
	export LD_LIBRARY_PATH="$builddir/build/$CTARGET/stage2/lib"

	"$srcdir"/check-rustc "$builddir"/build/$CTARGET/stage2/bin/rustc

# XXX: There's some problem with these tests, we will figure it out later.
#	make check \
#		LD_LIBRARY_PATH="$_stage0dir/lib" \
#		VERBOSE=1

	msg "Running tests for cargo..."
	CFG_DISABLE_CROSS_TESTS=1 $_python ./x.py test --no-fail-fast src/tools/cargo

	unset LD_LIBRARY_PATH
}

package() {
	mkdir -p "$pkgdir/usr"

	cd "$pkgdir"

	tar xf "$builddir"/build/dist/rustc-${pkgver}-${_target}.tar.gz \
		-C "$pkgdir/usr" --strip-components=2 --exclude=manifest.in --no-same-owner
	tar xf "$builddir"/build/dist/rust-std-${pkgver}-${_target}.tar.gz \
		-C "$pkgdir/usr" --strip-components=2 --exclude=manifest.in --no-same-owner
	tar xf "$builddir"/build/dist/rustc-dev-${pkgver}-${_target}.tar.gz \
		-C "$pkgdir/usr" --strip-components=2 --exclude=manifest.in --no-same-owner
	tar xf "$builddir"/build/dist/rust-analysis-${pkgver}-${_target}.tar.gz \
		-C "$pkgdir/usr" --strip-components=2 --exclude=manifest.in --no-same-owner
	tar xf "$builddir"/build/dist/rust-analyzer-${pkgver}-${_target}.tar.gz \
		-C "$pkgdir/usr" --strip-components=2 --exclude=manifest.in --no-same-owner
	tar xf "$builddir"/build/dist/rust-src-${pkgver}.tar.gz \
		-C "$pkgdir/usr" --strip-components=2 --exclude=manifest.in --no-same-owner
	tar xf "$builddir"/build/dist/cargo-${pkgver}-${_target}.tar.gz \
		-C "$pkgdir/usr" --strip-components=2 --exclude=manifest.in --no-same-owner
	tar xf "$builddir"/build/dist/clippy-${pkgver}-${_target}.tar.gz \
		-C "$pkgdir/usr" --strip-components=2 --exclude=manifest.in --no-same-owner
	tar xf "$builddir"/build/dist/miri-${pkgver}-${_target}.tar.gz \
		-C "$pkgdir/usr" --strip-components=2 --exclude=manifest.in --no-same-owner
	tar xf "$builddir"/build/dist/rls-${pkgver}-${_target}.tar.gz \
		-C "$pkgdir/usr" --strip-components=2 --exclude=manifest.in --no-same-owner
	tar xf "$builddir"/build/dist/rustfmt-${pkgver}-${_target}.tar.gz \
		-C "$pkgdir/usr" --strip-components=2 --exclude=manifest.in --no-same-owner

	# We don't want to include stuff like rust-llvm-* tools, as we will use the
	# system tools.
	rm -f usr/lib/rustlib/"$_target"/bin/rust-llvm-*

	# Python scripts are noarch, so move them to /usr/share.
	# Requires move-py-scripts-to-share.patch to be applied.
	_mv usr/lib/rustlib/etc/*.py $_sharedir/etc/
	rmdir -p usr/lib/rustlib/etc 2>/dev/null || true

	# Remove some clutter.
	cd "$pkgdir"/usr/lib/rustlib
	rm -f components install.log manifest-* rust-installer-version uninstall.sh
	if [ "$_build" != "$_target" ]; then
		rm -rf "$pkgdir"/usr/lib/rustlib/$_build
	fi
}

stdlib() {
	pkgdesc="Standard library for Rust (static rlibs)"
	depends=

	_mv "$pkgdir"/$_rlibdir/*.rlib "$subpkgdir"/$_rlibdir/
}

analysis() {
	pkgdesc="Compiler analysis data for the Rust standard library"
	depends="$pkgname-stdlib=$pkgver-r$pkgrel"

	_mv "$pkgdir"/$_rlibdir/../analysis "$subpkgdir"/${_rlibdir%/*}/
}

gdb() {
	pkgdesc="GDB pretty printers for Rust"
	depends="$pkgname=$pkgver-r$pkgrel gdb"

	mkdir -p "$subpkgdir"
	cd "$subpkgdir"

	_mv "$pkgdir"/usr/bin/rust-gdb usr/bin/
	_mv "$pkgdir"/$_sharedir/etc/gdb_*.py $_sharedir/etc/
}

lldb() {
	local _pyver=${_python#python}
	pkgdesc="LLDB pretty printers for Rust"
	depends="$pkgname=$pkgver-r$pkgrel lldb py$_pyver-lldb"

	mkdir -p "$subpkgdir"
	cd "$subpkgdir"

	_mv "$pkgdir"/usr/bin/rust-lldb usr/bin/
	_mv "$pkgdir"/$_sharedir/etc/lldb_*.py $_sharedir/etc/
}

src() {
	pkgdesc="$pkgdesc (source code)"
	depends="$pkgname=$pkgver-r$pkgrel"
	license="$license OFL-1.1 GPL-3.0-or-later GPL-3.0-with-GCC-exception CC-BY-SA-3.0 LGPL-3.0"

	_mv "$pkgdir"/usr/lib/rustlib/src/rust "$subpkgdir"/usr/src/
	rmdir -p "$pkgdir"/usr/lib/rustlib/src 2>/dev/null || true

	mkdir -p "$subpkgdir"/usr/lib/rustlib/src
	ln -s ../../../src/rust "$subpkgdir"/usr/lib/rustlib/src/rust
}

cargo() {
	pkgdesc="The Rust package manager"
	license="Apache-2.0 MIT UNLICENSE"
	depends="$pkgname=$pkgver-r$pkgrel"
	# XXX: See comment on top-level provides=.
	provides="cargo-bootstrap=$pkgver-r$pkgrel"

	_mv "$pkgdir"/usr/bin/cargo "$subpkgdir"/usr/bin/
}

_cargo_bashcomp() {
	pkgdesc="Bash completions for cargo"
	license="Apache-2.0 MIT"
	depends=""
	install_if="cargo=$pkgver-r$pkgrel bash-completion"

	cd "$pkgdir"
	_mv usr/etc/bash_completion.d/cargo \
		"$subpkgdir"/usr/share/bash-completion/completions/
	rmdir -p etc/bash_completion.d 2>/dev/null || true
}

_cargo_zshcomp() {
	pkgdesc="ZSH completions for cargo"
	license="Apache-2.0 MIT"
	depends=""
	install_if="cargo=$pkgver-r$pkgrel zsh"

	cd "$pkgdir"
	_mv usr/share/zsh/site-functions/_cargo \
		"$subpkgdir"/usr/share/zsh/site-functions/
	rmdir -p usr/share/zsh/site-functions 2>/dev/null || true
}

_cargo_doc() {
	pkgdesc="The Rust package manager (documentation)"
	license="Apache-2.0 MIT"
	install_if="docs cargo=$pkgver-r$pkgrel"

	# XXX: This is hackish!
	cd "$pkgdir"/../$pkgname-doc
	_mv usr/share/man/man1/cargo* "$subpkgdir"/usr/share/man/man1/
}

_mv() {
	local dest; for dest; do true; done  # get last argument
	mkdir -p "$dest"
	mv "$@"
}

sha512sums="
24073c46cff5a9ecb740b01a9d33ba37eb57eee8cb3fb6c29081e398bc48ffb63ef95a9d650a65554c17ebd85ed36c009ddbe5d2a3d8a37f0540308481c89432  rustc-1.52.1-src.tar.gz
4accbdf546e9f82f38d56169f65fcfb53839e1df89978b9a434a59a1dcb80b4d57c0272c0ece65530ce09ad0f7a7e880b4b97e2b8dd8f2bccace02a5874e6733  musl-fix-linux_musl_base.patch
2fa569ea83338af929f472abf68d39e889c93f0a0e07cba4017fc9da55ab40d4d598489b21cea688f9d9fe186f7a7207266bf3175bb226818f06934dfffd8e07  need-rpath.patch
bc28e1edae88f48eb0368cd0905280c323d521c7e13b6fc2bb1fb6e57274fa418afdc9cb3342f4928842e309d0573b98e82976159541c88b35694dceaf7a82e4  need-ssp_nonshared.patch
03a179e31c95f88a98fb1ba6b2fd0baaf9fe1a74ade76d3096fe45ddc5e453c25109355e667783d9be1bcc585445d07b7270cb3e6e403de971049714f2c6f91a  alpine-move-py-scripts-to-share.patch
aa1681386c13a7ef103ca3083cc173bb5db0d37436f2579410233a542d71185be88a4478b9e2d90b848ffc5577f78bffef466cd5883786dfbf4e4a08d1007509  alpine-target.patch
7d59258d4462eba0207739a5c0c8baf1f19d9a396e5547bb4d59d700eb94d50ba6add2e523f3e94e29e993821018594625ea4ac86304fb58f7f8c82622a26ab0  install-template-shebang.patch
c31fdfe8a9b3411576c75da46645cf0465b9053000a2ab49cf9b2f2733f679d6d33acbf236d67a20e14935d094a685453b7f1840180249f39d610fd0902c3125  check-rustc
d5d3ccc5c3a73bf1816106ba00805346ea28f2e6337d960e9e9f776ba59d22abd8864382f163d32dd9a278df38c080949dafc70169728f44080ddc04f1e7f125  link-musl-dynamically.patch
fa67468667903290b8e6d16d6777f80aac49d987e8e60c43f8302da77fa1e0e35c4d363d216867c79989c8c35d552c0d5dd6bce69734ed0ce75b4b67ca924953  0006-Prefer-libgcc_eh-over-libunwind-for-musl.patch
7af23c34096f7a03c5a1b40aa07e00dd6193743c872881018a9baa900f240c6e44918e481ab5ed7787a70ef361e4aeec2a7719bcd695f52988262e23271b44e5  0007-do-not-install-libunwind-source.patch
4cb2592d30cd1a776375522631aa284dd077eaa39b109921d6ee5906fd0130b048e07d3adef1d7221f5c001d1df5187feb3e3687e0aa5d19279099065a7d4cb7  mips-softfloat.patch
"