]> git.lizzy.rs Git - rust.git/blob - build.sh
Default to Cranelift newBE
[rust.git] / build.sh
1 #!/bin/bash
2 set -e
3
4 # Settings
5 export CHANNEL="release"
6 build_sysroot=1
7 target_dir='build'
8 oldbe=''
9 while [[ $# != 0 ]]; do
10     case $1 in
11         "--debug")
12             export CHANNEL="debug"
13             ;;
14         "--without-sysroot")
15             build_sysroot=0
16             ;;
17         "--target-dir")
18             target_dir=$2
19             shift
20             ;;
21         "--oldbe")
22             oldbe='--features oldbe'
23             ;;
24         *)
25             echo "Unknown flag '$1'"
26             echo "Usage: ./build.sh [--debug] [--without-sysroot] [--target-dir DIR] [--oldbe]"
27             exit 1
28             ;;
29     esac
30     shift
31 done
32
33 # Build cg_clif
34 unset CARGO_TARGET_DIR
35 export RUSTFLAGS="-Zrun_dsymutil=no"
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='-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 rm -rf "$target_dir"
53 mkdir "$target_dir"
54 mkdir "$target_dir"/bin "$target_dir"/lib
55 ln target/$CHANNEL/cg_clif{,_build_sysroot} "$target_dir"/bin
56 ln target/$CHANNEL/*rustc_codegen_cranelift* "$target_dir"/lib
57 ln rust-toolchain scripts/config.sh scripts/cargo.sh "$target_dir"
58
59 if [[ "$build_sysroot" == "1" ]]; then
60     echo "[BUILD] sysroot"
61     export CG_CLIF_INCR_CACHE_DISABLED=1
62     dir=$(pwd)
63     cd "$target_dir"
64     time "$dir/build_sysroot/build_sysroot.sh"
65     cp lib/rustlib/*/lib/libstd-* lib/
66 fi