Skip to content

Commit

Permalink
[drake_bazel_external] Port to use MODULE.bazel (#348)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwnimmer-tri authored Jan 10, 2025
1 parent 96be1de commit 431d6d2
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 108 deletions.
4 changes: 0 additions & 4 deletions drake_bazel_external/.bazelrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# SPDX-License-Identifier: MIT-0

# Don't use bzlmod yet.
common --enable_workspace=true
common --enable_bzlmod=false

# Default to an optimized build.
build --compilation_mode=opt

Expand Down
1 change: 1 addition & 0 deletions drake_bazel_external/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

/bazel-*
/user.bazelrc
/MODULE.bazel.lock
58 changes: 58 additions & 0 deletions drake_bazel_external/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# SPDX-License-Identifier: MIT-0

module(name = "drake_external_examples")

# If you don't want to support building on macOS, you may remove the next line.
# Note that it must appear prior to loading "rules_cc", per the documentation:
# https://github.com/bazelbuild/apple_support?tab=readme-ov-file#bazel-7-setup
bazel_dep(name = "apple_support", version = "1.17.1")

# Add the Bazel rules we need.
bazel_dep(name = "rules_cc", version = "0.0.17")
bazel_dep(name = "rules_python", version = "0.40.0")

# Here we introduce Drake as a module dependency, but note that Drake is not
# published to any Bazel registry. Below, we'll override it with a github
# source archive.
bazel_dep(name = "drake")

# By default, this example always uses the latest Drake master branch.
DRAKE_COMMIT = "master"
DRAKE_CHECKSUM = None

# You can choose a specific revision of Drake to use, e.g.:
# DRAKE_COMMIT = "19bb4703fdf4950d4b3530d496d8a0ff1ca5fc22"
# DRAKE_CHECKSUM = "489d255db3cb1c8ff7a91ae0f961d76b6083a1d4a3f58150371b4b359683adb6"
#
# You can also use DRAKE_COMMIT to choose a Drake release; e.g.:
# DRAKE_COMMIT = "v0.15.0"
# DRAKE_CHECKSUM = "... TBD ..."
#
# Before changing the COMMIT, temporarily uncomment the next line so that Bazel
# displays the suggested new value for the CHECKSUM.
# DRAKE_CHECKSUM = "0" * 64

# This declares the `@drake` module as a source code archive from github.
# See README.md for instructions to use a local path, instead.
archive_override(
module_name = "drake",
urls = [x.format(DRAKE_COMMIT) for x in [
"https://github.com/RobotLocomotion/drake/archive/{}.tar.gz",
]],
sha256 = DRAKE_CHECKSUM,
strip_prefix = "drake-{}".format(DRAKE_COMMIT.lstrip("v")),
)

# Use the host system /usr/bin/python3.
python_repository = use_repo_rule(
"@drake//tools/workspace/python:repository.bzl",
"python_repository",
)

python_repository(
name = "python",
linux_interpreter_path = "/usr/bin/python3",
requirements_flavor = "build",
)

register_toolchains("@python//:all")
9 changes: 9 additions & 0 deletions drake_bazel_external/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ cause differences. This is important when using tools like
`drake::FindResource` / `pydrake.common.FindResource`.
You may generally want to stick to using `bazel run` when able.

### Using a local checkout of Drake

To use Drake sources on disk instead of downloaded from github, pass the flag
``--override_module=drake=/home/user/stuff/drake`` to bazel on the command line
or add a line such as the following to ``user.bazelrc`` in the current directory:
```
build --override_module=drake=/home/user/stuff/drake
```

## Python Versions

By default, Python 3 is the Python interpreter that Drake will use when built
Expand Down
55 changes: 0 additions & 55 deletions drake_bazel_external/WORKSPACE

This file was deleted.

45 changes: 0 additions & 45 deletions drake_bazel_external/environ.bzl

This file was deleted.

4 changes: 0 additions & 4 deletions private/test/file_sync_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,13 @@
for path in [
".bazelignore",
".bazelproject",
".bazelrc",
".clang-format",
".github/ci_build_test",
".github/setup",
".github/ubuntu_setup",
".gitignore",
"BUILD.bazel",
"CPPLINT.cfg",
"LICENSE",
"WORKSPACE",
"apps/BUILD.bazel",
"apps/exec.sh",
"apps/find_resource_test.py",
Expand All @@ -84,7 +81,6 @@
"apps/simple_adder_test.cc",
"apps/simple_continuous_time_system.cc",
"apps/simple_logging_example.py",
"environ.bzl",
"setup/install_prereqs",
]
])
Expand Down

0 comments on commit 431d6d2

Please sign in to comment.