bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
22.71k stars 3.98k forks source link

pass variable to rule by command line #22869

Open xiedeacc opened 2 weeks ago

xiedeacc commented 2 weeks ago

Description of the feature request:

when I write a bazel rule for jemalloc, and need support self define namespace, after googled a lot, I find this is impossible. so bazel should add mechanism to pass a variable to bazel rule, that mechanism may like config_setting

Which category does this issue belong to?

No response

What underlying problem are you trying to solve with this feature?

No response

Which operating system are you running Bazel on?

No response

What is the output of bazel info release?

No response

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

fmeum commented 2 weeks ago

If the rule supports Make variable expansion, you can use https://github.com/bazelbuild/bazel-skylib/blob/main/docs/common_settings_doc.md#string_flag-make_variable to achieve this.

xiedeacc commented 2 weeks ago

finally, I write a rule use ctx.var.get archive get variable from command line, but why cannot pass variable to BUILD file, it' seems silly to write a rule just substitute some value then to call another native cc_library

xiedeacc commented 2 weeks ago

If the rule supports Make variable expansion, you can use https://github.com/bazelbuild/bazel-skylib/blob/main/docs/common_settings_doc.md#string_flag-make_variable to achieve this.

after read the doc and example from https://github.com/bazelbuild/examples/blob/4d9f5e6c1332ac902a0798b634c67fda4ec5c43b/configurations/select_on_build_setting/BUILD , it seams Make variable cannot archieve it, under jemalloc private namespace scene, private namespace can be any name, but make varialble seams limit to value defined in config_setting, am I right? @fmeum