rust: update to 1.80.0
[void-pkg.git] / srcpkgs / rust / template
blob9327db52dc3a005bf4bf5a8cf293def44b3f8ab1
1 # Template file for 'rust'
2 # partially adapted from Alpine/Adélie's Rust APKBUILD
4 # Permission to use rust and cargo trademark is granted.
5 # See: https://github.com/rust-lang/core-team/issues/4
7 # Always make sure custom distfiles used for bootstrap are
8 # uploaded to https://repo-default.voidlinux.org/distfiles/
10 pkgname=rust
11 version=1.80.0
12 revision=1
13 hostmakedepends="curl pkg-config python3 tar cargo-bootstrap"
14 makedepends="libffi-devel ncurses-devel libxml2-devel zlib-devel llvm18-devel"
15 depends="rust-std gcc"
16 short_desc="Safe, concurrent, practical systems language"
17 maintainer="Enno Boland <gottox@voidlinux.org>"
18 license="MIT, Apache-2.0"
19 homepage="https://www.rust-lang.org/"
20 distfiles="https://static.rust-lang.org/dist/rustc-${version}-src.tar.gz"
21 checksum=6f606c193f230f6b2cae4576f7b24d50f5f9b25dff11dbf9b22f787d3521d672
22 lib32disabled=yes
23 make_check=no # CBA for now
24 python_version=3 # needed for python files in rust-src
26 build_options="bindist"
27 desc_option_bindist="Generate tarballs for bootstrap"
29 if [ "$XBPS_LIBC" = "musl" ]; then
30         hostmakedepends+=" libexecinfo-devel"
32 if [ "$XBPS_TARGET_LIBC" = "musl" ]; then
33         makedepends+=" libexecinfo-devel"
36 if [ "$CROSS_BUILD" ]; then
37         hostmakedepends+=" rust llvm18-devel"
38         # These are required for building the buildhost's stage0/1
39         hostmakedepends+=" libffi-devel libxml2-devel ncurses-devel zlib-devel"
40 else
41         hostmakedepends+=" rust-bootstrap"
44 # we need this because cargo verifies checksums of all files in vendor
45 # crates when it builds and gives us no way to override or update the
46 # file sanely... so just clear out the file list
47 _clear_vendor_checksums() {
48         sed -i 's/\("files":{\)[^}]*/\1/' vendor/$1/.cargo-checksum.json
51 post_patch() {
52         rm -rf src/llvm-project
53         if [ "$build_option_bindist" ]; then
54                 for x in ${FILESDIR}/patches/static-llvm/*.patch; do
55                         msg_normal "Applying patch $x\n"
56                         patch -sNp1 -i ${x}
57                 done
58         fi
60         # clear out all the checksum nonsense of patched vendor crates
61         _clear_vendor_checksums libc-0.2.155
63         # pre-configure 01-override-config overwrites vendor files
64         _clear_vendor_checksums onig_sys-69.8.1
67 do_configure() {
68         local _local_rebuild _debug _debug_rustc _rpath _docs _llvm_shared
69         local _cross_args
71         if [ "$CROSS_BUILD" ]; then
72                 _local_rebuild="enable"
73         else
74                 _local_rebuild="disable"
75         fi
77         # disable rustc debug info as it bloats up rust-std significantly
78         # set to 1 or 2 if you wish to have debug info for rustc, it won't
79         # link on 32-bit platforms though (too big)
80         _debug_rustc="0"
81         # just disable debug for now
82         _debug="0"
84         # if true, the binaries will be built with rpath, so the binaries will be
85         # usable directly from the build directory, this is not desirable for
86         # packaging but is useful when building bootstrap binaries
87         if [ "$build_option_bindist" ]; then
88                 _rpath="enable"
89                 _docs="disable"
90                 _llvm_shared="disable"
91         else
92                 _rpath="disable"
93                 _docs="enable"
94                 _llvm_shared="enable"
95         fi
97         if [ "$CROSS_BUILD" ]; then
98                 _cross_args="--set=target.${RUST_TARGET}.llvm-config=/usr/bin/llvm-config
99                  --set=target.${RUST_TARGET}.crt-static=false
100                  --set=target.${RUST_TARGET}.cc=${CC}
101                  --set=target.${RUST_TARGET}.cxx=${CXX}
102                  --set=target.${RUST_TARGET}.ar=${AR}
103                  --set=target.${RUST_TARGET}.linker=${CC}"
104         fi
106         ./configure \
107                 --build="${RUST_BUILD}" \
108                 --host="${RUST_TARGET}" \
109                 --target="${RUST_TARGET}" \
110                 --prefix=/usr \
111                 --python=python3 \
112                 --enable-vendor \
113                 --enable-locked-deps \
114                 --enable-verbose-tests \
115                 --disable-full-bootstrap \
116                 --enable-extended \
117                 --disable-codegen-tests \
118                 --disable-dist-src \
119                 --${_llvm_shared}-llvm-link-shared \
120                 --${_rpath}-rpath \
121                 --${_local_rebuild}-local-rebuild \
122                 --${_docs}-docs \
123                 --debuginfo-level="${_debug}" \
124                 --debuginfo-level-rustc="${_debug_rustc}" \
125                 --debuginfo-level-tests=0 \
126                 --release-channel=stable \
127                 --release-description="Void Linux" \
128                 --llvm-libunwind=no \
129                 --llvm-config=/usr/bin/llvm-config \
130                 --tools=clippy,rustdoc,rustfmt,rust-analyzer-proc-macro-srv \
131                 --set="rust.optimize=true" \
132                 --set="rust.debug=false" \
133                 --set="rust.codegen-units=1" \
134                 --set="rust.codegen-units-std=1" \
135                 --set="rust.incremental=false" \
136                 --set="rust.parallel-compiler=false" \
137                 --set="rust.jemalloc=false" \
138                 --set="build.submodules=false" \
139                 --set="build.rustc=/usr/bin/rustc" \
140                 --set="build.cargo=/usr/bin/cargo" \
141                 --set="build.optimized-compiler-builtins=false" \
142                 --set="target.${RUST_BUILD}.crt-static=false" \
143                 --set="target.${RUST_BUILD}.cc=${CC_host:-$CC}" \
144                 --set="target.${RUST_BUILD}.cxx=${CXX_host:-$CXX}" \
145                 --set="target.${RUST_BUILD}.ar=${AR_host:-$AR}" \
146                 --set="target.${RUST_BUILD}.linker=${CC_host:-$CC}" \
147                 --set="dist.src-tarball=false" \
148                 ${_cross_args}
151 # Set the correct CFLAGS for the build host, we have to compile libbacktrace
152 # for it during stage1. Otherwise it attemps to use CFLAGS, which are the CFLAGS
153 # of the cross host.
154 do_build() {
155         export RUST_BACKTRACE=1
156         export JEMALLOC_SYS_WITH_LG_PAGE=16
157         export CARGO_HOME="$wrksrc/.cargo"
158         export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
159         # prevent sysroot from leaking in
160         export RUSTFLAGS=""
161         env CFLAGS_${RUST_BUILD}="${CFLAGS_host}" \
162                 CXXFLAGS_${RUST_BUILD}="${CXXFLAGS_host}" \
163                 CFLAGS_${RUST_TARGET}="${CFLAGS}" \
164                 CXXFLAGS_${RUST_TARGET}="${CXXFLAGS}" \
165                 python3 x.py dist --jobs $XBPS_MAKEJOBS
168 do_check() {
169         export RUST_BACKTRACE=1
171         python3 x.py test ${makejobs} --no-doc --no-fail-fast \
172                 src/test/codegen \
173                 src/test/codegen-units \
174                 src/test/incremental \
175                 src/test/mir-opt \
176                 src/test/pretty \
177                 src/test/run-make \
178                 src/test/run-make-fulldeps \
179                 src/test/ui \
180                 src/test/ui-fulldeps
183 do_install() {
184         if [ "$build_option_bindist" ]; then
185                 mkdir -p ${XBPS_SRCDISTDIR}/distfiles
186                 install -m 0644 \
187                         build/dist/rustc-${version}-${RUST_TARGET}.tar.xz \
188                         build/dist/rust-std-${version}-${RUST_TARGET}.tar.xz \
189                         ${XBPS_SRCDISTDIR}/distfiles
190                 exit 1
191         fi
193         vmkdir usr
194         tar xf build/dist/rustc-${version}-${RUST_TARGET}.tar.gz \
195          -C "$DESTDIR/usr" --strip-components=2 --exclude=manifest.in
196         tar xf build/dist/rust-std-${version}-${RUST_TARGET}.tar.gz \
197          -C "$DESTDIR/usr/lib" --strip-components=3 --exclude=manifest.in
198         tar xf build/dist/rustc-dev-${version}-${RUST_TARGET}.tar.gz \
199          -C "$DESTDIR/usr/lib" --strip-components=3 --exclude=manifest.in
200         tar xf build/dist/rust-docs-${version}-${RUST_TARGET}.tar.gz \
201          -C "$DESTDIR/usr" --strip-components=2 --exclude=manifest.in
202         tar xf build/dist/rust-src-${version}.tar.gz \
203          -C "$DESTDIR/usr" --strip-components=2 --exclude=manifest.in
204         tar xf build/dist/rustfmt-${version}-${RUST_TARGET}.tar.gz \
205          -C "$DESTDIR/usr" --strip-components=2 --exclude=manifest.in
206         tar xf build/dist/clippy-${version}-${RUST_TARGET}.tar.gz \
207          -C "$DESTDIR/usr" --strip-components=2 --exclude=manifest.in
209         vlicense COPYRIGHT
210         vlicense LICENSE-APACHE
211         vlicense LICENSE-MIT
213         cd ${DESTDIR}/usr/lib
214         # symlinks instead of copies
215         rm *.so
216         ln -sf rustlib/${RUST_TARGET}/lib/*.so .
219 rust-doc_package() {
220         short_desc+=" - documentation"
221         pkg_install() {
222                 vmove usr/share/doc
223         }
226 rust-std_package() {
227         short_desc+=" - standard library"
228         if [ "$XBPS_TARGET_LIBC" = "musl" ]; then
229                 depends="libexecinfo-devel"
230         fi
231         pkg_install() {
232                 vmove usr/lib/rustlib/${RUST_TARGET}
233                 vmove usr/lib/rustlib/rustc-src
234         }
237 rust-src_package() {
238         short_desc+=" - source code"
239         pkg_install() {
240                 vmove usr/lib/rustlib/src
241         }