aboutsummaryrefslogtreecommitdiffstats
path: root/classes/bazel.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'classes/bazel.bbclass')
-rw-r--r--classes/bazel.bbclass109
1 files changed, 86 insertions, 23 deletions
diff --git a/classes/bazel.bbclass b/classes/bazel.bbclass
index 7b318cb..59b78e1 100644
--- a/classes/bazel.bbclass
+++ b/classes/bazel.bbclass
@@ -1,102 +1,165 @@
DEPENDS += "bazel-native \
- openjdk-8-native \
+ openjdk-11-native \
"
-DEPENDS_append_class-target = " python3"
+DEPENDS:append:class-target = " python3"
+
+inherit bazel-base
BAZEL_DIR ?= "${WORKDIR}/bazel"
BAZEL_OUTPUTBASE_DIR ?= "${BAZEL_DIR}/output_base"
-export BAZEL_ARGS="--output_user_root=${BAZEL_DIR}/user_root \
+export USER="unused-bazel-user"
+export BAZEL_STARTUP_OPTIONS="--output_user_root=${BAZEL_DIR}/user_root \
--output_base=${BAZEL_OUTPUTBASE_DIR} \
--bazelrc=${S}/bazelrc \
+ --batch \
"
-export JAVA_HOME="${STAGING_LIBDIR_NATIVE}/jvm/openjdk-8-native"
-
BAZEL ?= "${BAZEL_DIR}/bazel"
do_prepare_recipe_sysroot[postfuncs] += "do_install_bazel"
do_install_bazel() {
mkdir -p ${BAZEL_DIR}
install -m 0755 ${STAGING_BINDIR_NATIVE}/bazel ${BAZEL_DIR}
- create_cmdline_wrapper ${BAZEL} \$BAZEL_ARGS
+ create_cmdline_wrapper ${BAZEL} \$BAZEL_STARTUP_OPTIONS
zip -A ${BAZEL}.real
}
-def bazel_get_flags(d):
+def bazel_get_target_flags(d):
flags = ""
for i in d.getVar("CC").split()[1:]:
- flags += "--conlyopt=%s --cxxopt=%s --linkopt=%s " % (i, i, i)
+ flags += "# From CC\n"
+ flags += "build --conlyopt=%s --cxxopt=%s --linkopt=%s\n" % (i, i, i)
for i in d.getVar("CFLAGS").split():
if i == "-g":
continue
- flags += "--conlyopt=%s " % i
+ flags += "# From CFLAGS\n"
+ flags += "build --conlyopt=%s\n" % i
for i in d.getVar("BUILD_CFLAGS").split():
- flags += "--host_conlyopt=%s " % i
+ flags += "# From BUILD_CFLAGS\n"
+ flags += "build --host_conlyopt=%s\n" % i
for i in d.getVar("CXXFLAGS").split():
if i == "-g":
continue
- flags += "--cxxopt=%s " % i
+ flags += "# From CXXFLAGS\n"
+ flags += "build --cxxopt=%s\n" % i
for i in d.getVar("BUILD_CXXFLAGS").split():
- flags += "--host_cxxopt=%s " % i
+ flags += "# From BUILD_CXXFLAGS\n"
+ flags += "build --host_cxxopt=%s\n" % i
for i in d.getVar("CPPFLAGS").split():
if i == "-g":
continue
- flags += "--conlyopt=%s --cxxopt=%s " % (i, i)
+ flags += "# From CPPFLAGS\n"
+ flags += "build --conlyopt=%s --cxxopt=%s\n" % (i, i)
for i in d.getVar("BUILD_CPPFLAGS").split():
- flags += "--host_conlyopt=%s --host_cxxopt=%s " % (i, i)
+ flags += "# From BUILD_CPPFLAGS\n"
+ flags += "build --host_conlyopt=%s --host_cxxopt=%s\n" % (i, i)
for i in d.getVar("LDFLAGS").split():
if i == "-Wl,--as-needed":
continue
- flags += "--linkopt=%s " % i
+ flags += "# From LDFLAGS\n"
+ flags += "build --linkopt=%s\n" % i
for i in d.getVar("BUILD_LDFLAGS").split():
if i == "-Wl,--as-needed":
continue
- flags += "--host_linkopt=%s " % i
+ flags += "# From BUILD_LDFLAGS\n"
+ flags += "build --host_linkopt=%s\n" % i
for i in d.getVar("TOOLCHAIN_OPTIONS").split():
if i == "-Wl,--as-needed":
continue
- flags += "--linkopt=%s " % i
+ flags += "# From TOOLCHAIN_OPTIONS\n"
+ flags += "build --linkopt=%s\n" % i
+
+ return flags
+
+def bazel_get_flags(d):
+ flags = ""
+
+ if d.getVar("BAZEL_JOBS"):
+ flags += "# From BAZEL_JOBS\n"
+ flags += "build --jobs=%s --local_cpu_resources=%s\n" % (d.getVar("BAZEL_JOBS"), d.getVar("BAZEL_JOBS"))
+
+ if d.getVar("BAZEL_MEM"):
+ flags += "# From BAZEL_MEM\n"
+ flags += "build --local_ram_resources=%s\n" % (d.getVar("BAZEL_MEM"))
return flags
-TS_DL_DIR ??= "${DL_DIR}"
bazel_do_configure () {
cat > "${S}/bazelrc" <<-EOF
build --verbose_failures
build --spawn_strategy=standalone --genrule_strategy=standalone
-build --jobs=${@oe.utils.cpu_count()}
test --verbose_failures --verbose_test_summary
test --spawn_strategy=standalone --genrule_strategy=standalone
-build --linkopt=-Wl,-latomic
build --linkopt=-Wl,--no-as-needed
build --host_linkopt=-Wl,--no-as-needed
+build --host_conlyopt=-D_PYTHON_INCLUDE_NATIVE --host_cxxopt=-D_PYTHON_INCLUDE_NATIVE
+build --conlyopt=-D_PYTHON_INCLUDE_TARGET --cxxopt=-D_PYTHON_INCLUDE_TARGET
+
build --strip=never
+build --python_path=python3
+
fetch --distdir=${TS_DL_DIR}
build --distdir=${TS_DL_DIR}
+${@bazel_get_flags(d)}
+
EOF
}
-bazel_do_configure_append_class-target () {
+bazel_do_configure:append:class-target () {
cat >> "${S}/bazelrc" <<-EOF
-# FLAGS
-build ${@bazel_get_flags(d)}
+# FLAGS begin
+${@bazel_get_target_flags(d)}
+# FLAGS end
+
EOF
sed -i "s:${WORKDIR}:${BAZEL_OUTPUTBASE_DIR}/external/yocto_compiler:g" ${S}/bazelrc
+
+ # Unzip bazel packages
+ ${BAZEL} ${BAZEL_STARTUP_OPTIONS} version
+
+ for binary in build-runfiles daemonize linux-sandbox process-wrapper; do
+ # Modify interpreter for bazel built-in binaries
+ patchelf-uninative --set-interpreter "${UNINATIVE_LOADER}" ${BAZEL_DIR}/user_root/install/*/$binary
+
+ # Set modification time somewhere in the future to avoid "corrupt installation: file PATH is missing or modified"
+ # in this case modification is required for successful build
+ touch -m -t 203712120101 ${BAZEL_DIR}/user_root/install/*/$binary
+ done
}
EXPORT_FUNCTIONS do_configure
+
+PSEUDO_IGNORE_PATHS .= ",${WORKDIR}/bazel"
+
+inherit unsupportarch
+
+export YOCTO_NATIVE_SYSROOT="${BAZEL_OUTPUTBASE_DIR}/external/yocto_compiler/recipe-sysroot-native"
+
+do_rm_work[prefuncs] += "clean_bazel"
+do_clean[prefuncs] += "clean_bazel"
+clean_bazel() {
+ if [ -d ${S} ]; then
+ cd ${S}
+ if [ -e ${BAZEL} ] && [ -e ${S}/bazelrc ]; then
+ ${BAZEL} clean
+ fi
+ fi
+ rm ${BAZEL_DIR} -rf
+}
+
+do_compile[network] = "1"