From 0a839087ee90cde8522faf20992a0b2f8422ec40 Mon Sep 17 00:00:00 2001 From: Martin Medler Date: Thu, 4 Jan 2024 11:30:34 +0100 Subject: [PATCH] Migrate main workspace to bzlmod 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. --- MODULE.bazel | 45 +++---------------- WORKSPACE | 31 +------------ WORKSPACE.bzlmod | 0 dev_setup_step_1.bzl | 10 ----- dev_setup_step_2.bzl | 28 ------------ dev_setup_step_3.bzl | 7 --- setup_step_2.bzl | 1 + ...ev_dependencies.bzl => dev_extensions.bzl} | 10 +++-- third_party/extensions.bzl | 8 ---- 9 files changed, 14 insertions(+), 126 deletions(-) delete mode 100644 WORKSPACE.bzlmod delete mode 100644 dev_setup_step_1.bzl delete mode 100644 dev_setup_step_2.bzl delete mode 100644 dev_setup_step_3.bzl rename third_party/{dev_dependencies.bzl => dev_extensions.bzl} (74%) diff --git a/MODULE.bazel b/MODULE.bazel index 76763f76..87e74baa 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -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, ) @@ -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", @@ -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") diff --git a/WORKSPACE b/WORKSPACE index 60dd1101..3005471c 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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. diff --git a/WORKSPACE.bzlmod b/WORKSPACE.bzlmod deleted file mode 100644 index e69de29b..00000000 diff --git a/dev_setup_step_1.bzl b/dev_setup_step_1.bzl deleted file mode 100644 index 137b8c0a..00000000 --- a/dev_setup_step_1.bzl +++ /dev/null @@ -1,10 +0,0 @@ -load("//third_party:dev_dependencies.bzl", "dev_dependencies") - -def dev_setup_step_1(): - """ - Perform the initial development setup steps for this project. - - We cannot execute load statements from external workspaces until they have been defined. Thus, we have to perform - multiple iterations of loading a setup function and executing it from the WORKSPACE file. - """ - dev_dependencies() diff --git a/dev_setup_step_2.bzl b/dev_setup_step_2.bzl deleted file mode 100644 index 844848c5..00000000 --- a/dev_setup_step_2.bzl +++ /dev/null @@ -1,28 +0,0 @@ -load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") -load("@mypy_integration//repositories:repositories.bzl", mypy_integration_repositories = "repositories") -load("@rules_python//python:pip.bzl", "pip_parse") -load("@rules_python//python:repositories.bzl", "python_register_multi_toolchains") - -def dev_setup_step_2(): - """ - Perform the second development setup step. - """ - bazel_skylib_workspace() - - mypy_integration_repositories() - - pip_parse( - name = "dwyu_mypy_deps", - requirements_lock = "//third_party:mypy_requirements.txt", - ) - - # Choose different version via: --@rules_python//python/config_settings:python_version=X - python_register_multi_toolchains( - name = "python", - default_version = "3.10", - python_versions = [ - "3.8", - "3.9", - "3.11", - ], - ) diff --git a/dev_setup_step_3.bzl b/dev_setup_step_3.bzl deleted file mode 100644 index 2b3428b1..00000000 --- a/dev_setup_step_3.bzl +++ /dev/null @@ -1,7 +0,0 @@ -load("@dwyu_mypy_deps//:requirements.bzl", install_mypy_deps = "install_deps") - -def dev_setup_step_3(): - """ - Perform the third development setup step. - """ - install_mypy_deps() diff --git a/setup_step_2.bzl b/setup_step_2.bzl index 756a6f98..c3212cee 100644 --- a/setup_step_2.bzl +++ b/setup_step_2.bzl @@ -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", ) diff --git a/third_party/dev_dependencies.bzl b/third_party/dev_extensions.bzl similarity index 74% rename from third_party/dev_dependencies.bzl rename to third_party/dev_extensions.bzl index c51a5013..b3f13569 100644 --- a/third_party/dev_dependencies.bzl +++ b/third_party/dev_extensions.bzl @@ -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, +) diff --git a/third_party/extensions.bzl b/third_party/extensions.bzl index eb8501b4..61c0ea41 100644 --- a/third_party/extensions.bzl +++ b/third_party/extensions.bzl @@ -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()