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