Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmake] Use Bazelisk to download Bazel #20064

Merged
merged 4 commits into from
Aug 29, 2023

Conversation

jwnimmer-tri
Copy link
Collaborator

@jwnimmer-tri jwnimmer-tri commented Aug 25, 2023

Closes #19923.

See also bazelbuild/bazelisk#494.


This change is Reviewable

@jwnimmer-tri jwnimmer-tri added the release notes: fix This pull request contains fixes (no new features) label Aug 25, 2023
@jwnimmer-tri jwnimmer-tri force-pushed the bazelisk branch 2 times, most recently from f9d296e to d1e3077 Compare August 25, 2023 23:24
@jwnimmer-tri jwnimmer-tri added priority: low status: commits are properly curated https://drake.mit.edu/reviewable.html#curated-commits labels Aug 25, 2023
@jwnimmer-tri

This comment was marked as outdated.

@jwnimmer-tri

This comment was marked as outdated.

jwnimmer-tri

This comment was marked as outdated.

@jwnimmer-tri

This comment was marked as outdated.

jwnimmer-tri

This comment was marked as outdated.

@jwnimmer-tri
Copy link
Collaborator Author

@drake-jenkins-bot linux-focal-unprovisioned-gcc-cmake-experimental-release please
@drake-jenkins-bot linux-jammy-unprovisioned-gcc-cmake-experimental-release please
@drake-jenkins-bot mac-arm-monterey-unprovisioned-clang-cmake-experimental-release please
@drake-jenkins-bot mac-arm-ventura-unprovisioned-clang-cmake-experimental-release please
@drake-jenkins-bot linux-focal-unprovisioned-gcc-wheel-experimental-release please

jwnimmer-tri

This comment was marked as outdated.

@jwnimmer-tri
Copy link
Collaborator Author

+@svenevs and/or +@mwoehlke-kitware for feature review, please. Feel free to unassign the other if you think your own review will be sufficient.

@svenevs
Copy link
Contributor

svenevs commented Aug 28, 2023

@drake-jenkins-bot mac-arm-monterey-unprovisioned-clang-wheel-experimental-release please.

running mac wheel while testing locally

Copy link
Contributor

@svenevs svenevs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 6 files at r5.
Reviewable status: 1 unresolved discussion, LGTM missing from assignees svenevs,mwoehlke-kitware, needs platform reviewer assigned, when planning a "properly curated" merge commit the PR must always be rebased onto latest master (waiting on @jwnimmer-tri)


cmake/modules/FindBazel.cmake line 6 at r5 (raw file):

find_program(Bazel_EXECUTABLE
  NAMES bazel bazelisk bazelisk.py
  PATHS "${PROJECT_SOURCE_DIR}/third_party/com_github_bazelbuild_bazelisk"

Working, I'm having a hard time understanding our desired outcome here. Just using a single thread here, at the very least we probably want to add NO_DEFAULT_PATHS to CMake's find_program and probably every other NO_*_PATH variable.

When looking at how things are being done differently on macOS vs linux in the install_prereqs_user_environment.sh, I don't understand why we're keeping the split. I was under the impression that if we're going to vendor com_github_bazelbuild_bazelisk, then we want our setup/ scripts to stop installing bazel at all (on macOS we are still installing bazelisk from brew, and on linux we still download it if it is not already there).

I believe the impact here is that what happens in CMake and what happens in bazel are different now. Are we not trying to remove the stuff from setup/ using this?

Copy link
Contributor

@mwoehlke-kitware mwoehlke-kitware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r1.
Reviewable status: 1 unresolved discussion, LGTM missing from assignees svenevs,mwoehlke-kitware, needs platform reviewer assigned, when planning a "properly curated" merge commit the PR must always be rebased onto latest master (waiting on @jwnimmer-tri)


cmake/modules/FindBazel.cmake line 6 at r5 (raw file):

Previously, svenevs (Stephen McDowell) wrote…

Working, I'm having a hard time understanding our desired outcome here. Just using a single thread here, at the very least we probably want to add NO_DEFAULT_PATHS to CMake's find_program and probably every other NO_*_PATH variable.

When looking at how things are being done differently on macOS vs linux in the install_prereqs_user_environment.sh, I don't understand why we're keeping the split. I was under the impression that if we're going to vendor com_github_bazelbuild_bazelisk, then we want our setup/ scripts to stop installing bazel at all (on macOS we are still installing bazelisk from brew, and on linux we still download it if it is not already there).

I believe the impact here is that what happens in CMake and what happens in bazel are different now. Are we not trying to remove the stuff from setup/ using this?

If I understand the docs correctly, NO_DEFAULT_PATHS is the superset of NO_*_PATH.

Do we want that? It's unclear; as written, we'll still use bazel if it exists in the user's environment. I was (also?) under the impression the idea was to always use bazelisk, but maybe that impression is wrong?

Copy link
Collaborator Author

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 unresolved discussion, LGTM missing from assignees svenevs,mwoehlke-kitware, needs platform reviewer assigned, when planning a "properly curated" merge commit the PR must always be rebased onto latest master (waiting on @jwnimmer-tri)


cmake/modules/FindBazel.cmake line 6 at r5 (raw file):

... at the very least we probably want to add NO_DEFAULT_PATHS

What would be the upside of that? If the user has a proper bazel already installed on a default path, I think we should use it without any extra downloads. Our vendored bazelisk is intended to be a fallback of last resort.

The thing I didn't implement here, but considered as future work, would be to keep searching the paths (in a proper order) until a suitable version is found, in case some earlier hits were too old. My thinking was to defer that until necessary, since install_prereqs.sh still defaults to installing a proper bazel or bazelisk natively.

I don't understand why we're keeping the split.

Our vendored python bazelisk is neutered. The native homebrew version has a lot more features, and is better for Drake developers to use.

Copy link
Collaborator Author

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 unresolved discussion, LGTM missing from assignees svenevs,mwoehlke-kitware, needs platform reviewer assigned, when planning a "properly curated" merge commit the PR must always be rebased onto latest master (waiting on @jwnimmer-tri)


cmake/modules/FindBazel.cmake line 6 at r5 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

... at the very least we probably want to add NO_DEFAULT_PATHS

What would be the upside of that? If the user has a proper bazel already installed on a default path, I think we should use it without any extra downloads. Our vendored bazelisk is intended to be a fallback of last resort.

The thing I didn't implement here, but considered as future work, would be to keep searching the paths (in a proper order) until a suitable version is found, in case some earlier hits were too old. My thinking was to defer that until necessary, since install_prereqs.sh still defaults to installing a proper bazel or bazelisk natively.

I don't understand why we're keeping the split.

Our vendored python bazelisk is neutered. The native homebrew version has a lot more features, and is better for Drake developers to use.

Or in other words...

If a Drake developer or user keeps doing the default "install prereqs with bazel" setup, the changes to this file are a no-op.

If a linux user does "install prereqs without bazel" (and does not have any bazel-like things installed anywhere, e.g., in a docker container) then this will fall back to the vendored bazelisk. This allows people building using CMake in a container to depend only on stock Ubuntu debs.

Copy link
Contributor

@svenevs svenevs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r1, 6 of 12 files at r2, 1 of 1 files at r3, 2 of 2 files at r4, 5 of 6 files at r5, all commit messages.
Reviewable status: 2 unresolved discussions, LGTM missing from assignees svenevs,mwoehlke-kitware, needs platform reviewer assigned, when planning a "properly curated" merge commit the PR must always be rebased onto latest master (waiting on @jwnimmer-tri)


cmake/modules/FindBazel.cmake line 6 at r5 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

Or in other words...

If a Drake developer or user keeps doing the default "install prereqs with bazel" setup, the changes to this file are a no-op.

If a linux user does "install prereqs without bazel" (and does not have any bazel-like things installed anywhere, e.g., in a docker container) then this will fall back to the vendored bazelisk. This allows people building using CMake in a container to depend only on stock Ubuntu debs.

Ok, I don't think this does that correctly. Before looking at implementing, if somebody (a) has bazel installed and (b) it is too old of a version, should the build fail? Or should it get the one we need?

Making it fail makes life a little easier, but the idea is in the CMakeLists.txt we probably want to do something a little more differently:

# The version passed to find_package(Bazel) should match the
# minimum_bazel_version value in the call to versions.check() in WORKSPACE.
set(MINIMUM_BAZEL_VERSION 4.0)
find_package(Bazel ${MINIMUM_BAZEL_VERSION} MODULE)
if(NOT Bazel_FOUND)
  # manually search our vendored third party and run `bazelisk version`?
  # do not put this logic in the find module, makes it more difficult for no reason
  # e.g., I don't want to find_package(Bazel) here with a new Bazel_ROOT
  # and different names to search for (bazelisk and bazelisk.py)
endif()

Like, I think we want it to "find the first bazel" (user is responsible for this, e.g., via PATH). If not found, we can either error, or get the right one. If their system version is too old, we have a similar choice.


tools/wheel/image/build-drake.sh line 12 at r5 (raw file):

git apply < /image/pip-drake.patch

export BAZELISK_HOME=/var/cache/bazel/bazelisk

working, this path concerns me, waiting for the mac monterey queue to run the wheel job but if it takes too long I will test locally

Copy link
Collaborator Author

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 2 unresolved discussions, LGTM missing from assignees svenevs,mwoehlke-kitware, needs platform reviewer assigned, when planning a "properly curated" merge commit the PR must always be rebased onto latest master (waiting on @jwnimmer-tri)


cmake/modules/FindBazel.cmake line 6 at r5 (raw file):

If somebody (a) has bazel installed and (b) it is too old of a version, should the build fail? Or should it get the one we need?

All else being equal, fetching the one we need would be nice. However, on master today the build would fail, so sticking with "fail" for now is OK.

I don't think this does that correctly.

Could you describe the conditions where something goes wrong?

In any case, I need to turn some of the context in this discussion into comments in the code, but I'm holding off on that until we're on the same page.


tools/wheel/image/build-drake.sh line 12 at r5 (raw file):

Previously, svenevs (Stephen McDowell) wrote…

working, this path concerns me, waiting for the mac monterey queue to run the wheel job but if it takes too long I will test locally

This is the path where downloads of the versioned bazel get dumped. It seemed nice to keep them in the cache instead of always re-downloading them.

(I should add a comment about this.)

@mwoehlke-kitware
Copy link
Contributor

cmake/modules/FindBazel.cmake line 6 at r5 (raw file):

Our vendored bazelisk is intended to be a fallback of last resort

Okay, I guess I'd missed that.

I wonder if this isn't over-thinking things. I suspect it makes sense to accept bazelisk as an alternate spelling of bazel (is that sufficient for homebrew?). But on further consideration, I'm not sure FindBazel.cmake should know anything about our vendored Bzelisk. Maybe we should just make the find_package not required and add if(NOT Bazel_FOUND) followed by setting Bazel_EXECUTABLE to our internal Bazelisk. (Possibly with a warning that we're doing so.)

Copy link
Collaborator Author

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 2 unresolved discussions, LGTM missing from assignees svenevs,mwoehlke-kitware, needs platform reviewer assigned, when planning a "properly curated" merge commit the PR must always be rebased onto latest master


cmake/modules/FindBazel.cmake line 6 at r5 (raw file):
On homebrew, brew bazelisk provides both bazel and bazelisk on the default path (and they are both symlinks to the bottled bazelisk binary).

Maybe we should just make the find_package not required ...

Now that you mention it, that does sound a lot simpler. I'll try that out locally.

@mwoehlke-kitware
Copy link
Contributor

cmake/modules/FindBazel.cmake line 6 at r5 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

On homebrew, brew bazelisk provides both bazel and bazelisk on the default path (and they are both symlinks to the bottled bazelisk binary).

Maybe we should just make the find_package not required ...

Now that you mention it, that does sound a lot simpler. I'll try that out locally.

Right; I think our current thoughts are:

  • Don't add PATHS to the find module. NAMES bazelisk is probably good; not sure if bazelisk.py still makes sense.
  • find_package(Bazel) is not REQUIRED
  • if(NOT Bazel_FOUND) then set Bazel_EXECUTABLE to vendored Bazelisk. Maybe warn that we're doing so.

Stephen also pointed out that if the module finds Bazelisk, the execute_process is going to download Bazel. We might want to try to detect first if Bazel_EXECUTABLE is Bazelisk and skip the version check if so.

Copy link
Contributor

@mwoehlke-kitware mwoehlke-kitware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 6 of 12 files at r2, 1 of 1 files at r3, 2 of 2 files at r4, 4 of 6 files at r5.
Reviewable status: 3 unresolved discussions, LGTM missing from assignees svenevs,mwoehlke-kitware, needs platform reviewer assigned, when planning a "properly curated" merge commit the PR must always be rebased onto latest master (waiting on @jwnimmer-tri)


-- commits line 9 at r5:
FYI, I take it this is the list of people that authored bazelisk.py? (Do we normally do this when importing sources, vs. just having authorship information alongside somewhere?)


tools/workspace/bazelisk/test/lint_test.py line 9 at r5 (raw file):

$ cp bazel-drake/external/bazelisk/LICENSE \
     bazel-drake/external/bazelisk/bazelisk.py \
     third_party/com_github_bazelbuild_bazelisk/

cp -t¹ won't accidentally overwrite src2 with src1... (One might add -i also, but that might be excessive.)

(¹ ...although -t is GNU-only; is it okay to specify doing this on Ubuntu?)

Suggestion:

$ cp -t third_party/com_github_bazelbuild_bazelisk/ \
     bazel-drake/external/bazelisk/LICENSE \
     bazel-drake/external/bazelisk/bazelisk.py

@jwnimmer-tri jwnimmer-tri force-pushed the bazelisk branch 2 times, most recently from bfa81ce to 084a19b Compare August 28, 2023 21:05
Copy link
Collaborator Author

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 4 of 4 files at r6, 1 of 1 files at r7, all commit messages.
Reviewable status: 3 unresolved discussions, LGTM missing from assignees svenevs,mwoehlke-kitware, needs platform reviewer assigned


-- commits line 9 at r5:

Previously, mwoehlke-kitware (Matthew Woehlke) wrote…

FYI, I take it this is the list of people that authored bazelisk.py? (Do we normally do this when importing sources, vs. just having authorship information alongside somewhere?)

I got carried away. Removed.


cmake/modules/FindBazel.cmake line 6 at r5 (raw file):

Previously, mwoehlke-kitware (Matthew Woehlke) wrote…

Right; I think our current thoughts are:

  • Don't add PATHS to the find module. NAMES bazelisk is probably good; not sure if bazelisk.py still makes sense.
  • find_package(Bazel) is not REQUIRED
  • if(NOT Bazel_FOUND) then set Bazel_EXECUTABLE to vendored Bazelisk. Maybe warn that we're doing so.

Stephen also pointed out that if the module finds Bazelisk, the execute_process is going to download Bazel. We might want to try to detect first if Bazel_EXECUTABLE is Bazelisk and skip the version check if so.

Makes sense, thanks. I took a stab at it.


tools/wheel/image/build-drake.sh line 12 at r5 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

This is the path where downloads of the versioned bazel get dumped. It seemed nice to keep them in the cache instead of always re-downloading them.

(I should add a comment about this.)

Commented.


tools/workspace/bazelisk/test/lint_test.py line 9 at r5 (raw file):

Previously, mwoehlke-kitware (Matthew Woehlke) wrote…

cp -t¹ won't accidentally overwrite src2 with src1... (One might add -i also, but that might be excessive.)

(¹ ...although -t is GNU-only; is it okay to specify doing this on Ubuntu?)

It's probably only going to be run on Ubuntu, but anyway I don't think the mistake is very likely or recovery from it very difficult. If we find the instructions are too difficult as-is, the plan would be to provide a program to do it (e.g. an --update argparse flag to this test).

@jwnimmer-tri
Copy link
Collaborator Author

@drake-jenkins-bot linux-focal-unprovisioned-gcc-cmake-experimental-release please
@drake-jenkins-bot linux-jammy-unprovisioned-gcc-cmake-experimental-release please

@drake-jenkins-bot mac-arm-monterey-unprovisioned-clang-cmake-experimental-release please
@drake-jenkins-bot mac-arm-ventura-unprovisioned-clang-cmake-experimental-release please

@drake-jenkins-bot linux-focal-unprovisioned-gcc-wheel-experimental-release please
@drake-jenkins-bot mac-arm-monterey-unprovisioned-clang-wheel-experimental-release please

Copy link
Contributor

@mwoehlke-kitware mwoehlke-kitware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 4 of 4 files at r6, 1 of 1 files at r7, all commit messages.
Reviewable status: 2 unresolved discussions, LGTM missing from assignee svenevs, needs platform reviewer assigned, when planning a "properly curated" merge commit the PR must always be rebased onto latest master (waiting on @jwnimmer-tri)


-- commits line 9 at r5:

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

I got carried away. Removed.

👍


cmake/modules/FindBazel.cmake line 6 at r5 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

Makes sense, thanks. I took a stab at it.

👍


tools/workspace/bazelisk/test/lint_test.py line 9 at r5 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

It's probably only going to be run on Ubuntu, but anyway I don't think the mistake is very likely or recovery from it very difficult. If we find the instructions are too difficult as-is, the plan would be to provide a program to do it (e.g. an --update argparse flag to this test).

🤷

Copy link
Collaborator Author

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+@rpoyner-tri for platform review, please.

We still have some feature comments from @svenevs pending, but I'm hoping this is close enough to final form that platform review now will be OK.

Reviewable status: 2 unresolved discussions, LGTM missing from assignees svenevs,rpoyner-tri(platform), when planning a "properly curated" merge commit the PR must always be rebased onto latest master (waiting on @jwnimmer-tri)

Copy link
Contributor

@svenevs svenevs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:LGTM:

Reviewed 4 of 4 files at r6, 1 of 1 files at r7, all commit messages.
Reviewable status: LGTM missing from assignee rpoyner-tri(platform), when planning a "properly curated" merge commit the PR must always be rebased onto latest master (waiting on @jwnimmer-tri)


tools/wheel/image/build-drake.sh line 12 at r5 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

Commented.

done, I misunderstood what the impact of this path was

Copy link
Contributor

@rpoyner-tri rpoyner-tri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 2 of 2 files at r1, 6 of 12 files at r2, 1 of 1 files at r3, 3 of 6 files at r5, 4 of 4 files at r6, 1 of 1 files at r7, all commit messages.
Reviewable status: when planning a "properly curated" merge commit the PR must always be rebased onto latest master (waiting on @jwnimmer-tri)

@jwnimmer-tri jwnimmer-tri merged commit 77863fa into RobotLocomotion:master Aug 29, 2023
@jwnimmer-tri jwnimmer-tri deleted the bazelisk branch August 29, 2023 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: low release notes: fix This pull request contains fixes (no new features) status: commits are properly curated https://drake.mit.edu/reviewable.html#curated-commits
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CMakeLists should auto-fetch Bazel
4 participants