Skip to content

[protobuf] Make target libprotoc opt-in for non-native builds#51545

Open
dudantas wants to merge 11 commits intomicrosoft:masterfrom
dudantas:dudantas/protobuf-no-target-libprotoc
Open

[protobuf] Make target libprotoc opt-in for non-native builds#51545
dudantas wants to merge 11 commits intomicrosoft:masterfrom
dudantas:dudantas/protobuf-no-target-libprotoc

Conversation

@dudantas
Copy link
Copy Markdown

@dudantas dudantas commented May 4, 2026

Summary

This PR makes target libprotoc an explicit opt-in feature of the protobuf port.

For non-native builds where TARGET_TRIPLET != HOST_TRIPLET, the port already uses the host protobuf package to provide the protoc build-time executable. In that scenario, this PR stops building/installing target libprotoc and libupb unless the new libprotoc feature is requested.

Native builds keep the existing behavior: when TARGET_TRIPLET == HOST_TRIPLET, protoc and target libprotoc are still built together.

Motivation

Currently, non-native target builds use host protobuf for the protoc executable, but still build and install target libprotoc and libupb.

Many consumers only need the protobuf runtime libraries, such as libprotobuf or libprotobuf-lite, plus the host protoc tool for code generation. They do not need to link target protobuf::libprotoc.

libprotoc is a public library target, so it should be requested explicitly by consumers that need it, rather than modeled as a default feature.

Changes

This PR introduces an opt-in libprotoc feature to the protobuf port.

  • protobuf[core] / default non-native target builds no longer build target libprotoc or target libupb.
  • protobuf[libprotoc] builds target libprotoc and target libupb for non-UWP target builds.
  • Native builds still build protoc and libprotoc because protobuf_BUILD_PROTOC_BINARIES remains enabled when TARGET_TRIPLET == HOST_TRIPLET.
  • Existing registry consumers that link protobuf::libprotoc now request protobuf[libprotoc] explicitly:
    • brpc
    • offscale-libetcd-cpp

Behavior after this change

Scenario Requested feature protoc binary Target libprotoc
TARGET_TRIPLET == HOST_TRIPLET any built built
TARGET_TRIPLET != HOST_TRIPLET none / core provided by host protobuf not built
TARGET_TRIPLET != HOST_TRIPLET libprotoc provided by host protobuf built
UWP any not built not built

Validation

Validated locally with separate install/build/package roots.

Non-native target build without libprotoc

Command shape used:

vcpkg install protobuf[core] ^
  --triplet=x64-windows-static ^
  --host-triplet=x64-windows ^
  --x-install-root=<separate-test-install-root> ^
  --x-buildtrees-root=<separate-test-buildtrees-root> ^
  --x-packages-root=<separate-test-packages-root>

Expected result:

  • target x64-windows-static installs libprotobuf
  • target x64-windows-static installs libprotobuf-lite
  • target x64-windows-static does not install target libprotoc
  • target x64-windows-static does not install target libupb
  • host x64-windows provides protoc.exe

Non-native target build with libprotoc

Command shape used:

vcpkg install protobuf[libprotoc] ^
  --triplet=x64-windows-static ^
  --host-triplet=x64-windows ^
  --x-install-root=<separate-test-install-root> ^
  --x-buildtrees-root=<separate-test-buildtrees-root> ^
  --x-packages-root=<separate-test-packages-root>

Expected result:

  • target x64-windows-static installs libprotobuf
  • target x64-windows-static installs libprotobuf-lite
  • target x64-windows-static installs target libprotoc
  • target x64-windows-static installs target libupb
  • host x64-windows provides protoc.exe

Native build behavior

The change preserves native behavior because protobuf_BUILD_LIBPROTOC remains enabled when protobuf_BUILD_PROTOC_BINARIES is enabled.

Port update checklist

  • Changes comply with the maintainer guide.
  • SHA512s are updated for each updated download, or no downloads were changed.
  • The "supports" clause reflects platforms that may be fixed by this new version, or no changes were necessary.
  • Any fixed CI baseline and CI feature baseline entries are removed from that file, or no entries needed to be changed.
  • All patch files in the port are applied and succeed.
  • The version database is fixed by rerunning ./vcpkg x-add-version protobuf brpc offscale-libetcd-cpp and committing the result.
  • Exactly one version is added in each modified versions file.

Copilot AI review requested due to automatic review settings May 4, 2026 21:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the protobuf port to skip building/installing target libprotoc (and related libupb) when doing non-native builds (TARGET_TRIPLET != HOST_TRIPLET), reusing the existing protobuf_BUILD_PROTOC_BINARIES decision to reduce build time and package size for cross-compilation scenarios.

Changes:

  • Tie protobuf_BUILD_LIBPROTOC to protobuf_BUILD_PROTOC_BINARIES (so it’s disabled for non-native target builds, and still disabled for UWP).
  • Bump the protobuf port-version to 2.
  • Update the versions database and baseline to reflect the new port-version.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
ports/protobuf/portfile.cmake Disables building libprotoc (and libupb) for non-native target builds by reusing protobuf_BUILD_PROTOC_BINARIES.
ports/protobuf/vcpkg.json Bumps port-version to 2.
versions/baseline.json Updates baseline protobuf port-version to 2.
versions/p-/protobuf.json Adds a new entry for protobuf 6.33.4 port-version 2.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ports/protobuf/portfile.cmake Outdated
Add a libprotoc feature to the protobuf port and make it a default feature. Map the feature to protobuf_BUILD_TARGET_LIBPROTOC in portfile.cmake and adjust logic to enable libprotoc when building protoc binaries or when the libprotoc feature is requested; keep it off by default for non-UWP unless enabled. Also update the recorded git-tree for protobuf to the new commit hash.
@dudantas
Copy link
Copy Markdown
Author

dudantas commented May 4, 2026

@microsoft-github-policy-service agree

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ports/protobuf/vcpkg.json Outdated
@dudantas dudantas requested a review from Copilot May 4, 2026 22:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ports/protobuf/vcpkg.json Outdated
Comment thread ports/protobuf/vcpkg.json
Copy link
Copy Markdown
Member

@BillyONeal BillyONeal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Request changes" is for adding the default-feature, the comment is just a nitpick.

Comment thread ports/protobuf/vcpkg.json Outdated
Comment thread ports/protobuf/portfile.cmake Outdated
Comment on lines 26 to 32
if(VCPKG_TARGET_IS_UWP)
set(protobuf_BUILD_LIBPROTOC OFF)
else()
elseif(protobuf_BUILD_PROTOC_BINARIES OR protobuf_BUILD_TARGET_LIBPROTOC)
set(protobuf_BUILD_LIBPROTOC ON)
else()
set(protobuf_BUILD_LIBPROTOC OFF)
endif()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be better as just the expression rather than mixing mutually exclusive if/elseif chains flipping between off and on. Consider:

if(VCPKG_TARGET_IS_UWP OR NOT (protobuf_BUILD_PROTOC_BINARIES OR protobuf_BUILD_TARGET_LIBPROTOC))
    set(protobuf_BUILD_LIBPROTOC OFF)
else()
    set(protobuf_BUILD_LIBPROTOC ON)
endif()

or

set(protobuf_BUILD_LIBPROTOC OFF)
if(NOT VCPKG_TARGET_IS_UWP AND (protobuf_BUILD_PROTOC_BINARIES OR protobuf_BUILD_TARGET_LIBPROTOC))
    set(protobuf_BUILD_LIBPROTOC ON)
endif()

(or possibly even)

set(protobuf_BUILD_LIBPROTOC OFF)
if(NOT VCPKG_TARGET_IS_UWP)
    if(protobuf_BUILD_PROTOC_BINARIES OR protobuf_BUILD_TARGET_LIBPROTOC)
        set(protobuf_BUILD_LIBPROTOC ON)
    endif()
endif()

@BillyONeal BillyONeal marked this pull request as draft May 5, 2026 01:52
Make libprotoc an opt-in feature (non-UWP) and update ports that require it. Changes: protobuf portfile and vcpkg.json now treat libprotoc as a feature that supports !uwp and only builds libprotoc on non-UWP when requested; removed libprotoc from protobuf default-features. brpc and offscale-libetcd-cpp ports now request the protobuf feature libprotoc and have their port-version incremented. Updated corresponding versions entries and baseline to reflect the new port-versions and updated git-tree for protobuf.
@dudantas dudantas force-pushed the dudantas/protobuf-no-target-libprotoc branch from cbd5a41 to b58bc0a Compare May 5, 2026 11:35
@dudantas
Copy link
Copy Markdown
Author

dudantas commented May 5, 2026

"Request changes" is for adding the default-feature, the comment is just a nitpick.

Thanks, @BillyONeal, I've updated.

I removed libprotoc from default-features and kept it as explicit opt-in (protobuf[libprotoc]).
ports/protobuf/portfile.cmake now uses the simplified expression form you suggested.
I also updated the known target-link consumers (brpc, offscale-libetcd-cpp) to explicitly request protobuf[libprotoc], with port-version bumps and version DB updates.
Validation confirms:

  • non-native default protobuf no longer installs target libprotoc;
  • non-native protobuf[libprotoc] does install target libprotoc.

@dudantas dudantas marked this pull request as ready for review May 5, 2026 11:37
Remove libprotoc mapping from vcpkg_check_features and instead explicitly initialize protobuf_BUILD_TARGET_LIBPROTOC to OFF, then set it ON if "libprotoc" is present in the FEATURES list. This ensures the variable is always defined and robustly reflects whether the libprotoc feature was enabled before later logic that may enable building libprotoc.
@dudantas dudantas changed the title [protobuf] Don't build libprotoc for non-native target builds [protobuf] Make target libprotoc opt-in for non-native builds May 5, 2026
Copy link
Copy Markdown
Member

@BillyONeal BillyONeal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dudantas#2 fixes the version database and has 1 nitpick.

@BillyONeal BillyONeal marked this pull request as draft May 5, 2026 22:59
@dudantas
Copy link
Copy Markdown
Author

dudantas commented May 5, 2026

dudantas#2 fixes the version database and has 1 nitpick.

Can you check again, please? I've updated this.

@dudantas dudantas marked this pull request as ready for review May 5, 2026 23:26
Copy link
Copy Markdown
Member

@BillyONeal BillyONeal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@BillyONeal BillyONeal enabled auto-merge (squash) May 5, 2026 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants