glib: make Python script execution with toolchain.#7467
glib: make Python script execution with toolchain.#7467bazel-io merged 1 commit intobazelbuild:mainfrom
Conversation
|
Hello @jmillikin, modules you maintain (glib) have been updated in this PR. |
|
note, I am not a toolchain expert, so it would be good if someone looked at it carefully. |
10d7d59 to
50f48e2
Compare
|
The tools to execute are defined with Using a If a simple |
In the The |
|
Possible idea -- if
I tried following the logic within You could try For comparison/reference, this is the code I use in my own projects for something similar (just JS instead of Python). It just calls def _nodejs_binary(ctx):
nodejs = nodejs_toolchain(ctx)
out = ctx.actions.declare_file(ctx.attr.name)
ctx.actions.write(
output = out,
content = """#!/bin/sh
exec "{node_js}" -- "{main_js}" "$@"
""".format(
node_js = nodejs.node_tool.executable.path,
main_js = ctx.file.src.path,
),
) |
|
From the on the rules_python bug I filed it looks like that the python toolchain uses the system python too bootstrap, which will not work if there is no Python. They also seem to have an alternative like the The genrule using the output of If ok by you, I'll change this PR using that technique. |
|
Given the complexity of the GLib compilation process, I'd prefer to stick to using standard Bazel machinery ( I'm sympathetic to the ideal of builds that use only the bare minimum of system dependencies (e.g. POSIX-guaranteed Note in particular that Bazel in general has a hard dependency on system Bash (or a Bash-compatible) shell, Finally, even if you used workarounds to get this one version working in NixOS, there's no CI coverage for that platform in BCR. Any future refactoring might break it without anybody noticing. Aside: I notice in the linked ticket that the If you can fix that error, then I believe you can set the Then you won't need to individually patch module dependencies to support NixOS. |
|
The Using the robust choice with a genrule() to directly invoke the script , and that works, vs. going a roundabout way of I am working on getting nix added to the bazel CI separately. |
|
cc @bazelbuild/bcr-maintainers for visibility + guidance regarding |
|
+1 asking for guidance. |
|
Disclaimer: I have no expertise in this area and can't give any guidance. But I see bazel-contrib/rules_python#3575 is fixed. Does that enable using cc also @rickeylev in case he has anything to say about this. |
|
I think that change will not fix this one (there is still the assumption of a Python existing on the system; this change uses the Python coming from the toolchain, so makes it more hermetic) |
50f48e2 to
1f83ca9
Compare
On hermetic systems, the Python interpreter can't be fetched from the environment, so make sure the Python scripts necessary to build are coming from the `@rules_python`-provided toolchain. So instead of `run_binary()`, this now uses a genrule() with toolchain; in the mkenums rule, the interpreter is also pulled from the toolchain. Without, errors like the following are seen on hermetic systems (e.g. NixOS). ``` gen-visibility-macros failed: error executing RunBinary command (from target @@glib~//gmodule:gmodule-visibility_h) env: 'python3': No such file or directory ``` With: it works now to compile `@glib//...` on NixOS. Signed-off-by: Henner Zeller <[email protected]>
1f83ca9 to
4f80905
Compare
|
Yes, this is basically working around a lack of strict-posix compliance in rules_python. NixOS much more strictly enforces such compliance, and rules_python's py_binary is either a python script (which requires However, in this case, because it's just a single python file to execute without any dependencies, the orchestration logic of py_binary isn't strictly needed. A py_binary's main job is to deal with dependencies, edge cases, and features to run an arbitrary program. A simple |
jmillikin
left a comment
There was a problem hiding this comment.
OK, I'm just gonna approve it and if the Bazel folks want to improve the Python toolchain stuff later then they can do that separately.
bazel-io
left a comment
There was a problem hiding this comment.
All modules in this PR have been approved by their maintainers. This PR will be merged if all presubmit checks pass.
On hermetic systems, the Python interpreter can't be fetched from the environment, so make sure the Python scripts necessary to build are coming from the
@rules_python-provided toolchain.So instead of
run_binary(), this now usesa genrule() with toolchain; in the mkenums
rule, the interpreter is also pulled from the
toolchain.
Without, errors like the following are seen on
hermetic systems (e.g. NixOS).
With: it works now to compile
@glib//...on NixOS.