]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_cranelift/build.sh
Better English for documenting when to use unimplemented!()
[rust.git] / compiler / rustc_codegen_cranelift / 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 mkdir -p "$target_dir/lib/rustlib/$HOST_TRIPLE/lib/"
59 if [[ "$TARGET_TRIPLE" == "x86_64-pc-windows-gnu" ]]; then
60     cp $(rustc --print sysroot)/lib/rustlib/$TARGET_TRIPLE/lib/*.o "$target_dir/lib/rustlib/$TARGET_TRIPLE/lib/"
61 fi
62
63 case "$build_sysroot" in
64     "none")
65         ;;
66     "llvm")
67         cp -r $(rustc --print sysroot)/lib/rustlib/$TARGET_TRIPLE/lib "$target_dir/lib/rustlib/$TARGET_TRIPLE/"
68         if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then
69             cp -r $(rustc --print sysroot)/lib/rustlib/$HOST_TRIPLE/lib "$target_dir/lib/rustlib/$HOST_TRIPLE/"
70         fi
71         ;;
72     "clif")
73         echo "[BUILD] sysroot"
74         dir=$(pwd)
75         cd "$target_dir"
76         time "$dir/build_sysroot/build_sysroot.sh"
77         if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then
78             time TARGET_TRIPLE="$HOST_TRIPLE" "$dir/build_sysroot/build_sysroot.sh"
79         fi
80         cp lib/rustlib/*/lib/libstd-* lib/
81         ;;
82     *)
83         echo "Unknown sysroot kind \`$build_sysroot\`."
84         echo "The allowed values are:"
85         echo "    none A sysroot that doesn't contain the standard library"
86         echo "    llvm Copy the sysroot from rustc compiled by cg_llvm"
87         echo "    clif Build a new sysroot using cg_clif"
88         exit 1
89 esac