当前位置:   article > 正文

Mac搭建OpenHarmonyOS(开源鸿蒙系统)编译环境

warnings.warn('resource_tracker: there appear to be %d

从编译脚本上看是支持的mac的

  1. case $(uname -s) in
  2. Darwin)
  3. HOST_DIR="darwin-x86"
  4. HOST_OS="mac"
  5. ;;
  6. Linux)
  7. HOST_DIR="linux-x86"
  8. HOST_OS="linux"
  9. ;;
  10. *)
  11. echo "Unsupported host platform: $(uname -s)"
  12. RET=1
  13. exit $RET
  14. esac
  • mac平台的只能在mac上编译(目前是)
  • Linux上可以交叉编译出win
    • 编译命令默认也是会编译出Linux和win两个平台的sdk

mac上有一些要求,比如必须安装xcode
默认最小版本 10.12,但是高于11不行。

  1. _sdk_min_from_env = getenv("FORCE_MAC_SDK_MIN")
  2. declare_args() {
  3. # Minimum supported version of the Mac SDK.
  4. if (_sdk_min_from_env == "") {
  5. mac_sdk_min = "10.12"
  6. } else {
  7. mac_sdk_min = _sdk_min_from_env
  8. }
  9. }

-下面脚本只匹配的 10和11(目前是这样的,当前时间:20220528)

  1. sdk_dir = os.path.join(
  2. str(out.rstrip(), encoding="utf-8"),
  3. 'Platforms/MacOSX.platform/Developer/SDKs')
  4. # Xcode must be installed, its license agreement must be accepted, and its
  5. # command-line tools must be installed. Stand-alone installations (in
  6. # /Library/Developer/CommandLineTools) are not supported.
  7. # https://bugs.chromium.org/p/chromium/issues/detail?id=729990#c1
  8. file_path = os.path.relpath("/path/to/Xcode.app")
  9. if not os.path.isdir(sdk_dir) or not '.app/Contents/Developer' in sdk_dir:
  10. raise SdkError('Install Xcode, launch it, accept the license ' +
  11. 'agreement, and run `sudo xcode-select -s %s` ' % file_path +
  12. 'to continue.')
  13. sdks = [re.findall('^MacOSX(1[0,1]\.\d+)\.sdk$', s) for s in
  14. os.listdir(sdk_dir)]
  15. sdks = [s[0] for s in sdks if s] # [['10.5'], ['10.6']] => ['10.5', '10.6']
  16. sdks = [s for s in sdks # ['10.5', '10.6'] => ['10.6']
  17. if list(parse_version(s)) >= list(parse_version(min_sdk_version))]

环境

  • MacOS:10.12 - 11应该都可以,系统版本12目前不行

    • 我的 11.6.5 (20G527)
  • Xcode:必须安装

    • 我的 Version 11.5 (11E608c)
  • gitee账号

  • git

    • 参考后文
  • git-lfs

    • 参考后文
  • python3

    • 参考后文
  • repo

    • 参考后文
  • node

    • 参考后文
  • Java

    • 参考后文

Ubuntu

需要 Ubuntu 环境的可以参考下面链接

https://www.jianshu.com/p/24be266a1c4e

Brew

如果没有brew,百度安装

如果有提示,请按照提示操作

重置brew.git

  1. cd "$(brew --repo)"
  2. git remote set-url origin https://github.com/Homebrew/brew.git

重置核心软件仓库

  1. cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
  2. git remote set-url origin https://github.com/Homebrew/homebrew-core.git

重置Homebrew cask软件仓库

  1. cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask
  2. git remote set-url origin https://github.com/Homebrew/homebrew-cask

python

  • Version:3+

https://www.python.org/

brew install python3

git

gitee账号信息

  • 生成公私钥
ssh-keygen -t rsa -C "message"
  • 注册gitee

  • 将本机ssh公钥放置gitee上

install git

  • mac
brew install git

configure git

  1. git config --global user.name "binny"
  2. git config --global user.email "694285349@qq.com"
  3. git config --global credential.helper store

install git-lfs

https://gitee.com/mirrors/git-lfs?_from=gitee_search

install repo

  1. mkdir -p ~/.bin
  2. PATH="${HOME}/bin:${PATH}"
  3. curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > ~/.bin/repo
  4. chmod a+rx ~/.bin/repo
  5. pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple requests

download master

Download

repo init -u git@gitee.com:openharmony/manifest.git -b master --no-repo-verify

Sync

repo sync -c -d -j8 --force-sync --fail-fast -q --no-tags --prune ; repo forall -j8 -c "git lfs pull"
  • 或者
repo sync -c
  • 同步大文件,好像是编译器之类的,没仔细看日志
repo forall -c 'git lfs pull'

这一步有输出警告,应该不影响,输出警告的文件:

vim /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/resource_tracker.py
  1. finally:
  2. # all processes have terminated; cleanup any remaining resources
  3. for rtype, rtype_cache in cache.items():
  4. if rtype_cache:
  5. try:
  6. warnings.warn('resource_tracker: There appear to be %d '
  7. 'leaked %s objects to clean up at shutdown' %
  8. (len(rtype_cache), rtype))
  9. except Exception:
  10. pass
  11. for name in rtype_cache:
  12. # For some reason the process which created and registered this
  13. # resource has failed to unregister it. Presumably it has
  14. # died. We therefore unlink it.
  15. try:
  16. try:
  17. _CLEANUP_FUNCS[rtype](name)
  18. except Exception as e:
  19. warnings.warn('resource_tracker: %r: %s' % (name, e))
  20. finally:
  21. pass

brew 安装工具包

我开始在 mac 上大环境的时候,也是对着 Linux 上的名字安装了一部分。缺少去网上搜吧,下图是我本机的,仅供参考(下面的不都是 ohos 需要的)

  1. ohos % brew list
  2. ==> Formulae
  3. brotli coreutils git icu4c libunistring mpdecimal openssl@1.1 readline wget
  4. c-ares gdbm git-lfs libidn2 libuv node@12 pcre2 sqlite xz
  5. ca-certificates gettext gmp libnghttp2 macos-term-size openjdk@17 python@3.9 tree
brew update
brew install wget
  • md5sum等
brew install coreutils

java环境

  • 没有的话,自己安装,这个我以前装过,装 Java 环境,好装,百度吧
brew install openjdk@17
sudo ln -sfn /usr/local/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
  1. echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> ~/.zshrc
  2. source ~/.zshrc
java -version

prebuilts

  • 执行prebuilts,在源码根目录下执行,安装编译器及二进制工具(注意文件名和路径,同事给我的名字有的都不一样了)
sudo bash build/prebuilts_download.sh –no-check-certificatie-skip-ssl
  • 缺少啥就装啥。
sudo npm i -g nan

版本编译

  • 编译 SDK
sudo ./build.sh --product-name ohos-sdk
  • 单独安装的不支持
  1. # Xcode must be installed, its license agreement must be accepted, and its
  2. # command-line tools must be installed. Stand-alone installations (in
  3. # /Library/Developer/CommandLineTools) are not supported.
  4. # https://bugs.chromium.org/p/chromium/issues/detail?id=729990#c1
  • 完成
  1. [OHOS INFO] [28/28] STAMP obj/build/core/gn/build_ohos_sdk.stamp
  2. [OHOS INFO] c targets overlap rate statistics
  3. [OHOS INFO] subsystem files NO. percentage builds NO. percentage overlap rate
  4. [OHOS INFO] graphic 8 0.1% 12 0.1% 1.50
  5. [OHOS INFO] hiviewdfx 4 0.0% 6 0.1% 1.50
  6. [OHOS INFO] multimedia 2 0.0% 3 0.0% 1.50
  7. [OHOS INFO] startup 2 0.0% 3 0.0% 1.50
  8. [OHOS INFO] global 13 0.2% 14 0.2% 1.08
  9. [OHOS INFO] third_party 3590 44.7% 3597 44.6% 1.00
  10. [OHOS INFO] thirdparty 3590 44.7% 3597 44.6% 1.00
  11. [OHOS INFO] arkui 1395 17.4% 1397 17.3% 1.00
  12. [OHOS INFO] aafwk 39 0.5% 39 0.5% 1.00
  13. [OHOS INFO] ark 67 0.8% 67 0.8% 1.00
  14. [OHOS INFO] developtools 61 0.8% 61 0.8% 1.00
  15. [OHOS INFO] securec 78 1.0% 78 1.0% 1.00
  16. [OHOS INFO] utils 50 0.6% 50 0.6% 1.00
  17. [OHOS INFO]
  18. [OHOS INFO] c overall build overlap rate: 1.00
  19. [OHOS INFO]
  20. [OHOS INFO]
  21. [OHOS INFO] sdk build success
  22. [OHOS INFO] cost time: 0:01:39
  23. =====build successful=====
  • 编译成功后,如果有文件权限问题
sudo chmod -R 777 out
  • 位置
/Users/binny/ohos/out/sdk/ohos-sdk/darwin
  1. =====build successful=====
  2. 2022-05-29 06:09:17
  3. ++++++++++++++++++++++++++++++++++++++++
  4. ohos % tree -L 2 -d /Users/binny/ohos/out/sdk/ohos-sdk
  5. /Users/binny/ohos/out/sdk/ohos-sdk
  6. └── darwin
  7. ├── ets
  8. ├── js
  9. ├── previewer
  10. └── toolchains
  11. 5 directories
  12. ohos %
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/259804
推荐阅读
相关标签
  

闽ICP备14008679号