Skip to content

Commit 17041e0

Browse files
authored
添加rust的bare bone工具链 (#197)
1 parent 26d84a3 commit 17041e0

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

tools/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ grub-2.06.tar.xz*
22
grub-2.06/
33
arch/i386/legacy/grub/*
44
arch/i386/efi/grub/*
5-
arch/x86_64/efi/grub/*
5+
arch/x86_64/efi/grub/*
6+
7+
*.tar.gz
8+
build/*

tools/init_rust_toolchain.sh

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# 当前脚本用于初始化自定义的Rust工具链
2+
if [ -z "$(which cargo)" ]; then
3+
echo "尚未安装Rust,请先安装Rust"
4+
exit 1
5+
fi
6+
7+
WORK_DIR=$(pwd)
8+
RUST_SRC_VERSION=1.66.0
9+
# 初始化bare bone工具链
10+
DRAGONOS_UNKNOWN_ELF_PATH=$(rustc --print sysroot)/lib/rustlib/x86_64-unknown-dragonos
11+
mkdir -p ${DRAGONOS_UNKNOWN_ELF_PATH}/lib
12+
# 设置工具链配置文件
13+
echo \
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

0 commit comments

Comments
 (0)