Bazel hello-world examples for C++, Go, Python, including custom toolchain setups for embedded C++ (KR260 and STM32 with ARM processors), pybind11 and gRPC server/clients running in various languages on Intel and/or ARM processors. The background and motiviation of this project can be found at bazel-discuss@.
git clone https://github.com/thx123/bazel-examples.git
cd bazel-examples
Ubuntu on Intel processors are supported out of the box. However, since not all C++ toolchains exist to cross-compile KR260 and STM32 targets from the MacOS, you'd have to run a docker container on Mac to build inside an Ubuntu image running on Intel processors.
- Start a long running container based on an multi-platform image that supports both Linux and MacOS:
docker run -itd -v $(realpath .):/home/builder/workspace --name bazel-examples thx123/ubuntu-with-bazelisk:latest
More information about the Docker image can be found at dockerhub.
- Connect to the container:
docker exec -it bazel-examples /bin/bash
To build and test:
bazel build //...
bazel test //...
If your source code lives on a GitLab instance, the following can be added for CI/CD, e.g. e.g. in .gitlab-ci.yml
:
stages:
- build
- test
.bazel-common:
variables:
GIT_SUBMODULE_STRATEGY: none
before_script:
- echo "Using ./bazel-common ..."
bazel-build:
image:
name: thx123/ubuntu-with-bazelisk:1.5
entrypoint: [""]
stage: build
extends: .bazel-common
script:
- bazel --bazelrc=./cfg-bazel/bazelrc/gitlab-runner.aws.rc info
- bazel --bazelrc=./cfg-bazel/bazelrc/gitlab-runner.aws.rc build //...
bazel-test:
image:
name: thx123/ubuntu-with-bazelisk:1.5
entrypoint: [""]
stage: test
extends: .bazel-common
script:
- bazel --bazelrc=./cfg-bazel/bazelrc/gitlab-runner.aws.rc info
- bazel --bazelrc=./cfg-bazel/bazelrc/gitlab-runner.aws.rc test //...