Skip to content

shell toolchain, design: including common bintools #5265

Closed

Description

@laszlocsomor

Description of the problem / feature request:

Design a mechanism to express that a rule executing a shell command depends on certain command line tools.

Feature requests: what underlying problem are you trying to solve with this feature?

Not every machine has Bash installed, and those that do don't always install Bash at the same location, or have another shell interpreter installed. To accommodate all scenarios, I designed how to turn Bash, or broadly speaking, the Shell, into a toolchain. The efforts is tracked as #4319.

However what Bazel treats as "the shell" is more than just the shell interpreter. Bazel assumes that not only Bash is the shell and it's installed at a fixed location, but also that common GNU binutils and other common programs such as "zip" or "grep" are also installed and are on the PATH.

Rules that execute shell commands also expect these tools to exist and be on the PATH. Bazel currently has no way to express that such rules depend on these tools.

Activity

  1. laszlocsomor commented on Jun 28, 2018

    @laszlocsomor
    ContributorAuthor

    FYI, I don't plan to work on this for the foreseeable future (in the next few months).

  2. removed their assignment
    on Jul 12, 2018
  3. added
    area-Windows
    untriaged
    on Feb 19, 2019
  4. jin commented on Feb 19, 2019

    @jin
    Member

    @laszlocsomor could you add a priority to this issue please?

  5. added
    P3
    and removed
    untriaged
    on Feb 20, 2019
  6. laszlocsomor commented on Feb 20, 2019

    @laszlocsomor
    ContributorAuthor

    Setting priority to P3 for now -- we will probably not see much advancement with this issue before Bazel 1.0, and while it is an important issue, it's not as critical as something like #6351 would be.

  7. robinp commented on Feb 22, 2019

    @robinp

    FYI if anyone is actively troubled by this, recently I successfully use rules_nixpkgs to source pinned version of binaries from nixpkgs (a reproducible set of linux/mac packages). No more depending on binaries being installed and put on PATH upfront.

    See this target example for depending on bison from a nixpkgs import. See this WORKSPACE entry for how can you add rules_nixpkgs to your workspace.

  8. laszlocsomor commented on Mar 12, 2019

    @laszlocsomor
    ContributorAuthor
  9. added
    team-OSS
    on Jun 15, 2020
  10. aherrmann commented on Nov 6, 2020

    @aherrmann
    Contributor

    However what Bazel treats as "the shell" is more than just the shell interpreter. Bazel assumes that not only Bash is the shell and it's installed at a fixed location, but also that common GNU binutils and other common programs such as "zip" or "grep" are also installed and are on the PATH.

    Rules that execute shell commands also expect these tools to exist and be on the PATH. Bazel currently has no way to express that such rules depend on these tools.

    rules_sh implements such a toolchain for Bazel, usage described in the README.

  11. meteorcloudy commented on Dec 23, 2021

    @meteorcloudy
    Member

    Looks like this issue is resolved by rules_sh and the modern toolchain resolution mechanism.

  12. uri-canva commented on Jan 12, 2023

    @uri-canva
    Contributor

    I think this is still relevant, rules_sh requires genrules to be written with support for it in mind, so it cannot be used with third party genrules. Can this be reopened?

  13. fmeum commented on Jan 12, 2023

    @fmeum
    Collaborator

    Doesn't rules_sh just define additional make variables via a toolchain that any genrule-like rule could use without supporting rules_sh specifically (but rather toolchains in general)? If that's the case, it may be sufficient to get the building blocks for doing that in a convenient location (e.g. skylib) or simply document good design choices for such rules

  14. uri-canva commented on Jan 13, 2023

    @uri-canva
    Contributor

    Yeah but that still requires the whole ecosystem to rewrite their genrules to use those make variables.

  15. fmeum commented on Jan 13, 2023

    @fmeum
    Collaborator

    Yeah but that still requires the whole ecosystem to rewrite their genrules to use those make variables.

    The effort wouldn't be specific to the make variables offered by rules_sh, but should apply to any make variable defined by any toolchain. Even if Bazel itself provided a shell toolchain, I think that third-party genrules would still need to support toolchain and the make variables to expose to make use of it.

    @alexeagle Do the rules_js genrules support toolchains and make variables? Maybe bazel-lib already has helpers for doing that properly and evaluating the make variables?

  16. uri-canva commented on Jan 17, 2023

    @uri-canva
    Contributor

    Even if Bazel itself provided a shell toolchain, I think that third-party genrules would still need to support toolchain and the make variables to expose to make use of it.

    Yeah absolutely, but there's things bazel itself can do that toolchains cannot to ease this transition or to support both ways of using it, for example by providing a shell toolchain, but also automatically adding all the locations of the binaries in the toolchain into the PATH that is passed to genrule actions.

    Alternatively bazel could provide a remote prebuilt shell toolchain, like it provides a remote jdk, and the user could specify their own or autodetect a locally installed one.

    This would allow bazel to use a wider range of systems as both its host environment and exec environment (very relevant in remote execution environments, where the exec environment could be a very barebones one), and improve the default hermeticity of bazel builds.

  17. uri-canva commented on Jan 17, 2023

    @uri-canva
    Contributor

    Is this it?

    native.register_toolchains("@local_config_sh//:local_sh_toolchain")

    I can see @bazel_tools//tools/sh:toolchain_type referenced in various parts of the bazel ecosystem: https://sourcegraph.com/search?q=context%3Aglobal+%40bazel_tools%2F%2Ftools%2Fsh%3Atoolchain_type&patternType=standard&sm=1&groupBy=repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3area-Windowscategory: misc > miscteam-OSStype: feature requesttype: process

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions