init_dragonos_toolchain.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # 当前脚本用于初始化自定义的Rust工具链
  2. if [ -z "$(which cargo)" ]; then
  3. echo "尚未安装Rust,请先安装Rust"
  4. exit 1
  5. fi
  6. # 是否强制覆盖已有的工具链配置文件
  7. FORCE=0
  8. while getopts "f" arg
  9. do
  10. case $arg in
  11. f)
  12. FORCE=1
  13. ;;
  14. ?)
  15. echo "unkonw argument"
  16. exit 1
  17. ;;
  18. esac
  19. done
  20. DRAGONOS_UNKNOWN_ELF_PATH=$(rustc --print sysroot)/lib/rustlib/x86_64-unknown-dragonos
  21. mkdir -p ${DRAGONOS_UNKNOWN_ELF_PATH}/lib
  22. echo $DRAGONOS_UNKNOWN_ELF_PATH
  23. # 判断是否已经存在工具链配置文件
  24. if [ -f "${DRAGONOS_UNKNOWN_ELF_PATH}/target.json" ]; then
  25. if [ $FORCE -eq 0 ]; then
  26. echo "已存在工具链配置文件,如需重新初始化,请使用-f参数"
  27. exit 0
  28. fi
  29. fi
  30. # 设置工具链配置文件
  31. echo \
  32. "{\
  33. \"arch\": \"x86_64\",
  34. \"code-model\": \"kernel\",
  35. \"cpu\": \"x86-64\",
  36. \"os\": \"dragonos\",
  37. \"target-endian\": \"little\",
  38. \"target-pointer-width\": \"64\",
  39. \"target-c-int-width\": \"32\",
  40. \"data-layout\": \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128\",
  41. \"disable-redzone\": true,
  42. \"features\": \"-3dnow,-3dnowa,-avx,-avx2\",
  43. \"linker\": \"rust-lld\",
  44. \"linker-flavor\": \"ld.lld\",
  45. \"llvm-target\": \"x86_64-unknown-none\",
  46. \"max-atomic-width\": 64,
  47. \"panic-strategy\": \"abort\",
  48. \"position-independent-executables\": true,
  49. \"relro-level\": \"full\",
  50. \"stack-probes\": {
  51. \"kind\": \"inline-or-call\",
  52. \"min-llvm-version-for-inline\": [
  53. 16,
  54. 0,
  55. 0
  56. ]
  57. },
  58. \"static-position-independent-executables\": true,
  59. \"supported-sanitizers\": [
  60. \"kcfi\"
  61. ],
  62. \"target-pointer-width\": \"64\"
  63. }" > ${DRAGONOS_UNKNOWN_ELF_PATH}/target.json || exit 1