]> git.lizzy.rs Git - rust.git/blob - build.sh
Disable value 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    dylib_ext='dylib'
38 else
39    echo "Unsupported os $unamestr"
40    exit 1
41 fi
42 if [[ "$CHANNEL" == "release" ]]; then
43     cargo build --release
44 else
45     cargo build
46 fi
47
48 source scripts/ext_config.sh
49
50 rm -rf "$target_dir"
51 mkdir "$target_dir"
52 mkdir "$target_dir"/bin "$target_dir"/lib
53 ln target/$CHANNEL/cg_clif{,_build_sysroot} "$target_dir"/bin
54 ln target/$CHANNEL/*rustc_codegen_cranelift* "$target_dir"/lib
55 ln rust-toolchain scripts/config.sh scripts/cargo.sh "$target_dir"
56
57 mkdir -p "$target_dir/lib/rustlib/$TARGET_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         ;;
68     "clif")
69         echo "[BUILD] sysroot"
70         dir=$(pwd)
71         cd "$target_dir"
72         time "$dir/build_sysroot/build_sysroot.sh"
73         cp lib/rustlib/*/lib/libstd-* lib/
74         ;;
75     *)
76         echo "Unknown sysroot kind \`$build_sysroot\`."
77         echo "The allowed values are:"
78         echo "    none A sysroot that doesn't contain the standard library"
79         echo "    llvm Copy the sysroot from rustc compiled by cg_llvm"
80         echo "    clif Build a new sysroot using cg_clif"
81         exit 1
82 esac