init_rust_toolchain.sh 2.6 KB

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