bazelbuild / bazelbuild/bazel

Add `bazel init` to setup new workspaces

Open
#15,604 8 comments 14 reactions 0 assignees View on GitHub
help wanted not stale P3 team-OSS type: feature request
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the feature request:

Add a `bazel init` command that sets up a skeleton Bazel workspace for new projects. It could create `WORKSPACE`, `BUILD.bazel`, `.bazelrc` and maybe others, using a template that applies modern best practices.

The `init` command is popular in other tools. E.g.,
* `git init` - create a new git repo
* `npm init` - create a new npm package
* `poetry init` - create a new Poetry (python) package
* `cargo init` - create a new Cargo (rust) package

### What underlying problem are you trying to solve with this feature?

New users often get tripped up by environment variables leaking into their builds and invalidating caches. The `--incompatible_strict_action_env` flag has existed for years and often solves the problem, but it is [disabled by default](https://github.com/bazelbuild/bazel/issues/7026) due (I think) to not being compatible with many existing workspaces.

Arguably `--incompatible_strict_action_env` should be enabled by default, as well as a variety of other flags for correctness, performance, and dev experience detailed in [this post](https://blog.aspect.dev/bazelrc-flags). `bazel init` would offer a place to put these more recent, incompatible flags for use in new repos, and also provide a skeleton to help new users get started.

Contributor guide

Open the contributing guide

Research direction

The issue names no implementation files, tests, or entry points. Start by locating Bazel's existing command-registration and workspace-setup paths, then clarify which files and best-practice flags the template should generate; done means an agreed `bazel init` workflow creates and validates the new workspace skeleton.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system, cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.