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