Skip to content

Commit

Permalink
Migrate main workspace to bzlmod
Browse files Browse the repository at this point in the history
All tests requiring an old Bazel version are located inside the integration
tests and examples which have their won sub workspaces.
Thus we can drop support for the legacy WORKSPACE setup in the main repo.
At the same time we simplify the main toolchain. It requires only a single
version.
  • Loading branch information
martis42 committed Jan 4, 2024
1 parent 0f317fe commit 0a83908
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 126 deletions.
45 changes: 5 additions & 40 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module(
name = "depend_on_what_you_use",
# Keep in sync with setup_step_2.bzl
bazel_compatibility = [">=5.4.0"],
compatibility_level = 0,
)
Expand Down Expand Up @@ -30,37 +31,14 @@ use_repo(non_module_dependencies, "dwyu_pcpp")
### Development Dependencies
###

# Update with each rules_python update for easy lookup until specifying the patch version for toolchain is possible again
# Keep in syc with test/aspect/execute_tests.py
# PATCH_MAPPING:
# "3.10": "3.10.13"
# "3.11": "3.11.6"
# "3.12": "3.12.0"
# "3.8": "3.8.18"
# "3.9": "3.9.18"
# Choose different version via: --@rules_python//python/config_settings:python_version=Major.Minor.Patch mathing one of
# the registered toolchains below.
python = use_extension(
"@rules_python//python/extensions:python.bzl",
"python",
dev_dependency = True,
)
python.toolchain(
is_default = True,
python_version = "3.8",
)
python.toolchain(
python_version = "3.9",
)
python.toolchain(
python_version = "3.10",
)
python.toolchain(
python_version = "3.11",
)
python.toolchain(
python_version = "3.12",
)

pip_dev = use_extension(
"@rules_python//python/extensions:pip.bzl",
Expand All @@ -74,22 +52,9 @@ pip_dev.parse(
)
use_repo(pip_dev, "dwyu_mypy_deps")

non_module_dev_dependencies = use_extension(
"//third_party:extensions.bzl",
"non_module_dev_dependencies",
dev_dependency = True,
)
use_repo(non_module_dev_dependencies, "mypy_integration")

###
### The Migration phase using WORKSPACE.bzlmod and MODULE.bazel together does not support properly loading the implicit
### Bazel dependencies. Thus, we need to load some basic things directly. This should become superfluous when we are
### only using bzlmod eventually
### Reference https://github.com/bazelbuild/bazel/blob/master/src/MODULE.tools
###

bazel_dep(
name = "platforms",
version = "0.0.7",
mypy_dep = use_extension(
"//third_party:dev_extensions.bzl",
"mypy_dependency",
dev_dependency = True,
)
use_repo(mypy_dep, "mypy_integration")
31 changes: 2 additions & 29 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,29 +1,2 @@
workspace(name = "depend_on_what_you_use")

#
# Setup of public dependencies of this project
#

load("//:setup_step_1.bzl", "setup_step_1")

setup_step_1()

load("//:setup_step_2.bzl", "setup_step_2")

setup_step_2()

#
# Setup of development dependencies of this project
#

load("//:dev_setup_step_1.bzl", "dev_setup_step_1")

dev_setup_step_1()

load("//:dev_setup_step_2.bzl", "dev_setup_step_2")

dev_setup_step_2()

load("//:dev_setup_step_3.bzl", "dev_setup_step_3")

dev_setup_step_3()
# For now we need a WORKSPACE file to mark the workspace root.
# The projects has however migrated to the MODULE.bazel approach and thus the WORKSPACE file is empty.
Empty file removed WORKSPACE.bzlmod
Empty file.
10 changes: 0 additions & 10 deletions dev_setup_step_1.bzl

This file was deleted.

28 changes: 0 additions & 28 deletions dev_setup_step_2.bzl

This file was deleted.

7 changes: 0 additions & 7 deletions dev_setup_step_3.bzl

This file was deleted.

1 change: 1 addition & 0 deletions setup_step_2.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def setup_step_2():

# Fail early for incompatible Bazel versions instead of printing obscure errors from within our implementation
versions.check(
# Keep in sync with MODULE.bazel
minimum_bazel_version = "5.4.0",
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

def dev_dependencies():
def _mypy_extension_extension_impl(_ctx):
version = "0a881be043e8eae72ad83610c6205e7972bcd5e1"
maybe(
http_archive,
http_archive(
name = "mypy_integration",
sha256 = "1b6c3b1d967ae87b83b7ec179a376a4ff501925488bb06960545e776a873aebd",
strip_prefix = "bazel-mypy-integration-{v}".format(v = version),
urls = ["https://github.com/martis42/bazel-mypy-integration/archive/{v}.tar.gz".format(v = version)],
)

mypy_dependency = module_extension(
implementation = _mypy_extension_extension_impl,
)
8 changes: 0 additions & 8 deletions third_party/extensions.bzl
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
load("//third_party:dev_dependencies.bzl", "dev_dependencies")
load("//third_party/pcpp:repository.bzl", "pcpp")

def _non_module_dev_dependencies_impl(_ctx):
dev_dependencies()

non_module_dev_dependencies = module_extension(
implementation = _non_module_dev_dependencies_impl,
)

def _non_module_dependencies_impl(_ctx):
pcpp()

Expand Down

0 comments on commit 0a83908

Please sign in to comment.