5 export CHANNEL="release"
8 while [[ $# != 0 ]]; do
11 export CHANNEL="debug"
22 echo "Unknown flag '$1'"
23 echo "Usage: ./build.sh [--debug] [--sysroot none|clif|llvm] [--target-dir DIR]"
31 unset CARGO_TARGET_DIR
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
39 echo "Unsupported os $unamestr"
42 if [[ "$CHANNEL" == "release" ]]; then
48 source scripts/ext_config.sh
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"
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/"
63 case "$build_sysroot" in
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/"
73 echo "[BUILD] sysroot"
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"
80 cp lib/rustlib/*/lib/libstd-* lib/
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"