Bazel on Bash on Ubuntu on Windows 14393

はじめに

とにかく Bash on Ubuntu on Windows で Bazel を動かしてみます。 Getting StartedHello World まで実行してみます。

環境

実施

JDK をインストール (JDK 1.7) します。

$ sudo apt-get install default-jdk

Bazel をインストール します。

Using Bazel custom API repository (recommended) の通り JDK 1.7 版をインストールします。

$ echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.7" | sudo tee /etc/apt/sources.list.d/bazel.list

$ curl https://storage.googleapis.com/bazel-apt/doc/apt-key.pub.gpg | sudo apt-key add -

$ sudo apt-get update && sudo apt-get install bazel

普通に bazel を実行すると JVM がハングします。

Java running issues (Consolidated) を参考に、 JIT を無効化して WSL の不具合を回避します (-Xint オプション)。

※追記(2016-10-01): Cumulative Update for Windows 10 Version 1607: September 29, 2016 (Build 14393.222) で回避が不要になっていることを確認。

$ touch WORKSPACE

$ cat > BUILD <<'EOF'
genrule(
  name = "hello",
  outs = ["hello_world.txt"],
  cmd = "echo Hello World > $@",
)
EOF

$ bazel --host_jvm_args="-Xint" build :hello
.
WARNING: Sandboxed execution is not supported on your system and thus hermeticity of actions cannot be guaranteed. See http://bazel.io/docs/bazel-user-manual.html#sandboxing for more information. You can turn off this warning via --ignore_unsupported_sandboxing.
INFO: Found 1 target...
Target //:hello up-to-date:
  bazel-genfiles/hello_world.txt
INFO: Elapsed time: 6.135s, Critical Path: 0.09s

$ cat bazel-genfiles/hello_world.txt
Hello World