Pier Francesco Berton
Pier Francesco Berton

Reputation: 21

Compiling Bazel on Beaglebone Black

My team and I are working on a Beaglebone Black and we need to install Bazel on it. We have tried with Bazel 0.18.1 (the latest available when we start) and the latest version of Java JDK. The first problem we encounter is lack of java heap space, with the following error:

The system is out of resources.
Consult the following stack trace for details.
java.lang.OutOfMemoryError: Java heap space
        at java.util.HashMap.resize(HashMap.java:704)
        at java.util.HashMap.putVal(HashMap.java:663)
        at java.util.HashMap.put(HashMap.java:612)
        at com.sun.tools.javac.parser.LazyDocCommentTable.putComment(LazyDocCommentTable.java:89)
        at com.sun.tools.javac.parser.JavacParser.attach(JavacParser.java:538)
        at com.sun.tools.javac.parser.JavacParser.methodDeclaratorRest(JavacParser.java:3609)
        at com.sun.tools.javac.parser.JavacParser.classOrInterfaceBodyDeclaration(JavacParser.java:3532)
        at com.sun.tools.javac.parser.JavacParser.classOrInterfaceBody(JavacParser.java:3436)
        at com.sun.tools.javac.parser.JavacParser.classDeclaration(JavacParser.java:3285)
        at com.sun.tools.javac.parser.JavacParser.classOrInterfaceOrEnumDeclaration(JavacParser.java:3226)
        at com.sun.tools.javac.parser.JavacParser.classOrInterfaceBodyDeclaration(JavacParser.java:3486)
        at com.sun.tools.javac.parser.JavacParser.classOrInterfaceBody(JavacParser.java:3436)
        at com.sun.tools.javac.parser.JavacParser.classDeclaration(JavacParser.java:3285)
        at com.sun.tools.javac.parser.JavacParser.classOrInterfaceOrEnumDeclaration(JavacParser.java:3226)
        at com.sun.tools.javac.parser.JavacParser.typeDeclaration(JavacParser.java:3215)
        at com.sun.tools.javac.parser.JavacParser.parseCompilationUnit(JavacParser.java:3155)
        at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:628)
        at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:665)
        at com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:950)
        at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:857)
        at com.sun.tools.javac.main.Main.compile(Main.java:523)
        at com.sun.tools.javac.main.Main.compile(Main.java:381)
        at com.sun.tools.javac.main.Main.compile(Main.java:370)
        at com.sun.tools.javac.main.Main.compile(Main.java:361)
        at com.sun.tools.javac.Main.compile(Main.java:56)
        at com.sun.tools.javac.Main.main(Main.java:42)

After a research on internet we tried to increase the available heap space exporting the BAZEL_JAVAC_OPTS (see this compile.sh - The system is out of resources) like this:

$ export BAZEL_JAVAC_OPTS="-J-Xms256m -J-Xmx384m"

but after that we can`t proceed anymore and we see the following code:

🍃  Building Bazel from scratch..scripts/bootstrap/buildenv.sh: line 186:  1740 Killed                  "${@}" >> "${errfile}" 2>&1
/usr/lib/jvm/java-8-openjdk-armhf/bin/javac -classpath third_party/opencensus/opencensus-contrib-grpc-metrics-0.11.0.jar:third_party/opencensus/opencensus-api-0.11.0.jar:third_party/mockito/mockito-all-1.10.19.jar:third_party/hamcrest/ha
mcrest-core-1.3.jar:third_party/apache_commons_pool2/commons-pool2-2.3.jar:third_party/netty_tcnative/netty-tcnative-boringssl-static-2.0.7.Final.jar:third_party/apache_httpcore/httpcore-4.4.6.jar:third_party/checker_framework_javacutil/
javacutil-2.5.3-sources.jar:third_party/checker_framework_javacutil/javacutil-2.5.3.jar:third_party/apache_commons_logging/commons-logging-1.1.1.jar:third_party/hungarian_algorithm/software-and-algorithms-1.0-src.jar:third_party/hungaria
n_algorithm/software-and-algorithms-1.0.jar:third_party/guava/guava-testlib-25.1-jre.jar:third_party/error_prone/error_prone_annotation-2.3.2-SNAPSHOT.jar:third_party/error_prone/error_prone_check_api-2.3.2-SNAPSHOT.jar:third_party/error
_prone/error_prone_annotations-2.2.0.jar:third_party/error_prone/error_prone_type_annotations-2.3.2-SNAPSHOT.jar:third_party/netty/netty-all-4.1.17.Final.jar:third_party/jcip_annotations/jcip-annotations-1.0-1.jar:third_party/jsch/jsch-0
.1.54.jar:third_party/checker_framework_dataflow/dataflow-2.5.3.jar:third_party/checker_framework_dataflow/dataflow-2.5.3-sources.jar:third_party/jimfs/jimfs-1.1.jar:third_party/turbine/turbine.jar:third_party/instrumentation/instrumenta
tion-api-0.4.3.jar:third_party/apache_commons_lang/commons-lang-2.6.jar:third_party/apache_httpclient/httpclient-4.5.3.jar:third_party/gson/gson-2.2.4.jar:third_party/apache_commons_compress/apache-commons-compress-1.9.jar:third_party/ae
ther/aether-impl-1.0.0.v20140518.jar:third_party/aether/aether-transport-http-1.0.0.v20140518.jar:third_party/aether/aether-transport-file-1.0.0.v20140518.jar:third_party/aether/aether-connector-basic-1.0.0.v20140518.jar:third_party/aeth
er/aether-transport-wagon-1.0.0.v20140518.jar:third_party/aether/aether-util-1.0.0.v20140518.jar:third_party/aether/aether-transport-classpath-1.0.0.v20140518.jar:third_party/aether/aether-spi-1.0.0.v20140518.jar:third_party/aether/aethe
r-api-1.0.0.v20140518.jar:third_party/auth/google-auth-library-credentials-0.6.0.jar:third_party/auth/google-auth-library-oauth2-http-0.6.0.jar:third_party/plexus_interpolation/plexus-interpolation-1.22.jar:third_party/ijar/test/libwrong
centraldir.jar:third_party/ijar/test/jar-with-manifest.jar:third_party/ijar/test/nestmates/nestmates.jar:third_party/ijar/test/jar-without-manifest.jar:third_party/ijar/test/jar-with-manifest-and-target-label.jar:third_party/javax_annota
tions/javax.annotation-api-1.3.2-sources.jar:third_party/javax_annotations/javax.annotation-api-1.3.2.jar:third_party/objenesis/objenesis-1_3.jar:third_party/plexus_utils/plexus-utils-3.0.21.jar:third_party/allocation_instrumenter/java-a
llocation-instrumenter-3.0.1.jar:third_party/truth8/truth-java8-extension-0.42.jar:third_party/slf4j/slf4j-jdk14-1.7.7.jar:third_party/slf4j/slf4j-api-1.7.7.jar:third_party/pcollections/pcollections-2.1.2.jar:third_party/apache_commons_c
ollections/commons-collections-3.2.2.jar:third_party/bazel_bootstrap/libregistered-singleton.jar:third_party/bazel_bootstrap/libautocodec-processor.jar:third_party/bazel_bootstrap/libserialization.jar:third_party/bazel_bootstrap/libautoc
odec-annotation.jar:third_party/bazel_bootstrap/libunsafe-provider.jar:third_party/compile_testing/compile-testing-0.13.jar:third_party/maven/maven-settings-3.3.3.jar:third_party/maven/maven-settings-builder-3.3.3.jar:third_party/maven/m
aven-builder-support-3.3.3.jar:third_party/truth/truth-0.42.jar:third_party/asm/asm-6.2.1-sources.jar:third_party/asm/asm-tree-6.2.1.jar:third_party/asm/asm-tree-6.2.1-sources.jar:third_party/asm/asm-util-6.2.1-sources.jar:third_party/as
m/asm-util-6.2.1.jar:third_party/asm/asm-6.2.1.jar:third_party/asm/asm-commons-6.2.1.jar:third_party/asm/asm-analysis-6.2.1.jar:third_party/asm/asm-commons-6.2.1-sources.jar:third_party/asm/asm-analysis-6.2.1-sources.jar:third_party/apac
he_commons_codec/commons-codec-1.9.jar:third_party/maven_model/maven-model-builder-3.2.3.jar:third_party/maven_model/maven-repository-metadata-3.2.3.jar:third_party/maven_model/maven-model-3.2.3.jar:third_party/maven_model/maven-aether-p
rovider-3.2.3.jar:third_party/java/android_databinding/v2_3_1/exec.jar:third_party/java/jdk/langtools/javac-9+181-r4173-1.jar:third_party/java/jdk/langtools/java_compiler-src.jar:third_party/java/jdk/langtools/jdk_compiler-src.jar:third_
party/java/jdk/langtools/java_compiler.jar:third_party/java/jdk/langtools/jdk_compiler.jar:third_party/java/proguard/proguard5.3.3/lib/retrace.jar:third_party/java/proguard/proguard5.3.3/lib/proguard.jar:third_party/java/proguard/proguar
d5.3.3/lib/proguardgui.jar:third_party/java/proguard/proguard5.3.3/examples/annotations/lib/annotations.jar:third_party/java/jacoco/org.jacoco.agent-0.7.5.201505241946-src.jar:third_party/java/jacoco/org.jacoco.core-0.7.5.201505241946.ja
r:third_party/java/jacoco/jacocoagent.jar:third_party/java/jacoco/org.jacoco.report-0.7.5.201505241946-src.jar:third_party/java/jacoco/org.jacoco.report-0.7.5.201505241946.jar:third_party/java/jacoco/org.jacoco.core-0.7.5.201505241946-sr
c.jar:third_party/java/jacoco/org.jacoco.agent-0.7.5.201505241946.jar:third_party/java/javapoet/javapoet-1.8.0.jar:third_party/java/jcommander/jcommander-1.48.jar:third_party/android_common/com.android.tools.external.lombok_lombok-ast_0.
2.3.jar:third_party/android_common/com.android.tools_sdklib_25.0.0.jar:third_party/android_common/com.android.tools.build_builder-model_2.0.0.jar:third_party/android_common/com.android.tools.build_builder-test-api_2.0.0.jar:third_party/a
ndroid_common/com.android.tools_dvlib_25.0.0.jar:third_party/android_common/com.android.tools_common_25.0.0.jar:third_party/android_common/com.android.tools_sdk-common_25.0.0.jar:third_party/android_common/com.android_annotations_25.0.0.
jar:third_party/android_common/com.android.tools.lint_lint-checks_25.0.0.jar:third_party/android_common/com.android.tools_repository_25.0.0.jar:third_party/android_common/com.android.tools_ddmlib_25.0.0.jar:third_party/android_common/com
.android.tools.layoutlib_layoutlib_26.1.2.jar:third_party/android_common/com.android.tools.build_manifest-merger_25.0.0.jar:third_party/android_common/com.android.tools.build_builder_2.0.0.jar:third_party/android_common/com.android.tools
.lint_lint-api_25.0.0.jar:third_party/auto/auto-service-1.0-rc2.jar:third_party/auto/auto-value-1.5.4.jar:third_party/auto/auto-common-0.3.jar:third_party/tomcat_annotations_api/tomcat-annotations-api-8.0.5.jar:third_party/xz/xz-1.5.jar:
third_party/jsr330_inject/javax.inject.jar:third_party/apache_velocity/velocity-1.7.jar:third_party/junit/junit-4.12.jar:third_party/diffutils/diffutils-1.3.0.jar:third_party/jsr305/jsr-305.jar:third_party/protobuf/3.6.1/libprotobuf_java
_util.jar:third_party/protobuf/3.6.1/libprotobuf_java.jar:third_party/api_client/google-api-client-jackson2-1.22.0.jar:third_party/api_client/google-http-client-1.22.0-SNAPSHOT.jar:third_party/api_client/google-http-client-jackson2-1.22.
0.jar:third_party/api_client/google-api-client-1.22.0.jar:third_party/jackson2/jackson-core-2.8.6.jar:third_party/jgit/org.eclipse.jgit-4.10.0.201712302008-r.jar:third_party/plexus_component_annotations/plexus-component-annotations-1.6.j
ar:third_party/grpc/grpc-core-1.10.0.jar:third_party/grpc/grpc-stub-1.10.0.jar:third_party/grpc/grpc-context-1.10.0.jar:third_party/grpc/grpc-protobuf-1.10.0.jar:third_party/grpc/grpc-protobuf-lite-1.10.0.jar:third_party/grpc/grpc-netty-
1.10.0.jar:third_party/grpc/grpc-auth-1.10.0.jar:third_party/guava/guava-25.1-jre.jar:third_party/error_prone/error_prone_core-2.3.2-SNAPSHOT.jar:/tmp/bazel_b8bs0DpB -sourcepath src/java_tools/singlejar/java/com/google/devtools/build/zip
:src/main/java:src/tools/xcode-common/java/com/google/devtools/build/xcode/common:src/tools/xcode-common/java/com/google/devtools/build/xcode/util:third_party/java/dd_plist/java:/tmp/bazel_b8bs0DpB/src -d /tmp/bazel_b8bs0DpB/classes -sou
rce 1.8 -target 1.8 -encoding UTF-8 -J-Xms256m -J-Xmx384m @/tmp/bazel_8YV1VpPi/param

Has anyone tried to compile bazel on arm32 before and have some clues?

Upvotes: 2

Views: 327

Answers (1)

László
László

Reputation: 4271

I suppose the Java compiler consumed too much memory and the OS killed it. 512MB RAM should be enough to run Bazel, but will probably not be enough to bootstrap Bazel. However there's hope.

Before I begin: your question indicates that there's a need to properly implement in the bootstrapping scripts what I'm about to describe. Alas it's not currently implemented, so you'll have to do lots of legwork.

First you have to understand how the bootstrap script (./compile.sh and the 3 scripts under scripts/bootstrap) work.

compile.sh drives the bootstrapping process, which consists of two phases:

  1. "Building Bazel from scratch" -- builds a minimal Bazel (purely Java)
  2. "Building Bazel with Bazel" -- runs the JVM with that minimal Bazel jar to build a proper Bazel binary

The first step is very memory hungry, because it runs a single javac to compile every .java source of Bazel. I believe the second step could run with just 512MB RAM.

1st phase: build minimal Bazel

We'll edit the bootstrap scripts to produce just the minimal Bazel jar. I'm pretty confident in the success of this step.

On a desktop computer:

  1. unpack the distribution archive (bazel-0.18.1-dist.zip)
  2. comment out this line, so that the script won't clean up its temporary outputs when exiting (including the .jar file we need)
  3. add echo "${ARCHIVE_DIR}/libblaze.jar" ; exit 0 above [this line](https://github.com/bazelbuild/bazel/blob/b18915752a69fbbc6ed94e1710198167593565fc/scripts/bootstrap/compile.sh#L411
  4. run ./compile.sh

This will produce libblaze.jar. Deploy this jar to the device.

2nd phase: build complete Bazel

We'll edit the bootstrap scripts to skip the "compiling from source" step and use the .jar file from the previous step. I'm less confident in the success of this step because I've never done it before, but let's give it a try.

On the device:

  1. copy "libblaze.jar" somewhere on the device, e.g. $HOME/libblaze.jar
  2. unpack the distribution archive (bazel-0.18.1-dist.zip)
  3. comment out these lines
  4. comment out these lines and replace them with cp $HOME/libblaze.jar ${ARCHIVE_DIR}/libblaze.jar
  5. run ./compile.sh

Hopefully this will bootstrap Bazel on the device. Please let know how it goes!

Update 1: I should've mentioned that the device should have a 64-bit CPU. The C++ code of Bazel requires a 64-bit architecture. You must also make sure the desktop JDK compiles for the same bitness and endianness as the on-device JDK would.

Update 2: The first purely-Java Bazel is only purely Java on Linux (and maybe macOS). On Windows it also contains a JNI library, built from scratch here.

Upvotes: 2

Related Questions