Skip to content

Commit 91fefdb

Browse files
committed
fix: enhance cross-compilation support for Linux arm64 in build scripts
1 parent c928de7 commit 91fefdb

3 files changed

Lines changed: 37 additions & 6 deletions

File tree

.github/workflows/build.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,20 @@ jobs:
6161
with:
6262
version: 0.11.0
6363

64-
- name: Install PC/SC development libraries (Linux)
65-
if: matrix.goos == 'linux'
64+
- name: Install PC/SC development libraries (Linux amd64)
65+
if: matrix.goos == 'linux' && matrix.goarch == 'amd64'
6666
run: sudo apt-get update && sudo apt-get install -y libpcsclite-dev
6767

68+
- name: Install PC/SC development libraries (Linux arm64 cross-compile)
69+
if: matrix.goos == 'linux' && matrix.goarch == 'arm64'
70+
run: |
71+
sudo dpkg --add-architecture arm64
72+
sudo sed -i 's/^deb /deb [arch=amd64] /' /etc/apt/sources.list
73+
echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports $(lsb_release -cs) main restricted universe multiverse" | sudo tee /etc/apt/sources.list.d/arm64.list
74+
echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports $(lsb_release -cs)-updates main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list.d/arm64.list
75+
sudo apt-get update
76+
sudo apt-get install -y libpcsclite-dev:arm64
77+
6878
- name: Build
6979
env:
7080
BUILD_VERSION: ${{ github.ref_type == 'tag' && github.ref_name || 'dev' }}

.github/workflows/release.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,20 @@ jobs:
4646
with:
4747
version: 0.11.0
4848

49-
- name: Install PC/SC development libraries (Linux)
50-
if: matrix.goos == 'linux'
49+
- name: Install PC/SC development libraries (Linux amd64)
50+
if: matrix.goos == 'linux' && matrix.goarch == 'amd64'
5151
run: sudo apt-get update && sudo apt-get install -y libpcsclite-dev
5252

53+
- name: Install PC/SC development libraries (Linux arm64 cross-compile)
54+
if: matrix.goos == 'linux' && matrix.goarch == 'arm64'
55+
run: |
56+
sudo dpkg --add-architecture arm64
57+
sudo sed -i 's/^deb /deb [arch=amd64] /' /etc/apt/sources.list
58+
echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports $(lsb_release -cs) main restricted universe multiverse" | sudo tee /etc/apt/sources.list.d/arm64.list
59+
echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports $(lsb_release -cs)-updates main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list.d/arm64.list
60+
sudo apt-get update
61+
sudo apt-get install -y libpcsclite-dev:arm64
62+
5363
- name: Build
5464
env:
5565
BUILD_VERSION: ${{ github.ref_name }}

scripts/build.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,19 @@ if [ "$TARGET_OS" != "$CURRENT_OS" ] || [ "$TARGET_ARCH" != "$CURRENT_ARCH" ]; t
4242
# Use Zig for Linux cross-compilation if ZIG_TARGET is set
4343
if [ -n "$ZIG_TARGET" ]; then
4444
echo " Using Zig target: $ZIG_TARGET"
45-
export CC="zig cc -target $ZIG_TARGET"
46-
export CXX="zig c++ -target $ZIG_TARGET"
45+
46+
# Set library search paths for cross-compilation
47+
if [ "$TARGET_ARCH" = "arm64" ] && [ "$TARGET_OS" = "linux" ]; then
48+
SYSROOT="/usr/aarch64-linux-gnu"
49+
LIB_PATH="/usr/lib/aarch64-linux-gnu"
50+
export CC="zig cc -target $ZIG_TARGET --sysroot=$SYSROOT -I/usr/include -L$LIB_PATH"
51+
export CXX="zig c++ -target $ZIG_TARGET --sysroot=$SYSROOT -I/usr/include -L$LIB_PATH"
52+
export PKG_CONFIG_PATH="$LIB_PATH/pkgconfig"
53+
export CGO_LDFLAGS="-L$LIB_PATH"
54+
else
55+
export CC="zig cc -target $ZIG_TARGET"
56+
export CXX="zig c++ -target $ZIG_TARGET"
57+
fi
4758
fi
4859

4960
# macOS can cross-compile between arm64/amd64 with native clang

0 commit comments

Comments
 (0)