Skip to content

Commit

Permalink
Add build for arm64 (#787)
Browse files Browse the repository at this point in the history
* Add build for arm64

* Use master channel for build-linux

* Add cache and reorder doctor

* Improve linux arm build

* Add alternative build for arm

* Improve arm builds

* Normalize binary name

* Remove arm appimage build
  • Loading branch information
CodeDoctorDE authored Jan 18, 2025
1 parent 6bca355 commit 2aa09bd
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 48 deletions.
130 changes: 93 additions & 37 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,17 @@ jobs:
path: |
app/linwood-butterfly-windows-setup-x86_64.exe
build-linux:
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
arch:
- image: ubuntu-24.04
name: x86_64
dir: x64
- image: ubuntu-24.04-arm
name: arm64
dir: arm64
runs-on: ${{ matrix.arch.image }}
defaults:
run:
working-directory: app
Expand Down Expand Up @@ -174,13 +184,17 @@ jobs:
- uses: subosito/[email protected]
with:
flutter-version-file: app/pubspec.yaml
channel: 'master'
cache: true
cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:'
cache-path: '${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:'
- name: ✅ Enable platforms
run: flutter config --enable-linux-desktop
- name: 📦 Get dependencies
run: |
flutter clean
flutter pub get
flutter doctor -v
flutter pub get
- name: 🏭 Build nightly
if: ${{ github.ref != 'refs/tags/stable' && (github.event_name != 'release' || github.event.release.prerelease) }}
run: |
Expand All @@ -193,64 +207,77 @@ jobs:
flutter build linux -v --release --dart-define=flavor=production
- name: 🏭 Make binary executable
run: |
chmod +x build/linux/x64/release/bundle/butterfly
chmod +x build/linux/${{ matrix.arch.dir }}/release/bundle/butterfly
- name: Build .deb executable
run: |
cp -fr build/linux/x64/release/bundle linux/debian/usr/bin
cp -fr build/linux/${{ matrix.arch.dir }}/release/bundle linux/debian/usr/bin
dpkg-deb --build --root-owner-group linux/debian
cp linux/*.deb linwood-butterfly-linux-x86_64.deb
cp linux/*.deb linwood-butterfly-linux-${{ matrix.arch.name }}.deb
- name: Build .rpm executable
run: |
bash scripts/build-rpm.sh
bash scripts/build-rpm.sh -d ${{ matrix.arch.dir }} -b ${{ matrix.arch.name }}
- name: Build .AppImage executable
if: ${{ matrix.arch.name == 'x86_64' }}
run: |
wget -O appimage-builder-x86_64.AppImage https://github.com/AppImageCrafters/appimage-builder/releases/download/v1.1.0/appimage-builder-1.1.0-x86_64.AppImage
chmod +x appimage-builder-x86_64.AppImage
sudo mv appimage-builder-x86_64.AppImage /usr/local/bin/appimage-builder
wget -O appimage-builder.AppImage https://github.com/AppImageCrafters/appimage-builder/releases/download/v1.1.0/appimage-builder-1.1.0-x86_64.AppImage
chmod +x appimage-builder.AppImage
sudo mv appimage-builder.AppImage /usr/local/bin/appimage-builder
appimage-builder --recipe AppImageBuilder.yml --skip-test
- name: Copy nessessary files
run: |
cp images/logo.svg build/linux/x64/release/bundle/dev.linwood.butterfly.svg
mkdir -p build/linux/x64/release/bundle/usr/share
cp -r linux/debian/usr/share build/linux/x64/release/bundle/usr
cp images/logo.svg build/linux/${{ matrix.arch.dir }}/release/bundle/dev.linwood.butterfly.svg
mkdir -p build/linux/${{ matrix.arch.dir }}/release/bundle/usr/share
cp -r linux/debian/usr/share build/linux/${{ matrix.arch.dir }}/release/bundle/usr
- name: Rename AppImage
if: ${{ matrix.arch.name == 'x86_64' }}
run: |
ls
mv ./*.AppImage linwood-butterfly-linux-x86_64.AppImage
mv ./*.AppImage linwood-butterfly-linux-${{ matrix.arch.name }}.AppImage
- name: Copy portable start script
run: |
chmod +x scripts/start.sh
cp scripts/start.sh build/linux/x64/release/bundle
cp scripts/start.sh build/linux/${{ matrix.arch.dir }}/release/bundle
- name: Archive
uses: actions/upload-artifact@v4
with:
name: linux-build
name: linux-${{ matrix.arch.name }}-build
path: |
app/build/linux/x64/release/bundle/**
app/build/linux/${{ matrix.arch.dir }}/release/bundle/**
- name: Archive .deb
uses: actions/upload-artifact@v4
with:
name: linux-deb
name: linux-${{ matrix.arch.name }}-deb
path: |
app/linwood-butterfly-linux-x86_64.deb
app/linwood-butterfly-linux-${{ matrix.arch.name }}.deb
- name: Archive .rpm
uses: actions/upload-artifact@v4
with:
name: linux-rpm
name: linux-${{ matrix.arch.name }}-rpm
path: |
app/build/linwood-butterfly-linux-x86_64.rpm
app/build/linwood-butterfly-linux-${{ matrix.arch.name }}.rpm
- name: Archive .AppImage
uses: actions/upload-artifact@v4
if: ${{ matrix.arch.name == 'x86_64' }}
with:
name: linux-appimage
name: linux-x86_64-appimage
path: |
app/linwood-butterfly-linux-x86_64.AppImage
build-flatpak:
name: build-flatpak
runs-on: ubuntu-22.04
defaults:
run:
working-directory: app
strategy:
fail-fast: false
matrix:
arch:
- image: ubuntu-22.04
name: x86_64
dir: x64
- image: ubuntu-22.04-arm
name: arm64
dir: arm64
runs-on: ${{ matrix.arch.image }}
steps:
- name: ⬆️ Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -280,6 +307,7 @@ jobs:
- uses: subosito/[email protected]
with:
flutter-version-file: app/pubspec.yaml
channel: 'master'
- name: ✅ Enable platforms
run: flutter config --enable-linux-desktop
- name: 📦 Get dependencies
Expand All @@ -299,11 +327,11 @@ jobs:
flutter build linux -v --release --dart-define=flavor=production
- name: Copy nessessary files
run: |
cp images/logo.svg build/linux/x64/release/bundle/dev.linwood.butterfly.svg
mkdir -p build/linux/x64/release/bundle/usr/share
cp -r linux/debian/usr/share build/linux/x64/release/bundle/usr
cp images/logo.svg build/linux/${{ matrix.arch.dir }}/release/bundle/dev.linwood.butterfly.svg
mkdir -p build/linux/${{ matrix.arch.dir }}/release/bundle/usr/share
cp -r linux/debian/usr/share build/linux/${{ matrix.arch.dir }}/release/bundle/usr
- name: Compress Flutter build
run: tar -C build/linux/x64/release/bundle -czf linwood-butterfly-linux-portable-x86_64.tar.gz .
run: tar -C build/linux/${{ matrix.arch.dir }}/release/bundle -czf linwood-butterfly-linux-portable-${{ matrix.arch.name }}.tar.gz .
# - name: Install flatpak
# run: |
# sudo apt-get update
Expand All @@ -326,8 +354,8 @@ jobs:
- name: Archive old portable
uses: actions/upload-artifact@v4
with:
name: linux-alternative-portable
path: app/build/linux/x64/release/bundle
name: linux-${{ matrix.arch.name }}-alternative-portable
path: app/build/linux/${{ matrix.arch.name }}/release/bundle
build-macos:
runs-on: macos-latest
defaults:
Expand Down Expand Up @@ -486,21 +514,35 @@ jobs:
path: windows-build/
- uses: actions/download-artifact@v4
with:
name: linux-build
path: linux-build/
name: linux-x86_64-build
path: linux-x86_64-build/
- uses: actions/download-artifact@v4
with:
name: linux-x86_64-deb
- uses: actions/download-artifact@v4
with:
name: linux-x86_64-rpm
- uses: actions/download-artifact@v4
with:
name: linux-x86_64-appimage
- uses: actions/download-artifact@v4
with:
name: linux-x86_64-alternative-portable
path: linux-x86_64-alternative-portable/
- uses: actions/download-artifact@v4
with:
name: linux-deb
name: linux-arm64-build
path: linux-arm64-build/
- uses: actions/download-artifact@v4
with:
name: linux-rpm
name: linux-arm64-deb
- uses: actions/download-artifact@v4
with:
name: linux-appimage
name: linux-arm64-rpm
- uses: actions/download-artifact@v4
with:
name: linux-alternative-portable
path: linux-alternative-portable/
name: linux-arm64-alternative-portable
path: linux-arm64-alternative-portable/
- uses: actions/download-artifact@v4
with:
name: windows-setup
Expand All @@ -516,8 +558,10 @@ jobs:
- name: 📦 Zip artifacts
run: |
zip -r linwood-butterfly-windows-x86_64.zip windows-build/*
tar -C linux-build -czf linwood-butterfly-linux-x86_64.tar.gz .
tar -C linux-alternative-portable -czf linwood-butterfly-linux-alternative-x86_64.tar.gz .
tar -C linux-x86_64-build -czf linwood-butterfly-linux-x86_64.tar.gz .
tar -C linux-arm64-build -czf linwood-butterfly-linux-arm64.tar.gz .
tar -C linux-x86_64-alternative-portable -czf linwood-butterfly-linux-alternative-x86_64.tar.gz .
tar -C linux-arm64-alternative-portable -czf linwood-butterfly-linux-alternative-arm64.tar.gz .
- name: Configure git
if: ${{ github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/main' }}
run: |
Expand Down Expand Up @@ -557,6 +601,10 @@ jobs:
linwood-butterfly-linux-x86_64.deb
linwood-butterfly-linux-x86_64.rpm
linwood-butterfly-linux-x86_64.AppImage
linwood-butterfly-linux-arm64.tar.gz
linwood-butterfly-linux-alternative-arm64.tar.gz
linwood-butterfly-linux-arm64.deb
linwood-butterfly-linux-arm64.rpm
linwood-butterfly-macos.zip
linwood-butterfly-macos.dmg
linwood-butterfly-android.apk
Expand All @@ -579,6 +627,10 @@ jobs:
linwood-butterfly-linux-x86_64.deb
linwood-butterfly-linux-x86_64.rpm
linwood-butterfly-linux-x86_64.AppImage
linwood-butterfly-linux-arm64.tar.gz
linwood-butterfly-linux-alternative-arm64.tar.gz
linwood-butterfly-linux-arm64.deb
linwood-butterfly-linux-arm64.rpm
linwood-butterfly-macos.zip
linwood-butterfly-macos.dmg
linwood-butterfly-android.apk
Expand All @@ -602,6 +654,10 @@ jobs:
linwood-butterfly-linux-x86_64.deb
linwood-butterfly-linux-x86_64.rpm
linwood-butterfly-linux-x86_64.AppImage
linwood-butterfly-linux-arm64.tar.gz
linwood-butterfly-linux-alternative-arm64.tar.gz
linwood-butterfly-linux-arm64.deb
linwood-butterfly-linux-arm64.rpm
linwood-butterfly-macos.zip
linwood-butterfly-macos.dmg
linwood-butterfly-android.apk
Expand Down
14 changes: 11 additions & 3 deletions app/linux/rpm/linwood-butterfly.spec
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ Name: linwood-butterfly
Version: 1.0.0
Release: 1%{?dist}
Summary: Powerful, minimalistic, cross-platform, opensource note-taking app
BuildArch: x86_64
BuildArch: %{_target_cpu}
URL: https://github.com/LinwoodDev/Butterfly
License: AGPLv3
Source0: %{name}-%{version}.tar.gz

Requires: bash

%description
Butterfly is a note app where your ideas come first. You can paint, add texts and export them easily on every device. This app works on android, windows, linux and in the web.
Butterfly is a note app where your ideas come first. You can paint, add texts and export them easily on every device. This app works on Android, Windows, Linux, and in the web.

%prep
%setup -q
Expand All @@ -20,11 +20,17 @@ rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/%{_bindir}
mkdir -p $RPM_BUILD_ROOT/%{_datadir}/%{name}
mkdir -p $RPM_BUILD_ROOT/%{_datadir}/pixmaps

# Copy binaries and architecture-specific files
cp %{name} $RPM_BUILD_ROOT/%{_datadir}/%{name}
cp -R lib $RPM_BUILD_ROOT/%{_datadir}/%{name}
cp -R data $RPM_BUILD_ROOT/%{_datadir}/%{name}

# Create symlink for the binary
ln -s %{_datadir}/%{name}/%{name} $RPM_BUILD_ROOT/%{_bindir}/%{name}
desktop-file-install %{name}.desktop

# Install the desktop file
desktop-file-install --dir=$RPM_BUILD_ROOT/usr/share/applications %{name}.desktop

%clean
rm -rf $RPM_BUILD_ROOT
Expand All @@ -33,3 +39,5 @@ rm -rf $RPM_BUILD_ROOT
%{_bindir}/%{name}
%{_datadir}/%{name}
/usr/share/applications/

%changelog
48 changes: 40 additions & 8 deletions app/scripts/build-rpm.sh
Original file line number Diff line number Diff line change
@@ -1,40 +1,72 @@
#!/bin/bash

# Default values for architecture
DIRECTORY_ARCH="x64" # Default directory name
BINARY_ARCH="x86_64" # Default binary name
RPM_ARCH="x86_64" # Default RPM architecture

# Parse command-line arguments
while getopts "d:b:" opt; do
case $opt in
d) DIRECTORY_ARCH="$OPTARG" ;; # Set the directory architecture
b) BINARY_ARCH="$OPTARG" ;; # Set the binary architecture
*)
echo "Usage: $0 [-d directory_arch] [-b binary_arch]"
exit 1
;;
esac
done
RPM_ARCH=$BINARY_ARCH

# Normalize architecture names for RPM
if [ "$RPM_ARCH" == "arm64" ]; then
RPM_ARCH="aarch64"
fi
# Read version from pubspec
BUTTERFLY_VERSION_REGEX="version:\s(.+)\+(.+)"
[[ $(grep -E "${BUTTERFLY_VERSION_REGEX}" pubspec.yaml) =~ ${BUTTERFLY_VERSION_REGEX} ]]
BUTTERFLY_VERSION="${BASH_REMATCH[1]}"

# Replace - with ~ to match RPM versioning
RPM_VERSION=$(echo $BUTTERFLY_VERSION | sed 's/-/~/g')
CURRENT_DIR=$(pwd)
echo "Building Butterfly $RPM_VERSION"
echo "Building Butterfly $RPM_VERSION for $DIRECTORY_ARCH/$BINARY_ARCH ($RPM_ARCH)"

# Clean and set up build directories
rm -rf build/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
mkdir -p build/{BUILD,RPMS,SOURCES,SPECS,SRPMS}

# Copy files
cp linux/rpm/linwood-butterfly.spec build/SPECS/linwood-butterfly.spec
cp -r build/linux/x64/release/bundle build/SOURCES/linwood-butterfly-$RPM_VERSION
cp -r build/linux/${DIRECTORY_ARCH}/release/bundle build/SOURCES/linwood-butterfly-$RPM_VERSION
chmod 755 build/SOURCES/linwood-butterfly-$RPM_VERSION/butterfly
mv build/SOURCES/linwood-butterfly-$RPM_VERSION/butterfly build/SOURCES/linwood-butterfly-$RPM_VERSION/linwood-butterfly
cp linux/rpm/linwood-butterfly.desktop build/SOURCES/linwood-butterfly-$RPM_VERSION/linwood-butterfly.desktop
# Change second line of spec file Version: to match version

# Update .spec file with the correct version
sed -i "2s/.*/Version: $RPM_VERSION/" build/SPECS/linwood-butterfly.spec
# Create tar

# Create tarball
cd build/SOURCES/
# Fix .so files using patchelf
cd linwood-butterfly-$RPM_VERSION/lib
for file in *.so; do
PATCHELF_OUTPUT=$(patchelf --print-rpath $file)
PATCHELF_OUTPUT=$(patchelf --print-rpath "$file")
echo "Checking $file: $PATCHELF_OUTPUT"
# Skip file if PATCHELF_OUTPUT does not contain CURRENT_DIR
if [[ ! $PATCHELF_OUTPUT =~ $CURRENT_DIR ]]; then
echo "Skipping $file"
continue
fi
echo "Fixing $file"
patchelf --set-rpath '$ORIGIN' $file
patchelf --set-rpath '$ORIGIN' "$file"
done
cd ../../
tar --create --file linwood-butterfly-$RPM_VERSION.tar.gz linwood-butterfly-$RPM_VERSION
cd ../../

# Build RPM
QA_RPATHS=$[ 0x0001|0x0010 ] rpmbuild -bb build/SPECS/linwood-butterfly.spec --define "_topdir $(pwd)/build"
# Copy RPM to build folder
cp build/RPMS/x86_64/linwood-butterfly-*.rpm build/linwood-butterfly-linux-x86_64.rpm

# Copy the RPM to the build folder
cp build/RPMS/${RPM_ARCH}/linwood-butterfly-*.rpm build/linwood-butterfly-linux-${BINARY_ARCH}.rpm

0 comments on commit 2aa09bd

Please sign in to comment.