The State of Path Mapping #22658
fmeum
started this conversation in
Show and tell
Replies: 3 comments 4 replies
-
FWIW rules_pkl is a starlark rule which supports path mapping, see https://github.com/apple/rules_pkl/blob/bf3de08ea8c7f05329a2d59d9790ec8653d2a28c/pkl/private/pkl.bzl#L232 for an example. |
Beta Was this translation helpful? Give feedback.
2 replies
-
Do you think that c++ support would be available at the next version (7.3.0)? |
Beta Was this translation helpful? Give feedback.
1 reply
-
Is there any plan to support android? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What is path mapping?
With path mapping enabled, Bazel automatically rewrites paths in action command lines with the aim of making them more likely to be disk or remote cache hits.
Specifically, configuration prefixes such as
bazel-out/darwin-amd64-fastbuild/bin
are replaced with a fixed string such asbazel-out/cfg/bin
, so that the result of an action that doesn't depend on all aspects of the configuration encoded in the path (e.g. the OS, architecture and build mode) can be shared between different target platforms and configurations.Path mapping by itself won't result in cache hits between different execution platforms because toolchains typically differ between platforms (in content, not just paths). One way to address this is to bundle toolchains for multiple execution platforms, see "Universal toolchains". Another is to use cache key scrubbing.
For more information on path mapping, watch the "Towards faster cross-platform builds" talk.
Using path mapping
Bazel has experimental support for path mapping for both native and Starlark rules as detailed below.
General requirements
--experimental_output_paths=strip
.remote
dynamic
sandboxed
multiplex-worker
with--experimental_worker_multiplex_sandbox
worker
with--worker_sandboxing
Java
Java compilation actions as well as header compilation actions support path mapping.
Requirements
Since the default Java toolchain doesn't enable support for multiplex sandboxing yet, non-remote execution with path mapping requires using a custom Java toolchain:
rules_java 7.5.0 and higher have support for multiplex sandboxing.
Go
rules_go optionally uses path mapping for its non-cgo compilation actions, including the stdlib.
Requirements
rules_go from HEAD including this commit.
Custom Starlark rules
Custom Starlark rules can opt into path mapping by adding an entry with the key
supports-path-mapping
to theexecution_requirements
dict passed toctx.actions.run
orctx.actions.run_shell
.They can also be opted in from the command line via
--modify_execution_info
.Additionally, command lines need to be constructed using
ctx.actions.args
and avoiding any of the methods onFile
that return a path string. Assuming thatsrc
is aFile
representing a file anddir
is aFile
representing a directory ("tree artifact"):args.add(src.path)
, useargs.add(src)
;args.add(dir.path)
, useargs.add_all([dir], expand_directories = False)
;args.add(src.dirname)
, use:Generally speaking, all functions that return a path string that may contain a configuration prefix such as
bazel-out/darwin-amd64-fastbuild/bin
must only be called inmap_each
callbacks, where they are automatically path mapped by Bazel.C++
Support for C++ compilation actions is work in progress here.
Beta Was this translation helpful? Give feedback.
All reactions