Skip to content

Commit

Permalink
Add remaining changes for bootstrap build on OpenBSD.
Browse files Browse the repository at this point in the history
I have tested these changes via a bootstrap build on OpenBSD 6.6-current (amd64 architecture). The resulting `bazel` binary appeared to work in some simple testing involving `cc_library`, `cc_binary`, `java_library`, and `java_binary`.

Known issues/limitations:

- Building a `java_binary`'s deploy JAR fails because the `singlejar` tool fails to build. I intend to investigate soon.

- Running Bazel requires a `--host_javabase=@local_jdk//:jdk` flag.

- Sandboxing is unsupported.

This change, split out of the larger PR #10274, is part of the OpenBSD port in #10250. Most of the changes in that larger PR have already been committed via several smaller PRs (see the PRs linked from #10250). This PR collects the remaining changes.

Closes #10567.

PiperOrigin-RevId: 290745757
  • Loading branch information
aldersondrive authored and copybara-github committed Jan 21, 2020
1 parent 99f8a8f commit d6145a0
Show file tree
Hide file tree
Showing 18 changed files with 77 additions and 18 deletions.
5 changes: 5 additions & 0 deletions scripts/bootstrap/buildenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ freebsd)
JAVA_HOME="${JAVA_HOME:-/usr/local/openjdk8}"
;;

openbsd)
# JAVA_HOME must point to a Java installation.
JAVA_HOME="${JAVA_HOME:-/usr/local/jdk-1.8.0}"
;;

darwin)
if [[ -z "$JAVA_HOME" ]]; then
JAVA_HOME="$(/usr/libexec/java_home -v ${JAVA_VERSION}+ 2> /dev/null)" \
Expand Down
5 changes: 3 additions & 2 deletions scripts/packages/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load(":self_extract_binary.bzl", "self_extract_binary")

package(default_visibility = ["//scripts/packages:__subpackages__"])

filegroup(
Expand All @@ -20,6 +22,7 @@ filegroup(
":zip-bazel-exe_nojdk",
],
"//src/conditions:freebsd": [],
"//src/conditions:openbsd": [],
"//src/conditions:darwin": [
":with-jdk/install.sh",
":without-jdk/install.sh",
Expand Down Expand Up @@ -120,8 +123,6 @@ genrule(
cmd = "mkdir -p $$(dirname $@); cp $< $@",
)

load(":self_extract_binary.bzl", "self_extract_binary")

[self_extract_binary(
name = "%s/install.sh" % kind,
flatten_resources = [
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 @@ -115,6 +115,10 @@ if [ -z "${JAVA_HOME-}" ]; then
JAVA_HOME="/usr/local/openjdk8"
BASHRC="~/.bashrc"
;;
openbsd)
JAVA_HOME="/usr/local/jdk-1.8.0"
BASHRC="~/.bashrc"
;;
darwin)
JAVA_HOME="$(/usr/libexec/java_home -v ${JAVA_VERSION}+ 2> /dev/null)" || true
BASHRC="~/.bash_profile"
Expand Down
20 changes: 16 additions & 4 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ load(":rule_size_test.bzl", "rule_size_test")

exports_files(["jdeps_modules.golden"])

# Keep only the first 32 chars (a hex md5sum) and no trailing newline.
md5_cmd = "set -e -o pipefail && echo $(SRCS) | sort | xargs %s | %s | head -c 32 > $@"
# We avoid using the `head` tool's `-c` option, since it does not exist on
# OpenBSD; here we use `dd` instead.
md5_cmd = "set -e -o pipefail && echo $(SRCS) | sort | xargs %s | %s | dd bs=32 count=1 > $@"

# TODO(bazel-team): find a better way to handle dylib extensions.
filegroup(
Expand Down Expand Up @@ -40,6 +41,7 @@ filegroup(
"//src/conditions:darwin": md5_cmd % ("/sbin/md5", "/sbin/md5"),
"//src/conditions:darwin_x86_64": md5_cmd % ("/sbin/md5", "/sbin/md5"),
"//src/conditions:freebsd": md5_cmd % ("/sbin/md5", "/sbin/md5"),
"//src/conditions:openbsd": md5_cmd % ("/bin/md5", "/bin/md5"),
"//conditions:default": md5_cmd % ("md5sum", "md5sum"),
}),
) for suffix, embedded_tools_target in {
Expand Down Expand Up @@ -354,8 +356,8 @@ filegroup(
],
}),
outs = ["package" + suffix + ".zip"],
cmd = "$(location :package-bazel.sh) $@ " + ("" if embed else "''") + " $(SRCS)",
tools = ["package-bazel.sh"],
cmd = "$(location :package_bazel_on_host_platform) $@ " + ("" if embed else "''") + " $(SRCS)",
tools = [":package_bazel_on_host_platform"],
) for suffix, embed in [
("_jdk_allmodules", True),
("_jdk_minimal", True),
Expand All @@ -364,6 +366,16 @@ filegroup(
("_nojdk", True),
]]

genrule(
name = "package_bazel_on_host_platform",
srcs = ["package-bazel.sh"],
outs = ["package-bazel-on-host-platform.sh"],
cmd = select({
"//src/conditions:openbsd": "cat $(SRCS) | sed -e 's@#!/bin/bash@#!/usr/local/bin/bash@' > $@",
"//conditions:default": "cp $(SRCS) $@",
}),
)

genrule(
name = "platforms_archive",
srcs = ["@platforms//:srcs"],
Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/blaze_util_bsd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ string GetSelfPath(const char* argv0) {
// Otherwise, if argv[0] contains a slash, then it's a relative path. Prepend
// the current directory to form an absolute path.
if (argv0str.length() > 0 && argv0str.find('/') != std::string::npos) {
return GetCwd() + "/" + argv0str;
return blaze_util::GetCwd() + "/" + argv0str;
}

// TODO(aldersondrive): Try to find the executable by inspecting the PATH.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ bind(
actual = "@local_jdk//:jni_md_header-freebsd",
)

bind(
name = "jni_md_header-openbsd",
actual = "@local_jdk//:jni_md_header-openbsd",
)

bind(
name = "java",
actual = "@local_jdk//:java",
Expand Down
6 changes: 4 additions & 2 deletions src/main/tools/BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package(default_visibility = ["//src:__subpackages__"])

load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")

package(default_visibility = ["//src:__subpackages__"])

cc_binary(
name = "daemonize",
srcs = ["daemonize.c"],
Expand Down Expand Up @@ -67,6 +67,7 @@ cc_binary(
"//src/conditions:darwin": ["dummy-sandbox.c"],
"//src/conditions:darwin_x86_64": ["dummy-sandbox.c"],
"//src/conditions:freebsd": ["dummy-sandbox.c"],
"//src/conditions:openbsd": ["dummy-sandbox.c"],
"//src/conditions:windows": ["dummy-sandbox.c"],
"//conditions:default": [
"linux-sandbox.cc",
Expand All @@ -82,6 +83,7 @@ cc_binary(
"//src/conditions:darwin": [],
"//src/conditions:darwin_x86_64": [],
"//src/conditions:freebsd": [],
"//src/conditions:openbsd": [],
"//src/conditions:windows": [],
"//conditions:default": [
":logging",
Expand Down
6 changes: 6 additions & 0 deletions src/main/tools/jdk.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ filegroup(
deprecation = DEPRECATION_MESSAGE,
)

filegroup(
name = "jni_md_header-openbsd",
srcs = ["include/openbsd/jni_md.h"],
deprecation = DEPRECATION_MESSAGE,
)

filegroup(
name = "jni_md_header-windows",
srcs = ["include/win32/jni_md.h"],
Expand Down
2 changes: 1 addition & 1 deletion src/main/tools/process-wrapper-legacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// The process-wrapper implementation that was used until and including Bazel
// 0.4.5. Waits for the wrapped process to exit and then kills its process
// group. Works on all POSIX operating systems (tested on Linux, macOS,
// FreeBSD).
// FreeBSD, and OpenBSD).
//
// Caveats:
// - Killing just the process group of the spawned child means that daemons or
Expand Down
2 changes: 1 addition & 1 deletion src/test/shell/bazel/remote/remote_execution_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ EOF

function test_remote_grpc_via_unix_socket() {
case "$PLATFORM" in
darwin|freebsd|linux)
darwin|freebsd|linux|openbsd)
;;
*)
return 0
Expand Down
2 changes: 1 addition & 1 deletion src/test/shell/shell_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function get_real_path() {
function md5_file() {
if [ $# -gt 0 ]; then
local result=""
if [[ ${PLATFORM} == "darwin" ]] || [[ ${PLATFORM} == "freebsd" ]]; then
if [[ ${PLATFORM} == "darwin" ]] || [[ ${PLATFORM} == "freebsd" ]] || [[ ${PLATFORM} == "openbsd" ]]; then
result=$(md5 -q $@ || echo)
else
result=$(md5sum $@ | awk '{print $1}' || echo)
Expand Down
7 changes: 6 additions & 1 deletion src/test/shell/unittest.bash
Original file line number Diff line number Diff line change
Expand Up @@ -734,9 +734,14 @@ if [ "$UNAME" = "linux" ] || [[ "$UNAME" =~ msys_nt* ]]; then
function timestamp() {
echo $(($(date +%s%N)/1000000))
}
elif [[ "$UNAME" = "openbsd" ]]; then
function timestamp() {
# OpenBSD does not have %N, so Python is the best we can do.
python3 -c 'import time; print(int(round(time.time() * 1000)))'
}
else
function timestamp() {
# OS X and FreeBSD do not have %N so python is the best we can do
# OS X and FreeBSD do not have %N, so Python is the best we can do.
python -c 'import time; print(int(round(time.time() * 1000)))'
}
fi
Expand Down
3 changes: 2 additions & 1 deletion src/tools/singlejar/diag.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
* Various useful diagnostics functions from Linux err.h file, wrapped
* for portability.
*/
#if defined(__APPLE__) || defined(__linux__) || defined(__FreeBSD__)
#if defined(__APPLE__) || defined(__linux__) || defined(__FreeBSD__) || \
defined(__OpenBSD__)

#include <err.h>
#define diag_err(...) err(__VA_ARGS__)
Expand Down
5 changes: 3 additions & 2 deletions src/tools/singlejar/mapped_file_posix.inc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@

#include "src/tools/singlejar/diag.h"

// The implementation is 64-bit Linux or OSX specific.
#if !((defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)) && \
// The implementation is specific to 64-bit Linux / OS X / BSD.
#if !((defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
defined(__OpenBSD__)) && \
__SIZEOF_POINTER__ == 8)
#error This code for 64 bit Unix.
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/tools/singlejar/zip_headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#if defined(__linux__)
#include <endian.h>
#elif defined(__FreeBSD__)
#elif defined(__FreeBSD__) || defined(__OpenBSD__)
#include <sys/endian.h>
#elif defined(__APPLE__) || defined(_WIN32)
// Hopefully OSX and Windows will keep running solely on little endian CPUs, so:
Expand Down
5 changes: 4 additions & 1 deletion tools/jdk/default_java_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ DEFAULT_TOOLCHAIN_CONFIGURATION = {
"@bazel_tools//tools/jdk:jdk_compiler_jar",
],
"javac_supports_workers": 1,
"jvm_opts": JDK9_JVM_OPTS,
"jvm_opts": select({
"@bazel_tools//src/conditions:openbsd": JDK8_JVM_OPTS,
"//conditions:default": JDK9_JVM_OPTS,
}),
"misc": DEFAULT_JAVACOPTS,
"singlejar": ["@bazel_tools//tools/jdk:singlejar"],
"bootclasspath": ["@bazel_tools//tools/jdk:platformclasspath"],
Expand Down
7 changes: 7 additions & 0 deletions tools/platforms/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ alias(
actual = "@platforms//os:freebsd",
)

alias(
name = "openbsd",
actual = "@platforms//os:openbsd",
)

alias(
name = "android",
actual = "@platforms//os:android",
Expand Down Expand Up @@ -109,6 +114,7 @@ platform(
os_constraints = [
"@platforms//os:osx",
"@platforms//os:freebsd",
"@platforms//os:openbsd",
"@platforms//os:linux",
"@platforms//os:windows",
],
Expand All @@ -129,6 +135,7 @@ platform(
os_constraints = [
"@platforms//os:osx",
"@platforms//os:freebsd",
"@platforms//os:openbsd",
"@platforms//os:linux",
"@platforms//os:windows",
],
Expand Down
7 changes: 7 additions & 0 deletions tools/platforms/BUILD.tools
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ alias(
actual = "@platforms//os:freebsd",
)

alias(
name = "openbsd",
actual = "@platforms//os:openbsd",
)

alias(
name = "android",
actual = "@platforms//os:android",
Expand Down Expand Up @@ -97,6 +102,7 @@ platform(
os_constraints = [
"@platforms//os:osx",
"@platforms//os:freebsd",
"@platforms//os:openbsd",
"@platforms//os:linux",
"@platforms//os:windows",
],
Expand All @@ -117,6 +123,7 @@ platform(
os_constraints = [
"@platforms//os:osx",
"@platforms//os:freebsd",
"@platforms//os:openbsd",
"@platforms//os:linux",
"@platforms//os:windows",
],
Expand Down

0 comments on commit d6145a0

Please sign in to comment.