Skip to content

Commit

Permalink
Modifications to port Bazel 4.1.0 to Illumos / SmartOS.
Browse files Browse the repository at this point in the history
  • Loading branch information
siepkes committed Sep 11, 2021
1 parent c4975ef commit e304b56
Show file tree
Hide file tree
Showing 51 changed files with 1,918 additions and 66 deletions.
73 changes: 72 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,75 @@
# [Bazel](https://bazel.build)
# 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 version 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 specific 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, Twitter, etc.).

## Building Bazel on SmartOS

Create a SmartOS container (joyent brand if your on Triton). To build and use Bazel you need an image which has GCC7. It's easiest to use an image which also uses GCC7 by default. This guide assumes you use image `1d05e788-5409-11eb-b12f-037bd7fee4ee` (20.4.0) with GCC 7.5. Beware that currently the `7.5.0` path is hardcoded in Bazel path (see known issues).

Install required build packages:

```
# pkgin -y install git-base zip unzip openjdk11 libtool cmake automake ninja-build autoconf gmake gcc7
```

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-4.1.0-dist.zip` (the Bazel distribution) from the [Bazel releases](https://github.com/bazelbuild/bazel/releases) page.

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

```
# mkdir bazel-4.1.0
# unzip bazel-4.1.0-dist.zip -d bazel-4.1.0
# git clone https://github.com/siepkes/bazel-smartos.git
# cd bazel-smartos
# git checkout smartos-4.1.0
# git format-patch -1
# cd ../bazel-4.1.0
# patch -p1 < ../bazel-smartos/0001-Modifications-to-port-Bazel-4.1.0-to-Illumos-SmartOS.patch
```

We are now ready to build Bazel!

```
# export JAVA_HOME="/opt/local/java/openjdk11"
# export EXTRA_BAZEL_ARGS="--host_javabase=@local_jdk//: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](https://docs.bazel.build/versions/master/command-line-reference.html) for more flags.

```
# export EXTRA_BAZEL_ARGS="--subcommands --verbose_failures --host_javabase=@local_jdk//:jdk"
```

## Notes on porting to Illumos

This port is dependent on the [platforms](https://github.com/siepkes/platforms) definition repository.

## Known issues

* `bazel/tools/cpp/CROSSTOOL` contains a hardcoded GCC version number in some paths. For example `/opt/local/gcc7/lib/gcc/x86_64-sun-solaris2.11/7.5.0/include-fixed`. This can break with GCC updates and will result in errors like when for example `7.3.0` is configured in Bazel instead of `7.5.0`:

```
ERROR: /root/.cache/bazel/_bazel_root/7558a64af10a6eb79f74e70211660103/external/com_google_protobuf/BUILD:414:1: undeclared inclusion(s) in rule '@com_google_protobuf//:protoc':
this rule is missing dependency declarations for the following files included by 'external/com_google_protobuf/src/google/protobuf/compiler/main.cc':
'/opt/local/gcc7/lib/gcc/x86_64-sun-solaris2.11/7.5.0/include/stddef.h'
'/opt/local/gcc7/lib/gcc/x86_64-sun-solaris2.11/7.5.0/include/stdint.h'
Target //source/exe:envoy-static failed to build
```

* 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.

# Original Bazel README.md

*{Fast, Correct} - Choose two*

Expand Down
49 changes: 23 additions & 26 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ distdir_tar(
# bazelbuild/bazel-skylib
"bazel-skylib-1.0.3.tar.gz",
# bazelbuild/platforms
"platforms-0.0.4.tar.gz",
"e2b0fddbd5f841432740a0029751168c054db622.zip",
# bazelbuild/rules_java
"7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip",
# bazelbuild/rules_cc
Expand All @@ -174,7 +174,7 @@ distdir_tar(
# protocolbuffers/protobuf
"v3.13.0.tar.gz",
# grpc/grpc
"v1.33.1.tar.gz",
"ab57044cd549668466f5c2167c41638e9eb45791.tar.gz",
# c-ares/c-ares
"e982924acee7f7313b4baa4ee5ec000c5e373c30.tar.gz",
# protocolbuffers/upb
Expand All @@ -201,7 +201,7 @@ distdir_tar(
# bazelbuild/bazel-skylib
"bazel-skylib-1.0.3.tar.gz": "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
# bazelbuild/platforms
"platforms-0.0.4.tar.gz": "079945598e4b6cc075846f7fd6a9d0857c33a7afc0de868c2ccb96405225135d",
"e2b0fddbd5f841432740a0029751168c054db622.zip": "7c6d68ce528ed7d409fe20e1674767bac6d192bd486281d91af4e7ef3a233280",
# bazelbuild/rules_java
"7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip": "bc81f1ba47ef5cc68ad32225c3d0e70b8c6f6077663835438da8d5733f917598",
# bazelbuild/rules_cc
Expand All @@ -215,7 +215,7 @@ distdir_tar(
# protocolbuffers/protobuf
"v3.13.0.tar.gz": "9b4ee22c250fe31b16f1a24d61467e40780a3fbb9b91c3b65be2a376ed913a1a",
# grpc/grpc
"v1.33.1.tar.gz": "58eaee5c0f1bd0b92ebe1fa0606ec8f14798500620e7444726afcaf65041cb63",
"ab57044cd549668466f5c2167c41638e9eb45791.tar.gz": "58eaee5c0f1bd0b92ebe1fa0606ec8f14798500620e7444726afcaf65041cb63",
# c-ares/c-ares
"e982924acee7f7313b4baa4ee5ec000c5e373c30.tar.gz": "e8c2751ddc70fed9dc6f999acd92e232d5846f009ee1674f8aee81f19b2b915a",
# protocolbuffers/upb
Expand Down Expand Up @@ -263,9 +263,8 @@ distdir_tar(
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
],
# bazelbuild/platforms
"platforms-0.0.4.tar.gz": [
"https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.4/platforms-0.0.4.tar.gz",
"https://github.com/bazelbuild/platforms/releases/download/0.0.4/platforms-0.0.4.tar.gz",
"e2b0fddbd5f841432740a0029751168c054db622.zip": [
"https://github.com/siepkes/platforms/archive/e2b0fddbd5f841432740a0029751168c054db622.zip",
],
# bazelbuild/rules_java
"7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip": [
Expand Down Expand Up @@ -298,9 +297,8 @@ distdir_tar(
"https://github.com/protocolbuffers/protobuf/archive/v3.13.0.tar.gz",
],
# grpc/grpc
"v1.33.1.tar.gz": [
"https://mirror.bazel.build/github.com/grpc/grpc/archive/v1.33.1.tar.gz",
"https://github.com/grpc/grpc/archive/v1.33.1.tar.gz",
"ab57044cd549668466f5c2167c41638e9eb45791.tar.gz": [
"https://github.com/siepkes/grpc/archive/ab57044cd549668466f5c2167c41638e9eb45791.tar.gz",
],
# c-ares/c-ares
"e982924acee7f7313b4baa4ee5ec000c5e373c30.tar.gz": [
Expand Down Expand Up @@ -582,7 +580,7 @@ distdir_tar(
# bazelbuild/bazel-skylib
"bazel-skylib-1.0.3.tar.gz",
# bazelbuild/platforms
"platforms-0.0.4.tar.gz",
"e2b0fddbd5f841432740a0029751168c054db622.zip",
# bazelbuild/rules_java
"7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip",
# bazelbuild/rules_cc
Expand Down Expand Up @@ -617,7 +615,7 @@ distdir_tar(
# bazelbuild/bazel-skylib
"bazel-skylib-1.0.3.tar.gz": "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
# bazelbuild/platforms
"platforms-0.0.4.tar.gz": "079945598e4b6cc075846f7fd6a9d0857c33a7afc0de868c2ccb96405225135d",
"e2b0fddbd5f841432740a0029751168c054db622.zip": "7c6d68ce528ed7d409fe20e1674767bac6d192bd486281d91af4e7ef3a233280",
# bazelbuild/rules_java
"7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip": "bc81f1ba47ef5cc68ad32225c3d0e70b8c6f6077663835438da8d5733f917598",
# bazelbuild/rules_cc
Expand All @@ -627,7 +625,7 @@ distdir_tar(
# protocolbuffers/protobuf
"v3.13.0.tar.gz": "9b4ee22c250fe31b16f1a24d61467e40780a3fbb9b91c3b65be2a376ed913a1a",
# grpc/grpc
"v1.33.1.tar.gz": "58eaee5c0f1bd0b92ebe1fa0606ec8f14798500620e7444726afcaf65041cb63",
"ab57044cd549668466f5c2167c41638e9eb45791.tar.gz": "58eaee5c0f1bd0b92ebe1fa0606ec8f14798500620e7444726afcaf65041cb63",
# c-ares/c-ares
"e982924acee7f7313b4baa4ee5ec000c5e373c30.tar.gz": "e8c2751ddc70fed9dc6f999acd92e232d5846f009ee1674f8aee81f19b2b915a",
# protocolbuffers/upb
Expand Down Expand Up @@ -656,9 +654,8 @@ distdir_tar(
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
],
# bazelbuild/platforms
"platforms-0.0.4.tar.gz": [
"https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.4/platforms-0.0.4.tar.gz",
"https://github.com/bazelbuild/platforms/releases/download/0.0.4/platforms-0.0.4.tar.gz",
"e2b0fddbd5f841432740a0029751168c054db622.zip": [
"https://github.com/siepkes/platforms/archive/e2b0fddbd5f841432740a0029751168c054db622.zip",
],
# bazelbuild/rules_java
"7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip": [
Expand All @@ -681,9 +678,8 @@ distdir_tar(
"https://github.com/protocolbuffers/protobuf/archive/v3.13.0.tar.gz",
],
# grpc/grpc
"v1.33.1.tar.gz": [
"https://mirror.bazel.build/github.com/grpc/grpc/archive/v1.33.1.tar.gz",
"https://github.com/grpc/grpc/archive/v1.33.1.tar.gz",
"ab57044cd549668466f5c2167c41638e9eb45791.tar.gz": [
"https://github.com/siepkes/grpc/archive/ab57044cd549668466f5c2167c41638e9eb45791.tar.gz",
],
# c-ares/c-ares
"e982924acee7f7313b4baa4ee5ec000c5e373c30.tar.gz": [
Expand Down Expand Up @@ -766,10 +762,11 @@ http_archive(

http_archive(
name = "platforms",
sha256 = "079945598e4b6cc075846f7fd6a9d0857c33a7afc0de868c2ccb96405225135d",
sha256 = "7c6d68ce528ed7d409fe20e1674767bac6d192bd486281d91af4e7ef3a233280",
strip_prefix = "platforms-e2b0fddbd5f841432740a0029751168c054db622",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.4/platforms-0.0.4.tar.gz",
"https://github.com/bazelbuild/platforms/releases/download/0.0.4/platforms-0.0.4.tar.gz",
# Based on platforms 0.0.4 release.
"https://github.com/siepkes/platforms/archive/e2b0fddbd5f841432740a0029751168c054db622.zip",
],
)

Expand Down Expand Up @@ -1233,11 +1230,11 @@ http_archive(
name = "com_github_grpc_grpc",
patch_args = ["-p1"],
patches = ["//third_party/grpc:grpc_1.33.1.patch"],
sha256 = "58eaee5c0f1bd0b92ebe1fa0606ec8f14798500620e7444726afcaf65041cb63",
strip_prefix = "grpc-1.33.1",
sha256 = "c3fccbff8f7c8ea8504be10e1b0f0e00df53a7bf0132bb1369151df0dd6fef17",
strip_prefix = "grpc-ab57044cd549668466f5c2167c41638e9eb45791",
urls = [
"https://mirror.bazel.build/github.com/grpc/grpc/archive/v1.33.1.tar.gz",
"https://github.com/grpc/grpc/archive/v1.33.1.tar.gz",
# Fork with Illumos changes of v1.33.1.
"https://github.com/siepkes/grpc/archive/ab57044cd549668466f5c2167c41638e9eb45791.tar.gz",
],
)

Expand Down
4 changes: 4 additions & 0 deletions scripts/bootstrap/buildenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ openbsd)
JAVA_HOME="${JAVA_HOME:-/usr/local/jdk-1.8.0}"
;;

sunos)
JAVA_HOME="${JAVA_HOME:-/opt/local/java/openjdk8}"
;;

darwin)
if [[ -z "$JAVA_HOME" ]]; then
JAVA_HOME="$(/usr/libexec/java_home -v ${JAVA_VERSION}+ 2> /dev/null)" \
Expand Down
1 change: 1 addition & 0 deletions scripts/packages/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ filegroup(
],
"//src/conditions:freebsd": [],
"//src/conditions:openbsd": [],
"//src/conditions:illumos": [],
"//src/conditions:darwin": [
":with-jdk/install.sh",
":without-jdk/install.sh",
Expand Down
4 changes: 4 additions & 0 deletions scripts/packages/template_bin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ if [ -z "${JAVA_HOME-}" ]; then
JAVA_HOME="/usr/local/jdk-1.8.0"
BASHRC="~/.bashrc"
;;
sunos)
JAVA_HOME="/opt/local/java/openjdk8"
BASHRC="~/.bashrc"
;;
darwin)
JAVA_HOME="$(/usr/libexec/java_home -v ${JAVA_VERSION}+ 2> /dev/null)" || true
BASHRC="~/.bash_profile"
Expand Down
14 changes: 14 additions & 0 deletions src/conditions/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ config_setting(
visibility = ["//visibility:public"],
)

config_setting(
name = "illumos",
values = {"cpu": "illumos"},
visibility = ["//visibility:public"],
)

config_setting(
name = "windows",
constraint_values = ["@platforms//os:windows"],
Expand All @@ -168,3 +174,11 @@ config_setting(
},
visibility = ["//visibility:public"],
)

config_setting(
name = "grpc_no_ares",
values = {
"define": "grpc_no_ares=true",
},
visibility = ["//visibility:public"],
)
6 changes: 6 additions & 0 deletions src/conditions/BUILD.tools
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ config_setting(
visibility = ["//visibility:public"],
)

config_setting(
name = "illumos",
values = {"cpu": "illumos"},
visibility = ["//visibility:public"],
)

config_setting(
name = "darwin",
constraint_values = ["@platforms//os:macos"],
Expand Down
8 changes: 8 additions & 0 deletions src/main/cpp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ cc_library(
"blaze_util_bsd.cc",
"blaze_util_posix.cc",
],
"//src/conditions:illumos": [
"blaze_util_illumos.cc",
"blaze_util_posix.cc",
],
"//src/conditions:windows": [
"blaze_util_windows.cc",
],
Expand All @@ -52,6 +56,8 @@ cc_library(
],
"//src/conditions:openbsd": [
],
"//src/conditions:illumos": [
],
"//src/conditions:windows": WIN_LINK_OPTS,
"//conditions:default": [
"-lrt",
Expand Down Expand Up @@ -113,6 +119,8 @@ cc_binary(
],
"//src/conditions:openbsd": [
],
"//src/conditions:illumos": [
],
"//src/conditions:windows": [
],
"//conditions:default": [
Expand Down
3 changes: 2 additions & 1 deletion src/main/cpp/blaze.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,8 @@ static ATTRIBUTE_NORETURN void RunClientServerMode(
// actually different because the two processes have different mount
// tables.
BAZEL_LOG(INFO) << "Server's cwd moved or deleted ("
<< server_cwd->AsPrintablePath() << ").";
<< server_cwd->AsPrintablePath() << ") - ("
<< workspace << ") Server PID: " << server->ProcessInfo().server_pid_;
server->KillRunningServer();
} else {
break;
Expand Down
Loading

0 comments on commit e304b56

Please sign in to comment.