blob: e0b6597286ff5b0b06212473d42d14b3a701b2f6 (
plain)
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: llvm
5 # Optional: sccache
6
7 name=rust
8 version=1.48.0
9 _date=2020-10-08
10 _rustc=1.47.0
11 _cargo=0.48.0
12 _llvm=11.0.0
13 release=1
14 source=(
15 https://static.rust-lang.org/dist/${name}c-$version-src.tar.xz
16 https://static.rust-lang.org/dist/$_date/rust-std-$_rustc-x86_64-unknown-linux-gnu.tar.xz
17 https://static.rust-lang.org/dist/$_date/rustc-$_rustc-x86_64-unknown-linux-gnu.tar.xz
18 https://static.rust-lang.org/dist/$_date/cargo-$_cargo-x86_64-unknown-linux-gnu.tar.xz
19 https://github.com/llvm/llvm-project/releases/download/llvmorg-$_llvm/compiler-rt-$_llvm.src.tar.xz
20 )
21
22 unpack_source() {
23 for file in ${source[@]}; do
24 case ${file##*/} in
25 rustc-${version}-src.tar.xz|compiler-rt-${_llvm}.src.tar.xz)
26 echo "Unpacking $(get_filename $file)";
27 bsdtar -p -o -C ${SRC} -xf $(get_filename $file) ;;
28 *.tar.xz)
29 echo "Copying $(get_filename $file)";
30 mkdir -p ${SRC}/${name}c-$version-src/build/cache/${_date} || true
31 cp $(get_filename $file) ${SRC}/${name}c-$version-src/build/cache/${_date} ;;
32 *)
33 cp $(get_filename $file) ${SRC} ;;
34 esac
35 done
36 }
37
38 build() {
39 cd "${name}c-$version-src"
40
41 local ERROR
42 local DATE="$(awk '/^date: / { print $2 }' src/stage0.txt)"
43 local RUSTC="$(awk '/^rustc: / { print $2 }' src/stage0.txt)"
44 local CARGO="$(awk '/^cargo: / { print $2 }' src/stage0.txt)"
45 if [ "$DATE" != "$_date" ]; then
46 printf "\e[031mError: _date $_date != $DATE\033[0m\n"
47 ERROR=1
48 fi
49 if [ "$RUSTC" != "$_rustc" ]; then
50 printf "\e[031mError: _rustc $_rustc != $RUSTC\033[0m\n"
51 ERROR=1
52 fi
53 if [ "$CARGO" != "$_cargo" ]; then
54 printf "\e[031mError: _cargo $_cargo != $CARGO\033[0m\n"
55 ERROR=1
56 fi
57 [ $ERROR ] && exit 1
58 unset DATE RUSTC CARGO ERROR
59
60 cat <<- EOF > $SRC/config.toml
61 [llvm]
62 ninja = true
63 link-shared = true
64
65 [install]
66 prefix = "/usr"
67
68 [rust]
69 channel = "stable"
70 rpath = false
71 codegen-units-std = 1
72 debuginfo-level-std = 2
73
74 [build]
75 target = ["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"]
76 tools = ["cargo", "rls", "clippy", "miri", "rustfmt", "analysis", "src"]
77 docs = false
78 extended = true
79 sanitizers = false
80 profiler = true
81 vendor = true
82 python = "/usr/bin/python3"
83 @CARGO@
84 @RUST@
85
86 [target.x86_64-unknown-linux-gnu]
87 llvm-config = "/usr/bin/llvm-config"
88 EOF
89
90 if [ -e '/usr/bin/rustc' ]; then
91 if [ -z "$(/usr/bin/ldd /usr/bin/rustc | egrep '.*libLLVM.*.so => not found')" ]; then
92 sed -e 's|@CARGO@|cargo = "/usr/bin/cargo"|' \
93 -e 's|@RUST@|rustc = "/usr/bin/rustc"|' \
94 -i $SRC/config.toml
95 else
96 sed -e 's|@CARGO@||' -e 's|@RUST@||' -i $SRC/config.toml
97 printf "\e[031mllvm broken symlink detected, not using system rust to bootstrap\033[0m\n"
98 fi
99 else
100 sed -e 's|@CARGO@||' -e 's|@RUST@||' -i $SRC/config.toml
101 fi
102
103 cat $SRC/config.toml
104
105 mkdir "$PKGMK_SOURCE_DIR/rust" || true
106 export CARGO_HOME="$PKGMK_SOURCE_DIR/rust"
107
108 if [ -e '/usr/bin/sccache' ]; then
109 export RUSTC_WRAPPER='/usr/bin/sccache'
110 export SCCACHE_IDLE_TIMEOUT='1500'
111 fi
112
113 export RUST_BACKTRACE=1
114 export RUST_COMPILER_RT_ROOT="$SRC/compiler-rt-$_llvm.src"
115 /usr/bin/python3 ./x.py build --config="${SRC}"/config.toml -j $(nproc)
116 DESTDIR=$PKG /usr/bin/python3 ./x.py --config="${SRC}"/config.toml install
117
118 [ -e '/usr/bin/zsh' ] || rm -r $PKG/usr/share/zsh
119
120 # cleanup
121 rm -r $PKG/usr/share/doc
122 rm -r $PKG/etc
123 rm $PKG/usr/lib/rustlib/{components,manifest-rustc,rust-installer-version,uninstall.sh}
124
125 # Remove analysis data for libs that weren't installed
126 local file lib
127 while read -rd '' file; do
128 lib="${file%.json}.rlib"
129 lib="${lib/\/analysis\///lib/}"
130 if [[ ! -e $lib ]]; then
131 echo "missing '$lib'"
132 rm -v "$file"
133 fi
134 done < <(find "$PKG/usr/lib/rustlib" -path '*/analysis/*.json' -print0)
135
136 install -d $PKG/etc/revdep.d
137 echo "/usr/lib/rustlib/i686-unknown-linux-gnu/lib" > $PKG/etc/revdep.d/rust
138 }
|