Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Close #143, close #153 (I think this PR provides a better solution to essentially the same problem so the older PR may be discarded).
This PR only makes the rules hermetic with respect to binaries, a separate PR for hermeticity with respect to
.so
files may be needed, although it's probably of lower priority.To understand the solution let's recall the ways in which hermeticity may be violated:
PATH
env variable is provided which points to a directory which contains other binaries in addition to the binary of interest (which is virtually always the case).ctx.actions.run_shell
is used. This automatically uses environment of host OS.ctx.actions.run
withuse_default_shell_env
is used, again we touch environment of host OS this way.It may seem that just specifying things as
input
s may be sufficient to resolve the hermeticity problem, but it isn't the case. There is a difference between Bazel's "domain of control" and outside world. Bazel can control visibility of artifacts it creates, i.e.File
s, because one can putFile
s ininputs
argument ofrun
and such.ctx.host_fragments.cpp
on the other hand provides a bunch of strings with locations of system binaries such asar
andgcc
(makes sense,File
s cannot have absolute paths in Bazel). This means that Bazel cannot control visibility ofar
,gcc
,ln
, etc. To it they are just strings and not artifacts produced by the build system. This is not very handly from the hermeticity point of view.The solution is to merge CPP fragments, GHC binaries, and binutils of interest and create symlinks to all of them in a special directory which won't contain anything else besides these symlinks to binaries. What we get this way:
PATH
, we put there just path to our directory with symlinks, which contains nothing extra, and visibility of what it contains is controlled by Bazel in addition to that.ctx.actions.run_shell
, redundantPATH
environment variables, we don't useuse_default_shell_env
.tools(ctx).bin_name
, e.g.tools(ctx).ghc
and are used only asexecutable
argument and ininputs
argument to make them visible.So that's it I guess, should be quite hermetic.