Skip to content

Commit

Permalink
[cmake] Use Bazelisk to download Bazel
Browse files Browse the repository at this point in the history
  • Loading branch information
jwnimmer-tri committed Aug 26, 2023
1 parent 66eac98 commit 5b8bd1c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 46 deletions.
15 changes: 7 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ else()
"tools/ubuntu-${UNIX_DISTRIBUTION_CODENAME}.bazelrc")
endif()

# 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 REQUIRED)

get_filename_component(C_COMPILER_REALPATH "${CMAKE_C_COMPILER}" REALPATH)
get_filename_component(C_COMPILER_NAME "${C_COMPILER_REALPATH}" NAME)

Expand Down Expand Up @@ -581,22 +576,26 @@ endforeach()
# name `drake_build_cwd` isn't important, it just needs to be unique.
configure_file(cmake/bazel.rc.in drake_build_cwd/.bazelrc @ONLY)
configure_file(cmake/WORKSPACE.in drake_build_cwd/WORKSPACE.bazel @ONLY)
file(CREATE_LINK "${PROJECT_SOURCE_DIR}/.bazeliskrc" drake_build_cwd/.bazeliskrc SYMBOLIC)

include(ExternalProject)

ExternalProject_Add(drake_cxx_python
SOURCE_DIR "${PROJECT_SOURCE_DIR}"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/drake_build_cwd"
CONFIGURE_COMMAND
"${Bazel_EXECUTABLE}"
"${Python_EXECUTABLE}"
"${PROJECT_SOURCE_DIR}/third_party/com_github_bazelbuild_bazelisk/bazelisk.py"
info --announce_rc
BUILD_COMMAND
"${Bazel_EXECUTABLE}"
"${Python_EXECUTABLE}"
"${PROJECT_SOURCE_DIR}/third_party/com_github_bazelbuild_bazelisk/bazelisk.py"
build
${BAZEL_INSTALL_TARGET}
BUILD_ALWAYS ON
INSTALL_COMMAND
"${Bazel_EXECUTABLE}"
"${Python_EXECUTABLE}"
"${PROJECT_SOURCE_DIR}/third_party/com_github_bazelbuild_bazelisk/bazelisk.py"
run
${BAZEL_INSTALL_TARGET}
--
Expand Down
3 changes: 1 addition & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ drake_clion_environment()
load("@bazel_skylib//lib:versions.bzl", "versions")

# This needs to be in WORKSPACE or a repository rule for native.bazel_version
# to actually be defined. The minimum_bazel_version value should match the
# version passed to the find_package(Bazel) call in the root CMakeLists.txt.
# to actually be defined.
versions.check(minimum_bazel_version = "4.0")
36 changes: 0 additions & 36 deletions cmake/modules/FindBazel.cmake

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ cat > "${bazelrc}" <<EOF
import %workspace%/tools/macos.bazelrc
import %workspace%/tools/macos-arch-${arch}.bazelrc
EOF

# Prefetch the bazelisk download of bazel.
(cd "${workspace_dir}" && bazelisk version) > /dev/null
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ cat > "${bazelrc}" <<EOF
import %workspace%/tools/ubuntu.bazelrc
import %workspace%/tools/ubuntu-${codename}.bazelrc
EOF

# Prefetch the bazelisk download of bazel.
(cd "${workspace_dir}" && ./third_party/com_github_bazelbuild_bazelisk/bazelisk.py version) > /dev/null

0 comments on commit 5b8bd1c

Please sign in to comment.