xref: /DragonOS/tools/init_rust_toolchain.sh (revision be63f3b2b6b472daa3ee17180aa607409cb9d182)
1# 当前脚本用于初始化自定义的Rust工具链
2if [ -z "$(which cargo)" ]; then
3    echo "尚未安装Rust,请先安装Rust"
4    exit 1
5fi
6
7WORK_DIR=$(pwd)
8RUST_SRC_VERSION=1.66.0
9# 初始化bare bone工具链
10DRAGONOS_UNKNOWN_ELF_PATH=$(rustc --print sysroot)/lib/rustlib/x86_64-unknown-dragonos
11mkdir -p ${DRAGONOS_UNKNOWN_ELF_PATH}/lib
12# 设置工具链配置文件
13echo   \
14"{\
15    \"arch\": \"x86_64\",
16    \"code-model\": \"kernel\",
17    \"cpu\": \"x86-64\",
18    \"os\": \"dragonos\",
19    \"target-endian\": \"little\",
20    \"target-pointer-width\": \"64\",
21    \"target-c-int-width\": \"32\",
22    \"data-layout\": \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128\",
23    \"disable-redzone\": true,
24    \"features\": \"-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float\",
25    \"linker\": \"rust-lld\",
26    \"linker-flavor\": \"ld.lld\",
27    \"llvm-target\": \"x86_64-unknown-none\",
28    \"max-atomic-width\": 64,
29    \"panic-strategy\": \"abort\",
30    \"position-independent-executables\": true,
31    \"relro-level\": \"full\",
32    \"stack-probes\": {
33      \"kind\": \"inline-or-call\",
34      \"min-llvm-version-for-inline\": [
35        16,
36        0,
37        0
38      ]
39    },
40    \"static-position-independent-executables\": true,
41    \"supported-sanitizers\": [
42      \"kcfi\"
43    ],
44    \"target-pointer-width\": \"64\"
45}" > ${DRAGONOS_UNKNOWN_ELF_PATH}/target.json || exit 1
46
47
48# echo   \
49# "{
50#   \"llvm-target\": \"x86_64-unknown-none\",
51#   \"data-layout\": \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\",
52#   \"arch\": \"x86_64\",
53#   \"target-endian\": \"little\",
54#   \"target-pointer-width\": \"64\",
55#   \"target-c-int-width\": \"32\",
56#   \"os\": \"dragonos\",
57#   \"linker\": \"rust-lld\",
58#   \"linker-flavor\": \"ld.lld\",
59#   \"executables\": true,
60#   \"features\": \"-mmx,-sse,+soft-float\",
61#   \"disable-redzone\": true,
62#   \"panic-strategy\": \"abort\"
63# }" > ${DRAGONOS_UNKNOWN_ELF_PATH}/target.json || exit 1
64
65
66# 编译标准库 (仍存在问题,不能编译)
67# mkdir -p build || exit 1
68# cd build
69# if [ ! -d "rust" ]; then
70#     git clone -b $RUST_SRC_VERSION https://github.com/rust-lang/rust.git --depth=1 --recursive || exit 1
71# fi
72
73# cd rust
74# git checkout $RUST_SRC_VERSION
75# git submodule update --init --recursive
76
77# cargo clean
78# export RUST_COMPILER_RT_ROOT=$(pwd)/src/llvm-project/compiler-rt
79# CARGO_PROFILE_RELEASE_DEBUG=0 \
80# CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS=true \
81# RUSTC_BOOTSTRAP=1 \
82# RUSTFLAGS="-Cforce-unwind-tables=yes -Cembed-bitcode=yes" \
83# __CARGO_DEFAULT_LIB_METADATA="stablestd" \
84#     ./x.py build --target x86_64-unknown-dragonos || exit 1
85