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
25 # Define a category for the output of the package name
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
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
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
48 tarname_rust_std_platform=
49 tarname_rustc_platform=
50 tarname_cargo_platform=
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
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
84 unpack "${tardir}/$tarname"
88 mkdir -p build/cache/$rustfetch_date
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
103 echo " Applying patch $file ..."
104 patch -Np1 -i "$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
118 sed -i 's/\("files":{\)[^}]*/\1/' vendor/${postdir}/.cargo-checksum.json
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|" \
129 # Set flags prior to build
131 CPPFLAGS="$QICPPFLAGS"
133 CXXFLAGS="$QICXXFLAGS"
135 SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
138 RUSTFLAGS="$RUSTFLAGS -C link-args=-lffi"
140 export CPPFLAGS CFLAGS CXXFLAGS LDFLAGS SSL_CERT_FILE RUST_BACKTRACE RUSTFLAGS
142 # Build and install Rust
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"
159 cd "${destdir}/$mandir"
160 find . -type f -exec lzip -9 {} +
161 find . -type l | while read -r file
163 ln -sf "$(readlink -- "$file").lz" "${file}.lz"