bazel-demo2_1

demo2_1目錄樹

├── app
│ ├── BUILD
│ ├── hello_world.cpp
│ └── lib
│ ├── BUILD
│ ├── func.cpp
│ └── func.hpp
├── README.md
└── WORKSPACEbash

咱們知道子目錄下再建立一個BUILD文件,那麼該子目錄也是一個Package。app

app/BUILD:函數

cc_binary(
    name = "hello_world",
    srcs = ["hello_world.cpp"],
    deps = ["//app/lib:hello_func",],
)

hello_world目標須要調用func1()函數,因此須要依賴lib包。code

lib/BUILD:it

cc_library(
    name = "hello_func",
    srcs = ["func.cpp"],
    hdrs = ["func.hpp"],
    visibility = ["//app:__pkg__"],
)

The visibility attribute on a rule controls whether the rule can be used by other packages. Rules are always visible to other rules declared in the same package.class

visibility屬性至關於設置規則的可見域,使其餘規則可以使用本規則。這裏的「//app:__pkg__」代表app包能夠訪問本規則。sed

本站公眾號
   歡迎關注本站公眾號,獲取更多信息