From 3ff5cc8297b9b745b8bce9f7473d042f0b8cb164 Mon Sep 17 00:00:00 2001 From: "Reid D. McKenzie" Date: Wed, 18 Jun 2025 11:49:53 -0600 Subject: [PATCH 01/12] More workflows as proposed by Dan --- .aspect/workflows/config.yaml | 100 ++++++++++++++++++++++++++++++++-- .github/workflows/ci.yaml | 18 ------ 2 files changed, 94 insertions(+), 24 deletions(-) diff --git a/.aspect/workflows/config.yaml b/.aspect/workflows/config.yaml index cb4c85c6..84b24cca 100644 --- a/.aspect/workflows/config.yaml +++ b/.aspect/workflows/config.yaml @@ -1,7 +1,95 @@ # See https://docs.aspect.build/workflows/configuration -tasks: - - test: - - finalization: - queue: aspect-small -notifications: - github: {} +--- +workspaces: + e2e/smoke: + tasks: + + bazelHEAD__linux: + target: //... + name: test + hook: echo "HEAD" > .bazelversion + queue: linux-runners + bazelHEAD__mac: + target: //... + name: test + hook: echo "HEAD" > .bazelversion + queue: mac-runners + bazel8__linux: + target: //... + name: test + hook: echo "8" > .bazelversion + queue: linux-runners + bazel8__mac: + target: //... + name: test + hook: echo "8" > .bazelversion + queue: mac-runners + + e2e/repository-rule-deps: + tasks: + bazelHEAD__linux: + target: //... + name: test + hook: echo "HEAD" > .bazelversion + queue: linux-runners + bazelHEAD__mac: + target: //... + name: test + hook: echo "HEAD" > .bazelversion + queue: mac-runners + bazel8__linux: + target: //... + name: test + hook: echo "8" > .bazelversion + queue: linux-runners + bazel8__mac: + target: //... + name: test + hook: echo "8" > .bazelversion + queue: mac-runners + + e2e/system-interpreter: + tasks: + bazelHEAD__linux: + target: //... + name: test + hook: echo "HEAD" > .bazelversion + queue: linux-runners + bazelHEAD__mac: + target: //... + name: test + hook: echo "HEAD" > .bazelversion + queue: mac-runners + bazel8__linux: + target: //... + name: test + hook: echo "8" > .bazelversion + queue: linux-runners + bazel8__mac: + target: //... + name: test + hook: echo "8" > .bazelversion + queue: mac-runners + + examples/uv_pip_compile: + tasks: + bazelHEAD__linux: + target: //... + name: test + hook: echo "HEAD" > .bazelversion + queue: linux-runners + bazelHEAD__mac: + target: //... + name: test + hook: echo "HEAD" > .bazelversion + queue: mac-runners + bazel8__linux: + target: //... + name: test + hook: echo "8" > .bazelversion + queue: linux-runners + bazel8__mac: + target: //... + name: test + hook: echo "8" > .bazelversion + queue: mac-runners diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e29aecf1..6d4c0cc9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -22,23 +22,6 @@ concurrency: cancel-in-progress: ${{ github.ref_name != 'main' }} jobs: - test: - uses: bazel-contrib/.github/.github/workflows/bazel.yaml@646899086d7aaee8e532540480f3e91e00596234 # 11 Dec 2024 - with: - # NB: the root folder is tested with Aspect Workflows on BuildKite, see /.aspect/workflows/config.yaml - folders: '["e2e/smoke", "e2e/repository-rule-deps", "e2e/system-interpreter", "examples/uv_pip_compile"]' - # TODO: Build Windows tools and add to toolchain - # TODO(alex): switch the root folder to bzlmod - # TODO: fix remaining folders on Bazel 8 - exclude: | - [ - {"os": "windows-latest"}, - {"folder": "e2e/repository-rule-deps", "bzlmodEnabled": false}, - {"folder": "e2e/system-interpreter", "bzlmodEnabled": false}, - {"folder": "examples/uv_pip_compile", "bzlmodEnabled": false}, - {"folder": "e2e/smoke", "bazelversion": "8.0.0"} - ] - pre-commit: runs-on: ubuntu-latest steps: @@ -81,7 +64,6 @@ jobs: # on "all matrix jobs were successful". conclusion: needs: - - test - verify-bcr-patches - test-release - pre-commit From 5911376ae43b95c44a02c3ecf4509bbb6acfec1d Mon Sep 17 00:00:00 2001 From: "Reid D. McKenzie" Date: Wed, 18 Jun 2025 12:04:20 -0600 Subject: [PATCH 02/12] [NO TESTS] WIP --- .aspect/workflows/config.yaml | 154 +++++++++++++++------------------- 1 file changed, 66 insertions(+), 88 deletions(-) diff --git a/.aspect/workflows/config.yaml b/.aspect/workflows/config.yaml index 84b24cca..1bc295ed 100644 --- a/.aspect/workflows/config.yaml +++ b/.aspect/workflows/config.yaml @@ -1,95 +1,73 @@ # See https://docs.aspect.build/workflows/configuration --- workspaces: - e2e/smoke: - tasks: + - . + - e2e/smoke + - e2e/repository-rule-deps + - e2e/system-interpreter + - examples/uv_pip_compile - bazelHEAD__linux: - target: //... - name: test - hook: echo "HEAD" > .bazelversion - queue: linux-runners - bazelHEAD__mac: - target: //... - name: test - hook: echo "HEAD" > .bazelversion - queue: mac-runners - bazel8__linux: - target: //... - name: test - hook: echo "8" > .bazelversion - queue: linux-runners - bazel8__mac: - target: //... - name: test - hook: echo "8" > .bazelversion - queue: mac-runners +tasks: + - test: + name: test-os:linux-bzl:head + queue: linux-runners + hooks: + - type: before_task + command: | + echo "HEAD" > .bazelversion - e2e/repository-rule-deps: - tasks: - bazelHEAD__linux: - target: //... - name: test - hook: echo "HEAD" > .bazelversion - queue: linux-runners - bazelHEAD__mac: - target: //... - name: test - hook: echo "HEAD" > .bazelversion - queue: mac-runners - bazel8__linux: - target: //... - name: test - hook: echo "8" > .bazelversion - queue: linux-runners - bazel8__mac: - target: //... - name: test - hook: echo "8" > .bazelversion - queue: mac-runners + - test: + name: test-os:mac-bzl:head + queue: mac-runners + hooks: + - type: before_task + command: | + echo "HEAD" > .bazelversion - e2e/system-interpreter: - tasks: - bazelHEAD__linux: - target: //... - name: test - hook: echo "HEAD" > .bazelversion - queue: linux-runners - bazelHEAD__mac: - target: //... - name: test - hook: echo "HEAD" > .bazelversion - queue: mac-runners - bazel8__linux: - target: //... - name: test - hook: echo "8" > .bazelversion - queue: linux-runners - bazel8__mac: - target: //... - name: test - hook: echo "8" > .bazelversion - queue: mac-runners + - test: + name: test-os:linux-bzl:8 + queue: linux-runners + hooks: + - type: before_task + command: | + echo "8" > .bazelversion - examples/uv_pip_compile: - tasks: - bazelHEAD__linux: - target: //... - name: test - hook: echo "HEAD" > .bazelversion - queue: linux-runners - bazelHEAD__mac: - target: //... - name: test - hook: echo "HEAD" > .bazelversion - queue: mac-runners - bazel8__linux: - target: //... - name: test - hook: echo "8" > .bazelversion - queue: linux-runners - bazel8__mac: - target: //... - name: test - hook: echo "8" > .bazelversion - queue: mac-runners + - test: + name: test-os:mac-bzl:8 + queue: mac-runners + hooks: + - type: before_task + command: | + echo "8" > .bazelversion + + - test: + name: test-os:linux-bzl:7 + queue: linux-runners + hooks: + - type: before_task + command: | + echo "7" > .bazelversion + + - test: + name: test-os:mac-bzl:7 + queue: mac-runners + hooks: + - type: before_task + command: | + echo "7" > .bazelversion + + - test: + name: test-os:linux-bzl:6 + queue: linux-runners + hooks: + - type: before_task + command: | + echo "6" > .bazelversion + + - test: + name: test-os:mac-bzl:6 + queue: mac-runners + hooks: + - type: before_task + command: | + echo "6" > .bazelversion From 132947ee4d01e8f3c6ac293d8f8bfebc1c316c60 Mon Sep 17 00:00:00 2001 From: "Reid D. McKenzie" Date: Wed, 18 Jun 2025 12:23:33 -0600 Subject: [PATCH 03/12] [NO TESTS] WIP --- .aspect/workflows/config.yaml | 64 +++++++++++++++++------------------ 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/.aspect/workflows/config.yaml b/.aspect/workflows/config.yaml index 1bc295ed..36d96fe9 100644 --- a/.aspect/workflows/config.yaml +++ b/.aspect/workflows/config.yaml @@ -10,64 +10,64 @@ workspaces: tasks: - test: name: test-os:linux-bzl:head - queue: linux-runners + queue: aspect-default hooks: - type: before_task command: | echo "HEAD" > .bazelversion - - test: - name: test-os:mac-bzl:head - queue: mac-runners - hooks: - - type: before_task - command: | - echo "HEAD" > .bazelversion + # - test: + # name: test-os:mac-bzl:head + # queue: mac-runners + # hooks: + # - type: before_task + # command: | + # echo "HEAD" > .bazelversion - test: name: test-os:linux-bzl:8 - queue: linux-runners + queue: aspect-default hooks: - type: before_task command: | echo "8" > .bazelversion - - test: - name: test-os:mac-bzl:8 - queue: mac-runners - hooks: - - type: before_task - command: | - echo "8" > .bazelversion + # - test: + # name: test-os:mac-bzl:8 + # queue: mac-runners + # hooks: + # - type: before_task + # command: | + # echo "8" > .bazelversion - test: name: test-os:linux-bzl:7 - queue: linux-runners + queue: aspect-default hooks: - type: before_task command: | echo "7" > .bazelversion - - test: - name: test-os:mac-bzl:7 - queue: mac-runners - hooks: - - type: before_task - command: | - echo "7" > .bazelversion + # - test: + # name: test-os:mac-bzl:7 + # queue: mac-runners + # hooks: + # - type: before_task + # command: | + # echo "7" > .bazelversion - test: name: test-os:linux-bzl:6 - queue: linux-runners + queue: aspect-default hooks: - type: before_task command: | echo "6" > .bazelversion - - test: - name: test-os:mac-bzl:6 - queue: mac-runners - hooks: - - type: before_task - command: | - echo "6" > .bazelversion + # - test: + # name: test-os:mac-bzl:6 + # queue: mac-runners + # hooks: + # - type: before_task + # command: | + # echo "6" > .bazelversion From df1f394d3626d6a154f35d888142f2cd42fbe5bf Mon Sep 17 00:00:00 2001 From: "Reid D. McKenzie" Date: Fri, 20 Jun 2025 15:20:04 -0600 Subject: [PATCH 04/12] [NO TESTS] WIP --- .aspect/workflows/config.yaml | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/.aspect/workflows/config.yaml b/.aspect/workflows/config.yaml index 36d96fe9..2477d1e5 100644 --- a/.aspect/workflows/config.yaml +++ b/.aspect/workflows/config.yaml @@ -14,7 +14,7 @@ tasks: hooks: - type: before_task command: | - echo "HEAD" > .bazelversion + echo "last_green" > .bazelversion # - test: # name: test-os:mac-bzl:head @@ -22,15 +22,15 @@ tasks: # hooks: # - type: before_task # command: | - # echo "HEAD" > .bazelversion + # echo "last_green" > .bazelversion - test: - name: test-os:linux-bzl:8 + name: test-os:linux-bzl:latest queue: aspect-default hooks: - type: before_task command: | - echo "8" > .bazelversion + echo "latest" > .bazelversion # - test: # name: test-os:mac-bzl:8 @@ -40,13 +40,21 @@ tasks: # command: | # echo "8" > .bazelversion + - test: + name: test-os:linux-bzl:8 + queue: aspect-default + hooks: + - type: before_task + command: | + echo "8.2.1" > .bazelversion + - test: name: test-os:linux-bzl:7 queue: aspect-default hooks: - type: before_task command: | - echo "7" > .bazelversion + echo "7.6.1" > .bazelversion # - test: # name: test-os:mac-bzl:7 @@ -62,7 +70,7 @@ tasks: hooks: - type: before_task command: | - echo "6" > .bazelversion + echo "6.5.0" > .bazelversion # - test: # name: test-os:mac-bzl:6 From 7486641764c9025922c807d986133574071dd99e Mon Sep 17 00:00:00 2001 From: "Reid D. McKenzie" Date: Fri, 20 Jun 2025 15:25:10 -0600 Subject: [PATCH 05/12] [NO TESTS] WIP --- .aspect/workflows/config.yaml | 49 +++++++++-------------------------- .bazelrc | 2 ++ 2 files changed, 14 insertions(+), 37 deletions(-) diff --git a/.aspect/workflows/config.yaml b/.aspect/workflows/config.yaml index 2477d1e5..a69dd140 100644 --- a/.aspect/workflows/config.yaml +++ b/.aspect/workflows/config.yaml @@ -8,21 +8,16 @@ workspaces: - examples/uv_pip_compile tasks: + # TODO(reid): symbolic versions seem broken + - test: name: test-os:linux-bzl:head queue: aspect-default hooks: - type: before_task command: | - echo "last_green" > .bazelversion - - # - test: - # name: test-os:mac-bzl:head - # queue: mac-runners - # hooks: - # - type: before_task - # command: | - # echo "last_green" > .bazelversion + rm .bazelversion + echo "USE_BAZEL_VERSION=last_green" > .bazeliskrc - test: name: test-os:linux-bzl:latest @@ -30,15 +25,8 @@ tasks: hooks: - type: before_task command: | - echo "latest" > .bazelversion - - # - test: - # name: test-os:mac-bzl:8 - # queue: mac-runners - # hooks: - # - type: before_task - # command: | - # echo "8" > .bazelversion + rm .bazelversion + echo "USE_BAZEL_VERSION=latest" > .bazeliskrc - test: name: test-os:linux-bzl:8 @@ -46,7 +34,8 @@ tasks: hooks: - type: before_task command: | - echo "8.2.1" > .bazelversion + rm .bazelversion + echo "USE_BAZEL_VERSION=8.2.1" > .bazeliskrc - test: name: test-os:linux-bzl:7 @@ -54,15 +43,8 @@ tasks: hooks: - type: before_task command: | - echo "7.6.1" > .bazelversion - - # - test: - # name: test-os:mac-bzl:7 - # queue: mac-runners - # hooks: - # - type: before_task - # command: | - # echo "7" > .bazelversion + rm .bazelversion + echo "USE_BAZEL_VERSION=7.6.1" > .bazeliskrc - test: name: test-os:linux-bzl:6 @@ -70,12 +52,5 @@ tasks: hooks: - type: before_task command: | - echo "6.5.0" > .bazelversion - - # - test: - # name: test-os:mac-bzl:6 - # queue: mac-runners - # hooks: - # - type: before_task - # command: | - # echo "6" > .bazelversion + rm .bazelversion + echo "USE_BAZEL_VERSION=6.5.0" > .bazeliskrc diff --git a/.bazelrc b/.bazelrc index 3cc4c9e5..26ad2baa 100644 --- a/.bazelrc +++ b/.bazelrc @@ -6,6 +6,8 @@ test --test_output=errors # TODO(alex): enable common --noenable_bzlmod +# TODO(reid): remove; needed for newest bazel to enable workspace +common --enable_workspace # Define value used by tests build --define=SOME_VAR=SOME_VALUE From 910a5d58a58a8701c35990be80d3d2e96ebaf5af Mon Sep 17 00:00:00 2001 From: "Reid D. McKenzie" Date: Fri, 20 Jun 2025 15:31:04 -0600 Subject: [PATCH 06/12] Don't backtest to 6; already dropped --- .aspect/workflows/config.yaml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.aspect/workflows/config.yaml b/.aspect/workflows/config.yaml index a69dd140..ff21924a 100644 --- a/.aspect/workflows/config.yaml +++ b/.aspect/workflows/config.yaml @@ -45,12 +45,3 @@ tasks: command: | rm .bazelversion echo "USE_BAZEL_VERSION=7.6.1" > .bazeliskrc - - - test: - name: test-os:linux-bzl:6 - queue: aspect-default - hooks: - - type: before_task - command: | - rm .bazelversion - echo "USE_BAZEL_VERSION=6.5.0" > .bazeliskrc From a74cbdc4520dfbcb727c559674d1b1c1de792d73 Mon Sep 17 00:00:00 2001 From: "Reid D. McKenzie" Date: Fri, 20 Jun 2025 15:33:01 -0600 Subject: [PATCH 07/12] Disable HEAD build for now --- .aspect/workflows/config.yaml | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/.aspect/workflows/config.yaml b/.aspect/workflows/config.yaml index ff21924a..da752786 100644 --- a/.aspect/workflows/config.yaml +++ b/.aspect/workflows/config.yaml @@ -8,16 +8,15 @@ workspaces: - examples/uv_pip_compile tasks: - # TODO(reid): symbolic versions seem broken - - - test: - name: test-os:linux-bzl:head - queue: aspect-default - hooks: - - type: before_task - command: | - rm .bazelversion - echo "USE_BAZEL_VERSION=last_green" > .bazeliskrc + # TODO(reid): Rosetta doesn't like HEAD version strings seemingly + # - test: + # name: test-os:linux-bzl:head + # queue: aspect-default + # hooks: + # - type: before_task + # command: | + # rm .bazelversion + # echo "USE_BAZEL_VERSION=last_green" > .bazeliskrc - test: name: test-os:linux-bzl:latest From 93ab1e8ed521b0bcf813e526bad61faee76bb8a8 Mon Sep 17 00:00:00 2001 From: "Reid D. McKenzie" Date: Fri, 20 Jun 2025 17:21:18 -0600 Subject: [PATCH 08/12] [NO TESTS] WIP --- .bazelrc | 4 +- MODULE.bazel | 43 ++- WORKSPACE | 318 ------------------ docs/py_test.md | 2 +- docs/virtual_deps.md | 2 +- examples/django/BUILD.bazel | 2 +- examples/django/mysite/BUILD.bazel | 2 +- examples/multi_version/BUILD.bazel | 8 +- examples/py_binary/BUILD.bazel | 2 +- examples/py_pex_binary/BUILD.bazel | 2 +- examples/py_venv/BUILD.bazel | 4 +- examples/pytest/BUILD.bazel | 10 +- examples/pytest/README.md | 2 +- examples/virtual_deps/BUILD.bazel | 4 +- internal_python_deps.bzl | 23 -- py/private/py_pytest_main.bzl | 2 +- py/repositories.bzl | 6 +- py/tests/external-deps/BUILD.bazel | 4 +- py/tests/external-deps/custom-macro/macro.bzl | 2 +- py/tests/py-binary/BUILD.bazel | 4 +- py/tests/py-external-venv/BUILD.bazel | 2 +- py/tests/py-internal-venv/BUILD.bazel | 2 +- py/tests/py-pex-binary/BUILD.bazel | 4 +- py/tests/py_image_layer/BUILD.bazel | 2 +- py/tests/py_venv_image_layer/BUILD.bazel | 2 +- .../bazel-contrib/rules_python/BUILD.bazel | 4 + .../bazel-contrib/rules_python/dev_pip.patch | 10 + 27 files changed, 90 insertions(+), 382 deletions(-) delete mode 100644 WORKSPACE delete mode 100644 internal_python_deps.bzl create mode 100644 third_party/com.github/bazel-contrib/rules_python/BUILD.bazel create mode 100644 third_party/com.github/bazel-contrib/rules_python/dev_pip.patch diff --git a/.bazelrc b/.bazelrc index 26ad2baa..1f0fc596 100644 --- a/.bazelrc +++ b/.bazelrc @@ -5,9 +5,7 @@ test --test_output=errors # TODO(alex): enable -common --noenable_bzlmod -# TODO(reid): remove; needed for newest bazel to enable workspace -common --enable_workspace +common --enable_bzlmod # Define value used by tests build --define=SOME_VAR=SOME_VALUE diff --git a/MODULE.bazel b/MODULE.bazel index 51cfce79..c776d04e 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -14,19 +14,48 @@ module( # py_image_layer needs repo_mapping fix. bazel_dep(name = "aspect_bazel_lib", version = "2.16.0") bazel_dep(name = "bazel_skylib", version = "1.4.2") -bazel_dep(name = "rules_python", version = "0.29.0") +bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.5.0") +bazel_dep(name = "rules_python", version = "1.0.0") +bazel_dep(name = "rules_python_gazelle_plugin", version = "1.0.0") +bazel_dep(name = "gazelle", version = "0.31.0", repo_name = "bazel_gazelle") bazel_dep(name = "platforms", version = "0.0.7") +single_version_override( + module_name = "rules_python", + version="1.0.0", + patches=[ + "//third_party/com.github/bazel-contrib/rules_python:dev_pip.patch" + ], + patch_strip=0, +) + bazel_lib = use_extension("@aspect_bazel_lib//lib:extensions.bzl", "toolchains") bazel_lib.expand_template() +bazel_lib.tar() +use_repo(bazel_lib, "bsd_tar_toolchains") # Custom python version for testing only python = use_extension("@rules_python//python/extensions:python.bzl", "python", dev_dependency = True) python.toolchain( - is_default = False, - python_version = "3.9", + is_default = True, + python_version = "3.11", +) + +pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip", dev_dependency = True) +pip.parse( + hub_name = "pypi", + python_version = "3.11", + requirements_lock = "//:requirements.txt", ) +pip.parse( + hub_name = "django", + python_version = "3.11", + requirements_lock = "//py/tests/virtual/django:requirements.txt", +) + +use_repo(pip, "pypi", "pypi_311_pytest", "django") + tools = use_extension("//py:extensions.bzl", "py_tools") tools.rules_py_tools() use_repo(tools, "rules_py_tools") @@ -110,3 +139,11 @@ oci.pull( tag = "latest", ) use_repo(oci, "ubuntu", "ubuntu_linux_amd64", "ubuntu_linux_arm64_v8") + +http_file = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file") +http_file( + name = "django_4_2_4", + urls = ["https://files.pythonhosted.org/packages/7f/9e/fc6bab255ae10bc57fa2f65646eace3d5405fbb7f5678b90140052d1db0f/Django-4.2.4-py3-none-any.whl"], + sha256 = "860ae6a138a238fc4f22c99b52f3ead982bb4b1aad8c0122bcd8c8a3a02e409d", + downloaded_file_path = "Django-4.2.4-py3-none-any.whl", +) diff --git a/WORKSPACE b/WORKSPACE deleted file mode 100644 index 62677825..00000000 --- a/WORKSPACE +++ /dev/null @@ -1,318 +0,0 @@ -# Declare the local Bazel workspace. -workspace(name = "aspect_rules_py") - -load("//tools/release:fetch.bzl", _release_deps = "fetch_deps") -load(":internal_deps.bzl", "rules_py_internal_deps") - -# Fetch deps needed only locally for development -rules_py_internal_deps() - -# Fetch deps needed only for a release. -_release_deps() - -load("//py:repositories.bzl", "rules_py_dependencies") - -# Fetch dependencies which users need as well -rules_py_dependencies() - -load("//py:toolchains.bzl", "rules_py_toolchains") - -rules_py_toolchains() - -load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains") - -python_register_toolchains( - name = "python_toolchain_3_8", - python_version = "3.8.12", - # Setting `set_python_version_constraint` will set special constraints on the registered toolchain. - # This means that this toolchain registration will only be selected for `py_binary` / `py_test` targets - # that have the `python_version = "3.8.12"` attribute set. Targets that have no `python_attribute` will use - # the default toolchain resolved which can be seen below. - set_python_version_constraint = True, -) - -# It is important to register the default toolchain at last as it will be selected for any -# py_test/py_binary target even if it has python_version attribute set. -python_register_toolchains( - name = "python_toolchain", - python_version = "3.9", -) - -py_repositories() - -############################################ -# Aspect bazel-lib -load("@aspect_bazel_lib//lib:repositories.bzl", "register_coreutils_toolchains", "register_expand_template_toolchains") - -register_coreutils_toolchains() - -register_expand_template_toolchains() - -load("@musl_toolchains//:repositories.bzl", "load_musl_toolchains") - -load_musl_toolchains(extra_target_compatible_with = ["@//tools/linkers:musl"]) - -load("@musl_toolchains//:toolchains.bzl", "register_musl_toolchains") - -register_musl_toolchains() - -############################################ -## CC toolchain using llvm -load("@toolchains_llvm//toolchain:deps.bzl", "bazel_toolchain_dependencies") - -bazel_toolchain_dependencies() - -load("@toolchains_llvm//toolchain:rules.bzl", "llvm_toolchain") - -llvm_toolchain( - name = "llvm_toolchain", - llvm_version = "17.0.2", - sha256 = { - "darwin-aarch64": "bb5144516c94326981ec78c8b055c85b1f6780d345128cae55c5925eb65241ee", - "darwin-x86_64": "800ec8401344a95f84588815e97523a0ed31fd05b6ffa9e1b58ce20abdcf69f1", - "linux-aarch64": "49eec0202b8cd4be228c8e92878303317f660bc904cf6e6c08917a55a638917d", - "linux-x86_64": "0c5096c157e196a04fc6ac58543266caef0da3e3c921414a7c279feacc2309d9", - }, - sysroot = { - "darwin-aarch64": "@sysroot_darwin_universal//:sysroot", - "darwin-x86_64": "@sysroot_darwin_universal//:sysroot", - "linux-aarch64": "@org_chromium_sysroot_linux_arm64//:sysroot", - "linux-x86_64": "@org_chromium_sysroot_linux_x86_64//:sysroot", - }, - urls = { - "darwin-aarch64": ["https://github.com/dzbarsky/static-clang/releases/download/v17.0.2-8/darwin_arm64_minimal.tar.xz"], - "darwin-x86_64": ["https://github.com/dzbarsky/static-clang/releases/download/v17.0.2-8/darwin_amd64_minimal.tar.xz"], - "linux-aarch64": ["https://github.com/dzbarsky/static-clang/releases/download/v17.0.2-8/linux_arm64_minimal.tar.xz"], - "linux-x86_64": ["https://github.com/dzbarsky/static-clang/releases/download/v17.0.2-8/linux_amd64_minimal.tar.xz"], - }, -) - -load("@llvm_toolchain//:toolchains.bzl", "llvm_register_toolchains") - -llvm_register_toolchains() - -############################################ -# Development dependencies from pypi -load("@python_toolchain//:defs.bzl", "interpreter") -load(":internal_python_deps.bzl", "rules_py_internal_pypi_deps") - -rules_py_internal_pypi_deps( - interpreter = interpreter, -) - -load("@pypi//:requirements.bzl", "install_deps") - -install_deps() - -load("@django//:requirements.bzl", install_django_deps = "install_deps") - -install_django_deps() - -################################ -# For running our own unit tests -load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") - -bazel_skylib_workspace() - -load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") - -############################################ -# Gazelle, for generating bzl_library targets -load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") - -go_rules_dependencies() - -go_register_toolchains(version = "1.19.3") - -gazelle_dependencies() - -load("@rules_python//gazelle:deps.bzl", _py_gazelle_deps = "gazelle_deps") - -_py_gazelle_deps() - -load("@bazel_skylib_gazelle_plugin//:workspace.bzl", "bazel_skylib_gazelle_plugin_workspace") - -bazel_skylib_gazelle_plugin_workspace() - -load("@bazel_skylib_gazelle_plugin//:setup.bzl", "bazel_skylib_gazelle_plugin_setup") - -bazel_skylib_gazelle_plugin_setup(register_go_toolchains = False) - -############################################ -# rules_rust dependencies for building tools -load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains", "rust_repository_set") - -rules_rust_dependencies() - -RUST_EDITION = "2021" - -RUST_VERSION = "1.81.0" - -# Declare cross-compilation toolchains -rust_repository_set( - name = "apple_darwin_aarch64", - edition = RUST_EDITION, - exec_triple = "aarch64-apple-darwin", - # and cross-compile to these platforms: - extra_target_triples = { - "aarch64-apple-darwin": [ - "@platforms//cpu:arm64", - "@platforms//os:macos", - ], - "aarch64-unknown-linux-musl": [ - "@platforms//cpu:arm64", - "@platforms//os:linux", - "@//tools/linkers:musl", - ], - "x86_64-apple-darwin": [ - "@platforms//cpu:x86_64", - "@platforms//os:macos", - ], - "x86_64-unknown-linux-musl": [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - "@//tools/linkers:musl", - ], - }, - versions = [RUST_VERSION], -) - -rust_repository_set( - name = "apple_darwin_x86_64", - edition = RUST_EDITION, - exec_triple = "x86_64-apple-darwin", - # and cross-compile to these platforms: - extra_target_triples = { - "aarch64-apple-darwin": [ - "@platforms//cpu:arm64", - "@platforms//os:macos", - ], - "aarch64-unknown-linux-musl": [ - "@platforms//cpu:arm64", - "@platforms//os:linux", - "@//tools/linkers:musl", - ], - "x86_64-apple-darwin": [ - "@platforms//cpu:x86_64", - "@platforms//os:macos", - ], - "x86_64-unknown-linux-musl": [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - "@//tools/linkers:musl", - ], - }, - versions = [RUST_VERSION], -) - -rust_repository_set( - name = "rust_linux_x86_64", - edition = RUST_EDITION, - exec_triple = "x86_64-unknown-linux-gnu", - extra_target_triples = { - "aarch64-unknown-linux-gnu": [ - "@platforms//cpu:arm64", - "@platforms//os:linux", - "@//tools/linkers:unknown", - ], - "aarch64-unknown-linux-musl": [ - "@platforms//cpu:arm64", - "@platforms//os:linux", - "@//tools/linkers:musl", - ], - "x86_64-unknown-linux-gnu": [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - "@//tools/linkers:unknown", - ], - "x86_64-unknown-linux-musl": [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - "@//tools/linkers:musl", - ], - }, - versions = [RUST_VERSION], -) - -rust_repository_set( - name = "rust_linux_aarch64", - edition = RUST_EDITION, - exec_triple = "aarch64-unknown-linux-gnu", - extra_target_triples = { - "aarch64-unknown-linux-gnu": [ - "@platforms//cpu:arm64", - "@platforms//os:linux", - "@//tools/linkers:unknown", - ], - "aarch64-unknown-linux-musl": [ - "@platforms//cpu:arm64", - "@platforms//os:linux", - "@//tools/linkers:musl", - ], - "x86_64-unknown-linux-gnu": [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - "@//tools/linkers:unknown", - ], - "x86_64-unknown-linux-musl": [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - "@//tools/linkers:musl", - ], - }, - versions = [RUST_VERSION], -) - -rust_register_toolchains( - edition = RUST_EDITION, - versions = [RUST_VERSION], -) - -load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies") - -crate_universe_dependencies() - -load("@rules_rust//crate_universe:defs.bzl", "crates_repository") - -crates_repository( - name = "crate_index", - cargo_lockfile = "//:Cargo.lock", - lockfile = "//:Cargo.Bazel.lock", - manifests = [ - "//:Cargo.toml", - "//py/tools/py:Cargo.toml", - "//py/tools/unpack_bin:Cargo.toml", - "//py/tools/venv_bin:Cargo.toml", - "//py/tools/venv_shim:Cargo.toml", - ], -) - -load("@crate_index//:defs.bzl", "crate_repositories") - -crate_repositories() - -load("@rules_oci//oci:dependencies.bzl", "rules_oci_dependencies") - -rules_oci_dependencies() - -load("@rules_oci//oci:repositories.bzl", "oci_register_toolchains") - -oci_register_toolchains(name = "oci") - -# You can pull your base images using oci_pull like this: -load("@rules_oci//oci:pull.bzl", "oci_pull") - -oci_pull( - name = "ubuntu", - digest = "sha256:b59d21599a2b151e23eea5f6602f4af4d7d31c4e236d22bf0b62b86d2e386b8f", - image = "ubuntu", - platforms = [ - "linux/arm64/v8", - "linux/amd64", - ], - tag = "latest", -) - -load("@container_structure_test//:repositories.bzl", "container_structure_test_register_toolchain") - -container_structure_test_register_toolchain(name = "cst") diff --git a/docs/py_test.md b/docs/py_test.md index ea1294df..b8532e41 100644 --- a/docs/py_test.md +++ b/docs/py_test.md @@ -84,7 +84,7 @@ py_pytest_main wraps the template rendering target and the final py_library. | :------------- | :------------- | :------------- | | name | The name of the runable target that updates the test entry file. | none | | py_library | Use this attribute to override the default py_library rule. | <unknown object com.google.devtools.build.skydoc.fakebuildapi.FakeStarlarkRuleFunctionsApi$RuleDefinitionIdentifier> | -| deps | A list containing the pytest library target, e.g., @pypi_pytest//:pkg. | [] | +| deps | A list containing the pytest library target, e.g., @pypi//pytest. | [] | | data | A list of data dependencies to pass to the py_library target. | [] | | testonly | A boolean indicating if the py_library target is testonly. | True | | kwargs | The extra arguments passed to the template rendering target. | none | diff --git a/docs/virtual_deps.md b/docs/virtual_deps.md index 01e2f459..b924da05 100644 --- a/docs/virtual_deps.md +++ b/docs/virtual_deps.md @@ -17,7 +17,7 @@ https://github.com/aspect-build/rules_py/issues/213 Simply move an element from the `deps` attribute to `virtual_deps`. For example, instead of getting a specific version of Django from -`deps = ["@pypi_django//:pkg"]` on a `py_library` target, +`deps = ["@pypi//django"]` on a `py_library` target, provide the package name with `virtual_deps = ["django"]`. > Note that any `py_binary` or `py_test` transitively depending on this `py_library` must be loaded from `aspect_rules_py` rather than `rules_python`, as the latter does not have a feature of resolving the virtual dep. diff --git a/examples/django/BUILD.bazel b/examples/django/BUILD.bazel index c798f375..b6244516 100644 --- a/examples/django/BUILD.bazel +++ b/examples/django/BUILD.bazel @@ -5,6 +5,6 @@ py_binary( srcs = ["manage.py"], deps = [ "//examples/django/mysite", - "@pypi_django//:pkg", + "@pypi//django", ], ) diff --git a/examples/django/mysite/BUILD.bazel b/examples/django/mysite/BUILD.bazel index 413c89e6..46238e55 100644 --- a/examples/django/mysite/BUILD.bazel +++ b/examples/django/mysite/BUILD.bazel @@ -11,6 +11,6 @@ py_library( ], visibility = ["//examples/django:__pkg__"], deps = [ - "@pypi_django//:pkg", + "@pypi//django", ], ) diff --git a/examples/multi_version/BUILD.bazel b/examples/multi_version/BUILD.bazel index 87eb71b2..138e6900 100644 --- a/examples/multi_version/BUILD.bazel +++ b/examples/multi_version/BUILD.bazel @@ -3,15 +3,15 @@ load("@aspect_rules_py//py:defs.bzl", "py_binary", "py_pytest_main", "py_test") py_binary( name = "multi_version", srcs = ["say.py"], - python_version = "3.8.12", + python_version = "3.11.0", deps = [ - "@pypi_cowsay//:pkg", + "@pypi//cowsay", ], ) py_pytest_main( name = "__test__", - deps = ["@pypi_pytest//:pkg"], + deps = ["@pypi//pytest"], ) py_test( @@ -21,7 +21,7 @@ py_test( ":__test__", ], main = ":__test__.py", - python_version = "3.8.12", + python_version = "3.11.0", deps = [ ":__test__", ], diff --git a/examples/py_binary/BUILD.bazel b/examples/py_binary/BUILD.bazel index 23fd4bac..5a38499c 100644 --- a/examples/py_binary/BUILD.bazel +++ b/examples/py_binary/BUILD.bazel @@ -13,6 +13,6 @@ py_binary( name = "py_binary", srcs = [":stamped"], deps = [ - "@pypi_cowsay//:pkg", + "@pypi//cowsay", ], ) diff --git a/examples/py_pex_binary/BUILD.bazel b/examples/py_pex_binary/BUILD.bazel index 1fb85906..64809b52 100644 --- a/examples/py_pex_binary/BUILD.bazel +++ b/examples/py_pex_binary/BUILD.bazel @@ -9,7 +9,7 @@ py_binary( }, deps = [ "@bazel_tools//tools/python/runfiles", - "@pypi_cowsay//:pkg", + "@pypi//cowsay", ], ) diff --git a/examples/py_venv/BUILD.bazel b/examples/py_venv/BUILD.bazel index ae0ee9a3..e28b5b7c 100644 --- a/examples/py_venv/BUILD.bazel +++ b/examples/py_venv/BUILD.bazel @@ -15,7 +15,7 @@ expand_template( py_venv( name = "venv", deps = [ - "@pypi_cowsay//:pkg", + "@pypi//cowsay", ], ) @@ -41,7 +41,7 @@ py_venv_binary( ], main = ":stamped", deps = [ - "@pypi_cowsay//:pkg", + "@pypi//cowsay", ], ) diff --git a/examples/pytest/BUILD.bazel b/examples/pytest/BUILD.bazel index 9256da54..adb7ca7b 100644 --- a/examples/pytest/BUILD.bazel +++ b/examples/pytest/BUILD.bazel @@ -21,10 +21,10 @@ py_test( pytest_main = True, deps = [ ":lib", - "@pypi_coverage//:pkg", - "@pypi_ftfy//:pkg", - "@pypi_neptune//:pkg", - "@pypi_pytest//:pkg", + "@pypi//coverage", + "@pypi//ftfy", + "@pypi//neptune", + "@pypi//pytest", ], ) @@ -36,5 +36,5 @@ py_test( package_collisions = "warning", pytest_main = True, shard_count = 2, - deps = ["@pypi_pytest//:pkg"], + deps = ["@pypi//pytest"], ) diff --git a/examples/pytest/README.md b/examples/pytest/README.md index 08b45c82..16b038b3 100644 --- a/examples/pytest/README.md +++ b/examples/pytest/README.md @@ -14,7 +14,7 @@ load("@aspect_rules_py//py:defs.bzl", "py_pytest_main") py_pytest_main( name = "__test__", - deps = ["@pypi_pytest//:pkg"], # change this to the pytest target in your repo. + deps = ["@pypi//pytest"], # change this to the pytest target in your repo. ) ``` diff --git a/examples/virtual_deps/BUILD.bazel b/examples/virtual_deps/BUILD.bazel index 6e34e56f..c1efef98 100644 --- a/examples/virtual_deps/BUILD.bazel +++ b/examples/virtual_deps/BUILD.bazel @@ -19,7 +19,7 @@ py_library( py_binary( name = "app", srcs = ["main.py"], - python_version = "3.8.12", + python_version = "3.11.0", resolutions = resolutions.from_requirements( [ "cowsay", @@ -35,7 +35,7 @@ py_binary( py_binary( name = "app_snake", srcs = ["main.py"], - python_version = "3.8.12", + python_version = "3.11.0", resolutions = resolutions.from_requirements( [ "snakesay", diff --git a/internal_python_deps.bzl b/internal_python_deps.bzl deleted file mode 100644 index 0300dbe2..00000000 --- a/internal_python_deps.bzl +++ /dev/null @@ -1,23 +0,0 @@ -"""Our "development" Python dependencies - -Users should *not* need to install these. If users see a load() -statement from these, that's a bug in our distribution. - -These happen after the regular internal dependencies loads as we need to reference the resolved interpreter -""" - -load("@rules_python//python:pip.bzl", "pip_parse") - -# buildifier: disable=function-docstring -def rules_py_internal_pypi_deps(interpreter): - pip_parse( - name = "pypi", - python_interpreter_target = interpreter, - requirements_lock = "//:requirements.txt", - ) - - pip_parse( - name = "django", - python_interpreter_target = interpreter, - requirements_lock = "//py/tests/virtual/django:requirements.txt", - ) diff --git a/py/private/py_pytest_main.bzl b/py/private/py_pytest_main.bzl index 4ce6292a..d48935bd 100644 --- a/py/private/py_pytest_main.bzl +++ b/py/private/py_pytest_main.bzl @@ -64,7 +64,7 @@ def py_pytest_main(name, py_library = default_py_library, deps = [], data = [], Args: name: The name of the runable target that updates the test entry file. py_library: Use this attribute to override the default py_library rule. - deps: A list containing the pytest library target, e.g., @pypi_pytest//:pkg. + deps: A list containing the pytest library target, e.g., @pypi//pytest. data: A list of data dependencies to pass to the py_library target. testonly: A boolean indicating if the py_library target is testonly. **kwargs: The extra arguments passed to the template rendering target. diff --git a/py/repositories.bzl b/py/repositories.bzl index 12b58e41..af056cc6 100644 --- a/py/repositories.bzl +++ b/py/repositories.bzl @@ -39,7 +39,7 @@ def rules_py_dependencies(): http_archive( name = "rules_python", - sha256 = "c68bdc4fbec25de5b5493b8819cfc877c4ea299c0dcb15c244c5a00208cde311", - strip_prefix = "rules_python-0.31.0", - url = "https://github.com/bazelbuild/rules_python/releases/download/0.31.0/rules_python-0.31.0.tar.gz", + sha256 = "4f7e2aa1eb9aa722d96498f5ef514f426c1f55161c3c9ae628c857a7128ceb07", + strip_prefix = "rules_python-1.0.0", + url = "https://github.com/bazelbuild/rules_python/releases/download/1.0.0/rules_python-1.0.0.tar.gz", ) diff --git a/py/tests/external-deps/BUILD.bazel b/py/tests/external-deps/BUILD.bazel index c2f3ad73..b2816fc2 100644 --- a/py/tests/external-deps/BUILD.bazel +++ b/py/tests/external-deps/BUILD.bazel @@ -6,7 +6,7 @@ py_library( name = "lib", srcs = ["lib.py"], deps = [ - "@pypi_colorama//:pkg", + "@pypi//colorama", ], ) @@ -15,7 +15,7 @@ py_binary( srcs = ["//py/tests/external-deps/custom-macro:__main__.py"], deps = [ # Referencing the external py_library rule generated by rules_python - "@pypi_click//:pkg", + "@pypi//click", ], ) diff --git a/py/tests/external-deps/custom-macro/macro.bzl b/py/tests/external-deps/custom-macro/macro.bzl index d5377ca8..2737f0e6 100644 --- a/py/tests/external-deps/custom-macro/macro.bzl +++ b/py/tests/external-deps/custom-macro/macro.bzl @@ -14,7 +14,7 @@ def click_cli_binary(name, deps = [], **kwargs): main = "//py/tests/external-deps/custom-macro:__main__.py", deps = deps + [ name + "_lib", - "@pypi_click//:pkg", + "@pypi//click", ], **kwargs ) diff --git a/py/tests/py-binary/BUILD.bazel b/py/tests/py-binary/BUILD.bazel index a99d987e..e9be9183 100644 --- a/py/tests/py-binary/BUILD.bazel +++ b/py/tests/py-binary/BUILD.bazel @@ -10,10 +10,10 @@ load("//py:defs.bzl", "py_binary", "py_test") # We happen to use pytest here only for convenience; it's a program already in our requirements.in. py_binary( name = "py_test_bin", - srcs = ["@pypi_pytest//:rules_python_wheel_entry_point_pytest"], + srcs = ["@pypi_311_pytest//:rules_python_wheel_entry_point_pytest"], # rules_python permits this label even though it's not a source file in this repository. main = "rules_python_wheel_entry_point_pytest.py", - deps = ["@pypi_pytest//:pkg"], + deps = ["@pypi//pytest"], ) genrule( diff --git a/py/tests/py-external-venv/BUILD.bazel b/py/tests/py-external-venv/BUILD.bazel index 3f7ad6cf..be4134da 100644 --- a/py/tests/py-external-venv/BUILD.bazel +++ b/py/tests/py-external-venv/BUILD.bazel @@ -3,7 +3,7 @@ load("//py/private/py_venv:defs.bzl", "py_venv", "py_venv_test") py_venv( name = "venv", deps = [ - "@pypi_cowsay//:pkg", + "@pypi//cowsay", ], ) diff --git a/py/tests/py-internal-venv/BUILD.bazel b/py/tests/py-internal-venv/BUILD.bazel index f6716781..017675de 100644 --- a/py/tests/py-internal-venv/BUILD.bazel +++ b/py/tests/py-internal-venv/BUILD.bazel @@ -10,6 +10,6 @@ py_venv_test( ], main = "test.py", deps = [ - "@pypi_cowsay//:pkg", + "@pypi//cowsay", ], ) diff --git a/py/tests/py-pex-binary/BUILD.bazel b/py/tests/py-pex-binary/BUILD.bazel index 3107a127..e70f14b6 100644 --- a/py/tests/py-pex-binary/BUILD.bazel +++ b/py/tests/py-pex-binary/BUILD.bazel @@ -8,8 +8,8 @@ py_binary( data = ["data.txt"], deps = [ "@bazel_tools//tools/python/runfiles", - "@pypi_cowsay//:pkg", - "@pypi_six//:pkg", + "@pypi//cowsay", + "@pypi//six", ], ) diff --git a/py/tests/py_image_layer/BUILD.bazel b/py/tests/py_image_layer/BUILD.bazel index a5a0cdfa..3d409c33 100644 --- a/py/tests/py_image_layer/BUILD.bazel +++ b/py/tests/py_image_layer/BUILD.bazel @@ -27,7 +27,7 @@ py_binary( deps = [ "//py/tests/internal-deps/adder", "//py/tests/py_image_layer/branding", - "@pypi_colorama//:pkg", + "@pypi//colorama", ], ) diff --git a/py/tests/py_venv_image_layer/BUILD.bazel b/py/tests/py_venv_image_layer/BUILD.bazel index 61d89467..fcc6b42d 100644 --- a/py/tests/py_venv_image_layer/BUILD.bazel +++ b/py/tests/py_venv_image_layer/BUILD.bazel @@ -29,7 +29,7 @@ py_venv_binary( deps = [ "//py/tests/internal-deps/adder", "//py/tests/py_image_layer/branding", - "@pypi_colorama//:pkg", + "@pypi//colorama", ], ) diff --git a/third_party/com.github/bazel-contrib/rules_python/BUILD.bazel b/third_party/com.github/bazel-contrib/rules_python/BUILD.bazel new file mode 100644 index 00000000..12615f55 --- /dev/null +++ b/third_party/com.github/bazel-contrib/rules_python/BUILD.bazel @@ -0,0 +1,4 @@ +exports_files( + ["dev_pip.patch"], + visibility = ["//visibility:public"], +) diff --git a/third_party/com.github/bazel-contrib/rules_python/dev_pip.patch b/third_party/com.github/bazel-contrib/rules_python/dev_pip.patch new file mode 100644 index 00000000..e1431679 --- /dev/null +++ b/third_party/com.github/bazel-contrib/rules_python/dev_pip.patch @@ -0,0 +1,10 @@ +--- MODULE.bazel ++++ MODULE.bazel +@@ -112,7 +112,6 @@ dev_pip = use_extension( + dev_pip = use_extension( + "//python/extensions:pip.bzl", + "pip", +- dev_dependency = True, + ) + dev_pip.parse( + download_only = True, From 7d55c6c483b7bc8538ff3435fe053c181ffb1adb Mon Sep 17 00:00:00 2001 From: "Reid D. McKenzie" Date: Fri, 20 Jun 2025 18:54:15 -0600 Subject: [PATCH 09/12] [NO TESTS] WIP --- MODULE.bazel | 110 +++++++++++++++++- .../toolchains_llvm/clang_ldd.patch | 6 +- tools/release/fetch.bzl | 34 +----- 3 files changed, 114 insertions(+), 36 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index c776d04e..a7b4d4d5 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -14,11 +14,13 @@ module( # py_image_layer needs repo_mapping fix. bazel_dep(name = "aspect_bazel_lib", version = "2.16.0") bazel_dep(name = "bazel_skylib", version = "1.4.2") -bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.5.0") -bazel_dep(name = "rules_python", version = "1.0.0") -bazel_dep(name = "rules_python_gazelle_plugin", version = "1.0.0") -bazel_dep(name = "gazelle", version = "0.31.0", repo_name = "bazel_gazelle") +bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.5.0", dev_dependency = True) +bazel_dep(name = "gazelle", version = "0.31.0", repo_name = "bazel_gazelle", dev_dependency = True) bazel_dep(name = "platforms", version = "0.0.7") +bazel_dep(name = "rules_python", version = "1.0.0") +bazel_dep(name = "rules_python_gazelle_plugin", version = "1.0.0", dev_dependency = True) +bazel_dep(name = "toolchains_musl", version = "0.1.20", dev_dependency = True) +bazel_dep(name = "toolchains_llvm", version = "1.4.0", dev_dependency = True) single_version_override( module_name = "rules_python", @@ -29,6 +31,14 @@ single_version_override( patch_strip=0, ) +# single_version_override( +# module_name = "toolchains_llvm", +# version = "0.10.3", +# patches = [ +# "//third_party/com.github/bazel-contrib/toolchains_llvm:clang_ldd.patch", +# ], +# ) + bazel_lib = use_extension("@aspect_bazel_lib//lib:extensions.bzl", "toolchains") bazel_lib.expand_template() bazel_lib.tar() @@ -75,6 +85,92 @@ register_toolchains( # NOTE: when publishing to BCR, we patch these to be dev_dependency, as we publish pre-built binaries # along with our releases. +release_tools = use_extension("//tools/release:fetch.bzl", "release_tools", dev_dependency = True) +use_repo(release_tools, + "org_chromium_sysroot_linux_arm64", + "org_chromium_sysroot_linux_x86_64", + "musl_toolchains", + "sysroot_darwin_universal", +) + +llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm") +inject_repo(llvm, + org_chromium_sysroot_linux_arm64 = "org_chromium_sysroot_linux_arm64", + org_chromium_sysroot_linux_x86_64 = "org_chromium_sysroot_linux_x86_64", + sysroot_darwin_universal = "sysroot_darwin_universal", +) + +llvm.toolchain( + name = "llvm_toolchain", + llvm_version = "17.0.2", +) +use_repo(llvm, "llvm_toolchain", "llvm_toolchain_llvm") +register_toolchains("@llvm_toolchain//:all") + +llvm.toolchain( + name = "llvm_toolchain_linux_x86_64", + llvm_version = "17.0.2", +) +llvm.toolchain_root( + name = "llvm_toolchain_linux_x86_64", + label = "@llvm_toolchain_llvm//:BUILD", +) +llvm.sysroot( + name = "llvm_toolchain_linux_x86_64", + label = "@org_chromium_sysroot_linux_x86_64//:sysroot", + targets = ["linux-x86_64"], +) +use_repo(llvm, "llvm_toolchain_linux_x86_64") +register_toolchains("@llvm_toolchain_linux_x86_64//:all") + +llvm.toolchain( + name = "llvm_toolchain_linux_aarch64", + llvm_version = "17.0.2", +) +llvm.toolchain_root( + name = "llvm_toolchain_linux_aarch64", + label = "@llvm_toolchain_llvm//:BUILD", +) +llvm.sysroot( + name = "llvm_toolchain_linux_aarch64", + label = "@org_chromium_sysroot_linux_arm64//:sysroot", + targets = ["linux-aarch64"], +) +use_repo(llvm, "llvm_toolchain_linux_aarch64") +register_toolchains("@llvm_toolchain_linux_aarch64//:all") + +llvm.toolchain( + name = "llvm_toolchain_darwin_x86_64", + llvm_version = "17.0.2", +) +llvm.toolchain_root( + name = "llvm_toolchain_darwin_x86_64", + label = "@llvm_toolchain_llvm//:BUILD", +) +llvm.sysroot( + name = "llvm_toolchain_darwin_x86_64", + label = "@sysroot_darwin_universal//:sysroot", + targets = ["darwin-x86_64"], +) +use_repo(llvm, "llvm_toolchain_darwin_x86_64") +register_toolchains("@llvm_toolchain_darwin_x86_64//:all") + +llvm.toolchain( + name = "llvm_toolchain_darwin_aarch64", + llvm_version = "17.0.2", +) +llvm.toolchain_root( + name = "llvm_toolchain_darwin_aarch64", + label = "@llvm_toolchain_llvm//:BUILD", +) +llvm.sysroot( + name = "llvm_toolchain_darwin_aarch64", + label = "@sysroot_darwin_universal//:sysroot", + targets = ["darwin-aarch64"], +) +use_repo(llvm, "llvm_toolchain_darwin_aarch64") +register_toolchains("@llvm_toolchain_darwin_aarch64//:all") + bazel_dep( name = "rules_rust", version = "0.53.0", @@ -89,6 +185,12 @@ rust = use_extension( rust.toolchain( edition = "2021", versions = ["1.81.0"], + extra_target_triples = [ + "aarch64-apple-darwin", + "aarch64-unknown-linux-gnu", + "x86_64-apple-darwin", + "x86_64-unknown-linux-gnu", + ] ) use_repo(rust, "rust_toolchains") diff --git a/third_party/com.github/bazel-contrib/toolchains_llvm/clang_ldd.patch b/third_party/com.github/bazel-contrib/toolchains_llvm/clang_ldd.patch index b3815010..064ed303 100644 --- a/third_party/com.github/bazel-contrib/toolchains_llvm/clang_ldd.patch +++ b/third_party/com.github/bazel-contrib/toolchains_llvm/clang_ldd.patch @@ -1,7 +1,5 @@ -diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl -index b2aa92a..87c6614 100644 ---- a/toolchain/cc_toolchain_config.bzl -+++ b/toolchain/cc_toolchain_config.bzl +--- toolchain/cc_toolchain_config.bzl ++++ toolchain/cc_toolchain_config.bzl @@ -112,8 +112,6 @@ def cc_toolchain_config( "-fdebug-prefix-map={}=__bazel_toolchain_llvm_repo__/".format(toolchain_path_prefix), ] diff --git a/tools/release/fetch.bzl b/tools/release/fetch.bzl index 787dcef1..f8ee1b87 100644 --- a/tools/release/fetch.bzl +++ b/tools/release/fetch.bzl @@ -2,37 +2,11 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -_SYSROOT_LINUX_BUILD_FILE = """ -filegroup( - name = "sysroot", - srcs = glob(["*/**"]), - visibility = ["//visibility:public"], -) -""" - -_SYSROOT_DARWIN_BUILD_FILE = """ -filegroup( - name = "sysroot", - srcs = glob( - include = ["**"], - exclude = ["**/*:*"], - ), - visibility = ["//visibility:public"], -) -""" -def fetch_deps(): +def _release_tools_impl(module_ctx): """Fetch dependencies only needed for release builds used for the legacy WORKSPACE support.""" - http_archive( - name = "toolchains_llvm", - sha256 = "b7cd301ef7b0ece28d20d3e778697a5e3b81828393150bed04838c0c52963a01", - strip_prefix = "toolchains_llvm-0.10.3", - canonical_id = "0.10.3", - url = "https://github.com/grailbio/bazel-toolchain/releases/download/0.10.3/toolchains_llvm-0.10.3.tar.gz", - patches = ["//third_party/com.github/bazel-contrib/toolchains_llvm:clang_ldd.patch"], - patch_args = ["-p1"], - ) + # FIXME: Replace this with the BCR release http_archive( name = "org_chromium_sysroot_linux_arm64", build_file_content = _SYSROOT_LINUX_BUILD_FILE, @@ -60,3 +34,7 @@ def fetch_deps(): strip_prefix = "sdk-macos-11.3-ccbaae84cc39469a6792108b24480a4806e09d59/root", urls = ["https://github.com/hexops-graveyard/sdk-macos-11.3/archive/ccbaae84cc39469a6792108b24480a4806e09d59.tar.gz"], ) + +release_tools = module_extension( + implementation = _release_tools_impl, +) From 671b3d9346dd89a483986c2294d345a6df8cf7d6 Mon Sep 17 00:00:00 2001 From: "Reid D. McKenzie" Date: Fri, 20 Jun 2025 18:55:45 -0600 Subject: [PATCH 10/12] [NO TESTS] WIP --- MODULE.bazel | 46 +++++++++++++++++++++++++---------------- tools/release/fetch.bzl | 3 +-- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index a7b4d4d5..6cb4c450 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -14,21 +14,24 @@ module( # py_image_layer needs repo_mapping fix. bazel_dep(name = "aspect_bazel_lib", version = "2.16.0") bazel_dep(name = "bazel_skylib", version = "1.4.2") + bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.5.0", dev_dependency = True) -bazel_dep(name = "gazelle", version = "0.31.0", repo_name = "bazel_gazelle", dev_dependency = True) +bazel_dep(name = "gazelle", version = "0.31.0", dev_dependency = True, repo_name = "bazel_gazelle") + bazel_dep(name = "platforms", version = "0.0.7") bazel_dep(name = "rules_python", version = "1.0.0") + bazel_dep(name = "rules_python_gazelle_plugin", version = "1.0.0", dev_dependency = True) bazel_dep(name = "toolchains_musl", version = "0.1.20", dev_dependency = True) bazel_dep(name = "toolchains_llvm", version = "1.4.0", dev_dependency = True) single_version_override( module_name = "rules_python", - version="1.0.0", - patches=[ - "//third_party/com.github/bazel-contrib/rules_python:dev_pip.patch" + patch_strip = 0, + patches = [ + "//third_party/com.github/bazel-contrib/rules_python:dev_pip.patch", ], - patch_strip=0, + version = "1.0.0", ) # single_version_override( @@ -57,14 +60,12 @@ pip.parse( python_version = "3.11", requirements_lock = "//:requirements.txt", ) - pip.parse( hub_name = "django", python_version = "3.11", requirements_lock = "//py/tests/virtual/django:requirements.txt", ) - -use_repo(pip, "pypi", "pypi_311_pytest", "django") +use_repo(pip, "django", "pypi", "pypi_311_pytest") tools = use_extension("//py:extensions.bzl", "py_tools") tools.rules_py_tools() @@ -86,15 +87,18 @@ register_toolchains( # along with our releases. release_tools = use_extension("//tools/release:fetch.bzl", "release_tools", dev_dependency = True) -use_repo(release_tools, - "org_chromium_sysroot_linux_arm64", - "org_chromium_sysroot_linux_x86_64", - "musl_toolchains", - "sysroot_darwin_universal", +use_repo( + release_tools, + "musl_toolchains", + "org_chromium_sysroot_linux_arm64", + "org_chromium_sysroot_linux_x86_64", + "sysroot_darwin_universal", ) llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm") -inject_repo(llvm, + +inject_repo( + llvm, org_chromium_sysroot_linux_arm64 = "org_chromium_sysroot_linux_arm64", org_chromium_sysroot_linux_x86_64 = "org_chromium_sysroot_linux_x86_64", sysroot_darwin_universal = "sysroot_darwin_universal", @@ -105,6 +109,7 @@ llvm.toolchain( llvm_version = "17.0.2", ) use_repo(llvm, "llvm_toolchain", "llvm_toolchain_llvm") + register_toolchains("@llvm_toolchain//:all") llvm.toolchain( @@ -121,6 +126,7 @@ llvm.sysroot( targets = ["linux-x86_64"], ) use_repo(llvm, "llvm_toolchain_linux_x86_64") + register_toolchains("@llvm_toolchain_linux_x86_64//:all") llvm.toolchain( @@ -137,6 +143,7 @@ llvm.sysroot( targets = ["linux-aarch64"], ) use_repo(llvm, "llvm_toolchain_linux_aarch64") + register_toolchains("@llvm_toolchain_linux_aarch64//:all") llvm.toolchain( @@ -153,6 +160,7 @@ llvm.sysroot( targets = ["darwin-x86_64"], ) use_repo(llvm, "llvm_toolchain_darwin_x86_64") + register_toolchains("@llvm_toolchain_darwin_x86_64//:all") llvm.toolchain( @@ -169,6 +177,7 @@ llvm.sysroot( targets = ["darwin-aarch64"], ) use_repo(llvm, "llvm_toolchain_darwin_aarch64") + register_toolchains("@llvm_toolchain_darwin_aarch64//:all") bazel_dep( @@ -184,13 +193,13 @@ rust = use_extension( ) rust.toolchain( edition = "2021", - versions = ["1.81.0"], extra_target_triples = [ "aarch64-apple-darwin", "aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu", - ] + ], + versions = ["1.81.0"], ) use_repo(rust, "rust_toolchains") @@ -243,9 +252,10 @@ oci.pull( use_repo(oci, "ubuntu", "ubuntu_linux_amd64", "ubuntu_linux_arm64_v8") http_file = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file") + http_file( name = "django_4_2_4", - urls = ["https://files.pythonhosted.org/packages/7f/9e/fc6bab255ae10bc57fa2f65646eace3d5405fbb7f5678b90140052d1db0f/Django-4.2.4-py3-none-any.whl"], - sha256 = "860ae6a138a238fc4f22c99b52f3ead982bb4b1aad8c0122bcd8c8a3a02e409d", downloaded_file_path = "Django-4.2.4-py3-none-any.whl", + sha256 = "860ae6a138a238fc4f22c99b52f3ead982bb4b1aad8c0122bcd8c8a3a02e409d", + urls = ["https://files.pythonhosted.org/packages/7f/9e/fc6bab255ae10bc57fa2f65646eace3d5405fbb7f5678b90140052d1db0f/Django-4.2.4-py3-none-any.whl"], ) diff --git a/tools/release/fetch.bzl b/tools/release/fetch.bzl index f8ee1b87..e70c085b 100644 --- a/tools/release/fetch.bzl +++ b/tools/release/fetch.bzl @@ -2,8 +2,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -def _release_tools_impl(module_ctx): +def _release_tools_impl(_module_ctx): """Fetch dependencies only needed for release builds used for the legacy WORKSPACE support.""" # FIXME: Replace this with the BCR release From ab376299b775621e679519470c9364934bea1f84 Mon Sep 17 00:00:00 2001 From: "Reid D. McKenzie" Date: Fri, 20 Jun 2025 20:09:26 -0600 Subject: [PATCH 11/12] [NO TESTS] WIP --- .bazelrc | 5 +++++ MODULE.bazel | 13 +++++-------- tools/release/fetch.bzl | 25 ++++++++++++++++++++++--- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/.bazelrc b/.bazelrc index 1f0fc596..cf9c54fe 100644 --- a/.bazelrc +++ b/.bazelrc @@ -12,8 +12,13 @@ build --define=SOME_VAR=SOME_VALUE common --features=-libtool common --incompatible_enable_cc_toolchain_resolution + +# Use prebuilt protoc +common --incompatible_enable_proto_toolchain_resolution common --per_file_copt=external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT common --host_per_file_copt=external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT +common --per_file_copt=external/.*grpc.*@--GRPC_WAS_NOT_SUPPOSED_TO_BE_BUILT +common --host_per_file_copt=external/.*grpc.*@--GRPC_WAS_NOT_SUPPOSED_TO_BE_BUILT # Use local rules_python # Enable with --config=dev diff --git a/MODULE.bazel b/MODULE.bazel index 6cb4c450..82a12e5d 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -24,6 +24,7 @@ bazel_dep(name = "rules_python", version = "1.0.0") bazel_dep(name = "rules_python_gazelle_plugin", version = "1.0.0", dev_dependency = True) bazel_dep(name = "toolchains_musl", version = "0.1.20", dev_dependency = True) bazel_dep(name = "toolchains_llvm", version = "1.4.0", dev_dependency = True) +bazel_dep(name = "toolchains_protoc", version = "0.4.3", dev_dependency = True) single_version_override( module_name = "rules_python", @@ -34,19 +35,15 @@ single_version_override( version = "1.0.0", ) -# single_version_override( -# module_name = "toolchains_llvm", -# version = "0.10.3", -# patches = [ -# "//third_party/com.github/bazel-contrib/toolchains_llvm:clang_ldd.patch", -# ], -# ) - bazel_lib = use_extension("@aspect_bazel_lib//lib:extensions.bzl", "toolchains") bazel_lib.expand_template() bazel_lib.tar() use_repo(bazel_lib, "bsd_tar_toolchains") +protoc = use_extension("@toolchains_protoc//protoc:extensions.bzl", "protoc") +use_repo(protoc, "toolchains_protoc_hub") +register_toolchains("@toolchains_protoc_hub//:all") + # Custom python version for testing only python = use_extension("@rules_python//python/extensions:python.bzl", "python", dev_dependency = True) python.toolchain( diff --git a/tools/release/fetch.bzl b/tools/release/fetch.bzl index e70c085b..3461e1b8 100644 --- a/tools/release/fetch.bzl +++ b/tools/release/fetch.bzl @@ -2,20 +2,39 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +SYSROOT_LINUX_BUILD_FILE = """ +filegroup( + name = "sysroot", + srcs = glob(["*/**"]), + visibility = ["//visibility:public"], +) +""" + +SYSROOT_DARWIN_BUILD_FILE = """ +filegroup( + name = "sysroot", + srcs = glob( + include = ["**"], + exclude = ["**/*:*"], + ), + visibility = ["//visibility:public"], +) +""" + def _release_tools_impl(_module_ctx): """Fetch dependencies only needed for release builds used for the legacy WORKSPACE support.""" # FIXME: Replace this with the BCR release http_archive( name = "org_chromium_sysroot_linux_arm64", - build_file_content = _SYSROOT_LINUX_BUILD_FILE, + build_file_content = SYSROOT_LINUX_BUILD_FILE, sha256 = "b199942a0bd9c34800e8d7b669778ef45f2054b9f106039439383dd66efcef31", urls = ["https://github.com/DavidZbarsky-at/sysroot-min/releases/download/v0.0.20/debian_bullseye_arm64_sysroot.tar.xz"], ) http_archive( name = "org_chromium_sysroot_linux_x86_64", - build_file_content = _SYSROOT_LINUX_BUILD_FILE, + build_file_content = SYSROOT_LINUX_BUILD_FILE, sha256 = "b279dd2926e7d3860bb4e134997a45df5106f680e160a959b945580ba4ec755f", urls = ["https://github.com/DavidZbarsky-at/sysroot-min/releases/download/v0.0.20/debian_bullseye_amd64_sysroot.tar.xz"], ) @@ -28,7 +47,7 @@ def _release_tools_impl(_module_ctx): http_archive( name = "sysroot_darwin_universal", - build_file_content = _SYSROOT_DARWIN_BUILD_FILE, + build_file_content = SYSROOT_DARWIN_BUILD_FILE, sha256 = "11870a4a3d382b78349861081264921bb883440a7e0b3dd4a007373d87324a38", strip_prefix = "sdk-macos-11.3-ccbaae84cc39469a6792108b24480a4806e09d59/root", urls = ["https://github.com/hexops-graveyard/sdk-macos-11.3/archive/ccbaae84cc39469a6792108b24480a4806e09d59.tar.gz"], From 9b3019af00863842e07eeee60d25fef97e9867ff Mon Sep 17 00:00:00 2001 From: "Reid D. McKenzie" Date: Fri, 20 Jun 2025 20:11:21 -0600 Subject: [PATCH 12/12] [NO TESTS] WIP --- MODULE.bazel | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 82a12e5d..d01c9ac7 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -26,6 +26,10 @@ bazel_dep(name = "toolchains_musl", version = "0.1.20", dev_dependency = True) bazel_dep(name = "toolchains_llvm", version = "1.4.0", dev_dependency = True) bazel_dep(name = "toolchains_protoc", version = "0.4.3", dev_dependency = True) +protoc = use_extension("@toolchains_protoc//protoc:extensions.bzl", "protoc") +use_repo(protoc, "toolchains_protoc_hub") +register_toolchains("@toolchains_protoc_hub//:all") + single_version_override( module_name = "rules_python", patch_strip = 0, @@ -40,10 +44,6 @@ bazel_lib.expand_template() bazel_lib.tar() use_repo(bazel_lib, "bsd_tar_toolchains") -protoc = use_extension("@toolchains_protoc//protoc:extensions.bzl", "protoc") -use_repo(protoc, "toolchains_protoc_hub") -register_toolchains("@toolchains_protoc_hub//:all") - # Custom python version for testing only python = use_extension("@rules_python//python/extensions:python.bzl", "python", dev_dependency = True) python.toolchain(