bazel包可以依赖另一个包中的源文件吗
几年前,我为巴泽尔(Bazel)编写了一套包装纸,使我能够使用它来构建FPGA代码。 FPGA位仅相关,因为完整的清洁构建需要许多CPU天,因此我真的很关心缓存和最大程度地减少重建。
使用Bazel v0.28,我从未找到过将Bazel软件包的方法取决于Git Repo中其他地方的单个源文件。感觉这不是巴泽尔设计的东西。
我们之所以要这样做,是因为我们有一个被参数化的VHDL源文件库,并且参数设置在实例化的VHDL源中。 (VHDL仿制药)。如果我们将此库本身宣布为Bazel包,那么当实际上只需要重建几个步骤时,更改一个库文件将重建所有内容(以巨大的时间成本)。
我使用python脚本进行了努力,将所有单个源文件复制到子目录中,然后生成build
文件以引用这些副本。由此产生的构建过程是:
- 调用Python准备脚本
- Bazel Build //:AllfPGAS
- Call Python结果提取器
这显然很丑陋,但好处很大,所以我们与之相处。
现在,我们想利用Bazel来构建我们的Java,C ++等,因此我想重新审视并尝试使一切与Bazel一起工作。
在最新的Bazel中,是否有一种方法可以使build
软件包取决于软件包目录之外的单个源文件?如果Bazel Cont,Buck Pants还是请。为我们的用例做得更好吗?
A few years ago I wrote a set of wrappers for Bazel that enabled me to use it to build FPGA code. The FPGA bit is only relevant because the full clean build takes many CPU days so I really care about caching and minimizing rebuilds.
Using Bazel v0.28 I never found a way to have my Bazel package depend on a single source file from somewhere else in the git repo. It felt like this wasn't something Bazel was designed for.
We want to do this because we have a library of VHDL source files that are parameterized and the parameters are set in the instantiating VHDL source. (VHDL generics). If we declare this library as a Bazel package in its own right then a change to one library file would rebuild everything (at huge time cost) when in practice only a couple of steps might need to be rebuilt.
I worked around this with a python script to copy all the individual source files into a subdirectory and then generate the BUILD
file to reference these copies. The resulting build process is:
- call python preparation script
- bazel build //:allfpgas
- call python result extractor
This is clearly quite ugly but the benefits were huge so we live with it.
Now we want to leverage Bazel to build our Java, C++ etc so I wanted to revisit and try and make everything work with Bazel alone.
In the latest Bazel is there a way to have a BUILD
package depend on individual source files outside of the package directory? If Bazel cant, would buck pants or please.build work better for our use case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
大多数语言的 Bazel 规则已经支持这样做。例如,Python 规则将多个包中的源文件捆绑在一起,而 C++ 规则则管理来自其他包的包含文件。不知何故,规则必须在 providers 中传递源文件,以便另一个规则可以生成 < a href="https://bazel.build/rules/rules#actions" rel="nofollow noreferrer">使用它们的操作。如果不知道您正在使用哪些规则,则很难更具体。
如果您只想复制文件,可以在 bazel 中使用 genrule 来完成此操作。在包含源文件的包中:
在使用它的包中:
如果要在使用它的多个包中删除重复文件,请将文件名放在列表中并写入 宏 来创建 genrule。
The Bazel rules for most languages support doing something like this already. For example, the Python rules bundle source files from multiple packages together, and the C++ rules manage include files from other packages. Somehow the rule has to pass the source files around in providers, so that another rule can generate actions which use them. Hard to be more specific without knowing which rules you're using.
If you just want to copy the files, you can do that in bazel with a genrule. In the package with the source file:
In the package that uses it:
If you want to deduplicate that across multiple packages that use it, put the filenames in a list and write a macro to create the genrule.