Skip to content
 
 

Latest commit

 

History

38,365 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Bazel illumos (and somewhat Solaris) port

(Scroll down for original Bazel README.md)

This repo contains a illumos port of Bazel. This port currently assumes the use of pkgsrc.

Previous versions of this port used Solaris as a target name but this version specifically targets illumos. Among things because I don't want to hijack the Solaris target name since this is acutally a illumos port. With a little effort (couple of ifdef's) it can probably also be made to work on Solaris. Since I personally don't have a need for such a port it's not here. However if you would like to adopt this port for use on Solaris and run into any issues while doing so please feel free to reach out to me via issues, Mastodon (@JasperSiepkes@mastodon.social) or BlueSky (@jasper.siepkes.nl).

Building Bazel on SmartOS

Create a SmartOS container (joyent brand if you are on Triton). To build and use Bazel you need an image which has GCC 13. This guide assumes you use image b933df4b-b8f4-4bef-ad1e-236a20304496 (25.4.0) with GCC 13. Be sure to fully update your container (pkgin -y upgrade).

Install required build packages:

# pkgin -y install git-base zip unzip openjdk21 libtool cmake automake ninja-build autoconf gmake gcc13 python311

Next we need to download the Bazel distribution and apply the changes of this forked repo. The reason why we need the Bazel distribution and can't simply compile the cloned fork is because in order to compile Bazel you need a working Bazel installation (usually an older version). The Bazel distribution contains things like pre-compiled protobuf messages (ie. java files generated by the protobuf compiler).

Download bazel-7.7.1-dist.zip (the Bazel distribution) from the Bazel releases page.

Next we will prepare our source tree by putting everything together:

# mkdir bazel-7.7.1
# unzip bazel-7.7.1-dist.zip -d bazel-7.7.1
# git clone https://github.com/siepkes/bazel-smartos.git
# cd bazel-smartos
# git switch -c smartos-7.7.1-gcc13 origin/smartos-7.7.1-gcc13
# git format-patch -1
# cd ../bazel-7.7.1
# patch -p1 < ../bazel-smartos/0001-Modifications-to-port-Bazel-7.7.1-to-illumos-SmartOS.patch

We are now ready to build Bazel!

# export LANG=en_US.UTF-8
# export JAVA_HOME="/opt/local/java/openjdk21"
# export EXTRA_BAZEL_ARGS="--tool_java_runtime_version=local_jdk"
# ./compile.sh

Grab a <INSERT FAVORITE BEVERAGE HERE> and wait for the build to complete.

Debugging Bazel build problems

When encountering issues with building Bazel the following EXTRA_BAZEL_ARGS can be set to get more information during the build. See the Bazel Command Line Reference for more flags.

# export EXTRA_BAZEL_ARGS="--subcommands --verbose_failures --tool_java_runtime_version=local_jdk"
# export CC_CONFIGURE_DEBUG=1

Troubleshooting

Package '@local_jdk//': Package '' contains errors

If you run in to an error like this:

ERROR: /root/.cache/bazel/_bazel_root/b3ceecd93235c3ff2b5d18da2360ca56/external/local_jdk/BUILD.bazel:183:10: @local_jdk//:jdk-lib: invalid label 'lib/perl5/man/man3/App::Cpan.3.gz' in element 7182 of attribute 'srcs' in 'filegroup' rule: invalid target name 'lib/perl5/man/man3/App::Cpan.3.gz': target names may not contain ':'
ERROR: Analysis of target '//main:hello-world' failed; build aborted: error loading package '@local_jdk//': Package '' contains errors

You probably need to specify where Java home is. For example:

$ export JAVA_HOME="/opt/local/java/openjdk21"

Porting projects which use Bazel to illumos

TLDR; Patches that make Bazel build on illumos, do not always carry over to projects you build with that Bazel.

Various language rule repos (such as rules_cc for C++) have been modified in this port to support illumos. However applications which you try to build might need manual patching of repo's like rules_cc if the project pulls in it's own version of such repo's.

Example with building gRPC java

The gRPC Java compiler (which is a C++ application) is such an example. It pulls in it's own rules_cc version. This version does not have any of the illumos support this Bazel illumos port has in it. Hence one needs to apply the following patches:

$ cat > ~/grpc-java/third_party/rules_cc/rules_cc-0.2.13-illumos.patch <<'PATCH'
--- a/cc/private/toolchain/unix_cc_configure.bzl
+++ b/cc/private/toolchain/unix_cc_configure.bzl
@@ -464,16 +464,22 @@
     use_libcpp = darwin or bsd
-    is_as_needed_supported = _is_linker_option_supported(
-        repository_ctx,
-        cc,
-        force_linker_flags,
-        "-Wl,-no-as-needed",
-        "-no-as-needed",
-    )
-    is_push_state_supported = _is_linker_option_supported(
-        repository_ctx,
-        cc,
-        force_linker_flags,
-        "-Wl,--push-state",
-        "--push-state",
-    )
+    # illumos/Solaris ld has no GNU --as-needed/--push-state. The probe links an
+    # empty program to /dev/null, which never exercises the as-needed code path,
+    # so it false-positives on illumos and bakes -Wl,-no-as-needed (plus the
+    # --push-state,-as-needed wrapping of -lstdc++/-lm) into the toolchain,
+    # breaking every real link. repository_ctx.os.name is "sunos" on illumos.
+    is_sunos = repository_ctx.os.name.find("sunos") != -1
+    is_as_needed_supported = not is_sunos and _is_linker_option_supported(
+        repository_ctx,
+        cc,
+        force_linker_flags,
+        "-Wl,-no-as-needed",
+        "-no-as-needed",
+    )
+    is_push_state_supported = not is_sunos and _is_linker_option_supported(
+        repository_ctx,
+        cc,
+        force_linker_flags,
+        "-Wl,--push-state",
+        "--push-state",
+    )
     if use_libcpp:
PATCH

We then need to register the patch file with the Bazel build:

$ cat > ~/grpc-java/third_party/rules_cc/BUILD <<'BUILD'
licenses(["notice"])

exports_files([
  "BUILD",
  "rules_cc-0.2.13-illumos.patch",
])
BUILD

And finally we need to make Bazel apply the patch file during the build:

$ cat >> ~/grpc-java/MODULE.bazel <<'EOF'
single_version_override(
    module_name = "rules_cc",
    version = "0.2.13",
    patch_strip = 1,
    patches = ["//third_party/rules_cc:rules_cc-0.2.13-illumos.patch"],
    patch_cmds = [
        # With illumos/Solaris ld the -S flag does not mean the same as with GNU ld, which causes issues.
        "sed 's|-Wl,-S|-Wl,-s|' cc/private/toolchain/unix_cc_toolchain_config.bzl > unix_cc_tc.tmp && mv unix_cc_tc.tmp cc/private/toolchain/unix_cc_toolchain_config.bzl",
    ],
)
EOF

Known issues

  • There are some FIXME: entries added to the code base which describe ugly hacks which have been applied. If these changes are ever to be upstreamed these would likely need to be addressed.

AI usage disclosure

Starting from the 7.7.1 port (so when the 6.5.1 patch was updated for 7.7.1) LLM's were used to assist in rebasing the illumos patch to newer versions.

Original Bazel README.md

{Fast, Correct} - Choose two

Build and test software of any size, quickly and reliably.

  • Speed up your builds and tests: Bazel rebuilds only what is necessary. With advanced local and distributed caching, optimized dependency analysis and parallel execution, you get fast and incremental builds.

  • One tool, multiple languages: Build and test Java, C++, Android, iOS, Go, and a wide variety of other language platforms. Bazel runs on Windows, macOS, and Linux.

  • Scalable: Bazel helps you scale your organization, codebase, and continuous integration solution. It handles codebases of any size, in multiple repositories or a huge monorepo.

  • Extensible to your needs: Easily add support for new languages and platforms with Bazel's familiar extension language. Share and re-use language rules written by the growing Bazel community.

Getting Started

Documentation

Reporting a Vulnerability

To report a security issue, please email security@bazel.build with a description of the issue, the steps you took to create the issue, affected versions, and, if known, mitigations for the issue. Our vulnerability management team will respond within 3 working days of your email. If the issue is confirmed as a vulnerability, we will open a Security Advisory. This project follows a 90 day disclosure timeline.

Contributing to Bazel

See CONTRIBUTING.md

Build status

About

SmartOS / illumos / Solaris port of Bazel; A fast, scalable, multi-language and extensible build system

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages