Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Battle of bazel build - OPTiM TECH NIGHT

optim
October 24, 2019

Battle of bazel build - OPTiM TECH NIGHT

optim

October 24, 2019
Tweet

More Decks by optim

Other Decks in Technology

Transcript

  1. Copyright © OPTiM Corp. All Right Reserved. 1 2019/10/24 OPTiM

    TECH NIGHT Battle of bazel build (Googleビルドツールではまらないための対策)
  2. Copyright © OPTiM Corp. All Right Reserved. 2 徳⽥ (

    @dakuton) OPTiM Corporation / R&D Team 2009年⼊社 定量・⾳声データ解析 + エッジ推論 ⾃⼰紹介 https://speakerdeck.com/dakuton
  3. Copyright © OPTiM Corp. All Right Reserved. 3 Getting Startedで

    Install Bazel and use bazel build って書いてあるけど… まとめ # Using Bazel's APT repository $ sudo apt-get install bazel Failed # for macOS $ brew install bazel Failed
  4. Copyright © OPTiM Corp. All Right Reserved. 4 Googleが中⼼となって開発しているOSS等で⽤いられているビルドツール Bazelとは︖

    並列実⾏ 差分ビルド(テスト) Platform: Java, C++, Go, Android, iOS, etc HostOS: Ubuntu, CentOS, macOS , Windows ビルド⼀意性を担保 CI等でビルド再現が容易 Fast Multiple Languages Reproducible Extensible Starlark(Python likeな⾔語)による ビルドスクリプト拡張 https://bazel.build/faq.html
  5. Copyright © OPTiM Corp. All Right Reserved. 7 Googleが中⼼となって開発しているOSS等で⽤いられているビルドツール MediapipeでのBazel活⽤

    並列実⾏ 差分ビルド(テスト) Platform: Java, C++, Go, Android, iOS, etc HostOS: Ubuntu, CentOS, macOS, Windows ビルド⼀意性を担保 CI等でビルド再現が容易 Fast Multiple Languages Extensible Starlark(Python likeな⾔語)による ビルドスクリプト拡張 Reproducible のクロスプラットフォームビルドを で実現
  6. Copyright © OPTiM Corp. All Right Reserved. 8 Build from

    sourceで Install Bazel and use bazel build に従うとBazelの破壊的変更で互換性がないバージョンがインストールされる Bazel利⽤による問題点1 # for macOS $ brew install bazel Success $ bazel build -c opt --config=android_arm64 mediapipe/examples/andr oid/src/java/com/google/mediapipe/apps/handtrackinggpu Failed 10/24時点で1.1.0がインストールされる
  7. Copyright © OPTiM Corp. All Right Reserved. 9 Bazel必要バージョン確認⽅法 •

    ⽐較的規模の⼤きいプロジェクトであればCI向けのビルドスクリプト or Dockerfileが ⽤意されているので利⽤しているバージョンを確認しインストール • https://github.com/tensorflow/tensorflow/blob/r2.0/tensorflow/tools/ci_build/ install/install_bazel.sh 破壊的変更のチェック⽅法 • --incompatible_xxxxxxx や --experimental_xxxxxxx と指定されているものが対象 • --all_incompatible_changes で影響をチェック Bazel利⽤による問題点1(対策)
  8. Copyright © OPTiM Corp. All Right Reserved. 10 Java系プロジェクトで起こっていた問題(現在は修正済み) bazel

    build対象プロジェクトとBazel本体で要求されるJDKが異なる Bazel利⽤による問題点2 <<<<<<< HEAD apt-get update && apt-get install -y openjdk-11-jdk ======= apt-get update && apt-get install -y openjdk-8-jdk >>>>>>> Project import generated by Copybara. https://github.com/google/mediapipe/commit/af676420555f60c71c481f597d5ed3aa3b4f6789 Android SDKはOpenJDK 11⾮対応
  9. Copyright © OPTiM Corp. All Right Reserved. 11 Bazel利⽤による問題点2(+対策) $

    sudo apt-get -qqy install gnupg2 $ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0xB1998361219BD9C9 $ sudo apt-add-repository "deb http://repos.azul.com/azure-only/zulu/apt stable main" $ sudo apt-get -q update $ sudo apt-get -y install zulu-8-azure-jdk $ bazel info java-runtime OpenJDK Runtime Environment (build 1.8.0_212-b04) by Azul Systems, Inc. https://mirror.bazel.build/openjdk/index.html 参考: 最適なOpenJDKディストリビューションの選び⽅ https://www.oracle.co.jp/campaign/code/2019/pdfs/oct2019_b-3-3.pdf LTSサポート終了したOpenJDKを回避する場合 Bazel JDKバンドル版が利⽤しているZulu OpenJDKを⽤いる
  10. Copyright © OPTiM Corp. All Right Reserved. 13 ローカル実⾏環境のリソースを⼤量に使ってビルドする ・デフォルト値だとCPUの半分+RAMの2/3を占有

    Bazel利⽤による問題点3(+対策) $ bazel build //foo ¥ --local_cpu_resources=2 ¥ --local_ram_resources=2048 ⼤規模プロジェクトでは CPU+RAMリソース利⽤量を指定するのが無難
  11. Copyright © OPTiM Corp. All Right Reserved. 14 • Install

    Bazel どおりだと bazel build は失敗する • バージョンは確認してビルドしましょう まとめ