]> git.lizzy.rs Git - rust.git/blob - build.sh
Add a feature flag to switch between oldbe and 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 newbe=''
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         "--newbe")
22             newbe='--features newbe'
23             ;;
24         *)
25             echo "Unknown flag '$1'"
26             echo "Usage: ./build.sh [--debug] [--without-sysroot] [--target-dir DIR] [--newbe]"
27             ;;
28     esac
29     shift
30 done
31
32 # Build cg_clif
33 unset CARGO_TARGET_DIR
34 export RUSTFLAGS="-Zrun_dsymutil=no"
35 unamestr=$(uname)
36 if [[ "$unamestr" == 'Linux' ]]; then
37    export RUSTFLAGS='-Clink-arg=-Wl,-rpath=$ORIGIN/../lib '$RUSTFLAGS
38 elif [[ "$unamestr" == 'Darwin' ]]; then
39    export RUSTFLAGS='-Clink-arg=-Wl,-rpath,@loader_path/../lib -Zosx-rpath-install-name '$RUSTFLAGS
40    dylib_ext='dylib'
41 else
42    echo "Unsupported os"
43    exit 1
44 fi
45 if [[ "$CHANNEL" == "release" ]]; then
46     cargo build $newbe --release
47 else
48     cargo build $newbe
49 fi
50
51 rm -rf "$target_dir"
52 mkdir "$target_dir"
53 mkdir "$target_dir"/bin "$target_dir"/lib
54 ln target/$CHANNEL/cg_clif{,_build_sysroot} "$target_dir"/bin
55 ln target/$CHANNEL/*rustc_codegen_cranelift* "$target_dir"/lib
56 ln rust-toolchain scripts/config.sh scripts/cargo.sh "$target_dir"
57
58 if [[ "$build_sysroot" == "1" ]]; then
59     echo "[BUILD] sysroot"
60     export CG_CLIF_INCR_CACHE_DISABLED=1
61     dir=$(pwd)
62     cd "$target_dir"
63     time "$dir/build_sysroot/build_sysroot.sh"
64     cp lib/rustlib/*/lib/libstd-* lib/
65 fi