Add `bazel init` to setup new workspaces
- 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
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