Skip to content

Commit

Permalink
Upgrade to rules_python 1.1.0-rc0
Browse files Browse the repository at this point in the history
  • Loading branch information
jsharpe committed Jan 10, 2025
1 parent 7273e20 commit 1d60ec3
Show file tree
Hide file tree
Showing 20 changed files with 102 additions and 41 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
13 changes: 5 additions & 8 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ 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")

# Dev dependencies
Expand All @@ -18,13 +19,9 @@ bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.5.0", dev_dependenc
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 +43,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
3 changes: 2 additions & 1 deletion 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
11 changes: 6 additions & 5 deletions foreign_cc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ bzl_library(
"//foreign_cc/private:framework",
"//foreign_cc/private:transitions",
"//toolchains/native_tools:tool_access",
"@rules_cc//cc:bzl_srcs",
],
)

Expand Down Expand Up @@ -123,14 +124,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
1 change: 1 addition & 0 deletions foreign_cc/meson.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""A rule for building projects using the [Meson](https://mesonbuild.com/) build system"""

load("@rules_cc//cc:defs.bzl", "CcInfo")
load("//foreign_cc:utils.bzl", "full_label")
load("//foreign_cc/built_tools:meson_build.bzl", "meson_tool")
load(
Expand Down
1 change: 1 addition & 0 deletions foreign_cc/ninja.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""A rule for building projects using the [Ninja](https://ninja-build.org/) build tool"""

load("@rules_cc//cc:defs.bzl", "CcInfo")
load(
"//foreign_cc/private:detect_root.bzl",
"detect_root",
Expand Down
7 changes: 7 additions & 0 deletions foreign_cc/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ bzl_library(
],
)

bzl_library(
name = "detect_xcompile",
srcs = ["detect_xcompile.bzl"],
visibility = ["//foreign_cc:__subpackages__"],
deps = ["//foreign_cc/private/framework:platform"],
)

bzl_library(
name = "run_shell_file_utils",
srcs = ["run_shell_file_utils.bzl"],
Expand Down
1 change: 1 addition & 0 deletions foreign_cc/private/cc_toolchain_util.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
load("@bazel_skylib//lib:collections.bzl", "collections")
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load("@rules_cc//cc:defs.bzl", "CcInfo", "cc_common")

LibrariesToLinkInfo = provider(
doc = "Libraries to be wrapped into CcLinkingInfo",
Expand Down
1 change: 1 addition & 0 deletions foreign_cc/private/framework.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ load("@bazel_features//:features.bzl", "bazel_features")
load("@bazel_skylib//lib:collections.bzl", "collections")
load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load("@rules_cc//cc:defs.bzl", "CcInfo", "cc_common")
load("//foreign_cc:providers.bzl", "ForeignCcArtifactInfo", "ForeignCcDepsInfo")
load("//foreign_cc/private:detect_root.bzl", "filter_containing_dirs_from_inputs")
load(
Expand Down
1 change: 1 addition & 0 deletions foreign_cc/private/transitions.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""This file contains rules for configuration transitions"""

load("@rules_cc//cc:defs.bzl", "CcInfo")
load("//foreign_cc:providers.bzl", "ForeignCcDepsInfo")

def _extra_toolchains_transition_impl(settings, attrs):
Expand Down
20 changes: 14 additions & 6 deletions foreign_cc/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,27 @@ def rules_foreign_cc_dependencies(
maybe(
http_archive,
name = "bazel_skylib",
sha256 = "bc283cdfcd526a52c3201279cda4bc298652efa898b10b4db0837dc51652756f",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.2.1/bazel-skylib-1.2.1.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.2.1/bazel-skylib-1.2.1.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz",
],
sha256 = "f7be3474d42aae265405a592bb7da8e171919d74c16f082a5457840f06054728",
)

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

maybe(
http_archive,
name = "rules_python",
sha256 = "84aec9e21cc56fbc7f1335035a71c850d1b9b5cc6ff497306f84cced9a769841",
strip_prefix = "rules_python-0.23.1",
url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/0.23.1.tar.gz",
sha256 = "0a158f883fc494724f25e2ce6a5c3d31fd52163a92d4b7180aef0ff9a0622f70",
strip_prefix = "rules_python-1.1.0-rc0",
url = "https://github.com/bazelbuild/rules_python/releases/download/1.1.0-rc0/rules_python-1.1.0-rc0.tar.gz",
)

maybe(
Expand Down
13 changes: 13 additions & 0 deletions test/standard_cxx_flags_test/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_depende

rules_foreign_cc_dependencies()

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

py_repositories()

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

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

protobuf_deps()

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

http_archive(
Expand Down

0 comments on commit 1d60ec3

Please sign in to comment.