Is it possible to split up WORKSPACE file in several files?
Asked Answered
A

1

6

I have a Bazel project with a WORKSPACE and many packages. WORKSPACE file is quite huge, so I wonder if it's possible to break it down in separated files and import them.

Appearance answered 16/3, 2020 at 15:47 Comment(0)
C
7

You can extract parts of the WORKSPACE into .bzl files, and load() these symbols for variables and functions into the WORKSPACE.

load("//foo/bar:file.bzl", "function_for_workspace")
function_for_workspace()

See Loading an extension for more information.

Collbaith answered 16/3, 2020 at 16:57 Comment(3)
Are there any examples of this? I can't figure out how to get the load and http_archive calls to play nice since load statements have to come first but won't resolve if run before http_archive.Croatian
I have exactly the same issue as @CroatianSurveying
The thing I did was making two files: one that'll load the http_archive and the other one that'll load the rules. Something like that: repo/thirdparty/gRPC/load.bzl (load archive) and repo/thirdparty/gRPC/rules.bzl (grpc rules). And then in my WORSKPACE, I'd call the load_grpc rule before the grpc_rules one. But that's a bit contraining cause you gotta have two files for each thirdparty, and it has some issues with archives that embed other archives (like rules_proto_grpc that embeds rules_proto)Lowenstern

© 2022 - 2024 — McMap. All rights reserved.