Commit 1c4ba9f0d6

1c4ba9f0d6300b816c42660b746b2ac21f22e093

parent: 9ee708e1dd

Unregistered key

Rushikesh Gaikwad <81632222+Wraient@users.noreply.github.com> · 2025-02-25 20:36 UTC
committer: <noreply@github.com>

Compatibility: Release x86 and arm64 binaries for Linux and MacOS (#48)

* Compatibility: Release x86 and arm64 binaries for Linux, Windows and MacOS

* Compatibility: Update script permissions

* Fix: Windows arm64 binary build

* Compatibility: Remove windows arm64 build (Broken due to npipe and rich-go)

Layout: unified · split

.github/workflows/ci-cd.yml +12 −8
@@ -26,9 +26,9 @@ jobs:
2626 ref: ${{ github.event.pull_request.head.sha || (github.event.inputs.pr_number && format('refs/pull/{0}/head', github.event.inputs.pr_number)) || github.sha }}
2727
2828 - name: Set up Go
29 uses: actions/setup-go@v2
29 uses: actions/setup-go@v4
3030 with:
31 go-version: '1.24.0'
31 go-version: '1.21'
3232
3333 - name: Install Dependencies
3434 run: go mod tidy
@@ -38,6 +38,7 @@ jobs:
3838 ./Build/buildlinux
3939 mkdir -p release/linux
4040 mv curd-linux-x86_64 release/linux/
41 mv curd-linux-arm64 release/linux/
4142 env:
4243 GITHUB_EVENT_NAME: ${{ github.event_name }}
4344 GITHUB_REF: ${{ github.ref }}
@@ -52,9 +53,9 @@ jobs:
5253 run: |
5354 ./Build/buildmac-arm64
5455
55 - name: Install LLVM
56 - name: Install LLVM and gcc-mingw-w64
5657 run: |
57 sudo apt-get update && sudo apt-get install -y llvm
58 sudo apt-get update && sudo apt-get install -y llvm gcc-mingw-w64
5859 # Find the llvm-lipo command
5960 LIPO_CMD=$(find /usr/bin -name "llvm-lipo*" | head -n 1)
6061 echo "Found lipo command: $LIPO_CMD"
@@ -72,7 +73,7 @@ jobs:
7273 run: |
7374 ./Build/buildwindows
7475 mkdir -p release/windows
75 mv curd-windows.exe release/windows
76 mv curd-windows-x86_64.exe release/windows/curd-windows-x86_64.exe
7677 env:
7778 GITHUB_EVENT_NAME: ${{ github.event_name }}
7879 GITHUB_REF: ${{ github.ref }}
@@ -85,10 +86,11 @@ jobs:
8586 name: curd-binaries
8687 path: |
8788 release/linux/curd-linux-x86_64
89 release/linux/curd-linux-arm64
8890 release/macos/curd-macos-x86_64
8991 release/macos/curd-macos-arm64
9092 release/macos/curd-macos-universal
91 release/windows/curd-windows.exe
93 release/windows/curd-windows-x86_64.exe
9294 retention-days: 1
9395 if-no-files-found: error
9496
@@ -142,11 +144,12 @@ jobs:
142144 Get-ChildItem -Path "Build" -Recurse
143145
144146 # Move files to their respective directories
145 Move-Item "Build/windows/curd-windows.exe" "$release_dir/windows/"
147 Move-Item "Build/windows/curd-windows-x86_64.exe" "$release_dir/windows/"
146148 Move-Item "Build/macos/curd-macos-universal" "$release_dir/macos/"
147149 Move-Item "Build/macos/curd-macos-x86_64" "$release_dir/macos/"
148150 Move-Item "Build/macos/curd-macos-arm64" "$release_dir/macos/"
149151 Move-Item "Build/linux/curd-linux-x86_64" "$release_dir/linux/"
152 Move-Item "Build/linux/curd-linux-arm64" "$release_dir/linux/"
150153 Copy-Item "Build/mpv/mpv.exe" "$release_dir/windows/"
151154 shell: pwsh
152155
@@ -174,10 +177,11 @@ jobs:
174177 generate_release_notes: true
175178 files: |
176179 releases/curd-${{ env.CURD_VERSION }}/linux/curd-linux-x86_64
180 releases/curd-${{ env.CURD_VERSION }}/linux/curd-linux-arm64
177181 releases/curd-${{ env.CURD_VERSION }}/macos/curd-macos-x86_64
178182 releases/curd-${{ env.CURD_VERSION }}/macos/curd-macos-arm64
179183 releases/curd-${{ env.CURD_VERSION }}/macos/curd-macos-universal
180 releases/curd-${{ env.CURD_VERSION }}/windows/curd-windows.exe
184 releases/curd-${{ env.CURD_VERSION }}/windows/curd-windows-x86_64.exe
181185 Build/Output/curd-windows-installer.exe
182186 env:
183187 GITHUB_TOKEN: ${{ secrets.ACTIONS_PAT }}
Build/buildlinux +4 −5
@@ -1,5 +1,4 @@
1VERSION=$(cat VERSION.txt)
2CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o curd-linux-x86_64 -ldflags="-X main.version=${VERSION} -s -w" -trimpath cmd/curd/main.go
3if [[ "$GITHUB_EVENT_NAME" == "push" && "$GITHUB_REF" == "refs/heads/main" && "$GITHUB_EVENT_HEAD_COMMIT_MESSAGE" == *"release:"* ]] || [[ "$COMPRESS" == "true" ]]; then
4 upx --best --ultra-brute curd-linux-x86_64
5fi
\ No newline at end of file
1#!/bin/bash
2
3./Build/buildlinux-arm64
4./Build/buildlinux-x86_64
Build/buildlinux-arm64 added +5
@@ -0,0 +1,5 @@
1VERSION=$(cat VERSION.txt)
2CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o curd-linux-arm64 -ldflags="-X main.version=${VERSION} -s -w" -trimpath cmd/curd/main.go
3if [[ "$GITHUB_EVENT_NAME" == "push" && "$GITHUB_REF" == "refs/heads/main" && "$GITHUB_EVENT_HEAD_COMMIT_MESSAGE" == *"release:"* ]] || [[ "$COMPRESS" == "true" ]]; then
4 upx --best --ultra-brute curd-linux-arm64
5fi
\ No newline at end of file
Build/buildlinux-x86_64 added +5
@@ -0,0 +1,5 @@
1VERSION=$(cat VERSION.txt)
2CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o curd-linux-x86_64 -ldflags="-X main.version=${VERSION} -s -w" -trimpath cmd/curd/main.go
3if [[ "$GITHUB_EVENT_NAME" == "push" && "$GITHUB_REF" == "refs/heads/main" && "$GITHUB_EVENT_HEAD_COMMIT_MESSAGE" == *"release:"* ]] || [[ "$COMPRESS" == "true" ]]; then
4 upx --best --ultra-brute curd-linux-x86_64
5fi
\ No newline at end of file
Build/buildmac
Build/buildwindows +13 −5
@@ -1,5 +1,13 @@
1VERSION=$(cat VERSION.txt)
2CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o curd-windows.exe -ldflags="-X main.version=${VERSION}" cmd/curd/main.go
3if [[ "$GITHUB_EVENT_NAME" == "push" && "$GITHUB_REF" == "refs/heads/main" && "$GITHUB_EVENT_HEAD_COMMIT_MESSAGE" == *"release:"* ]] || [[ "$COMPRESS" == "true" ]]; then
4 upx --best --ultra-brute curd-windows.exe
5fi
\ No newline at end of file
1#!/bin/bash
2
3# Set required Windows build environment variables
4export CGO_ENABLED=1
5export GOOS=windows
6
7# Build for ARM64 (Broken due to npipe and rich-go)
8# export GOARCH=arm64
9# CC=x86_64-w64-mingw32-gcc ./Build/buildwindows-arm64
10
11# Build for x86_64
12export GOARCH=amd64
13CC=x86_64-w64-mingw32-gcc ./Build/buildwindows-x86_64
Build/buildwindows-arm64 added +5
@@ -0,0 +1,5 @@
1VERSION=$(cat VERSION.txt)
2CGO_ENABLED=0 GOOS=windows GOARCH=arm64 go build -o curd-windows-arm64.exe -ldflags="-X main.version=${VERSION}" cmd/curd/main.go
3if [[ "$GITHUB_EVENT_NAME" == "push" && "$GITHUB_REF" == "refs/heads/main" && "$GITHUB_EVENT_HEAD_COMMIT_MESSAGE" == *"release:"* ]] || [[ "$COMPRESS" == "true" ]]; then
4 upx --best --ultra-brute curd-windows-arm64.exe
5fi
\ No newline at end of file
Build/buildwindows-x86_64 added +5
@@ -0,0 +1,5 @@
1VERSION=$(cat VERSION.txt)
2CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o curd-windows-x86_64.exe -ldflags="-X main.version=${VERSION}" cmd/curd/main.go
3if [[ "$GITHUB_EVENT_NAME" == "push" && "$GITHUB_REF" == "refs/heads/main" && "$GITHUB_EVENT_HEAD_COMMIT_MESSAGE" == *"release:"* ]] || [[ "$COMPRESS" == "true" ]]; then
4 upx --best --ultra-brute curd-windows-x86_64.exe
5fi
\ No newline at end of file
Build/curd-windows-build.iss +1 −1
@@ -15,7 +15,7 @@ Name: "desktopicon"; Description: "Create a &desktop shortcut"; GroupDescription
1515
1616[Files]
1717; Copy the Curd executable to the install directory
18Source: "..\releases\curd-{#SetupSetting("AppVersion")}\windows\curd-windows.exe"; DestDir: "{app}"; DestName: "curd.exe"; Flags: ignoreversion
18Source: "..\releases\curd-{#SetupSetting("AppVersion")}\windows\curd-windows-x86_64.exe"; DestDir: "{app}"; DestName: "curd.exe"; Flags: ignoreversion
1919Source: "mpv\mpv.exe"; DestDir: "{app}\bin"; Flags: ignoreversion
2020
2121[Icons]
Build/mpv.zip added

Binary file not shown.

Build/release +18 −3
@@ -23,6 +23,13 @@ else
2323 exit 1
2424fi
2525
26if [ -f "curd-linux-arm64" ]; then
27 mv curd-linux-arm64 "$linux_folder"
28else
29 echo "Linux build failed. Please check Build/buildlinux-arm64."
30 exit 1
31fi
32
2633# Build macOS binaries
2734echo "Building macOS binaries..."
2835bash Build/buildmac
@@ -63,13 +70,21 @@ mkdir -p "Build/mpv"
6370gunzip -c Build/mpv.exe.gz > "Build/mpv/mpv.exe"
6471
6572# Move the Windows binary to the release folder
66if [ -f "curd-windows.exe" ]; then
67 mv curd-windows.exe "$windows_folder"
73if [ -f "curd-windows-x86_64.exe" ]; then
74 mv curd-windows-x86_64.exe "$windows_folder"
6875else
69 echo "Windows build failed. Please check Build/buildwindows."
76 echo "Windows build failed. Please check Build/buildwindows-x86_64."
7077 exit 1
7178fi
7279
80# NOTE: Broken due to npipe and rich-go
81# if [ -f "curd-windows-arm64.exe" ]; then
82# mv curd-windows-arm64.exe "$windows_folder"
83# else
84# echo "Windows build failed. Please check Build/buildwindows-arm64."
85# exit 1
86# fi
87
7388# Create Windows installer with Inno Setup
7489echo "Creating Windows installer..."
7590wine "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" "$installer_script"
Build/requirements.txt added +2
@@ -0,0 +1,2 @@
1mingw-w64-gcc # Build arm64 windows binary
2llvm-lipo # Build universal macos binary
\ No newline at end of file
internal/curd.go +37 −19
@@ -457,8 +457,10 @@ func UpdateCurd(repo, fileName string) error {
457457 var binaryName string
458458 switch runtime.GOOS {
459459 case "windows":
460 if strings.HasSuffix(executablePath, "curd.exe") {
461 binaryName = "curd-windows.exe"
460 if runtime.GOARCH == "arm64" {
461 binaryName = "curd-windows-arm64.exe"
462 } else {
463 binaryName = "curd-windows-x86_64.exe"
462464 }
463465 case "darwin": // macOS
464466 switch runtime.GOARCH {
@@ -470,9 +472,12 @@ func UpdateCurd(repo, fileName string) error {
470472 binaryName = "curd-macos-universal"
471473 }
472474 case "linux":
473 if runtime.GOARCH == "amd64" {
475 switch runtime.GOARCH {
476 case "amd64":
474477 binaryName = "curd-linux-x86_64"
475 } else {
478 case "arm64":
479 binaryName = "curd-linux-arm64"
480 default:
476481 return fmt.Errorf("unsupported Linux architecture: %s", runtime.GOARCH)
477482 }
478483 default:
@@ -504,25 +509,38 @@ func UpdateCurd(repo, fileName string) error {
504509 }
505510 defer out.Close()
506511
507 // Write the downloaded content to the temporary file
508 _, err = io.Copy(out, resp.Body)
509 if err != nil {
510 return fmt.Errorf("failed to save downloaded file: %v", err)
512 // Set file permissions
513 if err := out.Chmod(0755); err != nil {
514 return fmt.Errorf("failed to set file permissions: %v", err)
511515 }
512516
513 // Close and rename the temporary file to replace the current executable
514 out.Close()
515
516 // Replace the current executable with the downloaded curd
517 if err := os.Rename(tmpPath, executablePath); err != nil {
518 return fmt.Errorf("failed to replace the current executable: %v", err)
517 // Copy the downloaded content to the temporary file
518 if _, err := io.Copy(out, resp.Body); err != nil {
519 return fmt.Errorf("failed to write to temporary file: %v", err)
519520 }
520 CurdOut(fmt.Sprintf("Downloaded curd executable to %v", executablePath))
521521
522 if runtime.GOOS != "windows" {
523 // Ensure the new file has executable permissions
524 if err := os.Chmod(executablePath, 0755); err != nil {
525 return fmt.Errorf("failed to set permissions on the new file: %v", err)
522 // Close the file before renaming
523 out.Close()
524
525 // Replace the old executable with the new one
526 if runtime.GOOS == "windows" {
527 // On Windows, we need to rename the old file first
528 oldPath := executablePath + ".old"
529 err = os.Rename(executablePath, oldPath)
530 if err != nil {
531 return fmt.Errorf("failed to rename old executable: %v", err)
532 }
533 err = os.Rename(tmpPath, executablePath)
534 if err != nil {
535 // Try to restore the old executable if the rename fails
536 os.Rename(oldPath, executablePath)
537 return fmt.Errorf("failed to rename new executable: %v", err)
538 }
539 os.Remove(oldPath)
540 } else {
541 // On Unix systems, we can directly rename
542 if err := os.Rename(tmpPath, executablePath); err != nil {
543 return fmt.Errorf("failed to replace executable: %v", err)
526544 }
527545 }
528546