Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/forked_pr_workflow_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
name: Check PR source
runs-on: ubuntu-latest
steps:
- run: >
${{ github.event.pull_request.head.repo.full_name == 'protocolbuffers/protobuf' }} ||
(echo "This pull request is from an unsafe fork (${{ github.event.pull_request.head.repo.full_name }}) and isn't allowed to modify workflow files!" && exit 1)
- run: echo "true"
# - run: >
# ${{ github.event.pull_request.head.repo.full_name == 'protocolbuffers/protobuf' }} ||
# (echo "This pull request is from an unsafe fork (${{ github.event.pull_request.head.repo.full_name }}) and isn't allowed to modify workflow files!" && exit 1)
16 changes: 13 additions & 3 deletions .github/workflows/test_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
- version: "3.13"
continuous-only: true
- version: "3.14"
kokoro_python_version: "3.14.4"
- type: C++
version: aarch64
targets: //python/... //python:aarch64_test
Expand All @@ -57,17 +58,24 @@
steps:
- name: Checkout pending changes
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
uses: protocolbuffers/protobuf-ci/checkout@v6

Check failure on line 61 in .github/workflows/test_python.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

zizmor/unpinned-uses

unpinned action reference: action is not pinned to a hash (required by blanket policy)

Check failure on line 61 in .github/workflows/test_python.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

unpinned-uses

test_python.yml:61: unpinned action reference: action is not pinned to a hash (required by blanket policy)
with:
ref: ${{ inputs.safe-checkout }}
- name: Run tests
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
uses: protocolbuffers/protobuf-ci/bazel-docker@v6

Check failure on line 66 in .github/workflows/test_python.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

zizmor/unpinned-uses

unpinned action reference: action is not pinned to a hash (required by blanket policy)

Check failure on line 66 in .github/workflows/test_python.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

unpinned-uses

test_python.yml:66: unpinned action reference: action is not pinned to a hash (required by blanket policy)
env:
KOKORO_PYTHON_VERSION: ${{ matrix.kokoro_python_version }}
with:
image: ${{ matrix.image || format('us-docker.pkg.dev/protobuf-build/containers/test/linux/python:9.2.0-{0}-5bb1a8fdfc30f8c21c1b38cf053d2db9fca865a7 ', matrix.version) }}
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: python_linux/${{ matrix.type }}_${{ matrix.version }}
bazel: test ${{ matrix.targets }} ${{ matrix.flags }} ${{ matrix.nobzlmod && '--noenable_bzlmod' || '' }} --test_env=KOKORO_PYTHON_VERSION
bazel: >-
test ${{ matrix.targets }} ${{ matrix.flags }}
${{ matrix.nobzlmod && '--noenable_bzlmod' || '' }}
${{ matrix.version != 'aarch64' && '--//python:use_hermetic_python=true' || '' }}
${{ matrix.version != 'aarch64' && format('--@rules_python//python/config_settings:python_version={0}', matrix.version) || '' }}
--test_env=KOKORO_PYTHON_VERSION=${{ matrix.kokoro_python_version }}


macos:
Expand All @@ -91,7 +99,7 @@
runs-on: macos-14
steps:
- name: Checkout pending changes
uses: protocolbuffers/protobuf-ci/checkout@v6
uses: protocolbuffers/protobuf-ci/checkout@v5

Check failure on line 102 in .github/workflows/test_python.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

zizmor/unpinned-uses

unpinned action reference: action is not pinned to a hash (required by blanket policy)

Check failure on line 102 in .github/workflows/test_python.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

unpinned-uses

test_python.yml:102: unpinned action reference: action is not pinned to a hash (required by blanket policy)
with:
ref: ${{ inputs.safe-checkout }}

Expand All @@ -111,7 +119,7 @@
source venv/bin/activate

- name: Run tests
uses: protocolbuffers/protobuf-ci/bazel@v6
uses: protocolbuffers/protobuf-ci/bazel@v5

Check failure on line 122 in .github/workflows/test_python.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

zizmor/unpinned-uses

unpinned action reference: action is not pinned to a hash (required by blanket policy)

Check failure on line 122 in .github/workflows/test_python.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

unpinned-uses

test_python.yml:122: unpinned action reference: action is not pinned to a hash (required by blanket policy)
env:
KOKORO_PYTHON_VERSION: ${{ matrix.version }}
with:
Expand All @@ -120,5 +128,7 @@
bazel-cache: python_macos/${{ matrix.type }}_${{ matrix.version }}
bazel: >-
test ${{ matrix.targets }} ${{ matrix.flags }}
--//python:use_hermetic_python=true
--@rules_python//python/config_settings:python_version=${{ matrix.version }}
--test_env=KOKORO_PYTHON_VERSION=${{ matrix.version }}
--macos_minimum_os=12.0
19 changes: 19 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ bazel_dep(name = "rules_kotlin", version = "2.3.20")
bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "rules_pkg", version = "1.0.1")
bazel_dep(name = "rules_python", version = "2.3.0")
git_override(
module_name = "rules_python",
commit = "84874d514e343a32ce1c611165b1f26952dedd79",
remote = "https://github.com/rsartor-cmd/rules_python.git",
)

bazel_dep(name = "rules_rust", version = "0.69.0")

bazel_dep(name = "rules_ruby", version = "0.20.1", dev_dependency = True)
Expand Down Expand Up @@ -174,13 +180,26 @@ local_runtime_toolchains_repo(
name = "local_toolchains",
dev_dependency = True,
runtimes = ["local_python3"],
target_settings = {
"local_python3": ["@//python:is_system_python"],
},
)

register_toolchains(
"@local_toolchains//:all",
dev_dependency = True,
)

python = use_extension("@rules_python//python/extensions:python.bzl", "python", dev_dependency = True)

[
python.toolchain(
is_default = (python_version == "3.10"),
python_version = python_version,
)
for python_version in SUPPORTED_PYTHON_VERSIONS
]

rust = use_extension("@rules_rust//rust:extensions.bzl", "rust", dev_dependency = True)

# As of October 2025, our minimum supported Rust version is 1.79. However, we
Expand Down
2 changes: 1 addition & 1 deletion conformance/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,8 @@ py_binary(
"//conformance/test_protos:test_messages_edition_unstable_py_pb2",
"//editions:test_messages_proto2_editions_py_pb2",
"//editions:test_messages_proto3_editions_py_pb2",
"//python:_message", # Make upb visible if we need it.
"//python:conformance_test_py_proto",
"//python:google/_upb/_message", # Make upb visible if we need it.
],
)

Expand Down
5 changes: 5 additions & 0 deletions examples/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ bazel_dep(name = "rules_cc", version = "0.2.18")
bazel_dep(name = "rules_java", version = "8.6.1")
bazel_dep(name = "rules_pkg", version = "1.0.1")
bazel_dep(name = "rules_python", version = "2.3.0")
git_override(
module_name = "rules_python",
commit = "84874d514e343a32ce1c611165b1f26952dedd79",
remote = "https://github.com/rsartor-cmd/rules_python.git",
)
28 changes: 26 additions & 2 deletions python/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
# https://developers.google.com/open-source/licenses/bsd

load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag")
load("@rules_python//python/cc:py_extension.bzl", "py_extension")
load("//python:build_targets.bzl", "build_targets")
load("//python:py_extension.bzl", "py_extension")
load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS", "UPB_DEFAULT_FEATURES")

build_targets(name = "python")
Expand Down Expand Up @@ -40,6 +40,26 @@ string_flag(
],
)

bool_flag(
name = "use_hermetic_python",
build_setting_default = False,
)

config_setting(
name = "is_hermetic_python",
flag_values = {":use_hermetic_python": "true"},
visibility = ["//visibility:public"],
)

config_setting(
name = "is_system_python",
flag_values = {
":python_version": "system",
":use_hermetic_python": "false",
},
visibility = ["//visibility:public"],
)

config_setting(
name = "limited_api_3.10",
flag_values = {
Expand Down Expand Up @@ -108,11 +128,15 @@ filegroup(
)

py_extension(
name = "_message",
name = "google/_upb/_message",
srcs = [":message_srcs"],
copts = UPB_DEFAULT_COPTS + select(LIMITED_API_FLAG_SELECT),
features = UPB_DEFAULT_FEATURES,
target_compatible_with = select(_message_target_compatible_with),
visibility = [
":__subpackages__",
"//conformance:__pkg__",
],
deps = [
":breaking_changes",
"//src/google/protobuf:descriptor_upb_minitable_proto",
Expand Down
2 changes: 1 addition & 1 deletion python/dist/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ licenses(["notice"])

py_dist_module(
name = "message_mod",
extension = "//python:_message_binary",
extension = "//python:google/_upb/_message",
module_name = "google._upb._message",
)

Expand Down
2 changes: 1 addition & 1 deletion python/dist/dist.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def _declare_module_file(ctx, module_name, python_version, limited_api):
#
# py_dist_module(
# name = "message_mod",
# extension = "//python:_message_binary",
# extension = "//python:google/_upb/_message",
# module_name = "google._upb._message",
# )
#
Expand Down
1 change: 1 addition & 0 deletions python/py_extension.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ load("@bazel_skylib//lib:selects.bzl", "selects")
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
load("@rules_python//python:py_library.bzl", "py_library")

# TODO: Remove this file once _message has successfully switched to OSS rules_python's py_extension.
def py_extension(name, srcs, copts, deps = [], **kwargs):
"""Creates a C++ library to extend python

Expand Down
51 changes: 50 additions & 1 deletion toolchain/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ load(
"flag_group",
"flag_set",
"tool_path",
"variable_with_value",
"with_feature_set",
)
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
Expand Down Expand Up @@ -176,10 +177,51 @@ def _impl(ctx):
],
)

archiver_flags = feature(
name = "archiver_flags",
enabled = True,
flag_sets = [
flag_set(
actions = [ACTION_NAMES.cpp_link_static_library],
flag_groups = [
flag_group(
flags = ["rcsD"],
),
flag_group(
expand_if_available = "output_execpath",
flags = ["%{output_execpath}"],
),
flag_group(
expand_if_available = "libraries_to_link",
iterate_over = "libraries_to_link",
flag_groups = [
flag_group(
expand_if_equal = variable_with_value(
"libraries_to_link.type",
"object_file",
),
flags = ["%{libraries_to_link.name}"],
),
flag_group(
expand_if_equal = variable_with_value(
"libraries_to_link.type",
"object_file_group",
),
iterate_over = "libraries_to_link.object_files",
flags = ["%{libraries_to_link.object_files}"],
),
],
),
],
),
],
)

features = [
linker_flags,
compiler_flags,
sysroot_flags,
archiver_flags,
feature(name = "dbg"),
feature(name = "opt"),
]
Expand All @@ -199,6 +241,13 @@ def _impl(ctx):
),
)

if "apple" in ctx.attr.target_full_name or "osx" in ctx.attr.target_full_name or "darwin" in ctx.attr.target_full_name:
target_libc = "macosx"
elif "mingw" in ctx.attr.target_full_name:
target_libc = "mingw"
else:
target_libc = ctx.attr.target_cpu

return cc_common.create_cc_toolchain_config_info(
abi_libc_version = ctx.attr.abi_version,
abi_version = ctx.attr.abi_version,
Expand All @@ -214,7 +263,7 @@ def _impl(ctx):
features = features,
host_system_name = "local",
target_cpu = ctx.attr.target_cpu,
target_libc = ctx.attr.target_cpu,
target_libc = target_libc,
target_system_name = ctx.attr.target_full_name,
toolchain_identifier = ctx.attr.target_full_name,
tool_paths = tool_paths,
Expand Down
25 changes: 25 additions & 0 deletions upb/bazel/private/upb_proto_library_internal/rule.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""Internal rule implementation for upb_*_proto_library() rules."""

load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")

def _filter_none(elems):
out = []
for elem in elems:
Expand Down Expand Up @@ -32,6 +35,28 @@ def upb_proto_rule_impl(ctx, cc_info_provider, srcs_provider):
lib.pic_static_library,
lib.dynamic_library,
])

linker_inputs = []
dep_prefix = dep.label.name + "."
for input in cc_info.linking_context.linker_inputs.to_list():
if input.owner == dep.label or (input.owner.package == dep.label.package and input.owner.name.startswith(dep_prefix)):
linker_inputs.append(cc_common.create_linker_input(
owner = ctx.label,
libraries = depset(input.libraries),
user_link_flags = depset(input.user_link_flags),
additional_inputs = depset(input.additional_inputs),
))
else:
linker_inputs.append(input)

linking_context = cc_common.create_linking_context(
linker_inputs = depset(linker_inputs, order = "topological"),
)
cc_info = CcInfo(
compilation_context = cc_info.compilation_context,
linking_context = linking_context,
)

return [
DefaultInfo(files = depset(files + srcs.hdrs + srcs.srcs)),
srcs,
Expand Down
12 changes: 2 additions & 10 deletions upb/bazel/upb_minitable_proto_library.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""upb_minitable_proto_library() exposes upb's generated minitables (foo.upb_minitable.h)"""

load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
load("//bazel/common:proto_info.bzl", "ProtoInfo")
load("//upb/bazel:visibility.bzl", "upb_clients")
Expand Down Expand Up @@ -28,22 +27,15 @@ def _upb_minitable_proto_library_aspect_impl(target, ctx):
cc_provider = UpbMinitableCcInfo,
dep_cc_provider = None,
file_provider = _UpbWrappedGeneratedSrcsInfo,
provide_cc_shared_library_hints = False,
)

def _get_upb_minitable_proto_library_aspect_provides():
provides = [
return [
UpbMinitableCcInfo,
_UpbWrappedGeneratedSrcsInfo,
]

if hasattr(cc_common, "CcSharedLibraryHintInfo"):
provides.append(cc_common.CcSharedLibraryHintInfo)
elif hasattr(cc_common, "CcSharedLibraryHintInfo_6_X_getter_do_not_use"):
# This branch can be deleted once 6.X is not supported by upb rules
provides.append(cc_common.CcSharedLibraryHintInfo_6_X_getter_do_not_use)

return provides

upb_minitable_proto_library_aspect = aspect(
attrs = {
"_copts": attr.label(
Expand Down
Loading