'Using Bazel platform select with load
I have a bazel file that has to load two different requirements files:
load("@python_turing_libs//:requirements.bzl", "requirement")
or
load("@python_ampere_libs//:requirements.bzl", "requirement")
I was hoping to use bazel platforms to do this via:
# Define GPU constraint values
constraint_setting(name = "gpu")
constraint_value(name = "turing", constraint_setting = "gpu")
constraint_value(name = "ampere", constraint_setting = "gpu")
constraint_value(name = "none", constraint_setting = "gpu")
# Platform
platform(
name = "gpu_server",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
":gpu",
],
)
select({
"@platforms//os:linux":
load("@python_perception_libs//:requirements.bzl", "requirement")
,
"//conditions:default": [],
})
syntax error at 'load': expected expression
or something, but clearly this syntax does not work
Solution 1:[1]
There isn't a mechanism to conditionally load from other bzl files, so instead, load both files, and use selects to select the different things within those files.
One issue is that the symbols have the same name in each file, and to address that you can have different symbols in the file that's doing the loading like this:
load("@python_turing_libs//:requirements.bzl", turing_requirement = "requirement")
load("@python_ampere_libs//:requirements.bzl", ampere_requirement = "requirement")
your_rule(
...
some_attribute = select({
":turing_condition": turing_requirement,
":ampere_condition": ampere_requirement,
})
...
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ahumesky |
