]> git.lizzy.rs Git - rust.git/blob - build.sh
Include rustc and cranelift version in debuginfo
[rust.git] / build.sh
1 #!/usr/bin/env bash
2 set -e
3
4 # Settings
5 export CHANNEL="release"
6 build_sysroot="clif"
7 target_dir='build'
8 while [[ $# != 0 ]]; do
9     case $1 in
10         "--debug")
11             export CHANNEL="debug"
12             ;;
13         "--sysroot")
14             build_sysroot=$2
15             shift
16             ;;
17         "--target-dir")
18             target_dir=$2
19             shift
20             ;;
21         *)
22             echo "Unknown flag '$1'"
23             echo "Usage: ./build.sh [--debug] [--sysroot none|clif|llvm] [--target-dir DIR]"
24             exit 1
25             ;;
26     esac
27     shift
28 done
29
30 # Build cg_clif
31 unset CARGO_TARGET_DIR
32 unamestr=$(uname)
33 if [[ "$unamestr" == 'Linux' || "$unamestr" == "FreeBSD" ]]; then
34    export RUSTFLAGS='-Clink-arg=-Wl,-rpath=$ORIGIN/../lib '$RUSTFLAGS
35 elif [[ "$unamestr" == 'Darwin' ]]; then
36    export RUSTFLAGS='-Csplit-debuginfo=unpacked -Clink-arg=-Wl,-rpath,@loader_path/../lib -Zosx-rpath-install-name '$RUSTFLAGS
37 else
38    echo "Unsupported os $unamestr"
39    exit 1
40 fi
41 if [[ "$CHANNEL" == "release" ]]; then
42     cargo build --release
43 else
44     cargo build
45 fi
46
47 source scripts/ext_config.sh
48
49 rm -rf "$target_dir"
50 mkdir "$target_dir"
51 mkdir "$target_dir"/bin "$target_dir"/lib
52 ln target/$CHANNEL/cg_clif{,_build_sysroot} "$target_dir"/bin
53 ln target/$CHANNEL/*rustc_codegen_cranelift* "$target_dir"/lib
54 ln rust-toolchain scripts/config.sh scripts/cargo.sh "$target_dir"
55
56 mkdir -p "$target_dir/lib/rustlib/$TARGET_TRIPLE/lib/"
57 mkdir -p "$target_dir/lib/rustlib/$HOST_TRIPLE/lib/"
58 if [[ "$TARGET_TRIPLE" == "x86_64-pc-windows-gnu" ]]; then
59     cp $(rustc --print sysroot)/lib/rustlib/$TARGET_TRIPLE/lib/*.o "$target_dir/lib/rustlib/$TARGET_TRIPLE/lib/"
60 fi
61
62 case "$build_sysroot" in
63     "none")
64         ;;
65     "llvm")
66         cp -r $(rustc --print sysroot)/lib/rustlib/$TARGET_TRIPLE/lib "$target_dir/lib/rustlib/$TARGET_TRIPLE/"
67         if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then
68             cp -r $(rustc --print sysroot)/lib/rustlib/$HOST_TRIPLE/lib "$target_dir/lib/rustlib/$HOST_TRIPLE/"
69         fi
70         ;;
71     "clif")
72         echo "[BUILD] sysroot"
73         dir=$(pwd)
74         cd "$target_dir"
75         time "$dir/build_sysroot/build_sysroot.sh"
76         if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then
77             time TARGET_TRIPLE="$HOST_TRIPLE" "$dir/build_sysroot/build_sysroot.sh"
78         fi
79         cp lib/rustlib/*/lib/libstd-* lib/
80         ;;
81     *)
82         echo "Unknown sysroot kind \`$build_sysroot\`."
83         echo "The allowed values are:"
84         echo "    none A sysroot that doesn't contain the standard library"
85         echo "    llvm Copy the sysroot from rustc compiled by cg_llvm"
86         echo "    clif Build a new sysroot using cg_clif"
87         exit 1
88 esac