Skip to content

Commit

Permalink
Upgrade rules_python to version 1.1.0-rc0 (#1355)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsharpe authored Jan 10, 2025
1 parent 7273e20 commit 2dd6fe2
Show file tree
Hide file tree
Showing 21 changed files with 153 additions and 58 deletions.
20 changes: 18 additions & 2 deletions .github/workflows/release_prep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ git archive --format=tar --prefix="${PREFIX}"/ "${TAG}" | gzip > "$ARCHIVE"
SHA="$(shasum -a 256 "$ARCHIVE" | awk '{print $1}')"

cat << EOF
## Using Bzlmod with Bazel 6
## Using Bzlmod
1. Enable with \`common --enable_bzlmod\` in \`.bazelrc\`.
2. Add to your \`MODULE.bazel\` file:
Expand All @@ -37,8 +37,24 @@ http_archive(
load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
# This sets up some common toolchains for building targets. For more details, please see
# https://bazelbuild.github.io/rules_foreign_cc/${TAG}/flatten.html#rules_foreign_cc_dependencies
# https://bazel-contrib.github.io/rules_foreign_cc/${TAG}/flatten.html#rules_foreign_cc_dependencies
rules_foreign_cc_dependencies()
# If you're not already using bazel_skylib, bazel_features or rules_python,
# you'll need to add these calls as well.
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
bazel_skylib_workspace()
load("@bazel_features//:deps.bzl", "bazel_features_deps")
bazel_features_deps()
load("@rules_python//python:repositories.bzl", "py_repositories")
py_repositories()
EOF

# TODO: add example of how to configure for bzlmod
Expand Down
20 changes: 10 additions & 10 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ module(
bazel_dep(name = "bazel_features", version = "1.15.0")
bazel_dep(name = "bazel_skylib", version = "1.3.0")
bazel_dep(name = "platforms", version = "0.0.5")
bazel_dep(name = "rules_python", version = "0.23.1")
bazel_dep(name = "rules_cc", version = "0.0.17")
bazel_dep(name = "rules_python", version = "1.1.0-rc0")
bazel_dep(name = "rules_shell", version = "0.3.0")

# This is only here because of the docs generation!
bazel_dep(name = "protobuf", version = "29.3", repo_name = "com_google_protobuf")

# Dev dependencies
bazel_dep(name = "gazelle", version = "0.34.0", dev_dependency = True, repo_name = "bazel_gazelle")
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.5.0", dev_dependency = True)
bazel_dep(name = "gazelle", version = "0.41.0", dev_dependency = True, repo_name = "bazel_gazelle")
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.7.1", dev_dependency = True)
bazel_dep(name = "stardoc", version = "0.5.6", dev_dependency = True, repo_name = "io_bazel_stardoc")
bazel_dep(name = "bazel_ci_rules", version = "1.0.0", dev_dependency = True)

# note that this dev_dependency is only needed because bazel_ci_rules
# depends on it. If you are not using bazel_ci_rules; ideally we'd be able to remove this.
bazel_dep(name = "rules_cc", version = "0.0.9", dev_dependency = True)

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(python_version = "3.9")
use_repo(python, "python_3_9")
python.toolchain(python_version = "3.12")
use_repo(python, "python_3_12")

tools = use_extension("@rules_foreign_cc//foreign_cc:extensions.bzl", "tools")
use_repo(
Expand All @@ -46,6 +46,6 @@ register_toolchains(
"@rules_foreign_cc_framework_toolchains//:all",
"@cmake_3.23.2_toolchains//:all",
"@ninja_1.12.1_toolchains//:all",
"@python_3_9//:all",
"@python_3_12//:all",
"@rules_foreign_cc//toolchains:all",
)
12 changes: 9 additions & 3 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@ load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

load("@rules_python//python:repositories.bzl", "python_register_toolchains")
load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")

py_repositories()

python_register_toolchains(
name = "python3_10",
python_version = "3.10",
name = "python_3_12",
python_version = "3.12",
)

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

load("//:docs/stardoc_repository.bzl", "stardoc_repository")

stardoc_repository()
Expand Down
2 changes: 1 addition & 1 deletion docs/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ bazel_dep(
)
bazel_dep(
name = "rules_python",
version = "1.0.0",
version = "1.1.0-rc0",
)
42 changes: 27 additions & 15 deletions docs/MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ python.toolchain(

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
name = "pip",
hub_name = "pip",
python_version = "3.10",
requirements_lock = "//:requirements_lock.txt",
requirements_windows = "//:requirements_windows.txt",
)
use_repo(pip, "pip")

Expand Down
27 changes: 13 additions & 14 deletions examples/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

maybe(
http_archive,
name = "rules_cc",
sha256 = "4dccbfd22c0def164c8f47458bd50e0c7148f3d92002cdb459c2a96a68498241",
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.1/rules_cc-0.0.1.tar.gz"],
)

load("//deps:repositories.bzl", "repositories")

repositories()
Expand All @@ -35,19 +25,24 @@ load("//deps:deps_jvm_external.bzl", "deps_jvm_external")

deps_jvm_external()

load("@rules_python//python:repositories.bzl", "python_register_toolchains")
load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")

py_repositories()

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

python_register_toolchains(
name = "python3_10",
name = "python_3_10",
python_version = "3.10",
)

load("@python3_10//:defs.bzl", py3_interpreter = "interpreter")
load("@rules_python//python:pip.bzl", "pip_parse")

pip_parse(
name = "pip",
python_interpreter_target = py3_interpreter,
python_interpreter_target = "@python_3_10_host//:python",
requirements_lock = "//:requirements_lock.txt",
)

Expand All @@ -68,6 +63,8 @@ load("@rules_foreign_cc_examples_third_party//:setup.bzl", examples_third_party_

examples_third_party_setup()

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "bazelci_rules",
sha256 = "eca21884e6f66a88c358e580fd67a6b148d30ab57b1680f62a96c00f9bc6a07e",
Expand Down Expand Up @@ -125,6 +122,8 @@ load(

apple_support_dependencies()

load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

maybe(
http_archive,
name = "rules_rust",
Expand Down
31 changes: 26 additions & 5 deletions foreign_cc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ bzl_library(
"//foreign_cc/private:transitions",
"//foreign_cc/private/framework:platform",
"//toolchains/native_tools:tool_access",
"@com_google_protobuf//bazel:cc_proto_library_bzl",
"@rules_cc//cc:bzl_srcs",
"@rules_cc//cc/common",
"@rules_cc//cc/toolchains:toolchain_rules",
],
)

Expand All @@ -41,6 +45,10 @@ bzl_library(
"//foreign_cc/private:framework",
"//foreign_cc/private:transitions",
"//toolchains/native_tools:tool_access",
"@com_google_protobuf//bazel:cc_proto_library_bzl",
"@rules_cc//cc:bzl_srcs",
"@rules_cc//cc/common",
"@rules_cc//cc/toolchains:toolchain_rules",
],
)

Expand Down Expand Up @@ -80,6 +88,10 @@ bzl_library(
"//foreign_cc/private:make_script",
"//foreign_cc/private:transitions",
"//toolchains/native_tools:tool_access",
"@com_google_protobuf//bazel:cc_proto_library_bzl",
"@rules_cc//cc:bzl_srcs",
"@rules_cc//cc/common",
"@rules_cc//cc/toolchains:toolchain_rules",
],
)

Expand All @@ -96,6 +108,11 @@ bzl_library(
"//foreign_cc/private:transitions",
"//toolchains/native_tools:native_tools_toolchain",
"//toolchains/native_tools:tool_access",
"@com_google_protobuf//bazel:cc_proto_library_bzl",
"@rules_cc//cc:bzl_srcs",
"@rules_cc//cc/common",
"@rules_cc//cc/toolchains:toolchain_rules",
"@rules_python//python:features_bzl",
],
)

Expand All @@ -107,6 +124,10 @@ bzl_library(
"//foreign_cc/private:detect_root",
"//foreign_cc/private:framework",
"//toolchains/native_tools:tool_access",
"@com_google_protobuf//bazel:cc_proto_library_bzl",
"@rules_cc//cc:bzl_srcs",
"@rules_cc//cc/common",
"@rules_cc//cc/toolchains:toolchain_rules",
],
)

Expand All @@ -123,14 +144,14 @@ bzl_library(
)

bzl_library(
name = "providers",
srcs = ["providers.bzl"],
name = "utils",
srcs = ["utils.bzl"],
visibility = ["//visibility:public"],
deps = ["@rules_shell//shell:rules_bzl"],
)

bzl_library(
name = "utils",
srcs = ["utils.bzl"],
name = "providers",
srcs = ["providers.bzl"],
visibility = ["//visibility:public"],
deps = ["@rules_shell//shell:rules_bzl"],
)
1 change: 1 addition & 0 deletions foreign_cc/boost_build.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
""" Rule for building Boost from sources. """

load("@rules_cc//cc:defs.bzl", "CcInfo")
load("//foreign_cc/private:detect_root.bzl", "detect_root")
load(
"//foreign_cc/private:framework.bzl",
Expand Down
4 changes: 4 additions & 0 deletions foreign_cc/built_tools/meson_build.bzl
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
""" Rule for building meson from source. """

load("@rules_python//python:defs.bzl", "py_binary")
load("@rules_python//python:features.bzl", "features")

def meson_tool(name, main, data, requirements = [], **kwargs):
kwargs.pop("precompile", None)
if not features.uses_builtin_rules:
kwargs["precompile"] = "disabled"
py_binary(
name = name,
srcs = [main],
Expand Down
1 change: 1 addition & 0 deletions foreign_cc/cmake.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ cmake(
[cct]: https://docs.bazel.build/versions/master/be/c-cpp.html#cc_toolchain
"""

load("@rules_cc//cc:defs.bzl", "CcInfo")
load(
"//foreign_cc/private:cc_toolchain_util.bzl",
"get_flags_info",
Expand Down
1 change: 1 addition & 0 deletions foreign_cc/configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ build tool
"""

load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load("@rules_cc//cc:defs.bzl", "CcInfo")
load(
"//foreign_cc/private:cc_toolchain_util.bzl",
"get_flags_info",
Expand Down
1 change: 1 addition & 0 deletions foreign_cc/make.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""A rule for building projects using the [GNU Make](https://www.gnu.org/software/make/) build tool"""

load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load("@rules_cc//cc:defs.bzl", "CcInfo")
load(
"//foreign_cc/private:cc_toolchain_util.bzl",
"get_flags_info",
Expand Down
Loading

0 comments on commit 2dd6fe2

Please sign in to comment.