Skip to content

Commit 64d451f

Browse files
guangy10facebook-github-bot
authored andcommitted
buck macros (#260)
Summary: Pull Request resolved: #260 Reviewed By: larryliu0820 Differential Revision: D49120267 fbshipit-source-id: 66c372996b7b9141c6f93aab03adad1c71b34e29
1 parent aecef92 commit 64d451f

File tree

4 files changed

+159
-1
lines changed

4 files changed

+159
-1
lines changed

shim/xplat/executorch/build/env_interface.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ _EXTERNAL_DEPS = {
3030
# Commandline flags library
3131
"gflags": "//third-party:gflags",
3232
"gmock": [], # TODO(larryliu0820): Add support
33+
"gtest": "//third-party:gtest",
3334
"libtorch": "//third-party:libtorch",
3435
"prettytable": "//third-party:prettytable",
3536
"pybind11": [], # TODO(larryliu0820): Add support

third-party/TARGETS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
load("@fbsource//xplat/executorch/build/runtime_wrapper.bzl", "runtime")
22
load(":gflags.bzl", "define_gflags")
33
load(":glob_defs.bzl", "subdir_glob")
4+
load(":gtest_defs.bzl", "define_gtest_targets")
45
load(":prebuilt_python_defs.bzl", "add_prebuilt_python_library_targets")
56
load("@prelude//rules.bzl", "prebuilt_cxx_library")
67

78
define_gflags()
89

10+
define_gtest_targets()
11+
912
prebuilt_python_library_defs = {
1013
"prettytable": {
1114
"additional_deps": [":wcwidth"],

third-party/gflags.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Cpoy from third-party/gflags/BUCK
1+
# Copied from third-party/gflags/BUCK
22
load(":gflags_defs.bzl", "gflags_library", "gflags_sources")
33

44
def define_gflags():

third-party/gtest_defs.bzl

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# Copied from fbsource/third-party/googletest
2+
3+
COMPILER_FLAGS = [
4+
"-std=c++17",
5+
]
6+
7+
# define_gtest_targets
8+
def define_gtest_targets():
9+
# Library that defines the FRIEND_TEST macro.
10+
# @lint-ignore BUCKLINT: native and fb_native are explicitly forbidden in fbcode.
11+
native.cxx_library(
12+
name = "gtest_prod",
13+
public_system_include_directories = ["googletest/googletest/include"],
14+
raw_headers = ["googletest/googletest/include/gtest/gtest_prod.h"],
15+
visibility = ["PUBLIC"],
16+
)
17+
18+
# # Google Test
19+
# @lint-ignore BUCKLINT: native and fb_native are explicitly forbidden in fbcode.
20+
native.cxx_library(
21+
name = "gtest",
22+
srcs = native.glob(
23+
[
24+
"googletest/googletest/src/*.cc",
25+
],
26+
exclude = [
27+
"googletest/googletest/src/gtest-all.cc",
28+
"googletest/googletest/src/gtest_main.cc",
29+
],
30+
),
31+
include_directories = [
32+
"googletest/googletest",
33+
],
34+
public_system_include_directories = [
35+
"googletest/googletest/include",
36+
],
37+
raw_headers = native.glob([
38+
"googletest/googletest/include/gtest/**/*.h",
39+
"googletest/googletest/src/*.h",
40+
]),
41+
visibility = ["PUBLIC"],
42+
compiler_flags = COMPILER_FLAGS,
43+
)
44+
45+
# @lint-ignore BUCKLINT: native and fb_native are explicitly forbidden in fbcode.
46+
native.cxx_library(
47+
name = "gmock",
48+
srcs = native.glob(
49+
[
50+
"googletest/googlemock/src/*.cc",
51+
],
52+
exclude = [
53+
"googletest/googlemock/src/gmock-all.cc",
54+
"googletest/googlemock/src/gmock_main.cc",
55+
],
56+
),
57+
include_directories = [
58+
"googletest/googletest",
59+
],
60+
public_system_include_directories = [
61+
"googletest/googlemock/include",
62+
],
63+
raw_headers = native.glob([
64+
"googletest/googlemock/include/gmock/**/*.h",
65+
]),
66+
exported_deps = [":gtest"],
67+
visibility = ["PUBLIC"],
68+
compiler_flags = COMPILER_FLAGS,
69+
)
70+
71+
# @lint-ignore BUCKLINT: native and fb_native are explicitly forbidden in fbcode.
72+
native.cxx_library(
73+
name = "gtest_headers",
74+
include_directories = [
75+
"googletest/googletest",
76+
],
77+
public_system_include_directories = [
78+
"googletest/googlemock/include",
79+
"googletest/googletest/include",
80+
],
81+
raw_headers = native.glob([
82+
"googletest/googlemock/include/gmock/**/*.h",
83+
"googletest/googletest/include/gtest/**/*.h",
84+
"googletest/googletest/src/*.h",
85+
]),
86+
visibility = ["PUBLIC"],
87+
compiler_flags = COMPILER_FLAGS,
88+
)
89+
90+
# @lint-ignore BUCKLINT: native and fb_native are explicitly forbidden in fbcode.
91+
native.cxx_library(
92+
name = "gtest_main",
93+
srcs = ["googletest/googletest/src/gtest_main.cc"],
94+
visibility = ["PUBLIC"],
95+
exported_deps = [":gtest"],
96+
compiler_flags = COMPILER_FLAGS,
97+
)
98+
99+
# # The following rules build samples of how to use gTest.
100+
# @lint-ignore BUCKLINT: native and fb_native are explicitly forbidden in fbcode.
101+
native.cxx_library(
102+
name = "gtest_sample_lib",
103+
srcs = [
104+
"googletest/googletest/samples/sample1.cc",
105+
"googletest/googletest/samples/sample2.cc",
106+
"googletest/googletest/samples/sample4.cc",
107+
],
108+
public_system_include_directories = [
109+
"googletest/googletest/samples",
110+
],
111+
raw_headers = [
112+
"googletest/googletest/samples/prime_tables.h",
113+
"googletest/googletest/samples/sample1.h",
114+
"googletest/googletest/samples/sample2.h",
115+
"googletest/googletest/samples/sample3-inl.h",
116+
"googletest/googletest/samples/sample4.h",
117+
],
118+
)
119+
120+
# @lint-ignore BUCKLINT: native and fb_native are explicitly forbidden in fbcode.
121+
native.cxx_library(
122+
name = "gtest_samples",
123+
# All Samples except:
124+
# sample9 (main)
125+
# sample10 (main and takes a command line option and needs to be separate)
126+
srcs = [
127+
"googletest/googletest/samples/sample1_unittest.cc",
128+
"googletest/googletest/samples/sample2_unittest.cc",
129+
"googletest/googletest/samples/sample3_unittest.cc",
130+
"googletest/googletest/samples/sample4_unittest.cc",
131+
"googletest/googletest/samples/sample5_unittest.cc",
132+
"googletest/googletest/samples/sample6_unittest.cc",
133+
"googletest/googletest/samples/sample7_unittest.cc",
134+
"googletest/googletest/samples/sample8_unittest.cc",
135+
],
136+
deps = [
137+
":gtest_main",
138+
":gtest_sample_lib",
139+
],
140+
)
141+
142+
# @lint-ignore BUCKLINT: native and fb_native are explicitly forbidden in fbcode.
143+
native.cxx_library(
144+
name = "sample9_unittest",
145+
srcs = ["googletest/googletest/samples/sample9_unittest.cc"],
146+
deps = [":gtest"],
147+
)
148+
149+
# @lint-ignore BUCKLINT: native and fb_native are explicitly forbidden in fbcode.
150+
native.cxx_library(
151+
name = "sample10_unittest",
152+
srcs = ["googletest/googletest/samples/sample10_unittest.cc"],
153+
deps = [":gtest"],
154+
)

0 commit comments

Comments
 (0)