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

Remove xattr via obj-c #3328

Merged
merged 3 commits into from
Mar 24, 2024
Merged

Remove xattr via obj-c #3328

merged 3 commits into from
Mar 24, 2024

Conversation

leaanthony
Copy link
Member

@leaanthony leaanthony commented Mar 20, 2024

Potentially Fixes: #3326

Summary by CodeRabbit

  • New Features
    • Introduced functionality to manage and fix extended attributes (xattrs) on files, enhancing file handling during the build process.

Copy link
Contributor

coderabbitai bot commented Mar 20, 2024

Walkthrough

This update introduces and integrates functionality for handling extended attributes (xattrs) on macOS, addressing issues with running and building applications on Mac M2 systems. It involves modifications across several files to incorporate Objective-C code through CGO for xattr removal and adjustments in build and binding generation processes to ensure compatibility and proper functioning on macOS.

Changes

File Path Change Summary
v2/internal/xattr/xattr.go Introduced functionality to remove xattrs using Objective-C and CGO.
v2/pkg/commands/.../bindings.go, v2/pkg/commands/.../build.go Added fixupXattrs variable; modified functions for xattr handling.
v2/pkg/commands/.../bindings_darwin.go, v2/pkg/commands/.../build_darwin.go Added macOS-specific xattr handling in bindings and build processes.

Assessment against linked issues

Objective Addressed Explanation
Issue Identification (#3326)
Reproducibility Steps (#3326) The code changes do not directly provide reproducibility steps; this is likely addressed outside the code.
Expected Behavior (#3326)
Compatibility (#3326)
Issue Identification (#3003) It's unclear if the duplicate symbols issue is directly addressed.
Compatibility with systray package (#3003) No specific changes related to systray package compatibility were mentioned.

Related issues

  • Linking problems on MacOS #3003: The changes may indirectly address the duplicate symbols issue by modifying how xattrs are handled, potentially resolving build errors on macOS.

Poem

In the realm of code, where rabbits dare,
A change was made, with skill and care.
🐇✨ On macOS land, where xattrs lie,
A fix was born, to make them fly.
No longer bound by error's chain,
Our builds succeed, time and again.
🎉 Let’s hop with joy, for we’ve prevailed,
In the quest where many have failed.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

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>.
    • Generate unit-tests 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 tests 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3694dd2 and 880a4e0.
Files selected for processing (5)
  • v2/internal/xattr/xattr.go (1 hunks)
  • v2/pkg/commands/bindings/bindings.go (2 hunks)
  • v2/pkg/commands/bindings/bindings_darwin.go (1 hunks)
  • v2/pkg/commands/build/build.go (2 hunks)
  • v2/pkg/commands/build/build_darwin.go (1 hunks)
Additional comments: 6
v2/pkg/commands/build/build_darwin.go (1)
  • 1-9: The changes in build_darwin.go correctly implement platform-specific initialization for macOS, ensuring that extended attributes are handled appropriately on this platform. The use of build tags and the init function are in line with Go best practices.
v2/pkg/commands/bindings/bindings_darwin.go (1)
  • 1-9: The changes in bindings_darwin.go correctly set up platform-specific initialization for macOS in the bindings package, ensuring consistent handling of extended attributes across the project. This approach is consistent with Go best practices.
v2/pkg/commands/bindings/bindings.go (2)
  • 16-17: The introduction of the fixupXattrs global variable is aligned with the PR's objectives and follows best practices for conditional platform-specific logic.
  • 63-65: The conditional use of fixupXattrs in the GenerateBindings function correctly implements the necessary logic for handling extended attributes on macOS, ensuring it only affects builds for this platform.
v2/pkg/commands/build/build.go (2)
  • 25-26: The introduction of the fixupXattrs global variable aligns with the PR's objectives to handle extended attributes on macOS and follows best practices for conditional platform-specific logic.
  • 332-336: The conditional use of fixupXattrs in the execBuildApplication function correctly implements the necessary logic for handling extended attributes on macOS, ensuring it only affects builds for this platform.

Comment on lines 1 to 34
package xattr

/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Foundation
#import <sys/xattr.h>
#include <stdlib.h>
#include <string.h>

void removeXattrFrom(const char *path) {
ssize_t xattrNamesSize = listxattr(path, NULL, 0, XATTR_NOFOLLOW);
if (xattrNamesSize <= 0) return;

char *xattrNames = (char *)malloc(xattrNamesSize);
xattrNamesSize = listxattr(path, xattrNames, xattrNamesSize, XATTR_NOFOLLOW);

ssize_t pos = 0;
while (pos < xattrNamesSize) {
char *name = xattrNames + pos;
removexattr(path, name, XATTR_NOFOLLOW);
pos += strlen(name) + 1;
}

free(xattrNames);
}
*/
import "C"
import "unsafe"

func RemoveXAttr(filepath string) {
cpath := C.CString(filepath)
defer C.free(unsafe.Pointer(cpath))
C.removeXattrFrom(cpath)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The implementation in xattr.go correctly uses CGO and Objective-C to remove extended attributes from files on macOS. The integration and memory management are handled appropriately.

Consider adding error handling to the removeXattrFrom Objective-C function and the RemoveXAttr Go function to report failures in removing extended attributes, enhancing the robustness of this feature.

Copy link

cloudflare-workers-and-pages bot commented Mar 20, 2024

Deploying wails with  Cloudflare Pages  Cloudflare Pages

Latest commit: a7e952c
Status: ✅  Deploy successful!
Preview URL: https://959fc92d.wails.pages.dev
Branch Preview URL: https://v2-3326-xattr.wails.pages.dev

View logs

@stukennedy
Copy link

is there a guide on how to build and run this PR locally?

@leaanthony
Copy link
Member Author

You can follow this guide and make sure you're using v3-alpha instead of master. Let us know how you get on 👍

@stukennedy
Copy link

You can follow this guide and make sure you're using v3-alpha instead of master. Let us know how you get on 👍

can't figure out how to build or run any of this.
the global version of wails is still the v2.8.0 no matter what I do.
running go install makes no difference.
trying to go install github.com/wailsapp/wails/v3/cmd/wails@v3-alpha or any combination of things just throws an error.
I'm totally lost.

why would I need to install v3 if I've pulled from the PR and go install from there?
Shouldn't that replace the version that's installed?

This was the problem I had in my app, once I upgraded (using wails upgrade to v2.8.0) I could find no way to revert to a previous version. Changing in the go.mod and running go mod tidy does nothing.

totally stuck here

@leaanthony
Copy link
Member Author

Sorry, ignore the v3 comment. Just follow the guide. If you want to revert to a previous version, just install using Go's @tag method and update go.mod in your project:

go install github.com/wailsapp/wails/v2/cmd/wails@<version>

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 880a4e0 and a7e952c.
Files selected for processing (2)
  • v2/pkg/commands/bindings/bindings.go (1 hunks)
  • v2/pkg/commands/build/build.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • v2/pkg/commands/bindings/bindings.go
  • v2/pkg/commands/build/build.go

@leaanthony leaanthony merged commit bf2d6d3 into master Mar 24, 2024
11 checks passed
@leaanthony leaanthony deleted the v2/3326-xattr branch March 24, 2024 01:32
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.

v2.8 not running on Mac M2
2 participants