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

[V3 Linux] aarch64 compilation #3854

Open
wants to merge 2 commits into
base: v3-alpha
Choose a base branch
from

Conversation

kodflow
Copy link

@kodflow kodflow commented Oct 23, 2024

Description

This pull request addresses an issue in the v3/internal/commands/appimage.go file, where the logic to generate AppImages was not functioning correctly on certain platforms. The modification ensures that the appimage.go command correctly handles the generation of AppImages for Linux environments by updating the build process.

Fixes #3840

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

The fix was tested by building the project on different Linux distributions and verifying that the AppImage generation now works correctly. Additional logging was added to confirm that all steps in the process are successfully executed.

  • Linux

Summary by CodeRabbit

  • New Features

    • Enhanced application image generation with architecture-specific handling for arm64 and x86_64.
    • Improved download process for necessary files with architecture-specific URLs for concurrent downloads.
  • Bug Fixes

    • Added error handling for unsupported architectures and file existence checks.
  • Refactor

    • Simplified GTK version determination logic for better clarity.

Copy link
Contributor

coderabbitai bot commented Oct 23, 2024

Walkthrough

The changes in this pull request enhance the GenerateAppImage functionality within the v3/internal/commands/appimage.go file. Key modifications include the introduction of architecture-specific handling for arm64 and x86_64, allowing for dynamic URL management for file downloads based on architecture. The application directory naming convention has been updated to reflect architecture, and error handling remains consistent. The logic for determining GTK versions has been simplified. Overall, these changes improve the flexibility and robustness of the application image generation process.

Changes

File Path Change Summary
v3/internal/commands/appimage.go - Introduced architecture-specific handling for arm64 and x86_64.
- Updated application directory naming to include architecture.
- Refactored download process to use architecture-based URLs for concurrent downloads.
- Simplified GTK version determination logic using a switch statement.
- Updated command for running linuxdeploy to reference architecture-specific AppImage.
- Maintained consistent error handling throughout the process.

Assessment against linked issues

Objective Addressed Explanation
Support 'wails bundle' for Windows (#3) The changes do not address Windows support.

Possibly related issues

Possibly related PRs

Suggested reviewers

  • leaanthony

🐇 In the land of code where rabbits play,
New paths for images brighten the way.
With arms of arm64 and x86_64,
We build our dreams, both big and small.
So hop along, let the changes unfold,
A tale of images, brave and bold! 🌟


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

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

🧹 Outside diff range and nitpick comments (2)
v3/internal/commands/appimage.go (2)

Line range hint 138-158: Correct the target directory path when copying GTK files.

The current method of constructing targetDir may lead to incorrect paths, causing files to be copied to unintended locations. Stripping the leading slash and then using filepath.Abs can result in paths outside the AppDir.

Modify the path construction to ensure files are copied relative to appDir:

     s.CD(appDir)
     for _, file := range files {
         targetDir := filepath.Dir(file)
         if targetDir[0] == '/' {
             targetDir = targetDir[1:]
         }
-        targetDir, err = filepath.Abs(targetDir)
+        targetDir = filepath.Join(appDir, targetDir)
         if err != nil {
             return err
         }
         s.MKDIR(targetDir)
         s.COPY(file, targetDir)
     }

Line range hint 187-198: Update log message to reflect the final AppImage location.

After moving the AppImage to the output directory, the log message references targetFile, which still points to the original location. Adjust the log to show the correct output path.

Apply this change to fix the log message:

     s.MOVE(targetFile, options.OutputDir)

-    log(p, "AppImage created: "+targetFile)
+    finalAppImagePath := filepath.Join(options.OutputDir, filepath.Base(targetFile))
+    log(p, "AppImage created: "+finalAppImagePath)
     return nil
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4325b06 and 0ba3edb.

📒 Files selected for processing (1)
  • v3/internal/commands/appimage.go (5 hunks)
🧰 Additional context used
🔇 Additional comments (2)
v3/internal/commands/appimage.go (2)

9-9: Good inclusion of the "runtime" package for architecture detection.

The addition of the runtime package is necessary for determining the current architecture, which is essential for the changes implemented.


174-184: Simplified GTK version detection is appropriate.

The use of a switch statement enhances readability and efficiently determines the GTK version required for deployment.

v3/internal/commands/appimage.go Show resolved Hide resolved
Comment on lines +113 to +135
// Download necessary files concurrently
log(p, "Downloading AppImage tooling")
var wg sync.WaitGroup
wg.Add(2)

go func() {
if !s.EXISTS(filepath.Join(options.BuildDir, "linuxdeploy-x86_64.AppImage")) {
s.DOWNLOAD("https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage", filepath.Join(options.BuildDir, "linuxdeploy-x86_64.AppImage"))
linuxdeployPath := filepath.Join(options.BuildDir, filepath.Base(urls["linuxdeploy"]))
if !s.EXISTS(linuxdeployPath) {
s.DOWNLOAD(urls["linuxdeploy"], linuxdeployPath)
}
s.CHMOD(filepath.Join(options.BuildDir, "linuxdeploy-x86_64.AppImage"), 0755)
s.CHMOD(linuxdeployPath, 0755)
wg.Done()
}()

go func() {
target := filepath.Join(appDir, "AppRun")
if !s.EXISTS(target) {
s.DOWNLOAD("https://github.com/AppImage/AppImageKit/releases/download/continuous/AppRun-x86_64", target)
s.DOWNLOAD(urls["AppRun"], target)
}
s.CHMOD(target, 0755)
wg.Done()
}()

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

Add error handling in the concurrent download goroutines.

Currently, errors from s.DOWNLOAD and s.CHMOD within the goroutines are not being captured. If a download fails or permission changes fail, the program may proceed without the necessary tools, leading to runtime errors. Consider handling these errors to ensure robustness.

One way to handle this is to collect errors via a channel:

     var wg sync.WaitGroup
+    errCh := make(chan error, 2)
     wg.Add(2)

     go func() {
         linuxdeployPath := filepath.Join(options.BuildDir, filepath.Base(urls["linuxdeploy"]))
         if !s.EXISTS(linuxdeployPath) {
-            s.DOWNLOAD(urls["linuxdeploy"], linuxdeployPath)
+            if err := s.DOWNLOAD(urls["linuxdeploy"], linuxdeployPath); err != nil {
+                errCh <- err
+                return
+            }
         }
-        s.CHMOD(linuxdeployPath, 0755)
+        if err := s.CHMOD(linuxdeployPath, 0755); err != nil {
+            errCh <- err
+            return
+        }
         wg.Done()
     }()

     go func() {
         target := filepath.Join(appDir, "AppRun")
         if !s.EXISTS(target) {
-            s.DOWNLOAD(urls["AppRun"], target)
+            if err := s.DOWNLOAD(urls["AppRun"], target); err != nil {
+                errCh <- err
+                return
+            }
         }
-        s.CHMOD(target, 0755)
+        if err := s.CHMOD(target, 0755); err != nil {
+            errCh <- err
+            return
+        }
         wg.Done()
     }()

     wg.Wait()
+    close(errCh)
+    for err := range errCh {
+        return err
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Download necessary files concurrently
log(p, "Downloading AppImage tooling")
var wg sync.WaitGroup
wg.Add(2)
go func() {
if !s.EXISTS(filepath.Join(options.BuildDir, "linuxdeploy-x86_64.AppImage")) {
s.DOWNLOAD("https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage", filepath.Join(options.BuildDir, "linuxdeploy-x86_64.AppImage"))
linuxdeployPath := filepath.Join(options.BuildDir, filepath.Base(urls["linuxdeploy"]))
if !s.EXISTS(linuxdeployPath) {
s.DOWNLOAD(urls["linuxdeploy"], linuxdeployPath)
}
s.CHMOD(filepath.Join(options.BuildDir, "linuxdeploy-x86_64.AppImage"), 0755)
s.CHMOD(linuxdeployPath, 0755)
wg.Done()
}()
go func() {
target := filepath.Join(appDir, "AppRun")
if !s.EXISTS(target) {
s.DOWNLOAD("https://github.com/AppImage/AppImageKit/releases/download/continuous/AppRun-x86_64", target)
s.DOWNLOAD(urls["AppRun"], target)
}
s.CHMOD(target, 0755)
wg.Done()
}()
// Download necessary files concurrently
log(p, "Downloading AppImage tooling")
var wg sync.WaitGroup
errCh := make(chan error, 2)
wg.Add(2)
go func() {
linuxdeployPath := filepath.Join(options.BuildDir, filepath.Base(urls["linuxdeploy"]))
if !s.EXISTS(linuxdeployPath) {
if err := s.DOWNLOAD(urls["linuxdeploy"], linuxdeployPath); err != nil {
errCh <- err
return
}
}
if err := s.CHMOD(linuxdeployPath, 0755); err != nil {
errCh <- err
return
}
wg.Done()
}()
go func() {
target := filepath.Join(appDir, "AppRun")
if !s.EXISTS(target) {
if err := s.DOWNLOAD(urls["AppRun"], target); err != nil {
errCh <- err
return
}
}
if err := s.CHMOD(target, 0755); err != nil {
errCh <- err
return
}
wg.Done()
}()
wg.Wait()
close(errCh)
for err := range errCh {
return err
}

Copy link

sonarcloud bot commented Oct 23, 2024

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.

1 participant