recipes: devel/rust: Downgraded to version 1.64.0
[dragora.git] / recipes / devel / rust / recipe
blobc475d3787a1647e8b4985d593f4c4f995cac530b
1 # Build recipe for rust.
3 # Copyright (c) 2022 Matias Fonzo, <selk@dragora.org>.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 #    http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Exit immediately on any error
18 set -e
20 program=rustc
21 pkgname=rust
22 version=1.64.0
23 release=1
25 # Define a category for the output of the package name
26 pkgcategory=devel
28 tarname=${program}-${version}-src.tar.gz
30 # Set remote source(s) according to the architecture/platform
31 fetch=https://static.rust-lang.org/dist/$tarname
33 rustfetch_date=2022-08-11
35 case $arch in
36 amd64 | x32 )
37     tarname_rust_std_platform=rust-std-1.63.0-x86_64-unknown-linux-musl.tar.xz
38     tarname_rustc_platform=rustc-1.63.0-x86_64-unknown-linux-musl.tar.xz
39     tarname_cargo_platform=cargo-1.63.0-x86_64-unknown-linux-musl.tar.xz
40     fetch="
41 $fetch
42 https://static.rust-lang.org/dist/${rustfetch_date}/$tarname_rust_std_platform
43 https://static.rust-lang.org/dist/${rustfetch_date}/$tarname_rustc_platform
44 https://static.rust-lang.org/dist/${rustfetch_date}/$tarname_cargo_platform
46     ;;
47 i586)
48     tarname_rust_std_platform=
49     tarname_rustc_platform=
50     tarname_cargo_platform=
52     fetch="
53 $fetch
54 https://static.rust-lang.org/dist/${rustfetch_date}/$tarname_rust_std_platform
55 https://static.rust-lang.org/dist/${rustfetch_date}/$tarname_rustc_platform
56 https://static.rust-lang.org/dist/${rustfetch_date}/$tarname_cargo_platform
58     ;;
59 esac
61 description="
62 The Rust programming language.
64 The Rust programming language helps you write faster, more reliable software.
65 High-level ergonomics and low-level control are often at odds in programming
66 language design; Rust challenges that conflict.  Through balancing powerful
67 technical capacity and a great developer experience, Rust gives you the
68 option to control low-level details (such as memory usage) without all the
69 hassle traditionally associated with such control.
72 homepage=https://www.rust-lang.org/
73 license="Apachev2.0, MIT"
75 # Source documentation
76 docs="";        # This build system already installs the documentation.
77 docsdir="${docdir}/${pkgname}-${version}"
79 # The source has a custom directory name
80 srcdir=${program}-${version}-src
82 build()
84     unpack "${tardir}/$tarname"
86     cd "$srcdir"
88     mkdir -p build/cache/$rustfetch_date
89     cp -f \
90      "${tardir}/$tarname_rust_std_platform" \
91      "${tardir}/$tarname_rustc_platform" \
92      "${tardir}/$tarname_cargo_platform" \
93      build/cache/$rustfetch_date
95     # Set sane permissions
96     chmod -R u+w,go-w,a+rX-s .
98     # Apply patches taken from "Void Linux" (Thanks!)
99     for file in "${worktree}"/patches/rust/void/*.patch
100     do
101         if test -f "$file"
102         then
103             echo "    Applying patch $file ..."
104             patch -Np1 -i "$file"
105         fi
106     done
107     unset -v file
109     # Uncomment this only if the build of LLVM is static
110     #rm -rf src/llvm-project
111     #patch -Np1 -i "${worktree}/patches/rust/llvm/llvm-with-dependencies.patch"
113     # We need this because cargo verifies checksums of all files in vendor
114     # crates when it builds and gives us no way to override or update the
115     # file sanely... so just clear out the file list (Thanks to "Void Linux")
116     for postdir in libc typenum cc target-lexicon tikv-jemallocator
117     do
118         sed -i 's/\("files":{\)[^}]*/\1/' vendor/${postdir}/.cargo-checksum.json
119     done
120     unset -v postdir
122     # Insert our custom config.toml
123     cp -f "${worktree}/archive/rust/config.toml" config.toml && \
124      sed -e "s|@prefix@|/usr|" \
125          -e "s|@libdir@|lib${libSuffix}|" \
126          -e "s|@docsdir@|$docsdir|" \
127          -i config.toml
129     # Set flags prior to build
131     CPPFLAGS="$QICPPFLAGS"
132     CFLAGS="$QICFLAGS"
133     CXXFLAGS="$QICXXFLAGS"
134     LDFLAGS="$QILDFLAGS"
135     SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
136     RUST_BACKTRACE=full
138     RUSTFLAGS="$RUSTFLAGS -C link-args=-lffi"
140     export CPPFLAGS CFLAGS CXXFLAGS LDFLAGS SSL_CERT_FILE RUST_BACKTRACE RUSTFLAGS
142     # Build and install Rust
144     python3 ./x.py build
145     DESTDIR="$destdir" python3 x.py install
147     unset -v CPPFLAGS CFLAGS CXXFLAGS LDFLAGS SSL_CERT_FILE RUST_BACKTRACE RUSTFLAGS \
148      rustfetch_date tarname_rust_std_platform tarname_rustc_platform tarname_cargo_platform
150     # Strip remaining binaries and libraries
151     find "$destdir" -type f | xargs file | \
152      awk '/ELF/ && /executable/ || /shared object/' | \
153       cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
155     # Compress and link man pages (if needed)
156     if test -d "${destdir}/$mandir"
157     then
158         (
159             cd "${destdir}/$mandir"
160             find . -type f -exec lzip -9 {} +
161             find . -type l | while read -r file
162             do
163                 ln -sf "$(readlink -- "$file").lz" "${file}.lz"
164                 rm -- "$file"
165             done
166         )
167     fi