]> git.lizzy.rs Git - rust.git/blob - build.sh
Split config.sh and add support for copying the mingw runtime objects
[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 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='-Csplit-debuginfo=unpacked -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 $oldbe --release
47 else
48     cargo build $oldbe
49 fi
50
51 source scripts/ext_config.sh
52
53 rm -rf "$target_dir"
54 mkdir "$target_dir"
55 mkdir "$target_dir"/bin "$target_dir"/lib
56 ln target/$CHANNEL/cg_clif{,_build_sysroot} "$target_dir"/bin
57 ln target/$CHANNEL/*rustc_codegen_cranelift* "$target_dir"/lib
58 ln rust-toolchain scripts/config.sh scripts/cargo.sh "$target_dir"
59
60 mkdir -p "$target_dir/lib/rustlib/$TARGET_TRIPLE/lib/"
61 if [[ "$TARGET_TRIPLE" == "x86_64-pc-windows-gnu" ]]; then
62     cp $(rustc --print sysroot)/lib/rustlib/$TARGET_TRIPLE/lib/*.o "$target_dir/lib/rustlib/$TARGET_TRIPLE/lib/"
63 fi
64
65 if [[ "$build_sysroot" == "1" ]]; then
66     echo "[BUILD] sysroot"
67     export CG_CLIF_INCR_CACHE_DISABLED=1
68     dir=$(pwd)
69     cd "$target_dir"
70     time "$dir/build_sysroot/build_sysroot.sh"
71     cp lib/rustlib/*/lib/libstd-* lib/
72 fi