Skip to content

Commit

Permalink
[1/2] Support for macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
lifeiteng committed Nov 21, 2020
1 parent 01d684d commit a7c2901
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 7 deletions.
1 change: 0 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ build --cxxopt="-std=c++14"
build --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0"
build --auto_output_filter=subpackages
build --copt="-Wall" --copt="-Wno-sign-compare"
build --linkopt="-lrt -lm"

# TF isn't built in dbg mode, so our dbg builds will segfault due to inconsistency
# of defines when using tf's headers. In particular in refcount.h.
Expand Down
8 changes: 8 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"""
import argparse
import os
import platform
import subprocess
import sys

Expand Down Expand Up @@ -69,6 +70,13 @@ def main():
reset_configure_bazelrc()
setup_python(environ_cp)

write_to_bazelrc('\n')
if platform.system() == 'Darwin':
write_to_bazelrc('# https://github.com/googleapis/google-cloud-cpp-spanner/issues/1003')
write_to_bazelrc('build --copt=-DGRPC_BAZEL_BUILD')
else:
write_to_bazelrc('build --linkopt="-lrt -lm"')


def get_from_env_or_user_or_default(environ_cp, var_name, ask_for_var,
var_default):
Expand Down
1 change: 1 addition & 0 deletions docker/dev.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ ARG pip_dependencies=' \
numpy \
oauth2client \
pandas \
platform \
portpicker'


Expand Down
1 change: 1 addition & 0 deletions docker/release.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ ARG pip_dependencies=' \
numpy \
oauth2client \
pandas \
platform \
portpicker'

# TODO(b/154930404): Update to 2.2.0 once it's out. May need to
Expand Down
9 changes: 9 additions & 0 deletions reverb/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ licenses(["notice"])

exports_files(["LICENSE"])

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

reverb_pytype_strict_library(
name = "reverb",
srcs = ["__init__.py"],
Expand Down
11 changes: 8 additions & 3 deletions reverb/cc/platform/default/build_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ def reverb_gen_op_wrapper_py(name, out, kernel_lib, linkopts = [], **kwargs):
],
linkshared = 1,
linkopts = linkopts + _rpath_linkopts(module_name) + [
"-Wl,--version-script",
"$(location %s)" % version_script_file,
],
**kwargs
Expand Down Expand Up @@ -359,7 +358,14 @@ def _rpath_linkopts(name):
# ops) are picked up as long as they are in either the same or a parent
# directory in the tensorflow/ tree.
levels_to_root = native.package_name().count("/") + name.count("/")
return ["-Wl,%s" % (_make_search_paths("$$ORIGIN", levels_to_root),)]
return select({
"//reverb:macos": [
"-Wl,%s" % (_make_search_paths("$$ORIGIN", levels_to_root),),
],
"//conditions:default": [
"-Wl,--version-script,%s" % (_make_search_paths("$$ORIGIN", levels_to_root),),
],
})

def reverb_pybind_extension(
name,
Expand Down Expand Up @@ -442,7 +448,6 @@ def reverb_pybind_extension(
"-fvisibility=hidden", # avoid pybind symbol clashes between DSOs.
],
linkopts = linkopts + _rpath_linkopts(module_name) + [
"-Wl,--version-script",
"$(location %s)" % version_script_file,
],
deps = depset(deps + [
Expand Down
18 changes: 15 additions & 3 deletions reverb/cc/platform/default/repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ def _find_python_solib_path(repo_ctx):
.format(exec_result.stderr))
version = exec_result.stdout.splitlines()[-1]
basename = "lib{}.so".format(version)
if repo_ctx.os.name.lower().find("mac") != -1:
basename = "lib{}m.a".format(version)

exec_result = repo_ctx.execute(
["{}-config".format(version), "--configdir"],
quiet = True,
Expand Down Expand Up @@ -219,17 +222,20 @@ filegroup(
def _tensorflow_solib_repo_impl(repo_ctx):
tf_lib_path = _find_tf_lib_path(repo_ctx)
repo_ctx.symlink(tf_lib_path, "tensorflow_solib")
suffix = "2.so"
if repo_ctx.os.name.lower().find("mac") != -1:
suffix = "2.dylib"

repo_ctx.file(
"BUILD",
content = """
cc_library(
name = "framework_lib",
srcs = ["tensorflow_solib/libtensorflow_framework.so.2"],
srcs = ["tensorflow_solib/libtensorflow_framework.{}"],
deps = ["@python_includes", "@python_includes//:numpy_includes"],
visibility = ["//visibility:public"],
)
""",
)
""".format(suffix))

def _python_includes_repo_impl(repo_ctx):
python_include_path = _find_python_include_path(repo_ctx)
Expand Down Expand Up @@ -332,6 +338,12 @@ def _reverb_protoc_archive(ctx):
urls = [
"https://github.com/protocolbuffers/protobuf/releases/download/v%s/protoc-%s-linux-x86_64.zip" % (version, version),
]
if ctx.os.name.lower().find("mac") != -1:
urls = [
"https://github.com/protocolbuffers/protobuf/releases/download/v%s/protoc-%s-osx-x86_64.zip" % (version, version),
]
sha256 = "" # TODO(Feiteng) set this in WORKSPACE

ctx.download_and_extract(
url = urls,
sha256 = sha256,
Expand Down

0 comments on commit a7c2901

Please sign in to comment.