英文:
How can I remove the first directory from the include path in bazel?
问题
我有以下的项目结构,我正在尝试从另一个构建系统迁移到Bazel:
MyProject/
├─ WORKSPACE.bazel
├─ app/
│ ├─ BUILD.bazel
│ ├─ main.cpp
├─ lib/
│ ├─ BUILD.bazel
│ ├─ lib1/
│ │ ├─ lib1.hpp
│ │ ├─ lib1.cpp
│ ├─ lib2/
│ │ ├─ lib2.hpp
│ │ ├─ lib2.cpp
├─ etc/
├─ test/
我已经成功编译了项目,但不得不更改包含路径,而我的团队的其他成员对此不满意,尽管他们喜欢改进的构建性能。我想把包含路径恢复到以前的状态,目前我的项目在main.cpp
中的包含路径如下:
#include "lib/lib1/lib1.hpp"
#include "lib/lib2/lib2.hpp"
但是我的团队希望回到以下的方式:
#include "lib1/lib1.hpp"
#include "lib2/lib2.hpp"
我的BUILD文件转移到Bazel也没有需要做太多复杂的更改:
app/BUILD.bazel
cc_binary(
name = "MyApp",
srcs = ["main.cpp"],
copts = [
...,
],
linkopts = [
...,
],
deps = [
"//lib:lib1",
"//lib:lib2",
],
)
lib/BUILD.bazel
cc_library(
name = "lib1",
hdrs = glob(["lib1/**/*.hpp"]),
srcs = glob(["lib1/**/*.cpp"]),
copts = [
...,
],
linkopts = [
...,
],
visibility = [
"//app:__pkg__",
"//test:__pkg__",
],
)
cc_library(
name = "lib2",
hdrs = glob(["lib2/**/*.hpp"]),
srcs = glob(["lib2/**/*.cpp"]),
copts = [
...,
],
linkopts = [
...,
],
visibility = [
"//app:__pkg__",
"//test:__pkg__",
],
)
这是否在Bazel中不可能实现,或者是我遗漏了什么?
英文:
I have the following project structure that I am trying to move to Bazel from another build system:
MyProject/
├─ WORKSPACE.bazel
├─ app/
│ ├─ BUILD.bazel
│ ├─ main.cpp
├─ lib/
│ ├─ BUILD.bazel
│ ├─ lib1/
│ │ ├─ lib1.hpp
│ │ ├─ lib1.cpp
│ ├─ lib2/
│ │ ├─ lib2.hpp
│ │ ├─ lib2.cpp
├─ etc/
├─ test/
I have managed to get the project to compile but have had to change the include paths and the rest of my team is not happy with this, though they do enjoy the improved build performance. I'm looking to return the include paths back to what they were before, currently I have the project compiling with:
#include "lib/lib1/lib1.hpp"
#include "lib/lib2/lib2.hpp"
in main.cpp
but the rest of the team really wants to go back to:
#include "lib1/lib1.hpp"
#include "lib2/lib2.hpp"
and my BUILD files to move to Bazel haven't required anything crazy either:
app/BUILD.bazel
load("@rules_cc//cc:defs.bzl", "cc_binary")
cc_binary(
name = "MyApp",
srcs = ["main.cpp"],
copts = [
...,
],
linkopts = [
...,
],
deps = [
"//lib:lib1",
"//lib:lib2",
],
)
lib/BUILD.bazel
load("@rules_cc//cc:defs.bzl", "cc_library")
cc_library(
name = "lib1",
hdrs = glob(["lib1/**/*.hpp"]),
srcs = glob(["lib1/**/*.cpp"]),
copts = [
...,
],
linkopts = [
...,
],
visibility = [
"//app:__pkg__",
"//test:__pkg__",
],
)
cc_library(
name = "lib2",
hdrs = glob(["lib2/**/*.hpp"]),
srcs = glob(["lib2/**/*.cpp"]),
copts = [
...,
],
linkopts = [
...,
],
visibility = [
"//app:__pkg__",
"//test:__pkg__",
],
)
Is this not possible using Bazel or is there something that I've missed?
答案1
得分: 0
将库中的 includes 设置为“.” 工作了:
load("@rules_cc//cc:defs.bzl", "cc_library")
cc_library(
name = "lib1",
hdrs = glob(["lib1/**/*.hpp"]),
srcs = glob(["lib1/**/*.cpp"]),
includes = [“.”],
copts = [
...,
],
linkopts = [
...,
],
visibility = [
"//app:__pkg__",
"//test:__pkg__",
],
)
cc_library(
name = "lib2",
hdrs = glob(["lib2/**/*.hpp"]),
srcs = glob(["lib2/**/*.cpp"]),
includes = [“.”],
copts = [
...,
],
linkopts = [
...,
],
visibility = [
"//app:__pkg__",
"//test:__pkg__",
],
)
英文:
Setting the includes on the library to "." worked:
load("@rules_cc//cc:defs.bzl", "cc_library")
cc_library(
name = "lib1",
hdrs = glob(["lib1/**/*.hpp"]),
srcs = glob(["lib1/**/*.cpp"]),
includes = ["."],
copts = [
...,
],
linkopts = [
...,
],
visibility = [
"//app:__pkg__",
"//test:__pkg__",
],
)
cc_library(
name = "lib2",
hdrs = glob(["lib2/**/*.hpp"]),
srcs = glob(["lib2/**/*.cpp"]),
includes = ["."],
copts = [
...,
],
linkopts = [
...,
],
visibility = [
"//app:__pkg__",
"//test:__pkg__",
],
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论