sepehr78
sepehr78

Reputation: 71

Exporting Local Dependency Folder with Bazel

I am a bit new to Bazel and have a question about exporting a bunch of dependencies from a single folder.

I have a folder full of folders, each of which are Bazel projects. These are all external dependencies that are present locally. I want to export these upwards from the external dependency folder.

I want to be able to refer to these dependencies (e.g. @dependency_one) in other workspaces (e.g. source_code). What kind of setup do I need in the external folder?

project
│    
│
└───external
│   │   WORKSPACE (?)
│   │   BUILD (?)
│   │
│   └───dependency_one
│   │   │   WORKSPACE
│   │   │   ...
│   │   │   ...
│   └───dependency_two
│   |   │   WORKSPACE
│   │   │   ...
│   │   │   ...
└───source_code
│   │   WORKSPACE (?)
│   │   ...

Thanks in advance.

Upvotes: 0

Views: 1610

Answers (1)

Brian Silverman
Brian Silverman

Reputation: 3868

local_repository is the way to create an external repository for those folders. Something like this in the top-level WORKSPACE:

local_repository(
  name = "dependency_one",
  path = "external/dependency_one",
)

local_repository(
  name = "dependency_two",
  path = "external/dependency_two",
)

If I'm interpreting your layout correctly, you want project to be the workspace directory, and then everything in source_code should be part of that, which means not creating a source_code/WORKSPACE file. A source_code/BUILD file to write your rules in makes sense though.

Make sure to keep in mind the normal transitive WORKSPACE dependency restrictions: you have to load all the external repositories required for dependency_one and dependency_two in the top-level WORKSPACE.

Also, I would avoid external as a top-level folder name. Bazel uses that path for some special cases related to external repositories. It's being phased out, but that's still in progress. --experimental_disable_external_package, --experimental_sibling_repository_layout, and --nolegacy_external_runfiles will disable some of that special treatment, but I'm not sure if those would be enough make your layout work, plus they may break various rules you want to use.

Upvotes: 1

Related Questions