Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

register toolchain only for container exec and use it in py*_image #1173

Merged
merged 12 commits into from
Oct 4, 2019
Prev Previous commit
Next Next commit
clean ups
  • Loading branch information
Nicolas Lopez committed Oct 3, 2019
commit ea1f19c9cec8091a1a67524444f46f458f71311d
4 changes: 2 additions & 2 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ platforms:
# Disabled e2e tests that pull from localhost in nested workspace
- "-//testing/new_pusher_tests/..."
build_flags:
- "--extra_toolchains=@buildkite_config//config:cc-toolchain,//toolchains:rbe_cc_toolchain"
- "--extra_toolchains=@buildkite_config//config:cc-toolchain,//toolchains:rbe_container_cc_toolchain"
- "--extra_execution_platforms=//toolchains:rbe_platform,//toolchains:rbe_container_platform"
- "--host_platform=//toolchains:rbe_platform"
- "--platforms=//toolchains:rbe_platform"
Expand Down Expand Up @@ -160,7 +160,7 @@ platforms:
- "-//tests/contrib/automatic_container_release:configs_test"
- "-//tests/contrib/automatic_container_release:configs_test_deps_spec_only"
test_flags:
- "--extra_toolchains=@buildkite_config//config:cc-toolchain,//toolchains:rbe_cc_toolchain"
- "--extra_toolchains=@buildkite_config//config:cc-toolchain,//toolchains:rbe_container_cc_toolchain"
- "--extra_execution_platforms=//toolchains:rbe_platform,//toolchains:rbe_container_platform"
- "--host_platform=//toolchains:rbe_platform"
- "--platforms=//toolchains:rbe_platform"
Expand Down
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1257,13 +1257,6 @@ python tools installed in a different location to those defined in
toolchain that points to these paths and register it _before_ the call to
`py*_images/image.bzl:deps` in your `WORKSPACE`.

Until Bazel 0.26.0 is relesed, registration of the default python toolchain
will result in all python targets using that same toolchain, which might
result in errors if any of those targets need to run locally.
Once Bazel 0.26.0 is out, this default toolchain will only be compatible with
python targets that run inside a container and will not interfere with
other python targets.

Use of python toolchain features, currently, only supports picking one
version of python for execution of host tools. `rules_docker` heavily depends
on execution of python host tools that are only compatible with python 2.
Expand Down
24 changes: 13 additions & 11 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -407,30 +407,32 @@ register_execution_platforms("//toolchains:local_container_platform")

http_archive(
name = "bazel_toolchains",
sha256 = "4cd2e510c8153a6a8e4bba85d27e270cd402d05bed9cc9dad1490ec34d789d7c",
strip_prefix = "bazel-toolchains-cc6aa72358302e908d3358bc1408636edaac2f51",
#sha256 = "4cd2e510c8153a6a8e4bba85d27e270cd402d05bed9cc9dad1490ec34d789d7c",
strip_prefix = "bazel-toolchains-0.29.8",
urls = [
"https://github.com/bazelbuild/bazel-toolchains/archive/cc6aa72358302e908d3358bc1408636edaac2f51.tar.gz",
"https://github.com/bazelbuild/bazel-toolchains/archive/0.29.8.tar.gz",
],
)

# Define several exec property repo rules to be used in testing.
load("@bazel_toolchains//rules/experimental/rbe:exec_properties.bzl", "merge_dicts", "rbe_exec_properties")

# A standard RBE execution property set repo rule.
rbe_exec_properties(
name = "exec_properties",
)

load("@bazel_toolchains//rules:rbe_repo.bzl", "rbe_autoconfig")
load("@exec_properties//:constants.bzl", "DOCKER_SIBLINGS_CONTAINERS", "NETWORK_ON")

rbe_autoconfig(
name = "buildkite_config",
base_container_digest = "sha256:4bfd33aa9ce73e28718385b8c01608a79bc6546906f01cf9329311cace1766a1",
digest = "sha256:c20046852a2d7910c55d76e0ec9c182b37532a9f0360d22dd5c9a1451b7c3a15",
exec_properties = merge_dicts(DOCKER_SIBLINGS_CONTAINERS, NETWORK_ON),
registry = "marketplace.gcr.io",
repository = "google/bazel",
use_legacy_platform_definition = False,
)

# gazelle:repo bazel_gazelle

# Define several exec property repo rules to be used in testing.
load("@bazel_toolchains//rules/experimental/rbe:exec_properties.bzl", "rbe_exec_properties")

# A standard RBE execution property set repo rule.
rbe_exec_properties(
name = "exec_properties",
)
46 changes: 30 additions & 16 deletions toolchains/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@bazel_toolchains//rules/experimental/rbe:exec_properties.bzl", "merge_dicts")
load("@exec_properties//:constants.bzl", "DOCKER_SIBLINGS_CONTAINERS", "NETWORK_ON")

package(default_visibility = ["//visibility:public"])

licenses(["notice"]) # Apache 2.0

# Constraints used to describe docker compatible toolchains.

constraint_setting(name = "containerized")

constraint_value(
name = "run_in_container",
constraint_setting = ":containerized",
)

# Toolchain required for xx_image targets that rely on xx_binary
# which transitively require a C/C++ toolchain (currently only
# py_binary). This is only needed for remote execution.
toolchain(
name = "rbe_cc_toolchain",
name = "rbe_container_cc_toolchain",
exec_compatible_with = [
"@io_bazel_rules_docker//toolchains:run_in_container",
"@bazel_tools//platforms:x86_64",
Expand All @@ -36,7 +45,13 @@ toolchain(
)

# Default host platform that has constraint_value set for the
# "@io_bazel_rules_docker//toolchains:run_in_container" constraint
# "@io_bazel_rules_docker//toolchains:run_in_container" constraint.
# This platform must be registered to run xx_image targets
# that require a custom toolchain to run inside the container
# (other than, e.g., the autogenerated toolchain). This
# currently only applies to py_image and py3_image targets
# as the autogenerated py toolchain might point to a different
# location than the py in the container.
platform(
name = "local_container_platform",
constraint_values = [
Expand All @@ -59,26 +74,25 @@ platform(
],
)

# Default RBE platform that has constraint_value set for the
# "@io_bazel_rules_docker//toolchains:run_in_container" constraint.
# This platform must be registered to run xx_image targets
# that require a custom toolchain to run inside the container
# (other than, e.g., the autogenerated toolchain). This
# currently only applies to py_image and py3_image targets
# as the autogenerated py toolchain might point to a different
# location than the py in the container.
platform(
name = "rbe_container_platform",
constraint_values = [
"@io_bazel_rules_docker//toolchains:run_in_container",
],
exec_properties = merge_dicts(DOCKER_SIBLINGS_CONTAINERS, NETWORK_ON),
parents = ["@buildkite_config//config:platform"],
)

# Default RBE platform for all other targets (i.e., that dont need
# custom toolchain(s)).
platform(
name = "rbe_platform",
exec_properties = merge_dicts(DOCKER_SIBLINGS_CONTAINERS, NETWORK_ON),
parents = ["@buildkite_config//config:platform"],
)

# Constraints used to describe docker compatible toolchains.

constraint_setting(name = "docker")

constraint_value(
name = "run_in_container",
constraint_setting = ":docker",
)
4 changes: 0 additions & 4 deletions toolchains/python/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ py_runtime_pair(
)

# A toolchain to run python outputs inside a container.
# If you are using --incompatible_use_python_toolchains this toolchain must
# be used to indicate the location of python tools inside the container as
# the auto-detected toolchain relies on using "which", which is not present
# in the default python containers.
# If you are using a custom base for py_image which has python tools in a
# different location, you must register that toolchain prior to the
# registration of this one in @io_bazel_rules_docker//python:image.bzl
Expand Down