Skip to content

Commit

Permalink
bazel: add bazelw wrapper (#1935)
Browse files Browse the repository at this point in the history
This wrapper allows developers to quickly get off the ground without
having to install bazel or bazelisk manually.

Signed-off-by: Keith Smiley <keithbsmiley@gmail.com>
  • Loading branch information
keith authored and Jose Nino committed Dec 15, 2021
1 parent 4d550e4 commit 502ccb2
Show file tree
Hide file tree
Showing 21 changed files with 90 additions and 52 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/android_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
bazelisk build \
./bazelw build \
--config=remote-ci-macos \
--remote_header="Authorization=Bearer $GITHUB_TOKEN" \
--fat_apk_cpu=x86 \
Expand Down Expand Up @@ -70,13 +70,13 @@ jobs:
- name: 'Start simulator'
run: ./ci/mac_start_emulator.sh
# Return to using:
# bazelisk mobile-install --fat_apk_cpu=x86 --start_app //examples/java/hello_world:hello_envoy
# ./bazelw mobile-install --fat_apk_cpu=x86 --start_app //examples/java/hello_world:hello_envoy
# When https://github.com/lyft/envoy-mobile/issues/853 is fixed.
- name: 'Start java app'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
bazelisk build \
./bazelw build \
--config=remote-ci-macos \
--remote_header="Authorization=Bearer $GITHUB_TOKEN" \
--fat_apk_cpu=x86 \
Expand Down Expand Up @@ -113,13 +113,13 @@ jobs:
- name: 'Start simulator'
run: ./ci/mac_start_emulator.sh
# Return to using:
# bazelisk mobile-install --fat_apk_cpu=x86 --start_app //examples/kotlin/hello_world:hello_envoy_kt
# ./bazelw mobile-install --fat_apk_cpu=x86 --start_app //examples/kotlin/hello_world:hello_envoy_kt
# When https://github.com/lyft/envoy-mobile/issues/853 is fixed.
- name: 'Start kotlin app'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
bazelisk build \
./bazelw build \
--config=remote-ci-macos \
--remote_header="Authorization=Bearer $GITHUB_TOKEN" \
--fat_apk_cpu=x86 \
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/android_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
bazel test \
./bazelw test \
--test_output=all \
--build_tests_only \
--config=remote-ci-macos \
Expand Down Expand Up @@ -81,7 +81,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
bazel test \
./bazelw test \
--test_output=all \
--build_tests_only \
--config=remote-ci-macos \
Expand Down Expand Up @@ -125,7 +125,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
bazel test \
./bazelw test \
--test_output=all \
--build_tests_only \
--config=remote-ci-linux-clang \
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
current_release_version=$(git describe --tag --abbrev=0)
bazelisk build \
./bazelw build \
--config=release-android \
--fat_apk_cpu=x86 \
--define=pom_version=$current_release_version \
Expand Down Expand Up @@ -114,7 +114,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
bazelisk build \
./bazelw build \
--config=release-ios \
--ios_multi_cpus=i386,x86_64,armv7,arm64 \
--config=remote-ci-macos \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/asan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: steps.check_context.outputs.run_tests == 'true'
run: |
bazel test --test_output=all \
./bazelw test --test_output=all \
--test_env=ENVOY_IP_TEST_VERSIONS=v4only \
--remote_header="Authorization=Bearer $GITHUB_TOKEN" \
--config=remote-ci-linux-asan \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cc_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
name: 'Run tests'
run: bazel test --action_env=LD_LIBRARY_PATH --test_output=all --config=remote-ci-linux --remote_header="Authorization=Bearer $GITHUB_TOKEN" //test/cc/...
run: ./bazelw test --action_env=LD_LIBRARY_PATH --test_output=all --config=remote-ci-linux --remote_header="Authorization=Bearer $GITHUB_TOKEN" //test/cc/...
2 changes: 1 addition & 1 deletion .github/workflows/core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
- name: 'Run tests'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: bazelisk test --test_output=all --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //test/common/...
run: ./bazelw test --test_output=all --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //test/common/...
4 changes: 2 additions & 2 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
bazel build \
./bazelw build \
--config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" \
//library/kotlin/io/envoyproxy/envoymobile:envoy_lib_lint \
//examples/kotlin/hello_world:hello_envoy_kt_lint
- name: 'Run Kotlin Formatter (ktlint)'
run: |
bazel build kotlin_format
./bazelw build kotlin_format
16 changes: 8 additions & 8 deletions .github/workflows/ios_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ jobs:
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
bazelisk shutdown
bazelisk build --config=ios --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //:ios_dist
./bazelw shutdown
./bazelw build --config=ios --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //:ios_dist
if: steps.check-cache.outputs.cache-hit != 'true'
name: 'Build Envoy.framework distributable'
swifthelloworld:
Expand All @@ -56,12 +56,12 @@ jobs:
name: 'Short-circuit'
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: bazelisk build --config=ios --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //examples/swift/hello_world:app
run: ./bazelw build --config=ios --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //examples/swift/hello_world:app
name: 'Build swift app'
# Run the app in the background and redirect logs.
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: bazelisk run --config=ios --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //examples/swift/hello_world:app &> /tmp/envoy.log &
run: ./bazelw run --config=ios --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //examples/swift/hello_world:app &> /tmp/envoy.log &
name: 'Run swift app'
- run: sed '/received headers with status 200/q' <(touch /tmp/envoy.log && tail -F /tmp/envoy.log)
name: 'Check connectivity'
Expand Down Expand Up @@ -90,12 +90,12 @@ jobs:
name: 'Short-circuit'
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: bazelisk build --config=ios --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //examples/swift/async_await:app
run: ./bazelw build --config=ios --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //examples/swift/async_await:app
name: 'Build swift app'
# Run the app in the background and redirect logs.
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: bazelisk run --config=ios --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //examples/swift/async_await:app &> /tmp/envoy.log &
run: ./bazelw run --config=ios --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //examples/swift/async_await:app &> /tmp/envoy.log &
name: 'Run swift app'
- run: sed '/\[2\] Uploaded 7 MB of data/q' <(touch /tmp/envoy.log && tail -F /tmp/envoy.log)
name: 'Check upload succeeded'
Expand Down Expand Up @@ -124,12 +124,12 @@ jobs:
name: 'Short-circuit'
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: bazelisk build --config=ios --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //examples/objective-c/hello_world:app
run: ./bazelw build --config=ios --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //examples/objective-c/hello_world:app
name: 'Build objective-c app'
# Run the app in the background and redirect logs.
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: bazelisk run --config=ios --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //examples/objective-c/hello_world:app &> /tmp/envoy.log &
run: ./bazelw run --config=ios --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //examples/objective-c/hello_world:app &> /tmp/envoy.log &
name: 'Run objective-c app'
- run: sed '/received headers with status 200/q' <(touch /tmp/envoy.log && tail -F /tmp/envoy.log)
name: 'Check connectivity'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ios_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
if: steps.check_context.outputs.run_tests == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: bazelisk test --test_output=all --config=ios --build_tests_only --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //test/swift/...
run: ./bazelw test --test_output=all --config=ios --build_tests_only --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //test/swift/...
2 changes: 1 addition & 1 deletion .github/workflows/python_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
bazel test \
./bazelw test \
--action_env=LD_LIBRARY_PATH \
--test_output=all \
--config=remote-ci-linux \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tsan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: steps.check_context.outputs.run_tests == 'true'
run: |
bazel test --test_output=all \
./bazelw test --test_output=all \
--test_env=ENVOY_IP_TEST_VERSIONS=v4only \
--remote_header="Authorization=Bearer $GITHUB_TOKEN" \
--config=remote-ci-linux-tsan \
Expand Down
38 changes: 38 additions & 0 deletions bazelw
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

set -euo pipefail

readonly bazelisk_version="1.10.1"
if [[ $OSTYPE == darwin* ]]; then
# TODO: Support M1 once https://github.com/envoyproxy/envoy/issues/16482
readonly bazel_platform="darwin-amd64"
readonly bazel_version_sha="e485bbf84532d02a60b0eb23c702610b5408df3a199087a4f2b5e0995bbf2d5a"
else
readonly bazel_platform="linux-amd64"
readonly bazel_version_sha="4cb534c52cdd47a6223d4596d530e7c9c785438ab3b0a49ff347e991c210b2cd"
fi

readonly bazel_version_url="https://github.com/bazelbuild/bazelisk/releases/download/v$bazelisk_version/bazelisk-$bazel_platform"
script_root="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly bazelisk="$script_root/tmp/bazel/versions/bazelisk-$bazelisk_version-$bazel_platform"

if [[ ! -x "$bazelisk" ]]; then
echo "Installing bazelisk..." >&2
mkdir -p "$(dirname "$bazelisk")"

download_bazelisk() {
curl --fail -L --retry 5 --retry-connrefused --silent --progress-bar \
--output "$bazelisk" "$bazel_version_url"
}

download_bazelisk || download_bazelisk
if echo "$bazel_version_sha $bazelisk" | shasum --check --status; then
chmod +x "$bazelisk"
else
echo "Bazelisk sha mismatch" >&2
rm -f "$bazelisk"
exit 1
fi
fi

exec "$bazelisk" "$@"
2 changes: 1 addition & 1 deletion docs/root/development/debugging/android_local.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ With the project ready, you can now start debugging with Android Studio.
For example:
::

$ bazelisk build android_dist --config=android --fat_apk_cpu=x86 -c dbg
$ ./bazelw build android_dist --config=android --fat_apk_cpu=x86 -c dbg

Android supported archs are `arm64_v8a`, `armeabi-v7a`, `x86`, `x86_64`.

Expand Down
2 changes: 1 addition & 1 deletion docs/root/development/performance/binary_size.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ necessary tools::
The binary being compiled is ``//test/performance:test_binary_size``.
The binary is getting built with the following build command::

bazelisk build //test/performance:test_binary_size --config=sizeopt --copt=-ggdb3 --linkopt=-fuse-ld=lld
./bazelw build //test/performance:test_binary_size --config=sizeopt --copt=-ggdb3 --linkopt=-fuse-ld=lld

Thus the binary is compiled with the following flags pertinent to reducing
binary size:
Expand Down
6 changes: 3 additions & 3 deletions docs/root/development/performance/cpu_battery_impact.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ Modified versions of the "hello world" example apps were used to run these exper

Getting the build:

1. Build the library using ``bazelisk build android_dist --config=android --fat_apk_cpu=armeabi-v7a``
2. Control: ``bazel mobile-install //examples/kotlin/control:hello_control_kt``
3. Envoy: ``bazel mobile-install //examples/kotlin/hello_world:hello_envoy_kt --fat_apk_cpu=armeabi-v7a``
1. Build the library using ``./bazelw build android_dist --config=android --fat_apk_cpu=armeabi-v7a``
2. Control: ``./bazelw mobile-install //examples/kotlin/control:hello_control_kt``
3. Envoy: ``./bazelw mobile-install //examples/kotlin/hello_world:hello_envoy_kt --fat_apk_cpu=armeabi-v7a``

Battery usage experiment steps:

Expand Down
2 changes: 1 addition & 1 deletion docs/root/development/performance/device_connectivity.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Android configuration

2. Build and run the example app:

``bazelisk mobile-install //examples/kotlin/hello_world:hello_envoy_kt --fat_apk_cpu=armeabi-v7a``
``./bazelw mobile-install //examples/kotlin/hello_world:hello_envoy_kt --fat_apk_cpu=armeabi-v7a``

~~~~~~~~~~~
Open issues
Expand Down
8 changes: 4 additions & 4 deletions docs/root/development/testing/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,31 @@ Common (C/C++) tests

To run the entire C/C++ test suite locally, use the following Bazel command:

``bazelisk test --test_output=all //test/common/...``
``./bazelw test --test_output=all //test/common/...``

----------
Java tests
----------

To run the entire Java unit test suite locally, use the following Bazel command:

``bazelisk test --test_output=all --build_tests_only //test/java/...``
``./bazelw test --test_output=all --build_tests_only //test/java/...``

------------
Kotlin tests
------------

To run the entire Kotlin unit test suite locally, use the following Bazel command:

``bazelisk test --test_output=all --build_tests_only //test/kotlin/...``
``./bazelw test --test_output=all --build_tests_only //test/kotlin/...``

-----------
Swift tests
-----------

To run the entire Swift unit test suite locally, use the following Bazel command:

``bazelisk test --config=ios --test_output=all --build_tests_only //test/swift/...``
``./bazelw test --config=ios --test_output=all --build_tests_only //test/swift/...``

--------
Coverage
Expand Down
7 changes: 3 additions & 4 deletions docs/root/development/tools/intellij.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ Using IntelliJ with Envoy Mobile

To get started using IntelliJ with Envoy Mobile:

1. Locally install `Bazel <https://docs.bazel.build/versions/master/install-os-x.html#install-on-mac-os-x-homebrew>`_
2. Download a supported `IntelliJ version <https://www.jetbrains.com/idea/download/other.html>`_ supported by the Bazel plugin
3. Apply local hacks to make IntelliJ work using the branch `hack-for-intellij <https://github.com/lyft/envoy-mobile/tree/hack-for-intellij>`_
4. Open up the Envoy Mobile project using the Bazel import project wizard
1. Download a supported `IntelliJ version <https://www.jetbrains.com/idea/download/other.html>`_ supported by the Bazel plugin
2. Apply local hacks to make IntelliJ work using the branch `hack-for-intellij <https://github.com/lyft/envoy-mobile/tree/hack-for-intellij>`_
3. Open up the Envoy Mobile project using the Bazel import project wizard


Known issues
Expand Down
2 changes: 1 addition & 1 deletion docs/root/development/tools/tulsi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ To get started using Tulsi with Envoy Mobile:

1. Download and `install Tulsi <https://tulsi.bazel.build/docs/gettingstarted.html>`_
2. Open the :repo:`envoy-mobile.tulsiproj <envoy-mobile.tulsiproj>` file
3. From the ``Packages`` tab, click ``Bazel..`` and select the ``bazelw`` binary from at the root of the Envoy Mobile directory (to ensure you're building with the local version of Bazel)
3. From the ``Packages`` tab, click ``Bazel..`` and select the ``bazelw`` binary from at the root of the Envoy Mobile directory (to ensure you're building with the correct version of Bazel)
4. Click on the ``Configs`` tab in Tulsi, and click ``Generate``
5. Open up the Xcode project, and build

Expand Down
15 changes: 8 additions & 7 deletions docs/root/start/building/building.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ Bazel requirements
Envoy Mobile is compiled using the version of Bazel specified in the
:repo:`.bazelversion <.bazelversion>` file.

To simplify build consistency across environments, bazelisk is used.
Follow `these Envoy instructions <https://github.com/envoyproxy/envoy/blob/master/bazel/README.md#installing-bazelisk-as-bazel>`_ to install bazelisk as bazel.
To simplify build consistency across environments, the `./bazelw` script manages
using the correct version. Instead of using `bazel build ...` use `./bazelw build ...`
for all bazel commands.

--------------------
Java requirements
Expand Down Expand Up @@ -67,7 +68,7 @@ Android AAR
Envoy Mobile can be compiled into an ``.aar`` file for use with Android apps.
This command is defined in the main :repo:`BUILD <BUILD>` file of the repo, and may be run locally:

``bazelisk build android_dist --config=android --fat_apk_cpu=<arch1,arch2>``
``./bazelw build android_dist --config=android --fat_apk_cpu=<arch1,arch2>``

Upon completion of the build, you'll see an ``envoy.aar`` file at :repo:`dist/envoy.aar <dist>`.

Expand All @@ -80,7 +81,7 @@ an example of how this artifact may be used.
**When building the artifact for release** (usage outside of development), be sure to include the
``--config=release-android`` option, along with the architectures for which the artifact is being built:

``bazelisk build android_dist --config=release-android --fat_apk_cpu=x86,armeabi-v7a,arm64-v8a``
``./bazelw build android_dist --config=release-android --fat_apk_cpu=x86,armeabi-v7a,arm64-v8a``

For a demo of a working app using this artifact, see the :ref:`hello_world` example.

Expand All @@ -93,7 +94,7 @@ iOS static framework
Envoy Mobile supports being compiled into a ``.framework`` for consumption by iOS apps.
This command is defined in the main :repo:`BUILD <BUILD>` file of the repo, and may be run locally:

``bazelisk build ios_dist --config=ios``
``./bazelw build ios_dist --config=ios``

Upon completion of the build, you'll see a ``Envoy.framework`` directory at
:repo:`dist/Envoy.framework <dist>`.
Expand All @@ -107,7 +108,7 @@ example of how this artifact may be used.
**When building the artifact for release** (usage outside of development), be sure to include the
``--config=release-ios`` option, along with the architectures for which the artifact is being built:

``bazelisk build ios_dist --config=release-ios --ios_multi_cpus=i386,x86_64,armv7,arm64``
``./bazelw build ios_dist --config=release-ios --ios_multi_cpus=i386,x86_64,armv7,arm64``

For a demo of a working app using this artifact, see the :ref:`hello_world` example.

Expand Down Expand Up @@ -171,7 +172,7 @@ Android
To deploy Envoy Mobile's aar to your local maven repository, run the following commands::

# To build Envoy Mobile. --fat_apk_cpu takes in a list of architectures: [x86|armeabi-v7a|arm64-v8a].
bazelisk build android_dist --config=android --fat_apk_cpu=x86
./bazelw build android_dist --config=android --fat_apk_cpu=x86

# To publish to local maven.
dist/sonatype_nexus_upload.py --files dist/envoy.aar dist/envoy-pom.xml --local
Expand Down
Loading

0 comments on commit 502ccb2

Please sign in to comment.