bazelbuild / bazelisk

A user-friendly launcher for Bazel.
Apache License 2.0
1.95k stars 300 forks source link

How to avoid bazel installation? #560

Open adamjstewart opened 3 months ago

adamjstewart commented 3 months ago

This may come counter to everything this repo stands for, but here it goes anyway...

I'm a developer for the Spack package manager. I'm trying to build a package (tensorstore) which uses bazelisk. However, Spack has a couple constraints that make it difficult to use bazelisk:

  1. We need to be able to build on air-gapped networks, so we can't download things during build-time
  2. We need to use Spack's compiler wrappers, which require environment variables, which bazel purges

Spack has its own bazel recipe, which patches bazel to avoid unsetting these environment variables. However, tensorstore uses bazelisk which downloads and installs its own copy of bazel, so even if I add a dependency on bazel, it's skipped.

Is there a way to tell bazelisk not to do anything and just use a pre-installed bazel from the PATH? Or an env var I can set to tell it to do this? Or is it possible to tell bazel not to unset all env vars?

@tgamblin

brentleyjones commented 3 months ago

The USE_BAZEL_VERSION environment variable (which can also be set in .bazeliskrc) can point to a path instead of a version number. It won't download anything in that case.

adamjstewart commented 3 months ago

Unfortunately this didn't work. The code failed on this line:

  Traceback (most recent call last):
    File "/tmp/adam/spack-stage/spack-stage-py-tensorstore-0.1.54-qt43dqks2rfboadkdose2dbxwfl5u47w/spack-src/bazelisk.py", line 492, in <module>
      sys.exit(main())
    File "/tmp/adam/spack-stage/spack-stage-py-tensorstore-0.1.54-qt43dqks2rfboadkdose2dbxwfl5u47w/spack-src/bazelisk.py", line 477, in main
      bazel_path = get_bazel_path()
    File "/tmp/adam/spack-stage/spack-stage-py-tensorstore-0.1.54-qt43dqks2rfboadkdose2dbxwfl5u47w/spack-src/bazelisk.py", line 470, in get_bazel_path
      return download_bazel_into_directory(bazel_version, is_commit, bazel_directory)
    File "/tmp/adam/spack-stage/spack-stage-py-tensorstore-0.1.54-qt43dqks2rfboadkdose2dbxwfl5u47w/spack-src/bazelisk.py", line 294, in download_bazel_into_directory
      bazel_filename = determine_bazel_filename(version)
    File "/tmp/adam/spack-stage/spack-stage-py-tensorstore-0.1.54-qt43dqks2rfboadkdose2dbxwfl5u47w/spack-src/bazelisk.py", line 216, in determine_bazel_filename
      supported_machines = get_supported_machine_archs(version, operating_system)
    File "/tmp/adam/spack-stage/spack-stage-py-tensorstore-0.1.54-qt43dqks2rfboadkdose2dbxwfl5u47w/spack-src/bazelisk.py", line 237, in get_supported_machine_archs
      major, minor = int(versions[0]), int(versions[1])
  ValueError: invalid literal for int() with base 10: '/home/adam/spack/opt/spack/linux-ubuntu22'

The only thing I've found that works so far is to create a symlink in tools/bazel that points to the bazel installation I would like to use.

jbms commented 3 months ago

It looks like the Python implementation does not support USE_BAZEL_VERSION being a path to a binary, but the go implementation does. It would probably make sense to fix the Python implementation.

meteorcloudy commented 3 months ago

Please migrate to the go version

jbms commented 3 months ago

The tensorstore project uses a copy of Python bazelisk in its repository in order to avoid the need for users building it to install or even know about bazel when building the Python package.

In order to use the go bazelisk for the same purpose we would need a way to bootstrap it, which would basically amount to a python bazeliskisk that is similar to the existing Python bazelisk except it downloads go bazelisk binaries instead of bazel binaries. That would be added complexity for no real benefit.

In principle a Python pypi package version of the go bazelisk would also work, and would have some advantages, though embedding the Python bazelisk is hard to beat in convenience and reliability.

meteorcloudy commented 3 months ago

Unfortunately, the Bazel team currently doesn't have capacity to maintain the python version of Bazelisk. But happy to take contributions from the community!