Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加rust的bare bone工具链 #197

Merged
merged 1 commit into from
Mar 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tools/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ grub-2.06.tar.xz*
grub-2.06/
arch/i386/legacy/grub/*
arch/i386/efi/grub/*
arch/x86_64/efi/grub/*
arch/x86_64/efi/grub/*

*.tar.gz
build/*
84 changes: 84 additions & 0 deletions tools/init_rust_toolchain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# 当前脚本用于初始化自定义的Rust工具链
if [ -z "$(which cargo)" ]; then
echo "尚未安装Rust,请先安装Rust"
exit 1
fi

WORK_DIR=$(pwd)
RUST_SRC_VERSION=1.66.0
# 初始化bare bone工具链
DRAGONOS_UNKNOWN_ELF_PATH=$(rustc --print sysroot)/lib/rustlib/x86_64-unknown-dragonos
mkdir -p ${DRAGONOS_UNKNOWN_ELF_PATH}/lib
# 设置工具链配置文件
echo \
"{\
\"arch\": \"x86_64\",
\"code-model\": \"kernel\",
\"cpu\": \"x86-64\",
\"os\": \"dragonos\",
\"target-endian\": \"little\",
\"target-pointer-width\": \"64\",
\"target-c-int-width\": \"32\",
\"data-layout\": \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128\",
\"disable-redzone\": true,
\"features\": \"-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float\",
\"linker\": \"rust-lld\",
\"linker-flavor\": \"ld.lld\",
\"llvm-target\": \"x86_64-unknown-none\",
\"max-atomic-width\": 64,
\"panic-strategy\": \"abort\",
\"position-independent-executables\": true,
\"relro-level\": \"full\",
\"stack-probes\": {
\"kind\": \"inline-or-call\",
\"min-llvm-version-for-inline\": [
16,
0,
0
]
},
\"static-position-independent-executables\": true,
\"supported-sanitizers\": [
\"kcfi\"
],
\"target-pointer-width\": \"64\"
}" > ${DRAGONOS_UNKNOWN_ELF_PATH}/target.json || exit 1


# echo \
# "{
# \"llvm-target\": \"x86_64-unknown-none\",
# \"data-layout\": \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\",
# \"arch\": \"x86_64\",
# \"target-endian\": \"little\",
# \"target-pointer-width\": \"64\",
# \"target-c-int-width\": \"32\",
# \"os\": \"dragonos\",
# \"linker\": \"rust-lld\",
# \"linker-flavor\": \"ld.lld\",
# \"executables\": true,
# \"features\": \"-mmx,-sse,+soft-float\",
# \"disable-redzone\": true,
# \"panic-strategy\": \"abort\"
# }" > ${DRAGONOS_UNKNOWN_ELF_PATH}/target.json || exit 1


# 编译标准库 (仍存在问题,不能编译)
# mkdir -p build || exit 1
# cd build
# if [ ! -d "rust" ]; then
# git clone -b $RUST_SRC_VERSION https://github.com/rust-lang/rust.git --depth=1 --recursive || exit 1
# fi

# cd rust
# git checkout $RUST_SRC_VERSION
# git submodule update --init --recursive

# cargo clean
# export RUST_COMPILER_RT_ROOT=$(pwd)/src/llvm-project/compiler-rt
# CARGO_PROFILE_RELEASE_DEBUG=0 \
# CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS=true \
# RUSTC_BOOTSTRAP=1 \
# RUSTFLAGS="-Cforce-unwind-tables=yes -Cembed-bitcode=yes" \
# __CARGO_DEFAULT_LIB_METADATA="stablestd" \
# ./x.py build --target x86_64-unknown-dragonos || exit 1