Skip to content

Commit 5183c0d

Browse files
committed
feat: support installing Bazel
1 parent c8cec57 commit 5183c0d

File tree

8 files changed

+67
-5
lines changed

8 files changed

+67
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Setting up a **cross-platform** environment for building and testing C++/C proje
1717
| category | tools |
1818
| --------------------- | ------------------------------------------------------------ |
1919
| compiler and analyzer | llvm, gcc, msvc, vcvarsall, cppcheck, clangtidy, clangformat |
20-
| build system | cmake, ninja, meson, make, task |
20+
| build system | cmake, ninja, meson, make, task, bazel |
2121
| package manager | vcpkg, conan, choco, brew, nala |
2222
| cache | cppcache |
2323
| documentation | doxygen, graphviz |

dist/setup_cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/setup_cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/setup_cpp.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/setup_cpp.mjs.map

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/bazel/__tests__/bazel.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { setupBazel } from "../bazel"
2+
import { testBin } from "../../utils/tests/test-helpers"
3+
import { InstallationInfo } from "../../utils/setup/setupBin"
4+
5+
jest.setTimeout(300000)
6+
describe("setup-bazel", () => {
7+
it("should setup bazel", async () => {
8+
const installInfo = await setupBazel("", "", process.arch)
9+
10+
await testBin("bazel", ["--version"], (installInfo as InstallationInfo | undefined)?.binDir)
11+
})
12+
})

src/bazel/bazel.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { setupAptPack } from "../utils/setup/setupAptPack"
2+
import { setupBrewPack } from "../utils/setup/setupBrewPack"
3+
import { setupChocoPack } from "../utils/setup/setupChocoPack"
4+
import { isArch } from "../utils/env/isArch"
5+
import { hasDnf } from "../utils/env/hasDnf"
6+
import { setupDnfPack } from "../utils/setup/setupDnfPack"
7+
import { isUbuntu } from "../utils/env/isUbuntu"
8+
import { execSudo } from "../utils/exec/sudo"
9+
10+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
11+
export async function setupBazel(version: string, _setupDir: string, _arch: string) {
12+
switch (process.platform) {
13+
case "win32": {
14+
return setupChocoPack("bazel", version)
15+
}
16+
case "darwin": {
17+
return setupBrewPack("bazel", version)
18+
}
19+
case "linux": {
20+
if (isArch()) {
21+
throw new Error("installing bazel on Arch linux is not supported yet")
22+
} else if (hasDnf()) {
23+
// https://bazel.build/install/redhat
24+
setupDnfPack("dnf-plugins-core", undefined)
25+
execSudo("dnf", ["copr", "enable", "vbatts/bazel"])
26+
return setupDnfPack("bazel4", undefined)
27+
} else if (isUbuntu()) {
28+
// https://bazel.build/install/ubuntu
29+
execSudo("bash", [
30+
"-c",
31+
"wget -qO - https://bazel.build/bazel-release.pub.gpg | gpg --dearmor >bazel-archive-keyring.gpg > /dev/null",
32+
])
33+
execSudo("bash", ["-c", "mv bazel-archive-keyring.gpg /usr/share/keyrings"])
34+
execSudo("bash", [
35+
"-c",
36+
'echo "deb [arch=amd64 signed-by=/usr/share/keyrings/bazel-archive-keyring.gpg] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list',
37+
])
38+
return setupAptPack("bazel", version, [], true)
39+
}
40+
throw new Error(`Unsupported linux distribution`)
41+
}
42+
default: {
43+
throw new Error(`Unsupported platform`)
44+
}
45+
}
46+
}

src/main.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { addEnv } from "./utils/env/addEnv"
4343
import { setupSevenZip } from "./sevenzip/sevenzip"
4444
import { setupGraphviz } from "./graphviz/graphviz"
4545
import { setupNala } from "./nala/nala"
46+
import { setupBazel } from "./bazel/bazel"
4647

4748
/** The setup functions */
4849
const setups = {
@@ -51,6 +52,7 @@ const setups = {
5152
ninja: setupNinja,
5253
python: setupPython,
5354
vcpkg: setupVcpkg,
55+
bazel: setupBazel,
5456
conan: setupConan,
5557
meson: setupMeson,
5658
gcovr: setupGcovr,
@@ -80,6 +82,7 @@ const tools: Array<keyof typeof setups> = [
8082
"brew",
8183
"python",
8284
"vcpkg",
85+
"bazel",
8386
"cmake",
8487
"ninja",
8588
"conan",
@@ -359,6 +362,7 @@ All the available tools:
359362
--cmake
360363
--ninja
361364
--vcpkg
365+
--bazel
362366
--meson
363367
--conan
364368
--make

0 commit comments

Comments
 (0)