This is an example in my actual WORKSPACE to enable TUT (Template Unit Test) to be seen by my projects, whether I am testing them on Windows or Linux.
new_local_repository(
name = "win32_tut",
path = "/d/diego/progs/c++/lib/tut/",
build_file_content = """
cc_library(
name = "tut",
srcs = glob([
"tut/*.hpp",
]),
hdrs = glob([
"*.h",
]),
visibility = ["//visibility:public"],
)
""",
)
new_local_repository(
name = "linux_tut",
path = "/usr/include/",
build_file_content = """
cc_library(
name = "tut",
srcs = glob([
"tut/*.hpp",
]),
hdrs = glob([
"tut.h",
]),
visibility = ["//visibility:public"],
)
""",
)
new_local_repository(
name = "tut",
path = ".",
build_file_content = """
cc_library(
name = "tut",
deps = select({
"@bazel_tools//src/conditions:windows": ["@win32_tut//:tut"],
"//conditions:default": ["@linux_tut//:tut"],
}),
visibility = ["//visibility:public"],
)
""",
)
All my cc_test rules are successfully depending on "@tut//:tut"
.
That is working for me, but it looks like I am abusing the WORKSPACE file. Is there a better way to achieve this?