1 # Description: The Rust language with Cargo included.
2 # URL: https://www.rust-lang.org/
3 # Maintainer: Danny Rawlins, crux at romster dot me
4 # Depends on: compiler-rt
5 # Optional: ccache libgit2 lld polly sccache
6
7 name=rust
8 version=1.66.0
9 _date=2022-11-03
10 _rustc=1.65.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-gnu.tar.xz
16 https://static.rust-lang.org/dist/$_date/rustc-$_rustc-x86_64-unknown-linux-gnu.tar.xz
17 https://static.rust-lang.org/dist/$_date/cargo-$_cargo-x86_64-unknown-linux-gnu.tar.xz
18 0001-bootstrap-Change-libexec-dir.patch
19 0002-compiler-Change-LLVM-targets.patch)
20
21 unpack_source() {
22 for file in ${source[@]}; do
23 case ${file##*/} in
24 rustc-${version}-src.tar.xz)
25 echo "Unpacking $(get_filename $file)";
26 bsdtar -p -o -C ${SRC} -xf $(get_filename $file) ;;
27 *.tar.xz)
28 echo "Copying $(get_filename $file)";
29 mkdir -p ${SRC}/${name}c-$version-src/build/cache/${_date} || true
30 cp $(get_filename $file) ${SRC}/${name}c-$version-src/build/cache/${_date} ;;
31 *)
32 cp $(get_filename $file) ${SRC} ;;
33 esac
34 done
35 }
36
37 _check_version() {
38 local ERROR
39 local DATE="$(awk '/^.*"date": / {gsub(/"|,/, "", $2); print $2 }' $SRC/${name}c-$version-src/src/stage0.json)"
40 local RUSTC="$(awk '/^.*"version": / {gsub(/"|,/, "", $2); print $2 }' $SRC/${name}c-$version-src/src/stage0.json)"
41
42 printf '\033[0;32m%s\033[0m\n' "Checking versions for bootstrap compiler.."
43 printf '\033[0;32m%s\033[0m\n' "Got _date = $_date && _rustc = $_rustc"
44
45 if [ "$DATE" != "$_date" ]; then
46 printf '\e[1;31m%-6s\e[m\n' "Error: _date $_date != $DATE"
47 ERROR=1
48 fi
49 if [ "$RUSTC" != "$_rustc" ]; then
50 printf '\e[1;31m%-6s\e[m\n' "Error: _rustc $_rustc != $RUSTC"
51 ERROR=1
52 fi
53
54 [ $ERROR ] && exit 1
55 printf '\033[0;32m%s\033[0m\n' "Versions check out! Proceeding.."
56 unset DATE RUSTC ERROR
57 }
58
59 build() {
60 _check_version
61
62 cd "${name}c-$version-src"
63
64 # Patch cargo so credential helpers are in /usr/lib instead of /usr/libexec
65 patch -p1 -i $SRC/0001-bootstrap-Change-libexec-dir.patch
66
67 # Use our *-pc-linux-gnu targets, making LTO with clang simpler
68 patch -p1 -i $SRC/0002-compiler-Change-LLVM-targets.patch
69
70 cat <<- EOF > $SRC/config.toml
71 changelog-seen = 2
72
73 [llvm]
74 ninja = true
75 link-shared = true
76 @POLLY@
77 @CCACHE@
78
79 [install]
80 prefix = "/usr"
81
82 [rust]
83 # LLVM crashes when passing an object through ThinLTO twice. This is triggered
84 # when using rust code in cross-language LTO if libstd was built using ThinLTO.
85 # http://blog.llvm.org/2019/09/closing-gap-cross-language-lto-between.html
86 # https://github.com/rust-lang/rust/issues/54872
87 codegen-units-std = 1
88 debuginfo-level-std = 2
89 codegen-tests = false
90
91 description = "CRUX"
92 channel = "stable"
93 parallel-compiler = true
94 rpath = false
95 optimize = true
96 @LLD@
97
98 [build]
99 target = ["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"]
100 tools = ["cargo", "clippy", "rustfmt", "analysis", "src", "rust-demangler", "rust-analyzer"]
101 docs = false
102 extended = true
103 sanitizers = true
104 profiler = true
105 vendor = true
106 python = "/usr/bin/python3"
107 @CARGO@
108 @RUST@
109 @RUSTFMT@
110
111 [target.x86_64-unknown-linux-gnu]
112 llvm-config = "/usr/bin/llvm-config"
113 llvm-filecheck = "/usr/bin/FileCheck"
114 cc = "/usr/bin/gcc"
115 cxx = "/usr/bin/g++"
116 ar = "/usr/bin/gcc-ar"
117 ranlib = "/usr/bin/gcc-ranlib"
118
119 [target.i686-unknown-linux-gnu]
120 cc = "/usr/bin/gcc"
121 cxx = "/usr/bin/g++"
122 ar = "/usr/bin/gcc-ar"
123 ranlib = "/usr/bin/gcc-ranlib"
124 EOF
125
126 if [ -e '/usr/bin/rustc' ]; then
127 if [[ -z "$(/usr/bin/ldd /usr/bin/rustc | egrep '.*libLLVM.*.so => not found')" && \
128 -z "$(/usr/bin/ldd /usr/bin/cargo | egrep 'libgit2.so.* => not found')" ]]; then
129
130 sed -e 's|@CARGO@|cargo = "/usr/bin/cargo"|' \
131 -e 's|@RUST@|rustc = "/usr/bin/rustc"|' \
132 -e 's|@RUSTFMT@|rustfmt = "/usr/bin/rustfmt"|' \
133 -i $SRC/config.toml
134 else
135 sed -e 's|@CARGO@||' -e 's|@RUST@||' -e 's|@RUSTFMT@||' -i $SRC/config.toml
136 printf "\e[031mShared library missing, not using system rust to bootstrap.\033[0m\n"
137 fi
138 else
139 sed -e 's|@CARGO@||' -e 's|@RUST@||' -e 's|@RUSTFMT@||' -i $SRC/config.toml
140 fi
141
142 if [ -e '/usr/bin/ccache' ]; then
143 sed -e 's|@CCACHE@|ccache = "/usr/bin/ccache"|' -i $SRC/config.toml
144 PATH=$(echo ${PATH} | awk -v RS=: -v ORS=: '/ccache/ {next} {print}' | sed 's/:*$//')
145 else
146 sed -e 's|@CCACHE@||' -i $SRC/config.toml
147 fi
148
149 prt-get isinst lld && sed -e 's|@LLD@|use-lld = true|' -i $SRC/config.toml || sed -e 's|@LLD@||' -i $SRC/config.toml
150 prt-get isinst polly && sed -e 's|@POLLY@|polly = true|' -i $SRC/config.toml || sed -e 's|@POLLY@||' -i $SRC/config.toml
151
152 cat $SRC/config.toml
153
154 mkdir "$PKGMK_SOURCE_DIR/rust" || true
155 export CARGO_HOME="$PKGMK_SOURCE_DIR/rust"
156
157 if [ -e '/usr/bin/sccache' ]; then
158 export RUSTC_WRAPPER='/usr/bin/sccache'
159 export SCCACHE_IDLE_TIMEOUT='1500'
160 fi
161
162 #error: field is never read: `id`
163 # --> src/bootstrap/lib.rs:280:5
164 # = note: `-D dead-code` implied by `-D warnings`
165 export RUSTFLAGS+=' -A dead_code'
166
167 export LIBGIT2_NO_PKG_CONFIG=1
168 export RUST_BACKTRACE=full
169 /usr/bin/python3 ./x.py build --config="${SRC}"/config.toml -j ${JOBS-1}
170 DESTDIR=$PKG /usr/bin/python3 ./x.py --config="${SRC}"/config.toml install
171
172 [ -e '/usr/bin/zsh' ] || rm -r $PKG/usr/share/zsh
173
174 # cleanup
175 rm -r $PKG/usr/share/doc
176 rm -r $PKG/etc
177 rm $PKG/usr/lib/rustlib/{components,manifest-rustc,rust-installer-version,uninstall.sh}
178
179 # Remove analysis data for libs that weren't installed
180 local file lib
181 while read -rd '' file; do
182 lib="${file%.json}.rlib"
183 lib="${lib/\/analysis\///lib/}"
184 if [[ ! -e $lib ]]; then
185 echo "missing '$lib'"
186 rm -v "$file"
187 fi
188 done < <(find "$PKG/usr/lib/rustlib" -path '*/analysis/*.json' -print0)
189
190 install -d $PKG/etc/revdep.d
191 echo "/usr/lib/rustlib/i686-unknown-linux-gnu/lib" > $PKG/etc/revdep.d/$name
192 }
|