请告诉我在 Bazel 中拥有多平台 WORKSPACE 的更好方法
please tell me a better way to have a multiplatform WORKSPACE in Bazel
这是我实际 WORKSPACE 中的一个示例,使我的项目能够看到 TUT(模板单元测试),无论我是在 Windows 还是 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"],
)
""",
)
我的所有 cc_test 规则都成功取决于 "@tut//:tut"
。
这对我有用,但看起来我在滥用 WORKSPACE 文件。有没有更好的方法来实现这个?
我觉得你的解决方案不错。
it looks like I am abusing the WORKSPACE file
或者,创建一个自定义存储库规则 detects the OS [1], creates a symlink to the d:/diego/progs/c++/lib/tut
or /usr/include
directory, and creates a BUILD file 只有一个 cc_library,将所有文件放在符号链接下。
看到 。
[1] 例如repository_ctx.os.name.lower().startswith("windows")
这是我实际 WORKSPACE 中的一个示例,使我的项目能够看到 TUT(模板单元测试),无论我是在 Windows 还是 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"],
)
""",
)
我的所有 cc_test 规则都成功取决于 "@tut//:tut"
。
这对我有用,但看起来我在滥用 WORKSPACE 文件。有没有更好的方法来实现这个?
我觉得你的解决方案不错。
it looks like I am abusing the WORKSPACE file
或者,创建一个自定义存储库规则 detects the OS [1], creates a symlink to the d:/diego/progs/c++/lib/tut
or /usr/include
directory, and creates a BUILD file 只有一个 cc_library,将所有文件放在符号链接下。
看到
[1] 例如repository_ctx.os.name.lower().startswith("windows")