Pkgfile (7070B)
1 # Description: The Rust language with Cargo included. 2 # URL: https://www.rust-lang.org/ 3 # Maintainer: Emmett1, emmett1 dot 2miligrams at protonmail dot com 4 # Depends on: clang 5 # Optional: ccache libgit2 lld polly sccache 6 7 name=rust 8 version=1.88.0 9 _date=2025-04-03 10 _rustc=1.86.0 11 _cargo=$_rustc 12 release=1 13 14 source=(https://static.rust-lang.org/dist/${name}c-$version-src.tar.xz 15 https://static.rust-lang.org/dist/$_date/rust-std-$_rustc-x86_64-unknown-linux-musl.tar.xz 16 https://static.rust-lang.org/dist/$_date/rustc-$_rustc-x86_64-unknown-linux-musl.tar.xz 17 https://static.rust-lang.org/dist/$_date/cargo-$_cargo-x86_64-unknown-linux-musl.tar.xz 18 0001-bootstrap-Change-libexec-dir.patch 19 0002-bootstrap-Change-bash-completion-dir.patch 20 0003-compiler-Change-LLVM-targets.patch 21 0004-compiler-Use-wasm-ld-for-wasm-targets.patch 22 fix-linux_musl_base.patch 23 fix-curl.patch) 24 25 unpack_source() { 26 for file in ${source[@]}; do 27 case ${file##*/} in 28 rustc-${version}-src.tar.xz) 29 echo "Unpacking $(get_filename $file)"; 30 bsdtar -p -o -C ${SRC} -xf $(get_filename $file) ;; 31 *.tar.xz) 32 echo "Copying $(get_filename $file)"; 33 mkdir -p ${SRC}/${name}c-$version-src/build/cache/${_date} || true 34 cp $(get_filename $file) ${SRC}/${name}c-$version-src/build/cache/${_date} ;; 35 *) 36 cp $(get_filename $file) ${SRC} ;; 37 esac 38 done 39 } 40 41 _check_version() { 42 local ERROR 43 local DATE="$(awk -F'=' '/^compiler_date=/ {print $2}' $SRC/${name}c-$version-src/src/stage0)" 44 local RUSTC="$(awk -F'=' '/^compiler_version=/ {print $2}' $SRC/${name}c-$version-src/src/stage0)" 45 46 printf '\033[0;32m%s\033[0m\n' "Checking versions for bootstrap compiler.." 47 printf '\033[0;32m%s\033[0m\n' "Got _date = $_date && _rustc = $_rustc" 48 49 if [ "$DATE" != "$_date" ]; then 50 printf '\e[1;31m%-6s\e[m\n' "Error: _date $_date != $DATE" 51 ERROR=1 52 fi 53 if [ "$RUSTC" != "$_rustc" ]; then 54 printf '\e[1;31m%-6s\e[m\n' "Error: _rustc $_rustc != $RUSTC" 55 ERROR=1 56 fi 57 58 [ $ERROR ] && exit 1 59 printf '\033[0;32m%s\033[0m\n' "Versions check out! Proceeding.." 60 unset DATE RUSTC ERROR 61 } 62 63 build() { 64 _check_version 65 66 cd "${name}c-$version-src" 67 68 patch -p1 -i $SRC/0001-bootstrap-Change-libexec-dir.patch 69 patch -p1 -i $SRC/0002-bootstrap-Change-bash-completion-dir.patch 70 patch -p1 -i $SRC/0003-compiler-Change-LLVM-targets.patch 71 patch -p1 -i $SRC/0004-compiler-Use-wasm-ld-for-wasm-targets.patch 72 patch -p1 -i $SRC/fix-curl.patch 73 patch -p1 -i $SRC/fix-linux_musl_base.patch 74 75 sed -i 's/\(crt_static_default = \)true/\1false/' compiler/rustc_target/src/spec/base/linux_musl.rs 76 sed -i 's/\("files":{\)[^}]*/\1/' vendor/curl-sys-0.4.52+curl-7.81.0/.cargo-checksum.json 77 sed -i 's/\("files":{\)[^}]*/\1/' vendor/curl-sys-0.4.78+curl-8.11.0/.cargo-checksum.json 78 sed -i 's/\("files":{\)[^}]*/\1/' vendor/curl-sys-0.4.80+curl-8.12.1/.cargo-checksum.json 79 80 cat <<- EOF > $SRC/config.toml 81 change-id = 102579 82 83 [llvm] 84 ninja = true 85 link-shared = true 86 download-ci-llvm = false 87 @POLLY@ 88 @CCACHE@ 89 90 [install] 91 prefix = "/usr" 92 93 [rust] 94 # LLVM crashes when passing an object through ThinLTO twice. This is triggered 95 # when using rust code in cross-language LTO if libstd was built using ThinLTO. 96 # http://blog.llvm.org/2019/09/closing-gap-cross-language-lto-between.html 97 # https://github.com/rust-lang/rust/issues/54872 98 codegen-units-std = 1 99 debuginfo-level-std = 2 100 codegen-tests = false 101 backtrace-on-ice = true 102 jemalloc = false 103 remap-debuginfo = false 104 105 description = "CRUX" 106 channel = "stable" 107 rpath = false 108 optimize = true 109 codegen-backends = ["llvm"] 110 @LLD@ 111 112 [build] 113 build = "x86_64-unknown-linux-musl" 114 host = [ "x86_64-unknown-linux-musl" ] 115 target = [ "x86_64-unknown-linux-musl" ] 116 tools = ["cargo", 117 "clippy", 118 "rustfmt", 119 "analysis", 120 "src", 121 "rust-demangler", 122 "rust-analyzer", 123 "rust-analyzer-proc-macro-srv", 124 "rustdoc"] 125 docs = false 126 extended = true 127 sanitizers = false 128 profiler = false 129 vendor = true 130 locked-deps = true 131 python = "/usr/bin/python3" 132 optimized-compiler-builtins = true 133 @CARGO@ 134 @RUST@ 135 @RUSTFMT@ 136 137 [target.x86_64-unknown-linux-musl] 138 crt-static = false 139 llvm-config = "/usr/bin/llvm-config" 140 llvm-filecheck = "/usr/bin/FileCheck" 141 cc = @TARGETCC@ 142 cxx = @TARGETCXX@ 143 ar = @TARGETAR@ 144 ranlib = @TARGETRANLIB@ 145 EOF 146 147 if [ -e '/usr/bin/rustc' ]; then 148 if ! /usr/bin/ldd /usr/bin/rustc | grep -q -E '.*not found'; then 149 sed -e 's|@CARGO@|cargo = "/usr/bin/cargo"|' \ 150 -e 's|@RUST@|rustc = "/usr/bin/rustc"|' \ 151 -e 's|@RUSTFMT@|rustfmt = "/usr/bin/rustfmt"|' \ 152 -i $SRC/config.toml 153 else 154 sed -e 's|@CARGO@||' -e 's|@RUST@||' -e 's|@RUSTFMT@||' -i $SRC/config.toml 155 printf "\e[031mShared library missing, not using system rust to bootstrap.\033[0m\n" 156 fi 157 else 158 sed -e 's|@CARGO@||' -e 's|@RUST@||' -e 's|@RUSTFMT@||' -i $SRC/config.toml 159 fi 160 161 if [ -e '/usr/bin/ccache' ]; then 162 sed -e 's|@CCACHE@|ccache = "/usr/bin/ccache"|' -i $SRC/config.toml 163 PATH=$(echo ${PATH} | awk -v RS=: -v ORS=: '/ccache/ {next} {print}' | sed 's/:*$//') 164 else 165 sed -e 's|@CCACHE@||' -i $SRC/config.toml 166 fi 167 168 if prt-get isinst clang lld; then 169 sed -e 's|@TARGETCC@|"clang"|g' -e 's|@TARGETCXX@|"clang++"|g' -e 's|@TARGETAR@|"llvm-ar"|g' -e 's|@TARGETRANLIB@|"llvm-ranlib"|g' -i $SRC/config.toml 170 else 171 sed -e 's|@TARGETCC@|"gcc"|g' -e 's|@TARGETCXX@|"g++"|g' -e 's|@TARGETAR@|"gcc-ar"|g' -e 's|@TARGETRANLIB@|"gcc-ranlib"|g' -i $SRC/config.toml 172 fi 173 prt-get isinst lld && sed -e 's|@LLD@|use-lld = true\nlld = true|' -i $SRC/config.toml || sed -e 's|@LLD@||' -i $SRC/config.toml 174 prt-get isinst polly && sed -e 's|@POLLY@|polly = true|' -i $SRC/config.toml || sed -e 's|@POLLY@||' -i $SRC/config.toml 175 176 cat $SRC/config.toml 177 178 mkdir "$PKGMK_SOURCE_DIR/rust" || true 179 export CARGO_HOME="$PKGMK_SOURCE_DIR/rust" 180 181 ## sccache currently leads to errors 182 #if [ -e '/usr/bin/sccache' ]; then 183 # export RUSTC_WRAPPER='/usr/bin/sccache' 184 # export SCCACHE_IDLE_TIMEOUT='1500' 185 #fi 186 187 #error: field is never read: `id` 188 # --> src/bootstrap/lib.rs:280:5 189 # = note: `-D dead-code` implied by `-D warnings` 190 export RUSTFLAGS+=' -A dead_code' 191 192 { [ ! -e /usr/include/libssh2.h ] || 193 export LIBSSH2_SYS_USE_PKG_CONFIG=1; } 194 export RUST_BACKTRACE=full 195 /usr/bin/python3 ./x.py build --config="${SRC}"/config.toml -j ${JOBS-1} 196 DESTDIR=$PKG /usr/bin/python3 ./x.py --config="${SRC}"/config.toml install 197 198 prt-get isinst bash-completion || rm -r $PKG/usr/share/bash-completion 199 prt-get isinst zsh || rm -r $PKG/usr/share/zsh 200 201 install -d $PKG/etc/revdep.d 202 echo "/usr/lib/rustlib/i686-unknown-linux-musl/lib" > $PKG/etc/revdep.d/$name 203 204 # cleanup 205 rm -r $PKG/usr/share/doc 206 rm $PKG/usr/lib/rustlib/{components,manifest-rustc,rust-installer-version,uninstall.sh} 207 208 # Remove analysis data for libs that weren't installed 209 local file lib 210 while read -rd '' file; do 211 lib="${file%.json}.rlib" 212 lib="${lib/\/analysis\///lib/}" 213 if [[ ! -e $lib ]]; then 214 echo "missing '$lib'" 215 rm -v "$file" 216 fi 217 done < <(find "$PKG/usr/lib/rustlib" -path '*/analysis/*.json' -print0) 218 219 find $PKG/usr -name "*.old" -delete 220 rm $PKG/usr/lib/rustlib/{install.log,manifest-*} 221 }