You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

macos_whl_env_prepare.sh 4.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/bin/bash -e
  2. #install env before use greadlink
  3. function try_install_brew() {
  4. which brew
  5. if [ $? -eq 0 ]; then
  6. echo "find install brew, use it"
  7. else
  8. echo "DO NOT FIND brew, now try install, may ask root password, please input manually!!"
  9. /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  10. #try double check
  11. which brew
  12. if [ $? -eq 0 ]; then
  13. echo "find install brew, use it"
  14. else
  15. echo "ERR: INSTALL brew failed!!, please install manually!!"
  16. exit -1
  17. fi
  18. fi
  19. }
  20. function install_brew_package() {
  21. BREW_PACKAGE="openssl readline sqlite3 xz gdbm zlib pyenv wget swig coreutils llvm git-lfs ninja bzip2"
  22. for pak in ${BREW_PACKAGE}
  23. do
  24. echo "###### do command: brew install ${pak}"
  25. brew install ${pak}
  26. done
  27. git lfs install
  28. }
  29. try_install_brew
  30. install_brew_package
  31. READLINK=readlink
  32. OS=$(uname -s)
  33. if [ $OS = "Darwin" ];then
  34. READLINK=greadlink
  35. else
  36. echo "ERR: only run at macos env"
  37. exit -1
  38. fi
  39. SRC_DIR=$($READLINK -f "`dirname $0`/../../../")
  40. echo ${SRC_DIR}
  41. ALL_PYTHON="3.6.10 3.7.7 3.8.3 3.9.4 3.10.1"
  42. USER=$(whoami)
  43. function install_python_package() {
  44. for pak in ${ALL_PYTHON}
  45. do
  46. echo "###### do command: env PYTHON_CONFIGURE_OPTS=\"--enable-shared\" pyenv install ${pak}"
  47. if [ -e /Users/${USER}/.pyenv/versions/${pak} ];then
  48. echo "FOUND install /Users/${USER}/.pyenv/versions/${pak} strip it..."
  49. else
  50. os_ver=$(sw_vers -productVersion | awk '{print int($0)}')
  51. if [ $os_ver -lt 11 ];then
  52. env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install ${pak}
  53. else
  54. PYTHON_CONFIGURE_OPTS="--enable-shared" \
  55. CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include \
  56. -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" \
  57. LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" \
  58. pyenv install --patch ${pak} < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)
  59. fi
  60. fi
  61. echo "###### do command: /Users/${USER}/.pyenv/versions/${pak}/bin/python3 -m pip install --upgrade pip"
  62. /Users/${USER}/.pyenv/versions/${pak}/bin/python3 -m pip install --upgrade pip
  63. echo "###### do command: /Users/$USER/.pyenv/versions/${pak}/bin/python3 -m pip install -r ${SRC_DIR}/imperative/python/requires.txt"
  64. /Users/$USER/.pyenv/versions/${pak}/bin/python3 -m pip install -r ${SRC_DIR}/imperative/python/requires.txt
  65. done
  66. }
  67. function install_cmake() {
  68. CMAKE_INSTALL_DIR="/Users/${USER}/megengine_use_cmake"
  69. if [ -f /Users/${USER}/megengine_use_cmake/install/bin/cmake ];then
  70. echo "find old build cmake, strip..."
  71. else
  72. if [ ! -d /Users/${USER}/megengine_use_cmake ];then
  73. echo "create dir for megengine_use_cmake"
  74. mkdir -p ${CMAKE_INSTALL_DIR}
  75. fi
  76. rm -rf ${CMAKE_INSTALL_DIR}/src/cmake-3.15.2.tar.gz
  77. mkdir ${CMAKE_INSTALL_DIR}/src
  78. cd ${CMAKE_INSTALL_DIR}/src
  79. wget https://cmake.org/files/v3.15/cmake-3.15.2.tar.gz
  80. tar -xvf cmake-3.15.2.tar.gz
  81. cd cmake-3.15.2
  82. mkdir build
  83. cd build
  84. ../configure --prefix=${CMAKE_INSTALL_DIR}/install
  85. make -j$(nproc)
  86. make install
  87. fi
  88. }
  89. function append_path_env_message() {
  90. echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++"
  91. echo "install env build megengine macos env successfully"
  92. echo "pls append path env at build script, if u use customization whl build script"
  93. echo "append detail:"
  94. echo "/Users/${USER}/megengine_use_cmake/install/bin/"
  95. echo "/usr/local/opt/findutils/libexec/gnubin"
  96. echo "/usr/local/opt/binutils/bin"
  97. echo "/usr/local/opt/llvm/bin"
  98. echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++"
  99. }
  100. ############install env now###########
  101. install_python_package
  102. install_cmake
  103. append_path_env_message