Skip to content

Commit

Permalink
Support pybind on mac
Browse files Browse the repository at this point in the history
  • Loading branch information
chokobole committed Mar 17, 2019
1 parent e7829b0 commit 9a04c92
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 41 deletions.
51 changes: 44 additions & 7 deletions bazel/felicia_cc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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
)
Expand All @@ -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
)

Expand All @@ -264,7 +280,6 @@ def fel_cc_shared_library(
deps = [],
data = [],
linkopts = [],
visibility = None,
**kwargs):
native.cc_binary(
name = "lib" + name + ".so",
Expand All @@ -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"],
)
3 changes: 2 additions & 1 deletion bazel/felicia_pybind.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
10 changes: 9 additions & 1 deletion felicia/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -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 = [
Expand All @@ -110,4 +118,4 @@ fel_cc_shared_library(
"//felicia/core/node",
"//felicia/core/util",
]
)
)
2 changes: 0 additions & 2 deletions felicia/core/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ fel_cc_library(
":error_codes_proto_cc",
"//third_party/chromium",
"@com_google_googletest//:gtest",
"@com_google_protobuf//:protobuf",
],
)

Expand All @@ -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",
Expand Down
1 change: 0 additions & 1 deletion felicia/core/master/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions felicia/core/util/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down
18 changes: 5 additions & 13 deletions felicia/python/core/node/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 3 additions & 13 deletions felicia/python/core/util/command_line_interface/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion third_party/chromium/base/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ chromium_cc_library(
],
"//conditions:default": [],
}),
linkstatic = 1,
deps = [
":third_party",
":buildflags",
Expand Down

0 comments on commit 9a04c92

Please sign in to comment.