Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flip --enable_workspace to false #23023

Closed
9 of 13 tasks
meteorcloudy opened this issue Jul 17, 2024 · 4 comments
Closed
9 of 13 tasks

Flip --enable_workspace to false #23023

meteorcloudy opened this issue Jul 17, 2024 · 4 comments
Assignees
Labels
area-Bzlmod Bzlmod-specific PRs, issues, and feature requests breaking-change-8.0 incompatible-change Incompatible/breaking change P1 I'll work on this now. (Assignee required) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: feature request

Comments

@meteorcloudy
Copy link
Member

meteorcloudy commented Jul 17, 2024

Motivation

Disabling WORKSPACE by default is the next step towards migrating the Bazel ecosystem to Bzlmod for managing external dependencies.

Benefits of Bzlmod over WORKSPACE:

  • Automatic MVS-based Bazel module dependency resolution
  • No need to declare transitive dependencies
  • Better integration with third-party package managers with module extension
  • Repo level visibility control
  • Easy to inspect dependency graph with bazel mod
  • Support for lockfile, vendor/offline mode

We plan to remove this flag and the entire WORKSPACE logic in Bazel 9.

For more information, check https://bazel.build/external/overview

Description

With --enable_workspace defaults to false, the WORKSPACE file is no longer needed and does not take any effect in a Bazel project.

You should expect the following breaking behaviours:

  • The root of a Bazel repo is no longer marked by WORKSPACE, but by MODULE.bazel (or REPO.bazel).
  • External dependencies defined in WORKSPACE are no longer effective. You may start to see errors like "unknown repo 'foo' requested from @@".
  • Toolchains/platforms registered in WORKSPACE are no longer effective
  • Bind statement (already deprecated) are no longer effective

If all your external dependencies have migrated to Bzlmod, WORSPACE and WORKSPACE.bzlmod files can be safely deleted. Otherwise, you can temporarily enable WORKSPACE via --enable_workspace=true.

Incompatible Flag

--noenable_workspace

Migration Guide

Please refer to https://bazel.build/external/migration on how to migrate from WORKSPACE to Bzlmod.

We'll continue to improve the migration guide on common issues and best practices, PRs from the community are also welcomed!

And please feel free to report issues that are blocking your migration.

In which Bazel LTS version will this incompatible change be enabled?

Bazel 8

Additional Context

No response

TODO List

@meteorcloudy meteorcloudy added P1 I'll work on this now. (Assignee required) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. incompatible-change Incompatible/breaking change area-Bzlmod Bzlmod-specific PRs, issues, and feature requests labels Jul 17, 2024
copybara-service bot pushed a commit that referenced this issue Jul 25, 2024
…zlmod are false

WorkspaceNameFunction is the first one to fail when those two flags are off.

Working towards: #23023

PiperOrigin-RevId: 656006850
Change-Id: I4f7dda4cc3c2b19085d22490fd457fc53f267ed6
copybara-service bot pushed a commit that referenced this issue Jul 25, 2024
Working towards: #23023

Closes #23034.

PiperOrigin-RevId: 656036106
Change-Id: I2753b24dfc3f55e262176ca77d965eb1ad168ce9
copybara-service bot pushed a commit that referenced this issue Jul 25, 2024
Working towards: #23023

Closes #23086.

PiperOrigin-RevId: 656036460
Change-Id: I7475d10964bfa9cefd9b919d300b5dc352d027b0
copybara-service bot pushed a commit that referenced this issue Aug 7, 2024
A part of #23087

Working towards: #23023

Android tests are leaving the Bazel codebases, so it's fine to not migrate the legacy tests to Bzlmod.

PiperOrigin-RevId: 660569455
Change-Id: Ibde570e27f6f76443fe7e74a92c7fa18d967e7af
copybara-service bot pushed a commit that referenced this issue Aug 8, 2024
- Added functions for setting up common dependencies in MODULE.bazel
- Use a shorter bazel_root on Windows
- Added setup_module_dot_bazel to replace write_default_lockfile eventually
- Removed TEST_REPOSITORY_HOME support

A part of #23087

Working towards: #23023

PiperOrigin-RevId: 660748611
Change-Id: I55193953b429c18414ec092f567c98af36d7c34a
copybara-service bot pushed a commit that referenced this issue Aug 8, 2024
A part of #23087

Working towards: #23023

PiperOrigin-RevId: 660758318
Change-Id: Icdfdaed35dc9920c628c4f89ac28ff38ef88a6d3
copybara-service bot pushed a commit that referenced this issue Aug 8, 2024
…nable_workspace=false

A part of #23087

Working towards: #23023

PiperOrigin-RevId: 660765907
Change-Id: I1abd86420b93f7dec174607c549fc1fa09f4730d
copybara-service bot pushed a commit that referenced this issue Aug 8, 2024
A part of #23087

Working towards: #23023

PiperOrigin-RevId: 660767730
Change-Id: I6ba96928d6aaa3e6bc93a4ce442aa1b04992c5c0
copybara-service bot pushed a commit that referenced this issue Aug 8, 2024
A part of #23087

Working towards: #23023

PiperOrigin-RevId: 660778111
Change-Id: I98469a867733204aa6d2e428d36faba60fa91cb6
copybara-service bot pushed a commit that referenced this issue Aug 8, 2024
A part of #23087

Working towards: #23023

PiperOrigin-RevId: 660787082
Change-Id: Iad10e9795db06421c104e149bd2e695262ff225b
copybara-service bot pushed a commit that referenced this issue Aug 9, 2024
A part of #23087

Working towards: #23023

PiperOrigin-RevId: 661156778
Change-Id: I7783ce606869dcc3b5f21cee765f196ba3b365cd
copybara-service bot pushed a commit that referenced this issue Aug 9, 2024
…ace=false

A part of #23087

Working towards: #23023

PiperOrigin-RevId: 661158600
Change-Id: Ib16db0042ff40baaf15937f3320e3a32f5211b36
copybara-service bot pushed a commit that referenced this issue Aug 9, 2024
Final part of #23087

Working towards #23023

PiperOrigin-RevId: 661381915
Change-Id: I1fca0e24bf2f424a3e438ab6fb68e9ae815118f6
copybara-service bot pushed a commit that referenced this issue Aug 19, 2024
Working towards: #19824

Related: #23023

Part of: #23253

PiperOrigin-RevId: 664876902
Change-Id: I8386b13fd12f5d4fb0599c0142df668b0c4a7f74
copybara-service bot pushed a commit that referenced this issue Aug 27, 2024
- Most test cases have migrated from WORKSPACE to MODULE.bazel
- Some test cases still enable WORKSPACE because they test WORKSPACE functionalities.

Part of #23253

Fixes #19824
Working towards #23023

PiperOrigin-RevId: 667901985
Change-Id: I35ee8050d835a62fed4cd7e6637bd0616766f3c4
copybara-service bot pushed a commit that referenced this issue Aug 27, 2024
- Better error message when //external is used when WORKSPACE is disabled.
- Warn about WORKSPACE deprecation in Bazel 9 when WORKSPACE is evaluated.

Related: #23023
PiperOrigin-RevId: 668104976
Change-Id: I967c4a34432847f3b83b4cd651a46c8376a29124
@Wyverald
Copy link
Member

Wyverald commented Aug 30, 2024

I was daydreaming a bit about what we could do after 8.0 is cut:

  1. Delete a whole bunch of code related to the WORKSPACE file.
    • Immediately, this means WorkspaceFileFunction, WorkspaceFactory, WorkspaceFactoryHelper, WorkspaceGlobals, all "resolved file" stuff, etc.
    • Further things that can be deleted: WorkspaceNameFunction (can be turned into a constant), BzlLoadFunction.KeyForWorkspace, ExternalPackageFunction, ExternalPackageHelper, the bit in PackageFunction that deals with the //external package (in fact, the entire //external package is gone), etc.
    • Also includes all the things in Package that only apply to the "external" package -- registered toolchains, exec platforms, "map of repo mappings for each given repo", "workspace name" (again, just a constant now), etc.
  2. Delete all native repo rules.
    • This requires hardcoding @bazel_tools in RepositoryDelegatorFunction as a symlink, which in turn requires a crapton of unit test fixes... Still working on that.
    • This would unblock merging StarlarkRepositoryFunction into RepositoryFunction, and potentially further merging with RepositoryDelegatorFunction -- which in turn would unblock some refactoring to get rid of awkward code structuring introduced with the worker thread stuff (because only StarlarkRepositoryFunction could use worker threads).
  3. Then, repo rules can stop using the Rule/RuleClass machinery intended for build rules.
    • A repository_rule can just be represented by a RepoRule class (instead of today's RuleClass). A ready-to-fetch repo can just be a Repo (instead of Rule). RepoSpec will remain the "dehydrated" Repo.
  4. Remove some Bzlmod-centric logic that nevertheless had to deal with WORKSPACE.
    • RepositoryMapping can no longer "fall back"; RepositoryMappingFunction can remove swaths of WORKSPACE handling (including the composition); RepositoryMappingValue.Key can lose the "main repo can see workspace" bit.
    • The list of "well-known modules" can be pared down to just bazel_tools.

Clock's ticking... rubs hands

@meteorcloudy
Copy link
Member Author

All look very attractive! I just have one small concern: all those changes are technically breaking changes and major refactors, so we're not going to backport them to Bazel 8. That means any further improvement to the external dependency system (e.g. shared repo cache) might be harder to backport due to diverged code. But I guess the benefits of removing WORKSPACE still outweighs the trouble it might cause for backporing.

@fmeum
Copy link
Collaborator

fmeum commented Aug 30, 2024

We might want to remove the code closer to Bazel 9 to facilitate cherry-picks into Bazel 8.

@meteorcloudy
Copy link
Member Author

Yeah, I think we can try to plan and estimate what kind of major changes we still want to make and backport, then decide when is a good time to start removing WORKSPACE from HEAD.

meteorcloudy added a commit to bazel-contrib/rules_go that referenced this issue Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Bzlmod Bzlmod-specific PRs, issues, and feature requests breaking-change-8.0 incompatible-change Incompatible/breaking change P1 I'll work on this now. (Assignee required) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: feature request
Projects
None yet
Development

No branches or pull requests

4 participants