aboutsummaryrefslogtreecommitdiff
path: root/srcpkgs/rust/template
blob: 21e116236386761bcededf6f49e95c16a4af7d87 (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
# Template file for 'rust'
# partially adapted from Alpine/Adélie's Rust APKBUILD
#
# Permission to use rust and cargo trademark is granted.
# See: https://github.com/rust-lang/core-team/issues/4
#
# Always make sure custom distfiles used for bootstrap are
# uploaded to https://repo-default.voidlinux.org/distfiles/
#
pkgname=rust
version=1.77.1
revision=1
hostmakedepends="curl pkg-config python3 tar cargo-bootstrap"
makedepends="libffi-devel ncurses-devel libxml2-devel zlib-devel llvm17-devel"
depends="rust-std gcc"
short_desc="Safe, concurrent, practical systems language"
maintainer="Enno Boland <gottox@voidlinux.org>"
license="MIT, Apache-2.0"
homepage="https://www.rust-lang.org/"
distfiles="https://static.rust-lang.org/dist/rustc-${version}-src.tar.gz"
checksum=ee106e4c569f52dba3b5b282b105820f86bd8f6b3d09c06b8dce82fb1bb3a4a1
lib32disabled=yes
make_check=no # CBA for now
python_version=3 # needed for python files in rust-src

build_options="bindist"
desc_option_bindist="Generate tarballs for bootstrap"

if [ "$XBPS_LIBC" = "musl" ]; then
	hostmakedepends+=" libexecinfo-devel"
fi
if [ "$XBPS_TARGET_LIBC" = "musl" ]; then
	makedepends+=" libexecinfo-devel"
fi

if [ "$CROSS_BUILD" ]; then
	hostmakedepends+=" rust llvm17-devel"
	# These are required for building the buildhost's stage0/1
	hostmakedepends+=" libffi-devel libxml2-devel ncurses-devel zlib-devel"
else
	hostmakedepends+=" rust-bootstrap"
fi

# we need this because cargo verifies checksums of all files in vendor
# crates when it builds and gives us no way to override or update the
# file sanely... so just clear out the file list
_clear_vendor_checksums() {
	sed -i 's/\("files":{\)[^}]*/\1/' vendor/$1/.cargo-checksum.json
}

post_patch() {
	rm -rf src/llvm-project
	if [ "$build_option_bindist" ]; then
		for x in ${FILESDIR}/patches/static-llvm/*.patch; do
			msg_normal "Applying patch $x\n"
			patch -sNp1 -i ${x}
		done
	fi

	# clear out all the checksum nonsense of patched vendor crates
	_clear_vendor_checksums libc
	_clear_vendor_checksums typenum
	_clear_vendor_checksums cc
	_clear_vendor_checksums target-lexicon
	_clear_vendor_checksums tikv-jemallocator
}

do_configure() {
	local _local_rebuild _debug _debug_rustc _rpath _docs _llvm_shared
	local _cross_args

	if [ "$CROSS_BUILD" ]; then
		_local_rebuild="enable"
	else
		_local_rebuild="disable"
	fi

	# disable rustc debug info as it bloats up rust-std significantly
	# set to 1 or 2 if you wish to have debug info for rustc, it won't
	# link on 32-bit platforms though (too big)
	_debug_rustc="0"
	# just disable debug for now
	_debug="0"

	# if true, the binaries will be built with rpath, so the binaries will be
	# usable directly from the build directory, this is not desirable for
	# packaging but is useful when building bootstrap binaries
	if [ "$build_option_bindist" ]; then
		_rpath="enable"
		_docs="disable"
		_llvm_shared="disable"
	else
		_rpath="disable"
		_docs="enable"
		_llvm_shared="enable"
	fi

	if [ "$CROSS_BUILD" ]; then
		_cross_args="--set=target.${RUST_TARGET}.llvm-config=/usr/bin/llvm-config
		 --set=target.${RUST_TARGET}.crt-static=false
		 --set=target.${RUST_TARGET}.cc=${CC}
		 --set=target.${RUST_TARGET}.cxx=${CXX}
		 --set=target.${RUST_TARGET}.ar=${AR}
		 --set=target.${RUST_TARGET}.linker=${CC}"
	fi

	./configure \
		--build="${RUST_BUILD}" \
		--host="${RUST_TARGET}" \
		--target="${RUST_TARGET}" \
		--prefix=/usr \
		--python=python3 \
		--enable-vendor \
		--enable-locked-deps \
		--enable-verbose-tests \
		--disable-full-bootstrap \
		--enable-extended \
		--disable-codegen-tests \
		--disable-dist-src \
		--${_llvm_shared}-llvm-link-shared \
		--${_rpath}-rpath \
		--${_local_rebuild}-local-rebuild \
		--${_docs}-docs \
		--debuginfo-level="${_debug}" \
		--debuginfo-level-rustc="${_debug_rustc}" \
		--debuginfo-level-tests=0 \
		--release-channel=stable \
		--release-description="Void Linux" \
		--llvm-libunwind=no \
		--llvm-config=/usr/bin/llvm-config \
		--tools=clippy,rustdoc,rustfmt,rust-analyzer-proc-macro-srv \
		--set="rust.optimize=true" \
		--set="rust.debug=false" \
		--set="rust.codegen-units=1" \
		--set="rust.codegen-units-std=1" \
		--set="rust.incremental=false" \
		--set="rust.parallel-compiler=false" \
		--set="rust.jemalloc=false" \
		--set="build.submodules=false" \
		--set="build.rustc=/usr/bin/rustc" \
		--set="build.cargo=/usr/bin/cargo" \
		--set="build.optimized-compiler-builtins=false" \
		--set="target.${RUST_BUILD}.crt-static=false" \
		--set="target.${RUST_BUILD}.cc=${CC_host:-$CC}" \
		--set="target.${RUST_BUILD}.cxx=${CXX_host:-$CXX}" \
		--set="target.${RUST_BUILD}.ar=${AR_host:-$AR}" \
		--set="target.${RUST_BUILD}.linker=${CC_host:-$CC}" \
		--set="dist.src-tarball=false" \
		${_cross_args}
}

# Set the correct CFLAGS for the build host, we have to compile libbacktrace
# for it during stage1. Otherwise it attemps to use CFLAGS, which are the CFLAGS
# of the cross host.
do_build() {
	export RUST_BACKTRACE=1
	export JEMALLOC_SYS_WITH_LG_PAGE=16
	export CARGO_HOME="$wrksrc/.cargo"
	export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
	# prevent sysroot from leaking in
	export RUSTFLAGS=""
	env CFLAGS_${RUST_BUILD}="${CFLAGS_host}" \
		CXXFLAGS_${RUST_BUILD}="${CXXFLAGS_host}" \
		CFLAGS_${RUST_TARGET}="${CFLAGS}" \
		CXXFLAGS_${RUST_TARGET}="${CXXFLAGS}" \
		python3 x.py dist --jobs $XBPS_MAKEJOBS
}

do_check() {
	export RUST_BACKTRACE=1

	python3 x.py test ${makejobs} --no-doc --no-fail-fast \
		src/test/codegen \
		src/test/codegen-units \
		src/test/incremental \
		src/test/mir-opt \
		src/test/pretty \
		src/test/run-make \
		src/test/run-make-fulldeps \
		src/test/ui \
		src/test/ui-fulldeps
}

do_install() {
	if [ "$build_option_bindist" ]; then
		mkdir -p ${XBPS_SRCDISTDIR}/distfiles
		install -m 0644 \
			build/dist/rustc-${version}-${RUST_TARGET}.tar.xz \
			build/dist/rust-std-${version}-${RUST_TARGET}.tar.xz \
			${XBPS_SRCDISTDIR}/distfiles
		exit 1
	fi

	vmkdir usr
	tar xf build/dist/rustc-${version}-${RUST_TARGET}.tar.gz \
	 -C "$DESTDIR/usr" --strip-components=2 --exclude=manifest.in
	tar xf build/dist/rust-std-${version}-${RUST_TARGET}.tar.gz \
	 -C "$DESTDIR/usr/lib" --strip-components=3 --exclude=manifest.in
	tar xf build/dist/rustc-dev-${version}-${RUST_TARGET}.tar.gz \
	 -C "$DESTDIR/usr/lib" --strip-components=3 --exclude=manifest.in
	tar xf build/dist/rust-docs-${version}-${RUST_TARGET}.tar.gz \
	 -C "$DESTDIR/usr" --strip-components=2 --exclude=manifest.in
	tar xf build/dist/rust-src-${version}.tar.gz \
	 -C "$DESTDIR/usr" --strip-components=2 --exclude=manifest.in
	tar xf build/dist/rustfmt-${version}-${RUST_TARGET}.tar.gz \
	 -C "$DESTDIR/usr" --strip-components=2 --exclude=manifest.in
	tar xf build/dist/clippy-${version}-${RUST_TARGET}.tar.gz \
	 -C "$DESTDIR/usr" --strip-components=2 --exclude=manifest.in

	vlicense COPYRIGHT
	vlicense LICENSE-APACHE
	vlicense LICENSE-MIT

	cd ${DESTDIR}/usr/lib
	# symlinks instead of copies
	rm *.so
	ln -sf rustlib/${RUST_TARGET}/lib/*.so .
}

rust-doc_package() {
	short_desc+=" - documentation"
	pkg_install() {
		vmove usr/share/doc
	}
}

rust-std_package() {
	short_desc+=" - standard library"
	if [ "$XBPS_TARGET_LIBC" = "musl" ]; then
		depends="libexecinfo-devel"
	fi
	pkg_install() {
		vmove usr/lib/rustlib/${RUST_TARGET}
		vmove usr/lib/rustlib/rustc-src
	}
}

rust-src_package() {
	short_desc+=" - source code"
	pkg_install() {
		vmove usr/lib/rustlib/src
	}
}