New comment by fosslinux on void-packages repository https://github.com/void-linux/void-packages/pull/24978#issuecomment-751678461 Comment: Ugh this reallly reallllly sucks. It: 1. runs a lot of random binaries 2. approx 0 cross support 3. downloads these binaries from the net Hence it is executing an absolute metric ton of cross stuff. To work around this I attempted to use binfmts and `build_helper=qemu` but due to bazel bugs https://github.com/bazelbuild/bazel/issues/12049 https://github.com/bazelbuild/bazel/issues/3320 it *still* failed on protobuf >:(. To this end, I have given up on full cross support, and left patches available to be picked up when these issues are resolved. Furthermore (this is not clearly referenced anywhere) the actual target built when using the bootstrap method is different from the normal method (using a source bazel). However, there were a large number of difficulties I ran into using the bootstrap method to bootstrap the normal method (using a source bazel), notably musl refusing to work at all! One thing that is still very perplexing is how musl works, if it is downloading all these binaries how do they work on musl? They are dynlinked..... My work here is done, I don't have the time or energy to do any more on this, and since it is a build system it works well enough. I might come back to this in a few months, but Ihave already spend wayyy more time than I would have liked on this thing. ``` diff --git a/srcpkgs/bazel/patches/fix-host-action-env.patch b/srcpkgs/bazel/patches/fix-host-action-env.patch new file mode 100644 index 0000000000..4b2bf2bd76 --- /dev/null +++ b/srcpkgs/bazel/patches/fix-host-action-env.patch @@ -0,0 +1,27 @@ +From e6670825b1e183f81f5c864aafd425d512fa9ff5 Mon Sep 17 00:00:00 2001 +From: mai93 +Date: Thu, 17 Dec 2020 06:34:40 -0800 +Subject: [PATCH] Pass --host_action_env to host options hostActionEnvironment + attribute + +This PR passes the value of `host_action_env` to `hostActionEnvironment` attribute of the host options in `CoreOptions.getHost`. + +Fixes: #12403 + +Closes #12694. + +PiperOrigin-RevId: 348011332 + +diff --git src/main/java/com/google/devtools/build/lib/analysis/config/CoreOptions.java src/main/java/com/google/devtools/build/lib/analysis/config/CoreOptions.java +index 64c84910b5a..bdc712ffb98 100644 +--- src/main/java/com/google/devtools/build/lib/analysis/config/CoreOptions.java ++++ src/main/java/com/google/devtools/build/lib/analysis/config/CoreOptions.java +@@ -963,6 +963,7 @@ public FragmentOptions getHost() { + + // Pass host action environment variables + host.actionEnvironment = hostActionEnvironment; ++ host.hostActionEnvironment = hostActionEnvironment; + + return host; + } +un_suite "Tests for bazel's handling of environment variables in actions" diff --git a/srcpkgs/bazel/patches/musl.patch b/srcpkgs/bazel/patches/musl.patch new file mode 100644 index 0000000000..75c44c89d4 --- /dev/null +++ b/srcpkgs/bazel/patches/musl.patch @@ -0,0 +1,21 @@ +musl compat with TEMP_FAILURE_RETRY. + +--- src/main/tools/linux-sandbox-pid1.cc 2020-12-26 09:57:40.680045570 +1100 ++++ src/main/tools/linux-sandbox-pid1.cc 2020-12-26 09:58:30.393411479 +1100 +@@ -49,6 +49,16 @@ + #include + #endif + ++// Some libcs (musl) don't define this macro. ++#ifndef TEMP_FAILURE_RETRY ++#define TEMP_FAILURE_RETRY(expression) \ ++ (__extension__ \ ++ ({ long int __result; \ ++ do __result = (long int) (expression); \ ++ while (__result == -1L && errno == EINTR); \ ++ __result; })) ++#endif ++ + #include "src/main/tools/linux-sandbox-options.h" + #include "src/main/tools/linux-sandbox.h" + #include "src/main/tools/logging.h" diff --git a/srcpkgs/bazel/patches/pass-ld-prefix.patch b/srcpkgs/bazel/patches/pass-ld-prefix.patch new file mode 100644 index 0000000000..1320315402 --- /dev/null +++ b/srcpkgs/bazel/patches/pass-ld-prefix.patch @@ -0,0 +1,14 @@ +Passes through QEMU_LD_PREFIX into the sandbox, which is required for +cross compilation of bazel. + +--- compile.sh 2020-12-28 11:45:33.688204017 +1100 ++++ compile.sh 2020-12-28 11:46:09.381470614 +1100 +@@ -65,6 +65,8 @@ + # host. + bazel_build "src:bazel_nojdk${EXE_EXT}" \ + --action_env=PATH \ ++ --action_env=QEMU_LD_PREFIX=${XBPS_CROSS_BASE} \ ++ --host_action_env=QEMU_LD_PREFIX=${XBPS_CROSS_BASE} \ + --host_platform=@local_config_platform//:host \ + --platforms=@local_config_platform//:host \ + || fail "Could not build Bazel" diff --git a/srcpkgs/bazel/template b/srcpkgs/bazel/template index ad742b0a56..7d8a3ddb47 100644 --- a/srcpkgs/bazel/template +++ b/srcpkgs/bazel/template @@ -1,23 +1,46 @@ # Template file for 'bazel' +# +# It would be really nice if we could use the full verion of bazel taken from +# the main source tarball instead of using the bootstrapping method, and change +# this to a bazel-bootstrap package (a la debian). However, using the main +# source tarball is extremely broken, particuarly on musl. This also has a few +# features missing that are only compiled in the main tarball. +# (reasoning: src/bazel vs src/bazel_nojdk targets being compiled) pkgname=bazel -version=3.5.0 +version=3.7.2 revision=1 -archs="~*-musl" create_wrksrc="yes" -hostmakedepends="gcc openjdk11 unzip which zip" +build_helper=qemu +hostmakedepends="openjdk11 which unzip zip python python3" makedepends="python3-devel" -short_desc="Fast, scalable, multi-language and extensible build system" +short_desc="Bazel bootstrap binary" maintainer="Wayne Van Son " license="Apache-2.0" homepage="https://www.bazel.build/" distfiles="https://github.com/bazelbuild/bazel/releases/download/${version}/bazel-${version}-dist.zip" -checksum=334429059cf82e222ca8a9d9dbbd26f8e1eb308613463c2b8655dd4201b127ec -nopie_files="/usr/bin/bazel" +checksum=de255bb42163a915312df9f4b86e5b874b46d9e8d4b72604b5123c3a845ed9b1 +nostrip=yes +nopie=yes +# All the patches are there and everything, it is so nearly ready to go. +# Two blockers: +# 1. Figure out how to manage binfmts in qemu-user-static within xbps-src. +# 2. bazel needs to fix issues #12049 and #3320. None of the workarounds listed +# there work here. FWIW, it fails with protobuf. XXX: Idea; manually override +# the protobuf repository and force it to use the host, then we can work around +# this problem (not possible for all the other things so the binfmt hack would +# still be required). +nocross=yes -do_install() { +export SOURCE_DATE_EPOCH=1608688514 + +if [ "$XBPS_TARGET_WORDSIZE" = "32" ]; then + broken="bazel does not support 32-bit targets" +fi + +do_build() { EXTRA_BAZEL_ARGS="--host_javabase=@local_jdk//:jdk" ./compile.sh } -post_install() { +do_install() { vbin "${wrksrc}/output/bazel" } ``` Or, https://ttm.sh/drp.txt. Oh, and builds are reproducible now.