bazelbuild / bazel-skylib

Common useful functions and rules for Bazel
https://bazel.build/
Apache License 2.0
376 stars 179 forks source link

Add `env` and `env_inherit` to `native_binary` and `native_test` (using `@bazel_features`) #484

Open redsun82 opened 6 months ago

redsun82 commented 6 months ago

This relies on the RunEnvironmentInfo that was introduced in bazel 5.3.0. To keep the library compatible with previous versions, bazel_features is used.

To make it possible to run CI and update the docs without all the dependencies from @bazel_features (some of which would be private and not visible to the doc generation rule), a bazel_features_stub directory is introduced which remains unused when using a released version of the library (it gets removed by MODULE.bazel-remove-override.patch).

Also, this requires a user to do an additional WORKSPACE setup step if they need to use native_binary.bzl and they are not using bzlmod.

Closes https://github.com/bazelbuild/bazel-skylib/issues/409

hvadehra commented 1 month ago

This relies on the RunEnvironmentInfo that was introduced in bazel 5.3.0. To keep the library compatible with previous versions, bazel_features is used.

FYI, going by https://bazel.build/release#support-matrix , v5.4.1 is now the minimum supported version, so if RunEnvironmentInfo is the only thing needed for this, I'd say it's safe to just assume it's available, and you can drop the dependency on bazel_features & related complexity.

(not a full review, I'll defer to @tetromino / @brandjon for that)

redsun82 commented 1 month ago

@hvadehra thanks for the heads up, that makes things way easier. @tetromino / @brandjon, the PR should be ready for another review pass now :rocket: