Skip to content

Refactor: Consolidate Go packages for standard toolchain compatibility #210

Open
wlanmac wants to merge 10 commits intoopenconfig:mainfrom
wlanmac:reorganize-for-go
Open

Refactor: Consolidate Go packages for standard toolchain compatibility #210
wlanmac wants to merge 10 commits intoopenconfig:mainfrom
wlanmac:reorganize-for-go

Conversation

@wlanmac
Copy link
Copy Markdown

@wlanmac wlanmac commented Mar 10, 2026

Problem
The previous project structure utilized a Bazel-centric layout for Protobuf generation. While this worked within a Bazel workspace, it created significant friction for standard Go
developers:

  1. Package Collisions: Multiple subdirectories (e.g., proto/common_definitions and proto/tpm_enrollz) generated code using the same Go package name (attestz). This caused
    "redeclaration" errors in standard Go builds unless complex aliasing was used.
  2. Import Friction: Standard Go tools (IDE autocomplete, go build, go get) could not resolve the types correctly because the directory structure did not align with Go's package
    expectations.
  3. Toolchain Locking: Non-Bazel users were forced to manually manage protoc and plugins just to consume the library.

Solution
This PR reorganizes the repository to follow idiomatic Go standards while maintaining 100% compatibility with existing Bazel/Blaze workflows:

  • Consolidated Proto Package: All generated Go code from .proto files now resides in the proto/ directory under a single package: github.com/openconfig/attestz/proto/attestz.
  • Symmetrical Build Support:
    • Go Users: Pre-generated .pb.go files are checked in, allowing for zero-setup go get usage.
    • Bazel Users: Updated BUILD.bazel rules ensure that Bazel continues to manage dependencies and auto-generate code transparently.
  • Improved Documentation: Added a "Go Module Usage" section to the README with clear examples for both proto and business logic imports.

Technical Impact

  • Interoperability: These changes are wire-compatible. The underlying protobuf package (openconfig.attestz) remains unchanged, ensuring that new clients can communicate with existing
    servers.
  • Source Compatibility: This is a source-breaking change for Go developers. Users will need to update their imports to the unified proto package (e.g., replacing epb and cpb aliases
    with a single apb import).
  • Maintenance: Updated regenerate-files.sh to work with the consolidated structure.

@wlanmac wlanmac requested review from a team, betuls, marcushines and morrowc as code owners March 10, 2026 16:33
@bstoll
Copy link
Copy Markdown
Contributor

bstoll commented Mar 10, 2026

I generally like this change because it aligns closer with how we have organized protobufs in other OpenConfig projects. I think it is easier for Gazelle and other tooling to autogenerate BUILD files when there is a 1:1 mapping of proto packages to a directory.

I don't know if it is reasonable to change, but I personally prefer the directory structure of proto/attestz/* instead of having all the files in the main proto/* directory. This makes the general project layout a bit cleaner when adding new/multiple incompatible protos and maintaining backwards compatibility - imagine introducing a proto/attestz_v2/, etc.

@MannyCabral MannyCabral self-assigned this Mar 11, 2026
wlanmac added 5 commits March 11, 2026 19:30
Following PR feedback, this commit:
- Moves all .proto and .pb.go files from proto/ to proto/attestz/.
- Updates 'option go_package' in .proto files to github.com/openconfig/attestz/proto/attestz.
- Updates all internal Go imports and Bazel rules to match the new structure.
- Updates documentation and examples in README.md.

This structure provides a cleaner layout for future expansion (e.g., proto/attestz_v2/).
This commit applies the clean, tool-generated Go code produced by the
'regenerate-files.sh' script. These files reflect the new consolidated
package structure and updated Protobuf configurations without any
manual edits.
betuls
betuls previously approved these changes Mar 13, 2026
Copy link
Copy Markdown
Contributor

@betuls betuls left a comment

Choose a reason for hiding this comment

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

Thanks for this cleanup. I agree with colsolidating the proto packages into /proto/attestz.

betuls
betuls previously approved these changes Mar 13, 2026
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.

4 participants