Skip to content

Zlib fix for updated MacOS #755

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

Merged
merged 2 commits into from
May 8, 2025
Merged

Zlib fix for updated MacOS #755

merged 2 commits into from
May 8, 2025

Conversation

chewy-zlai
Copy link
Collaborator

@chewy-zlai chewy-zlai commented May 8, 2025

Summary

This patches the fdopen issue for bazel build on MacOS.

Checklist

  • Added Unit Tests
  • Covered by existing CI
  • Integration tested
  • Documentation update

Summary by CodeRabbit

  • New Features
    • Added support for the zlib compression library, enabling integration with external zlib sources.
    • Introduced platform-specific build configurations, including macOS-specific fixes for improved compatibility.
  • Chores
    • Updated build and workspace configurations to manage new dependencies and control compiler warnings across platforms.

Copy link
Contributor

coderabbitai bot commented May 8, 2025

Walkthrough

Platform-specific build rules and compiler flags are added to the Bazel configuration for macOS and Linux. The zlib library is introduced as an external dependency, with a custom build file and a macOS-specific compatibility fix implemented via a wrapper function. New Bazel targets and settings support these changes.

Changes

File(s) Change Summary
.bazelrc Added platform-specific compiler flags for macOS and Linux builds.
WORKSPACE Added external dependency on zlib (via http_archive).
third_party/BUILD.bazel New build file: exports zlib.BUILD, defines macOS config, and adds macos_zlib_fix cc_library.
third_party/macos_zlib_fix.cc New file: defines my_fdopen_wrapper for macOS compatibility.
third_party/zlib.BUILD New build file: defines zlib cc_library with macOS-specific flags and wrapper, public visibility.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant Bazel
    participant zlib (external)
    participant macos_zlib_fix

    Developer->>Bazel: Build project
    Bazel->>zlib (external): Fetch and build zlib (with zlib.BUILD)
    alt If on macOS
        Bazel->>macos_zlib_fix: Build macOS wrapper
        Bazel->>zlib (external): Apply macOS-specific defines and wrapper
    end
    Bazel-->>Developer: Build artifacts with platform-specific settings
Loading

Poem

Zlib joins the build parade,
With macOS quirks now duly swayed.
Wrapper in place, warnings suppressed,
Bazel’s configs finely dressed.
Linux and Mac, both in sync,
Compression’s here—no need to think!
🎉🛠️

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

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: 2

🧹 Nitpick comments (1)
.bazelrc (1)

31-31: Linux host flags?
Consider adding --host_copt=-Wno-deprecated-function under build:linux.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 487d4d3 and e3f97ee.

📒 Files selected for processing (5)
  • .bazelrc (1 hunks)
  • WORKSPACE (1 hunks)
  • third_party/BUILD.bazel (1 hunks)
  • third_party/macos_zlib_fix.cc (1 hunks)
  • third_party/zlib.BUILD (1 hunks)
🔇 Additional comments (10)
.bazelrc (2)

20-23: Verify flag validity.
Ensure --enable_platform_specific_config exists in your Bazel version.


25-29: macOS warnings suppressed.
Flags look correct for macOS builds.

third_party/BUILD.bazel (3)

1-6: Visibility set correctly.


7-10: macOS config present.


12-16: Linkage check.
Confirm macos_zlib_fix is actually used by downstream targets.

WORKSPACE (1)

5-14: Verify zlib SHA.
Double-check the checksum matches upstream v1.2.11.

third_party/zlib.BUILD (4)

1-2: Public visibility OK.


4-7: macOS config OK.


15-24: Defines correct.


25-31: copts correct.

Comment on lines +1 to +8
#ifdef __APPLE__
/* This provides a redefinition-safe fdopen on macOS as zlib is incompatible without it */
#include <stdio.h>

FILE* my_fdopen_wrapper(int fd, const char* mode) {
return fdopen(fd, mode);
}
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Missing C linkage.
Wrapper must be declared extern "C" to avoid name mangling.

Comment on lines +10 to +32
cc_library(
name = "zlib",
srcs = glob(["*.c"], exclude = ["example.c", "minigzip.c"]),
hdrs = glob(["*.h"]),
includes = ["."],
defines = select({
":macos": [
"HAVE_UNISTD_H",
"NO_FSEEKO",
"HAVE_STDARG_H",
"_DARWIN_C_SOURCE",
"fdopen=my_fdopen_wrapper", # Redefine fdopen to avoid conflicts
],
"//conditions:default": [],
}),
copts = select({
":macos": [
"-Wno-macro-redefined",
"-Wno-deprecated-non-prototype",
],
"//conditions:default": [],
}),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Missing wrapper in deps.
Add

deps = select({":macos":["//third_party:macos_zlib_fix"],"//conditions:default":[]})

to link my_fdopen_wrapper.

@nikhil-zlai nikhil-zlai merged commit 6edb34b into main May 8, 2025
5 checks passed
@nikhil-zlai nikhil-zlai deleted the chewy/zlib-fix branch May 8, 2025 22:33
chewy-zlai added a commit that referenced this pull request May 15, 2025
chewy-zlai added a commit that referenced this pull request May 15, 2025
chewy-zlai added a commit that referenced this pull request May 16, 2025
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.

2 participants