Skip to content

Commit aef822e

Browse files
authored
feat: cargo workspace configuration and bazel build files for hermetic environment (#257)
RATIONALE: Since we're supporting multiple languages in the repo, over time the test running time and managing the environment to ensure we get hermetic builds will become complicated. As a result, it is prudent to use a proper build system to build and run tests orders of magnitude faster. CHANGELOG: - [ ] Add build files for go, ts. - [ ] Add stub smoke tests for cargo workspace and java. - [ ] Update setup script to install bazelisk. - [ ] Add bazel configuration. - [ ] Update hooks to run these tests.
1 parent 18cff7a commit aef822e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+11211
-22
lines changed

.bazelignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.trunk
2+
bazel-bin
3+
bazel-dotprompt
4+
bazel-out
5+
bazel-testlogs
6+
js/coverage
7+
js/dist
8+
js/node_modules
9+
node_modules
10+
target/
11+
third_party/docsite/node_modules

.bazelrc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Don't let environment variables like $PATH sneak into the build, which can
2+
# cause massive cache misses when they change.
3+
build --incompatible_strict_action_env
4+
# Speed up all builds by not checking if output files have been modified.
5+
build --noexperimental_check_output_files
6+
# Enforce Java 11 for compatibility
7+
build --java_language_version=11
8+
build --tool_java_language_version=11
9+
build --java_runtime_version=remotejdk_11
10+
11+
test --test_output=errors
12+
13+
import %workspace%/go.bazelrc
14+
import %workspace%/ts.bazelrc
15+
import %workspace%/java.bazelrc
16+
import %workspace%/rust.bazelrc
17+
18+
# Allow user overrides. This should be the very last line and this file should
19+
# be in .gitignore.
20+
try-import %workspace%/.user.bazelrc

.bazelversion

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

.github/workflows/bazel.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
17+
name: Bazel Build and Test
18+
19+
on:
20+
push:
21+
branches: [ main ]
22+
pull_request:
23+
branches: [ main ]
24+
25+
permissions: read-all # Needed for security checks, adjust if necessary
26+
27+
jobs:
28+
build_and_test:
29+
name: Build and Test
30+
runs-on: ubuntu-latest
31+
32+
steps:
33+
- name: Checkout Code
34+
uses: actions/checkout@v4
35+
36+
# Bazel needs a JDK. Setup Java 11 as required by the tests.
37+
- name: Setup Java JDK 11
38+
uses: actions/setup-java@v4
39+
with:
40+
distribution: 'temurin'
41+
java-version: '11'
42+
43+
# Set up Go environment for go install
44+
- name: Setup Go
45+
uses: actions/setup-go@v5
46+
with:
47+
go-version: '1.24.2'
48+
49+
# Use bazelisk to manage Bazel versions based on .bazelversion
50+
- name: Install Bazelisk via Go
51+
run: go install github.com/bazelbuild/bazelisk@latest
52+
53+
- name: Mount Bazel repository cache
54+
uses: actions/cache@v4
55+
with:
56+
path: |
57+
~/.cache/bazel/_bazel_${{ runner.os }}/repos
58+
~/.cache/bazel/_bazel_${{ runner.os }}/external
59+
key: bazel-repo-${{ hashFiles('**/MODULE.bazel.lock', '**/maven_install.json', '**/pnpm-lock.yaml') }}
60+
restore-keys: |
61+
bazel-repo-
62+
63+
# Setup Bazel action cache
64+
# Caching build results can significantly speed up CI.
65+
# Be cautious with cache size and eviction.
66+
- name: Mount Bazel action cache
67+
uses: actions/cache@v4
68+
with:
69+
path: ~/.cache/bazel/_bazel_${{ runner.os }}/execroot/**/bazel-out
70+
key: bazel-action-${{ github.sha }}-${{ hashFiles('**/MODULE.bazel.lock', '**/maven_install.json', '**/pnpm-lock.yaml') }}
71+
restore-keys: |
72+
bazel-action-${{ github.ref }}-${{ hashFiles('**/MODULE.bazel.lock', '**/maven_install.json', '**/pnpm-lock.yaml') }}
73+
bazel-action-
74+
75+
- name: Build all targets
76+
run: bazelisk build //...
77+
78+
- name: Test all targets
79+
# --test_output=errors only shows logs for failed tests
80+
run: bazelisk test //... --test_output=errors

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
- name: Install pnpm
4141
uses: pnpm/action-setup@v2
4242
with:
43-
version: 8
43+
version: 10
4444

4545
- name: Install dependencies
4646
run: pnpm -C js install

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
.DS_Store
2+
.aspect
23
.cache
34
.firebaserc
45
.idea
6+
.user.bazelrc
57
/js/coverage
68
/js/dist
79
/third_party/docsite/src/content/refdocs
@@ -12,3 +14,4 @@ python/.nox
1214
python/.tox
1315
python/handlebarrz/target
1416
site/
17+
target/

.npmrc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Disabling pnpm [hoisting](https://pnpm.io/npmrc#hoist) by setting `hoist=false` is recommended on
2+
# projects using rules_js so that pnpm outside of Bazel lays out a node_modules tree similar to what
3+
# rules_js lays out under Bazel (without a hidden node_modules/.pnpm/node_modules). See
4+
# https://github.com/aspect-build/rules_js/blob/7377f2d0387cc2a9251137929b1c53ccdb3fbcf0/docs/npm_import.md#npm_translate_lock
5+
# documentation for more information.
6+
hoist=false
7+
8+
# Not enabling this because it causes issues with sandboxing.
9+
#
10+
# and introduces errors when building Next.js applications.
11+
# Otherwise, you'd run into errors such as:
12+
#
13+
# node:internal/modules/cjs/loader:1148
14+
# throw err;
15+
# ^
16+
#
17+
# Error: Cannot find module './node-polyfill-crypto'
18+
# Require stack:
19+
# ...
20+
#shared-workspace-lockfile=false
21+
22+
#engine-strict = true

BUILD.bazel

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
load("@aspect_rules_js//npm:defs.bzl", "npm_link_package")
2+
load("@gazelle//:def.bzl", "gazelle")
3+
load("@npm//:defs.bzl", "npm_link_all_packages")
4+
5+
package(default_visibility = ["//visibility:public"])
6+
7+
# gazelle:prefix github.com/google/dotprompt
8+
gazelle(name = "gazelle")
9+
10+
# Building this package creates bazel-bin/node_modules/@google/dotprompt
11+
# so that other packages can depend on this target.
12+
npm_link_package(
13+
name = "node_modules/@google/dotprompt",
14+
src = "//js:pkg",
15+
package = "@google/dotprompt",
16+
visibility = ["//visibility:public"],
17+
)
18+
19+
# This macro expands to a npm_link_package for each of the dependencies in
20+
# package.json.
21+
npm_link_all_packages(name = "node_modules")

0 commit comments

Comments
 (0)