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.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. platform=$(uname -m | awk '{print $0}')
  42. if [ $platform = 'arm64' ];then
  43. ALL_PYTHON="3.8.10 3.9.4 3.10.1"
  44. else
  45. ALL_PYTHON="3.6.10 3.7.7 3.8.3 3.9.4 3.10.1"
  46. fi
  47. USER=$(whoami)
  48. function install_python_package() {
  49. for pak in ${ALL_PYTHON}
  50. do
  51. echo "###### do command: env PYTHON_CONFIGURE_OPTS=\"--enable-shared\" PYTHON_CONFIGURE_OPTS=\"--enable-framework\" pyenv install ${pak}"
  52. if [ -e /Users/${USER}/.pyenv/versions/${pak} ];then
  53. echo "FOUND install /Users/${USER}/.pyenv/versions/${pak} strip it..."
  54. else
  55. os_ver=$(sw_vers -productVersion | awk '{print int($0)}')
  56. if [[ $os_ver -lt 11 || $platform = 'arm64' ];then
  57. env PYTHON_CONFIGURE_OPTS="--enable-shared" PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install ${pak}
  58. else
  59. PYTHON_CONFIGURE_OPTS="--enable-shared" \
  60. PYTHON_CONFIGURE_OPTS="--enable-framework"\
  61. CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include \
  62. -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" \
  63. LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" \
  64. pyenv install --patch ${pak} < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)
  65. fi
  66. fi
  67. echo "###### do command: /Users/${USER}/.pyenv/versions/${pak}/bin/python3 -m pip install --upgrade pip"
  68. /Users/${USER}/.pyenv/versions/${pak}/bin/python3 -m pip install --upgrade pip
  69. echo "###### do command: /Users/$USER/.pyenv/versions/${pak}/bin/python3 -m pip install -r ${SRC_DIR}/imperative/python/requires.txt"
  70. /Users/$USER/.pyenv/versions/${pak}/bin/python3 -m pip install -r ${SRC_DIR}/imperative/python/requires.txt
  71. done
  72. }
  73. function install_cmake() {
  74. CMAKE_INSTALL_DIR="/Users/${USER}/megengine_use_cmake"
  75. if [ -f /Users/${USER}/megengine_use_cmake/install/bin/cmake ];then
  76. echo "find old build cmake, strip..."
  77. else
  78. if [ ! -d /Users/${USER}/megengine_use_cmake ];then
  79. echo "create dir for megengine_use_cmake"
  80. mkdir -p ${CMAKE_INSTALL_DIR}
  81. fi
  82. rm -rf ${CMAKE_INSTALL_DIR}/src/cmake-3.15.2.tar.gz
  83. mkdir ${CMAKE_INSTALL_DIR}/src
  84. cd ${CMAKE_INSTALL_DIR}/src
  85. wget https://cmake.org/files/v3.15/cmake-3.15.2.tar.gz
  86. tar -xvf cmake-3.15.2.tar.gz
  87. cd cmake-3.15.2
  88. mkdir build
  89. cd build
  90. ../configure --prefix=${CMAKE_INSTALL_DIR}/install
  91. make -j$(nproc)
  92. make install
  93. fi
  94. }
  95. function append_path_env_message() {
  96. echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++"
  97. echo "install env build megengine macos env successfully"
  98. echo "pls append path env at build script, if u use customization whl build script"
  99. echo "append detail:"
  100. echo "/Users/${USER}/megengine_use_cmake/install/bin/"
  101. echo "/usr/local/opt/findutils/libexec/gnubin"
  102. echo "/usr/local/opt/binutils/bin"
  103. echo "/usr/local/opt/llvm/bin"
  104. echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++"
  105. }
  106. ############install env now###########
  107. install_python_package
  108. install_cmake
  109. append_path_env_message