From 9a04c9278e219becb8636cccc06acafec4a445d9 Mon Sep 17 00:00:00 2001 From: wonyongkim Date: Sun, 17 Mar 2019 17:38:59 +0900 Subject: [PATCH] Support pybind on mac Apply solutions https://github.com/protocolbuffers/protobuf/issues/1941#issuecomment-284582895 --- bazel/felicia_cc.bzl | 51 ++++++++++++++++--- bazel/felicia_pybind.bzl | 3 +- felicia/BUILD | 10 +++- felicia/core/lib/BUILD | 2 - felicia/core/master/BUILD | 1 - felicia/core/util/BUILD | 4 +- felicia/python/core/node/BUILD | 18 ++----- .../core/util/command_line_interface/BUILD | 16 ++---- third_party/chromium/base/BUILD | 1 - 9 files changed, 65 insertions(+), 41 deletions(-) diff --git a/bazel/felicia_cc.bzl b/bazel/felicia_cc.bzl index 0cdbb420..e503eec3 100644 --- a/bazel/felicia_cc.bzl +++ b/bazel/felicia_cc.bzl @@ -156,12 +156,14 @@ def deps_with_felicia_headers(deps): def fel_c_library( name, - copts = [], + srcs = [], hdrs = [], deps = [], + copts = [], **kwargs): native.cc_library( name = name, + srcs = srcs, hdrs = hdrs, deps = deps, copts = fel_copts() + copts, @@ -177,12 +179,14 @@ def fel_c_library( def fel_cc_library( name, - copts = [], + srcs = [], hdrs = [], deps = [], + copts = [], **kwargs): native.cc_library( name = name, + srcs = srcs, hdrs = hdrs, deps = deps, copts = fel_cxxopts() + copts, @@ -198,12 +202,14 @@ def fel_cc_library( def fel_objc_library( name, - copts = [], + srcs = [], hdrs = [], deps = [], + copts = [], **kwargs): native.objc_library( name = name, + srcs = srcs, hdrs = hdrs, deps = deps, copts = fel_cxxopts() + copts, @@ -219,10 +225,14 @@ def fel_objc_library( def fel_cc_binary( name, + srcs = [], + deps = [], copts = [], **kwargs): native.cc_binary( name = name, + srcs = srcs, + deps = deps, copts = fel_cxxopts() + copts, **kwargs ) @@ -239,11 +249,17 @@ def fel_cc_binary( def fel_cc_test( name, + srcs = [], + deps = [], copts = [], + linkstatic = 1, **kwargs): native.cc_test( name = name, + srcs = srcs, + deps = deps, copts = fel_cxxopts() + copts, + linkstatic = linkstatic, **kwargs ) @@ -264,7 +280,6 @@ def fel_cc_shared_library( deps = [], data = [], linkopts = [], - visibility = None, **kwargs): native.cc_binary( name = "lib" + name + ".so", @@ -274,24 +289,46 @@ def fel_cc_shared_library( linkstatic = 1, data = data, linkopts = linkopts, - visibility = visibility, **kwargs ) collect_transitive_hdrs( name = "collect_" + name + "_hdrs", deps = [installed_headers_for_dep(x) for x in deps], - visibility = visibility, + visibility = ["//visibility:private"], ) native.filegroup( name = name + "_hdrs", srcs = [":collect_" + name + "_hdrs"], + visibility = ["//visibility:private"], ) native.cc_library( name = name, srcs = [":lib" + name + ".so"], hdrs = [":" + name + "_hdrs"], - visibility = visibility, + ) + +def fel_cc_third_party_shared_library( + name, + srcs = [], + deps = [], + data = [], + linkopts = [], + **kwargs): + native.cc_binary( + name = "lib" + name + ".so", + srcs = srcs, + deps = deps, + linkshared = 1, + linkstatic = 1, + data = data, + linkopts = linkopts, + **kwargs + ) + + native.cc_library( + name = name, + srcs = [":lib" + name + ".so"], ) diff --git a/bazel/felicia_pybind.bzl b/bazel/felicia_pybind.bzl index 267085fa..d3038c59 100644 --- a/bazel/felicia_pybind.bzl +++ b/bazel/felicia_pybind.bzl @@ -25,9 +25,10 @@ def fel_pybind_py_library( linkstatic = 1, deps = [ "//felicia:felicia", + "//felicia:protobuf", "//third_party/chromium", "@com_google_googletest//:gtest", - "@com_google_protobuf//:protobuf", + "@com_google_protobuf//:protobuf_headers", "@pybind11", ] + cc_deps, ) diff --git a/felicia/BUILD b/felicia/BUILD index d100aa0d..788c4ffe 100644 --- a/felicia/BUILD +++ b/felicia/BUILD @@ -2,6 +2,7 @@ load( "//bazel:felicia_cc.bzl", "fel_cc_library", "fel_cc_shared_library", + "fel_cc_third_party_shared_library", ) package(default_visibility = [":internal"]) @@ -101,6 +102,13 @@ fel_cc_library( }), ) +# Workaround to solve the issue related to +# https://github.com/protocolbuffers/protobuf/issues/1941#issuecomment-284582895 +fel_cc_third_party_shared_library( + name = "protobuf", + deps = ["@com_google_protobuf//:protobuf"], +) + fel_cc_shared_library( name = "felicia", deps = [ @@ -110,4 +118,4 @@ fel_cc_shared_library( "//felicia/core/node", "//felicia/core/util", ] -) \ No newline at end of file +) diff --git a/felicia/core/lib/BUILD b/felicia/core/lib/BUILD index 12747701..b1b194d9 100644 --- a/felicia/core/lib/BUILD +++ b/felicia/core/lib/BUILD @@ -45,7 +45,6 @@ fel_cc_library( ":error_codes_proto_cc", "//third_party/chromium", "@com_google_googletest//:gtest", - "@com_google_protobuf//:protobuf", ], ) @@ -57,7 +56,6 @@ fel_cc_test( "base/range_test.cc", "containers/pool_test.cc", ], - linkstatic = 1, # Failed at macos when built with opt deps = [ ":lib", "@com_google_googletest//:gtest_main", diff --git a/felicia/core/master/BUILD b/felicia/core/master/BUILD index 127e33d8..b161eb81 100644 --- a/felicia/core/master/BUILD +++ b/felicia/core/master/BUILD @@ -113,7 +113,6 @@ fel_cc_test( srcs = [ "master_test.cc", ], - linkstatic = 1, # Failed at macos when built with opt deps = [ ":master", "@com_google_googletest//:gtest_main", diff --git a/felicia/core/util/BUILD b/felicia/core/util/BUILD index 50ba4e49..a79ee39a 100644 --- a/felicia/core/util/BUILD +++ b/felicia/core/util/BUILD @@ -10,14 +10,14 @@ fel_cc_library( name = "command_line_interface", srcs = [ "command_line_interface/flag.cc", - "command_line_interface/flag_forward.h", "command_line_interface/flag_parser.cc", - "command_line_interface/flag_value_traits.h", "command_line_interface/table_writer.cc", ], hdrs = [ "command_line_interface/flag.h", + "command_line_interface/flag_forward.h", "command_line_interface/flag_parser.h", + "command_line_interface/flag_value_traits.h", "command_line_interface/table_writer.h", "command_line_interface/text_style.h", ], diff --git a/felicia/python/core/node/BUILD b/felicia/python/core/node/BUILD index 233a8d8c..c56412c3 100644 --- a/felicia/python/core/node/BUILD +++ b/felicia/python/core/node/BUILD @@ -6,22 +6,14 @@ load("//bazel:felicia_pybind.bzl", "fel_pybind_py_library") package(default_visibility = ["//felicia:internal"]) -fel_cc_library( - name = "py_node_lifecycle", - hdrs = [ - "py_node_lifecycle.h", - ], - deps = [ - "//felicia/core/node", - "//felicia/python/core:type_conversion", - "@pybind11", - ], -) - fel_pybind_py_library( name = "node", cc_deps = [ - ":py_node_lifecycle", + "//felicia/python/core:type_conversion", + ], + cc_srcs = [ + "py_node_lifecycle.h", + "node_py.cc", ], py_srcs = [ "node_lifecycle.py", diff --git a/felicia/python/core/util/command_line_interface/BUILD b/felicia/python/core/util/command_line_interface/BUILD index 2f9d7d49..b0557cc7 100644 --- a/felicia/python/core/util/command_line_interface/BUILD +++ b/felicia/python/core/util/command_line_interface/BUILD @@ -6,21 +6,11 @@ load("//bazel:felicia_pybind.bzl", "fel_pybind_py_library") package(default_visibility = ["//felicia:internal"]) -fel_cc_library( - name = "py_flag_parser_delegate", - hdrs = [ - "py_flag_parser_delegate.h", - ], - deps = [ - "//felicia/core/util:command_line_interface", - "@pybind11", - ], -) - fel_pybind_py_library( name = "flag", - cc_deps = [ - ":py_flag_parser_delegate" + cc_srcs = [ + "py_flag_parser_delegate.h", + "flag_py.cc", ], py_srcs = [ "flag_parser_delegate.py", diff --git a/third_party/chromium/base/BUILD b/third_party/chromium/base/BUILD index 2713d20f..9dbc09fd 100644 --- a/third_party/chromium/base/BUILD +++ b/third_party/chromium/base/BUILD @@ -95,7 +95,6 @@ chromium_cc_library( ], "//conditions:default": [], }), - linkstatic = 1, deps = [ ":third_party", ":buildflags",