Skip to content

Commit 859031f

Browse files
authored
bazel: Improve workspace setup (#726)
and bump `rules_pkg` Signed-off-by: Ryan Northey <ryan@synca.io>
1 parent 018ccb0 commit 859031f

12 files changed

Lines changed: 131 additions & 31 deletions

File tree

.bazelignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.bazelrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ common --color=yes
33
common:ci --noshow_progress
44
common:ci --noshow_loading_progress
55
common:ci --test_output=errors
6+
7+
common:examples --action_env=DEV_CONTAINER_ID
8+
common:examples --host_action_env=DEV_CONTAINER_ID
9+
10+
try-import %workspace%/user.bazelrc
11+
try-import %workspace%/repo.bazelrc

.github/workflows/verify-examples.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ jobs:
4343
sudo systemctl start docker
4444
if: steps.cache.outputs.cache-hit != 'true' && github.event_name != 'pull_request'
4545
46-
4746
- run: |
4847
TEMPDIR=/cache/docker
4948
sudo mkdir -p "${TEMPDIR}"
@@ -62,11 +61,11 @@ jobs:
6261
DEV_CONTAINER_ID=$(docker inspect --format='{{.Id}}' envoyproxy/envoy:dev)
6362
echo "DEV_CONTAINER_ID=${DEV_CONTAINER_ID}" >> $GITHUB_ENV
6463
- run: |
64+
echo "common:examples --sandbox_writable_path=$HOME/.docker/" > repo.bazelrc
65+
echo "common:examples --sandbox_writable_path=$HOME" >> repo.bazelrc
6566
bazel run --config=ci \
66-
--action_env="DEV_CONTAINER_ID=${DEV_CONTAINER_ID}" \
67-
--host_action_env="DEV_CONTAINER_ID=${DEV_CONTAINER_ID}" \
68-
--sandbox_writable_path="${HOME}/.docker/" \
69-
--sandbox_writable_path=$HOME :verify_examples
67+
--config=examples \
68+
//:verify_examples
7069
7170
- run: |
7271
sudo systemctl stop docker docker.socket

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ TAGS
4545
/tools/spelling/.aspell.en.pws
4646
clang-tidy-fixes.yaml
4747
clang.bazelrc
48+
repo.bazelrc
4849
user.bazelrc
4950
CMakeLists.txt
5051
cmake-build-debug

BUILD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ filegroup(
138138
"**/*",
139139
],
140140
exclude = [
141+
"**/*~",
142+
"**/.*",
143+
"**/#*",
144+
".*/**/*",
141145
"BUILD",
142146
".git/**/*",
143147
"bazel-*/**/*",

WORKSPACE

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
workspace(name = "envoy-examples")
22

3-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4-
http_archive(
5-
name = "rules_pkg",
6-
urls = [
7-
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz",
8-
"https://github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz",
9-
],
10-
sha256 = "8f9ee2dc10c1ae514ee599a8b42ed99fa262b757058f65ad3c384289ff70c4b8",
11-
)
12-
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
13-
rules_pkg_dependencies()
3+
load("//bazel:archives.bzl", "load_envoy_examples_archives")
4+
load_envoy_examples_archives()
5+
6+
load("//bazel:deps.bzl", "resolve_envoy_examples_dependencies")
7+
resolve_envoy_examples_dependencies()
8+
9+
load("//bazel:toolchains.bzl", "load_envoy_examples_toolchains")
10+
load_envoy_examples_toolchains()

bazel/BUILD

Whitespace-only changes.

bazel/archives.bzl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
2+
load("//bazel:versions.bzl", "VERSIONS")
3+
4+
def load_github_archives():
5+
for k, v in VERSIONS.items():
6+
if type(v) == type("") or v.get("type") != "github_archive":
7+
continue
8+
kwargs = dict(name = k, **v)
9+
# Format string values, but not lists
10+
formatted_kwargs = {}
11+
for arg_k, arg_v in kwargs.items():
12+
if arg_k in ["repo", "type", "version"]:
13+
continue
14+
if type(arg_v) == type(""):
15+
formatted_kwargs[arg_k] = arg_v.format(**kwargs)
16+
else:
17+
formatted_kwargs[arg_k] = arg_v
18+
http_archive(**formatted_kwargs)
19+
20+
def load_http_archives():
21+
for k, v in VERSIONS.items():
22+
if type(v) == type("") or v.get("type") != "http_archive":
23+
continue
24+
kwargs = dict(name = k, **v)
25+
# Format string values, but not lists
26+
formatted_kwargs = {}
27+
for arg_k, arg_v in kwargs.items():
28+
if arg_k in ["type", "version"]:
29+
continue
30+
if type(arg_v) == type(""):
31+
formatted_kwargs[arg_k] = arg_v.format(**kwargs)
32+
else:
33+
formatted_kwargs[arg_k] = arg_v
34+
http_archive(**formatted_kwargs)
35+
36+
def load_envoy_examples_archives():
37+
load_github_archives()
38+
load_http_archives()

bazel/deps.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies")
2+
load("@rules_python//python:repositories.bzl", "py_repositories")
3+
4+
def resolve_envoy_examples_dependencies():
5+
go_rules_dependencies()
6+
py_repositories()

bazel/toolchains.bzl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains")
2+
load("@rules_python//python:repositories.bzl", "python_register_toolchains")
3+
load("//bazel:versions.bzl", "VERSIONS")
4+
5+
def load_envoy_examples_toolchains():
6+
go_register_toolchains(VERSIONS["go"])
7+
python_register_toolchains(
8+
name = "python%s" % VERSIONS["python"].replace(".", "_"),
9+
python_version = VERSIONS["python"].replace("-", "_"),
10+
)

0 commit comments

Comments
 (0)