I am trying to make my build configurable with a custom flag.
It should be possible to specify the flag value when I build, e.g.
bazel build //test:bundle --//:foo_flag=bar
Here is my build target definition (using rules_js):
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@npm//test:webpack-cli/package_json.bzl", "bin")
npm_link_all_packages(
name = "node_modules",
)
bin.webpack_cli(
name = "bundle",
outs = [
"out/index.html",
"out/main.js",
],
args = [
"--config",
"webpack.config.js",
"-o",
"out",
],
srcs = [
"webpack.config.js",
":node_modules",
] + glob([
"src/**/*.js",
]),
chdir = package_name(),
env = {
# ?
},
visibility = [
"//visibility:public",
],
)
What is unclear from the various Bazel examples is how to actually pass the flag to the rule.
I am looking for something like this:
# Invalid
env = {
"FOO": "$(value //:foo_flag)",
},
How do I pass a flag in Bazel?