c++ 我怎样才能从bazel的include路径中删除第一个目录?

jmp7cifd  于 2023-03-09  发布在  其他
关注(0)|答案(1)|浏览(127)

我尝试将以下项目结构从另一个构建系统移动到Bazel:

MyProject/
├─ WORKSPACE.bazel
├─ app/
│  ├─ BUILD.bazel
│  ├─ main.cpp
├─ lib/
│  ├─ BUILD.bazel
│  ├─ lib1/
│  │  ├─ lib1.hpp
│  │  ├─ lib1.cpp
│  ├─ lib2/
│  │  ├─ lib2.hpp
│  │  ├─ lib2.cpp
├─ etc/
├─ test/

我已经设法让项目编译,但不得不改变包含路径,我的团队的其他人对此并不满意,尽管他们确实喜欢改进的构建性能。我希望将包含路径返回到以前的状态,目前我的项目编译使用:

#include "lib/lib1/lib1.hpp"
#include "lib/lib2/lib2.hpp"

但是团队的其他成员真的想回到:

#include "lib1/lib1.hpp"
#include "lib2/lib2.hpp"

我的BUILD文件也不需要任何疯狂的东西就可以转移到Bazel:
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__",
    ],
)

这是不可能使用Bazel还是有什么我错过了?

axr492tv

axr492tv1#

将库上的包含设置为.“”已完成:

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__",
    ],
)

相关问题