Skip to content

Commit fb7c591

Browse files
authored
Feat: Native build on linux arm64 runner (#1437)
* Feat: Native build on linux arm runner * Fix: Workaround flutter-action bug on arm64 linux * Chore: Reduce linux arm64 build timeout
1 parent 7af6b65 commit fb7c591

File tree

1 file changed

+36
-112
lines changed

1 file changed

+36
-112
lines changed

.github/workflows/linux.yml

Lines changed: 36 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,21 @@ jobs:
9797

9898
build-flutter-app-arm64:
9999
name: Build Flutter app (arm64)
100-
runs-on: ubuntu-latest
100+
runs-on: ubuntu-24.04-arm
101101
permissions:
102102
contents: write
103-
packages: write
104-
timeout-minutes: 120
103+
timeout-minutes: 20
105104
steps:
106105
- name: Checkout code
107106
uses: actions/checkout@v4
108107

108+
- name: Install apt dependencies
109+
uses: awalsh128/cache-apt-pkgs-action@latest
110+
with:
111+
packages: libgtk-3-dev libx11-dev pkg-config cmake ninja-build libblkid-dev libsecret-1-dev libjsoncpp-dev ghostscript libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libunwind-dev webkit2gtk-4.1-dev
112+
version: 1.0
113+
execute_install_scripts: true
114+
109115
- name: Setup cache
110116
uses: actions/cache@v4
111117
with:
@@ -114,124 +120,42 @@ jobs:
114120
key: ${{ runner.OS }}-saberarm64-${{ hashFiles('**/pubspec.lock') }}-${{ hashFiles('**/*.dart') }}
115121
restore-keys: |
116122
${{ runner.OS }}-saberarm64-
123+
124+
- name: Remove proprietary dependencies
125+
run: ./patches/remove_proprietary_dependencies.sh
117126

118-
- name: Build Linux (arm64)
119-
uses: uraimo/run-on-arch-action@v2
127+
- name: Setup Flutter
128+
uses: subosito/flutter-action@v2
120129
with:
121-
arch: aarch64
122-
distro: ubuntu_latest
123-
githubToken: ${{ github.token }}
124-
125-
setup: |
126-
mkdir -p "${PWD}/AppDir"
127-
mkdir -p "${PWD}/build/pub_cache"
128-
dockerRunArgs: |
129-
--volume "${PWD}/AppDir:/AppDir"
130-
131-
install: |
132-
quiet () {
133-
output=`"$@" 2>&1` || echo $output
134-
}
135-
unsudo () {
136-
sudo -u nonroot env "PATH=$PATH" "CARGO_HOME=$CARGO_HOME" "RUSTUP_HOME=$RUSTUP_HOME" PUB_CACHE="$PUB_CACHE" "$@"
137-
}
138-
139-
echo Installing dependencies
140-
quiet apt-get update -qq -y
141-
quiet apt-get install -qq -y \
142-
sudo \
143-
bash curl file git unzip xz-utils zip \
144-
clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev \
145-
libsecret-1-dev libjsoncpp-dev webkit2gtk-4.1-dev \
146-
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libunwind-dev
147-
148-
echo Creating nonroot user
149-
useradd -m -d /home/nonroot -s /bin/bash nonroot
150-
echo 'export PATH="$PATH:/opt/flutter/bin"' >> /home/nonroot/.bashrc
151-
echo 'export PATH="$PATH:/opt/cargo/bin"' >> /home/nonroot/.bashrc
152-
echo 'export CARGO_HOME=/opt/cargo' >> /home/nonroot/.bashrc
153-
echo 'export RUSTUP_HOME=/opt/rustup' >> /home/nonroot/.bashrc
154-
echo 'export PUB_CACHE=build/pub_cache' >> /home/nonroot/.bashrc
155-
export PATH="$PATH:/opt/flutter/bin"
156-
export PATH="$PATH:/opt/cargo/bin"
157-
export CARGO_HOME=/opt/cargo
158-
export RUSTUP_HOME=/opt/rustup
159-
export PUB_CACHE=build/pub_cache
160-
161-
echo Installing Flutter
162-
if [ -z "$(which flutter)" ]; then
163-
echo Flutter not installed, installing...
164-
mkdir -p /opt/flutter
165-
chown -R nonroot /opt/flutter
166-
unsudo git clone https://github.com/flutter/flutter.git -b stable /opt/flutter
167-
else
168-
echo Flutter already installed, updating...
169-
chown -R nonroot /opt/flutter
170-
unsudo flutter upgrade
171-
fi
172-
173-
echo flutter doctor
174-
unsudo flutter doctor -v
175-
176-
echo Precaching Flutter
177-
unsudo flutter precache --no-universal --linux
178-
179-
echo Installing Rust
180-
mkdir -p $CARGO_HOME
181-
mkdir -p $RUSTUP_HOME
182-
mkdir -p "$RUSTUP_HOME/tmp"
183-
chown -R nonroot $CARGO_HOME
184-
chown -R nonroot $RUSTUP_HOME
185-
unsudo curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -q -y
186-
chmod -R a+rw $CARGO_HOME
187-
chmod -R a+rw $RUSTUP_HOME
188-
unsudo ls -l $CARGO_HOME/bin
189-
unsudo which rustup
190-
191-
run: |
192-
unsudo () {
193-
sudo -u nonroot env "PATH=$PATH" "CARGO_HOME=$CARGO_HOME" "RUSTUP_HOME=$RUSTUP_HOME" PUB_CACHE="$PUB_CACHE" "$@"
194-
}
195-
196-
echo Setting up environment
197-
chown -R nonroot .
198-
chown -R nonroot /opt/flutter
199-
chown -R nonroot /opt/cargo
200-
export PATH="$PATH:/opt/flutter/bin"
201-
export PATH="$PATH:/opt/cargo/bin"
202-
export CARGO_HOME=/opt/cargo
203-
export RUSTUP_HOME=/opt/rustup
204-
export PUB_CACHE=build/pub_cache
205-
206-
echo Removing proprietary dependencies
207-
./patches/remove_proprietary_dependencies.sh
208-
209-
echo Disabling Flutter CLI animations
210-
unsudo flutter config --no-cli-animations
211-
212-
echo flutter pub get
213-
unsudo flutter pub get
214-
215-
echo Verifying that rustup is installed
216-
unsudo which rustup
217-
218-
echo Building
219-
unsudo flutter build linux \
220-
--target-platform linux-arm64 \
221-
--dart-define=DIRTY=${{ !startsWith(github.ref, 'refs/tags/') }}
222-
mv build/linux/arm64/release/bundle/* /AppDir/
223-
chown -R nonroot /AppDir/
224-
chmod -R a+rw /AppDir/
225-
chmod a+x /AppDir/saber
130+
# Workaround for https://github.com/subosito/flutter-action/issues/345, needs to be removed when fixed
131+
channel: master
132+
flutter-version: 3.29.0
133+
cache: true
134+
cache-key: 'flutter-:os:-:channel:-:version:-:arch:'
135+
136+
- name: Disable Flutter CLI animations
137+
run: flutter config --no-cli-animations
138+
139+
- run: flutter pub get
140+
141+
- name: Build Linux (x86_64)
142+
run: |
143+
flutter build linux \
144+
--target-platform linux-arm64 \
145+
--dart-define=DIRTY=$DIRTY
146+
env:
147+
DIRTY: ${{ !startsWith(github.ref, 'refs/tags/') }}
226148

227149
- name: Compress Flutter build
228150
id: compress
229151
run: |
230152
buildName=$(grep -oP "(?<=buildName = ').*(?=')" lib/data/version.dart)
231153
archiveName="Saber_v${buildName}_Linux_arm64.tar.gz"
232154
echo "archiveName=$archiveName" >> $GITHUB_OUTPUT
233-
234-
sudo chown -R $USER:$USER .
155+
156+
mkdir -p AppDir
157+
mv build/linux/arm64/release/bundle/* AppDir
158+
chmod +x AppDir/saber
235159
236160
install -Dm644 flatpak/com.adilhanney.saber.metainfo.xml -t AppDir/share/metainfo/
237161
install -Dm644 flatpak/com.adilhanney.saber.metainfo.xml -t AppDir/usr/share/metainfo/

0 commit comments

Comments
 (0)