Skip to content

Commit

Permalink
[drake_bazel_external_legacy] Add as fork of non-legacy repository
Browse files Browse the repository at this point in the history
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
jwnimmer-tri committed Dec 11, 2024
1 parent 3d48e66 commit 335d733
Show file tree
Hide file tree
Showing 31 changed files with 885 additions and 2 deletions.
43 changes: 43 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,49 @@ node('linux-jammy-unprovisioned') {
}
}
}
node('linux-jammy-unprovisioned') {
timeout(600) {
ansiColor('xterm') {
def triggers = []
if (env.BRANCH_NAME == 'main') {
triggers << cron('H H(7-8) * * *')
}
properties ([
pipelineTriggers(triggers)
])
try {
dir('src') {
stage('checkout') {
checkout scm
}
}
dir('src/drake_bazel_external_legacy'){
stage('bazel_external_legacy setup') {
sh '.github/setup'
}
stage('bazel_external_legacy build and test') {
sh '.github/ci_build_test'
}
}
} catch (e) {
if (env.BRANCH_NAME == 'main') {
emailext (
subject: "Build failed in Jenkins: ${env.JOB_NAME} #${env.BUILD_NUMBER}",
body: "See <${env.BUILD_URL}display/redirect?page=changes>",
recipientProviders: [[$class: 'DevelopersRecipientProvider']],
to: '$DEFAULT_RECIPIENTS',
)
}
throw e
} finally {
deleteDir()
dir("${env.WORKSPACE}@tmp") {
deleteDir()
}
}
}
}
}
node('linux-jammy-unprovisioned') {
timeout(600) {
ansiColor('xterm') {
Expand Down
5 changes: 4 additions & 1 deletion drake_bazel_external/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Bazel Project with Drake as an External

This pulls in Drake via the Bazel workspace mechanism.
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 will be rewriting this example to use Bazel modules ("bzlmod") in the near
future. Stay tuned!

For an introduction to Bazel, refer to
[Getting Started with Bazel](https://bazel.build/start).
Expand Down
2 changes: 2 additions & 0 deletions drake_bazel_external_legacy/.bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Used for setup, do not build
drake-master
7 changes: 7 additions & 0 deletions drake_bazel_external_legacy/.bazelproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-License-Identifier: MIT-0

directories:
.

targets:
//...:all
33 changes: 33 additions & 0 deletions drake_bazel_external_legacy/.bazelrc
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
1 change: 1 addition & 0 deletions drake_bazel_external_legacy/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8.0.0
22 changes: 22 additions & 0 deletions drake_bazel_external_legacy/.clang-format
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
7 changes: 7 additions & 0 deletions drake_bazel_external_legacy/.github/ci_build_test
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 //...
10 changes: 10 additions & 0 deletions drake_bazel_external_legacy/.github/setup
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
22 changes: 22 additions & 0 deletions drake_bazel_external_legacy/.github/ubuntu_setup
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
4 changes: 4 additions & 0 deletions drake_bazel_external_legacy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# SPDX-License-Identifier: MIT-0

/bazel-*
/user.bazelrc
4 changes: 4 additions & 0 deletions drake_bazel_external_legacy/BUILD.bazel
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.
7 changes: 7 additions & 0 deletions drake_bazel_external_legacy/CPPLINT.cfg
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
16 changes: 16 additions & 0 deletions drake_bazel_external_legacy/LICENSE
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.
41 changes: 41 additions & 0 deletions drake_bazel_external_legacy/README.md
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).
55 changes: 55 additions & 0 deletions drake_bazel_external_legacy/WORKSPACE
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()
Loading

0 comments on commit 335d733

Please sign in to comment.