Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(build): add build tags and missing flags/variables #2202

Merged
merged 3 commits into from
Feb 13, 2025

Conversation

helder-moreira
Copy link
Contributor

@helder-moreira helder-moreira commented Feb 11, 2025

No description provided.

@helder-moreira helder-moreira self-assigned this Feb 11, 2025
@helder-moreira helder-moreira requested a review from a team as a code owner February 11, 2025 15:02
Copy link
Contributor

coderabbitai bot commented Feb 11, 2025

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This pull request updates the build and release configurations. The changes include adding environment variables and modifying build flags in the .goreleaser.yml file, along with a new changelog entry documenting the update. Adjustments in the Makefiles remove deprecated variables and introduce new ones (e.g., CMT_VERSION, DARWIN_TAGS, and LINUX_TAGS), update linker flags to reference CometBFT and PebbleDB, and refine the build and release commands.

Changes

Files Summary
.goreleaser.yml Added GO111MODULE=on and DEFAULT_DB_BACKEND=pebbledb; updated build flags for Darwin (removed -ldl) and Linux (static linking) with new BuildTags and CMTSemVer values sourced from environment variables.
CHANGELOG.md Added a new changelog entry documenting the build flags and tags update (#2202) as part of a chore in the build process.
contrib/make/build.mk
contrib/make/release.mk
Removed deprecated variables (SDK_PACK, TM_VERSION); added CMT_VERSION; updated linker flags to reference CometBFT and PebbleDB; introduced -trimpath in build.mk; added DARWIN_TAGS and LINUX_TAGS with updated Docker env.

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer
    participant Mk as Makefile
    participant YQ as yq Tool (via Docker)
    participant Docker as Docker Container

    Dev->>Mk: Trigger release/release-snapshot
    Mk->>Mk: Execute shell to get CMT_VERSION
    Mk->>YQ: Extract DARWIN_TAGS & LINUX_TAGS from .goreleaser.yml
    YQ-->>Mk: Return tags values
    Mk->>Docker: Run container with env vars (CMT_VERSION, DARWIN_TAGS, LINUX_TAGS)
    Docker-->>Mk: Build & release artifacts
    Mk->>Dev: Echo release status
Loading

Poem

I'm a bunny, hopping with glee,
New flags and tags set my code free.
CometBFT and Pebbledb shine bright,
Trimmed paths make my build just right.
With every change, my heart does leap,
In this garden of code, my joy runs deep!
(_/), ( •_•), ( >🐰<)


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2182063 and 8029223.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • contrib/make/build.mk (3 hunks)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@helder-moreira helder-moreira force-pushed the chore/builds-missing-tags branch from 24551ff to 2182063 Compare February 11, 2025 15:03
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
contrib/make/release.mk (1)

9-17: Consider caching Docker YQ results.

The YQ commands are executed for every invocation of the Makefile targets. Consider caching the results in variables that are evaluated only once.

-DOCKER_YQ = docker run --rm -v $(PWD):/work -w /work mikefarah/yq:4
+DOCKER_YQ := docker run --rm -v $(PWD):/work -w /work mikefarah/yq:4

-DARWIN_TAGS := $(shell $(DOCKER_YQ) e \
+DARWIN_TAGS != $(DOCKER_YQ) e \
    '.builds | map(select(.id == "darwin")) | .[0].tags | join(",")' \
    .goreleaser.yml)

-LINUX_TAGS := $(shell $(DOCKER_YQ) e \
+LINUX_TAGS != $(DOCKER_YQ) e \
    '.builds | map(select(.id == "linux")) | .[0].tags | join(",")' \
    .goreleaser.yml)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between af38373 and 2182063.

📒 Files selected for processing (4)
  • .goreleaser.yml (3 hunks)
  • CHANGELOG.md (1 hunks)
  • contrib/make/build.mk (3 hunks)
  • contrib/make/release.mk (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
🔇 Additional comments (8)
contrib/make/release.mk (2)

7-7: LGTM! Good use of go list to extract CometBFT version.

The command correctly extracts the version from go.mod using go list -m and sed.


24-26: LGTM! Good addition of debug output and environment variables.

The echo statements help with debugging, and the environment variables are properly quoted.

Also applies to: 32-34

contrib/make/build.mk (3)

28-28: LGTM! Consistent with release.mk.

The CMT_VERSION extraction is identical to release.mk, ensuring consistency.


128-128: LGTM! Good addition of -trimpath flag.

The -trimpath flag helps create reproducible builds by removing file system paths from the binary.


56-57: Verify the impact of database backend change.

The switch from rocksdb to pebbledb as the default database backend is a significant change.

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Check for any hardcoded rocksdb references that might need updating
rg -l 'rocksdb' --type go

Length of output: 25


Database Backend Update Impact Verified

The search for "rocksdb" in the Go codebase produced no results, indicating that no parts of the repository rely on the old RocksDB backend. The build flag update to set the default to PebbleDB appears isolated and without additional side effects.

.goreleaser.yml (3)

5-6: LGTM! Good environment variable configuration.

The GO111MODULE and DEFAULT_DB_BACKEND environment variables are properly set.


36-38: LGTM! Consistent use of environment variables.

The build flags correctly use the environment variables defined in the Makefiles:

  • DARWIN_TAGS/LINUX_TAGS for BuildTags
  • CMT_VERSION for CMTSemVer
  • DEFAULT_DB_BACKEND for DBBackend

Also applies to: 78-80


40-40: Verify linker flags for both platforms.

The extldflags differ between Darwin and Linux builds:

  • Darwin: '-lrocksdb -lstdc++ -lz -lbz2'
  • Linux: '-static -lm -lbz2'

Ensure these flags are appropriate for each platform.

Also applies to: 82-82

✅ Verification successful

🌐 Web query:

What are the recommended linker flags for Go CGO builds on Darwin vs Linux?

💡 Result:

When building Go programs with CGO across different operating systems, linker flag requirements differ significantly between Darwin (macOS) and Linux due to platform-specific constraints:

Linux Recommendations

  1. Static Linking
    Use external linker mode combined with static flags:

    go build -ldflags "-linkmode external -extldflags '-static'"

    This forces full static compilation by invoking GCC's linker[3][5].
    Limitations: May fail if system libraries lack static versions[3][5].

  2. Dynamic Linking (Default)
    Works out-of-box when using standard CGO:

    go build

    Automatically links against system's shared libraries[3][8].

Darwin (macOS) Considerations

  1. System Library Constraints
    Apple's libSystem cannot be statically linked[3][10].

    # Partial static linking (non-system libs only)
    go build -ldflags "-linkmode external -extldflags '-static'"
  2. Framework Linking
    For macOS frameworks:

    // #cgo darwin LDFLAGS: -framework CoreFoundation

Cross-Platform Build Directives

Use conditional compilation in source files:

// #cgo linux LDFLAGS: -L/usr/local/lib -lfoo
// #cgo darwin LDFLAGS: -L/opt/homebrew/lib -lfoo
import "C"

Key differences table:

Platform Static Linking Support Common Flags Notes
Linux Full via -static -extldflags '-static' Requires static libs available
Darwin Partial -framework flags System libs remain dynamic

For architecture-specific paths (x86_64 vs ARM), use separate build tags rather than combined GOOS/GOARCH syntax[9]. When encountering "undefined reference" errors on Linux, verify library order in LDFLAGS matches linker requirements[1][8].

Citations:


Linker Flags Reviewed for Darwin vs. Linux

  • Darwin (macOS):
    The configuration uses
    -lrocksdb -lstdc++ -lz -lbz2
    which aligns with macOS requirements since full static linking isn’t supported. This set ensures that the necessary libraries—especially RocksDB—are linked dynamically, which is appropriate for Darwin.

  • Linux:
    The flag set is
    -static -lm -lbz2
    which is consistent with a fully static CGO build as recommended (i.e. using external linker flags to enforce static linking). Note that when using -static, it’s important to ensure that all required libraries (including math and bz2) have available static versions. If any library is missing its static variant, the build may fail; in that case, it might be necessary to switch to dynamic linking or adjust the flags accordingly.

Both configurations follow the platform-specific recommendations for Go CGO builds. Please verify that the required static libraries are available on Linux and that the dynamic libraries are correctly installed on Darwin.

@Unique-Divine Unique-Divine enabled auto-merge (squash) February 13, 2025 09:16
@Unique-Divine Unique-Divine merged commit b3c8d07 into main Feb 13, 2025
9 checks passed
@Unique-Divine Unique-Divine deleted the chore/builds-missing-tags branch February 13, 2025 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Completed
Development

Successfully merging this pull request may close these issues.

2 participants