-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[drake_bazel_external_legacy] Add as fork of non-legacy repository
The legacy example will show how to use WORKSPACE. The existing (non-legacy) example will switch to use MODULE soon. At the moment, all sources except README.md must remain identical across the two copies (per the file_sync_test). As we port to use bzlmod, a few files will start to differ and will be removed from the sync.
- Loading branch information
1 parent
3d48e66
commit 335d733
Showing
31 changed files
with
885 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Used for setup, do not build | ||
drake-master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# SPDX-License-Identifier: MIT-0 | ||
|
||
directories: | ||
. | ||
|
||
targets: | ||
//...:all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# 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 | ||
|
||
# Default build options. | ||
build --strip=never | ||
|
||
# Default test options. | ||
build --test_output=errors | ||
build --test_summary=terse | ||
|
||
# Use C++20. | ||
build --cxxopt=-std=c++20 | ||
build --host_cxxopt=-std=c++20 | ||
|
||
# https://github.com/bazelbuild/bazel/issues/1164 | ||
build --action_env=CCACHE_DISABLE=1 | ||
|
||
# For Ubuntu builds, this flag can cut build times in half. For macOS builds, | ||
# this flag might cause build errors. We suggest turning it on if and only if | ||
# your project doesn't use macOS. | ||
## build --force_pic=yes | ||
|
||
# TODO(jwnimmer-tri) We should see if we can reuse more of Drake's | ||
# customizations somehow. | ||
|
||
# Try to import user-specific configuration local to workspace. | ||
try-import %workspace%/user.bazelrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
8.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# -*- mode: yaml -*- | ||
# vi: set ft=yaml : | ||
# SPDX-License-Identifier: MIT-0 | ||
|
||
--- | ||
BasedOnStyle: Google | ||
--- | ||
Language: Cpp | ||
DerivePointerAlignment: false | ||
PointerAlignment: Left | ||
|
||
IncludeCategories: | ||
- Regex: '^[<"](aio|arpa/inet|assert|complex|cpio|ctype|curses|dirent|dlfcn|errno|fcntl|fenv|float|fmtmsg|fnmatch|ftw|glob|grp|iconv|inttypes|iso646|langinfo|libgen|limits|locale|math|monetary|mqueue|ndbm|netdb|net/if|netinet/in|netinet/tcp|nl_types|poll|pthread|pwd|regex|sched|search|semaphore|setjmp|signal|spawn|stdalign|stdarg|stdatomic|stdbool|stddef|stdint|stdio|stdlib|stdnoreturn|string|strings|stropts|sys/ipc|syslog|sys/mman|sys/msg|sys/resource|sys/select|sys/sem|sys/shm|sys/socket|sys/stat|sys/statvfs|sys/time|sys/times|sys/types|sys/uio|sys/un|sys/utsname|sys/wait|tar|term|termios|tgmath|threads|time|trace|uchar|ulimit|uncntrl|unistd|utime|utmpx|wchar|wctype|wordexp)\.h[">]$' | ||
Priority: 10 | ||
- Regex: '^[<"](algorithm|array|atomic|bitset|cassert|ccomplex|cctype|cerrno|cfenv|cfloat|chrono|cinttypes|ciso646|climits|clocale|cmath|codecvt|complex|condition_variable|csetjmp|csignal|cstdalign|cstdarg|cstdbool|cstddef|cstdint|cstdio|cstdlib|cstring|ctgmath|ctime|cuchar|cwchar|cwctype|deque|exception|forward_list|fstream|functional|future|initializer_list|iomanip|ios|iosfwd|iostream|istream|iterator|limits|list|locale|map|memory|mutex|new|numeric|ostream|queue|random|ratio|regex|scoped_allocator|set|shared_mutex|sstream|stack|stdexcept|streambuf|string|strstream|system_error|thread|tuple|type_traits|typeindex|typeinfo|unordered_map|unordered_set|utility|valarray|vector)[">]$' | ||
Priority: 20 | ||
- Regex: '^<' | ||
Priority: 30 | ||
- Regex: '^"(drake|drake_external_examples)' | ||
Priority: 50 | ||
- Regex: '^"' | ||
Priority: 40 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
# SPDX-License-Identifier: MIT-0 | ||
|
||
set -euxo pipefail | ||
|
||
bazel version | ||
bazel test //... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
# SPDX-License-Identifier: MIT-0 | ||
|
||
set -euxo pipefail | ||
|
||
# CI setup | ||
sudo .github/ubuntu_setup | ||
|
||
# drake source setup | ||
setup/install_prereqs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
# SPDX-License-Identifier: MIT-0 | ||
|
||
set -euxo pipefail | ||
|
||
if [[ "${EUID:-}" -ne 0 ]]; then | ||
echo 'This script must be run as root' >&2 | ||
exit 2 | ||
fi | ||
|
||
echo 'APT::Acquire::Retries "4";' > /etc/apt/apt.conf.d/80-acquire-retries | ||
echo 'APT::Get::Assume-Yes "true";' > /etc/apt/apt.conf.d/90-get-assume-yes | ||
|
||
export DEBIAN_FRONTEND='noninteractive' | ||
|
||
apt-get update | ||
apt-get install --no-install-recommends lsb-release | ||
|
||
if [[ "$(lsb_release -sc)" != 'jammy' ]]; then | ||
echo 'This script requires Ubuntu 22.04 (Jammy)' >&2 | ||
exit 3 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# SPDX-License-Identifier: MIT-0 | ||
|
||
/bazel-* | ||
/user.bazelrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# SPDX-License-Identifier: MIT-0 | ||
|
||
# This is an empty BUILD file, to ensure that this project's root directory is | ||
# a Bazel package. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# SPDX-License-Identifier: MIT-0 | ||
|
||
set noparent | ||
|
||
filter=-build/c++11 | ||
filter=-build/header_guard | ||
filter=-build/include_subdir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Copyright (c) 2017-2023 by the drake-external-examples developers. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Bazel Project with Drake as an External (legacy style) | ||
|
||
This pulls in Drake and builds it from source via Bazel's WORKSPACE mechanism, | ||
which is deprecated as of Bazel 8 and will be removed in Bazel 9. Therefore, | ||
we do not recommend using this example for new projects; instead, refer to | ||
the `drake_bazel_external` example. The legacy example primarily serves | ||
as a regression test for the deprecated behavior. | ||
|
||
For an introduction to Bazel, refer to | ||
[Getting Started with Bazel](https://bazel.build/start). | ||
|
||
## Instructions | ||
|
||
First, run the `install_prereqs` script to download the drake source and run | ||
drake's source setup script to install the required Ubuntu packages: | ||
|
||
``` | ||
setup/install_prereqs.sh | ||
``` | ||
|
||
Then, to build and test all apps: | ||
``` | ||
bazel test //... | ||
``` | ||
|
||
As an example to run a binary directly: | ||
``` | ||
bazel run //apps:simple_logging_example | ||
``` | ||
|
||
You may also run the binary directly per the `bazel-bin/...` path that the | ||
above command prints out; however, be aware that your working directories may | ||
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. | ||
|
||
## Python Versions | ||
|
||
By default, Python 3 is the Python interpreter that Drake will use when built | ||
with Bazel. To see which Python versions are supported, see the | ||
[supported configurations](https://drake.mit.edu/developers.html#supported-configurations). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# SPDX-License-Identifier: MIT-0 | ||
|
||
workspace(name = "drake_external_examples") | ||
|
||
DRAKE_COMMIT = "master" | ||
DRAKE_CHECKSUM = "" | ||
|
||
# Or choose a specific revision of Drake to use. | ||
# DRAKE_COMMIT = "be4f658487f739ba04ec079de46f9459b719636d" | ||
# DRAKE_CHECKSUM = "31ec8f87df3ceb6516de3c33a14c5d59ac5c003b4faf93ac526877d2e150b394" | ||
# | ||
# You can also use DRAKE_COMMIT to choose a Drake release; eg: | ||
# DRAKE_COMMIT = "v0.15.0" | ||
# | ||
# Before changing the COMMIT, temporarily uncomment the next line so that Bazel | ||
# displays the suggested new value for the CHECKSUM. | ||
# DRAKE_CHECKSUM = "0" * 64 | ||
|
||
# Or to temporarily build against a local checkout of Drake, at the bash prompt | ||
# set an environment variable before building: | ||
# export EXAMPLES_LOCAL_DRAKE_PATH=/home/user/stuff/drake | ||
|
||
# Load an environment variable. | ||
load("//:environ.bzl", "environ_repository") | ||
environ_repository(name = "environ", vars = ["EXAMPLES_LOCAL_DRAKE_PATH"]) | ||
load("@environ//:environ.bzl", EXAMPLES_LOCAL_DRAKE_PATH = "EXAMPLES_LOCAL_DRAKE_PATH") | ||
|
||
# This declares the `@drake` repository as an http_archive from github, | ||
# iff EXAMPLES_LOCAL_DRAKE_PATH is unset. When it is set, this declares a | ||
# `@drake_ignored` package which is never referenced, and thus is ignored. | ||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
http_archive( | ||
name = "drake" if not EXAMPLES_LOCAL_DRAKE_PATH else "drake_ignored", | ||
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")), | ||
) | ||
|
||
# This declares the `@drake` repository as a local directory, | ||
# iff EXAMPLES_LOCAL_DRAKE_PATH is set. When it is unset, this declares a | ||
# `@drake_ignored` package which is never referenced, and thus is ignored. | ||
local_repository( | ||
name = "drake" if EXAMPLES_LOCAL_DRAKE_PATH else "drake_ignored", | ||
path = EXAMPLES_LOCAL_DRAKE_PATH, | ||
) | ||
print("Using EXAMPLES_LOCAL_DRAKE_PATH={}".format(EXAMPLES_LOCAL_DRAKE_PATH)) if EXAMPLES_LOCAL_DRAKE_PATH else None # noqa | ||
|
||
# Reference external software libraries, tools, and toolchains per Drake's | ||
# defaults. Some software will come from the host system (Ubuntu or macOS); | ||
# other software will be downloaded in source or binary form from GitHub or | ||
# other sites. | ||
load("@drake//tools/workspace:default.bzl", "add_default_workspace") | ||
add_default_workspace() |
Oops, something went wrong.