Hello Snapcrafters,
I want to cross compile mygpsd snap containing gpsd.
Host Machine Arch: x86-64
Target Machine Arch: arm64
Problem 1:
I have mygpsd snap with gpsd3.20 working fine in UC20. I want to use the same gpsd in UC22.
While Building mygpsd snap for UC22 using gpsd=3.20, I got following error
2023-05-09 11:18:39.933 :: E: Can not find a package 'gpsd:arm64' with version '3.20-8'
2023-05-09 11:18:39.933 :: E: Unable to find a source package for gpsd:arm64=3.20-8
Attaching snapcraft-p1.yaml with this bug for your reference.
Problem 2:
When I use gpsd3.22 to build mygpsd for UC22, snap is getting generated without any issue. But the architecture for the binaries got pulled from gpsd repo(ex. cgps) is in x86-64 format.
Attaching snapcraft-p2.yaml with this bug for your reference.
The motto to mention these two problems is, I want to get cgps binary in aarch64 format as I was getting when I built snap for UC20.
cgps - UC20
khalid@ubuntu:bin$ file cgps cgps: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, BuildID[sha1]=b6dc758f122c3d9397bed2c8b33b2cd8257852b2, for GNU/Linux 3.7.0, stripped
cgps - UC22
khalid@ubuntu:bin$ file cgps cgps: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=d01ce01d1d0f95365b77d4a21f981dd8c489f846, for GNU/Linux 3.2.0, stripped
NOTE: location_patches in source are just some patches to overcome gpsd issue.
snapcraft-p1.yaml
name: mygpsd
base: core22
version: '0.1'
summary: Construct gpsd tar archive with serial patch
description: |
Construct gpsd tar archive with serial patch
grade: devel
confinement: devmode
architectures:
- build-on: [arm64, amd64]
build-for: arm64
parts:
gpsd-tar:
source: $SNAPCRAFT_PROJECT_DIR/location_patches
plugin: nil
build-environment:
- CFLAGS: "-I$SNAPCRAFT_PROJECT_DIR/../../../src/system/core/include \
-I$SNAPCRAFT_PROJECT_DIR/../../../kernel-headers/usr/include/ \
-I/usr/lib/aarch64-linux-gnu/dbus-1.0/include"
- CPPFLAGS: "-I$SNAPCRAFT_PROJECT_DIR/../../../src/system/core/include \
-I/usr/lib/aarch64-linux-gnu/dbus-1.0/include"
- LDFLAGS: "-L/usr/local/lib/ \
-L/usr/lib/aarch64-linux-gnu"
override-pull: |
craftctl default
cd $CRAFT_PART_SRC
echo "Creating gpsd tar archive..."
# section to fetch gpsd source and apply patch
if [ ! -d "gpsd-3.20" ]; then
apt-get -qq source gpsd:${CRAFT_TARGET_ARCH}=3.20-8
fi
cd gpsd-3.20
if [ ${SNAP_ARCH} == "amd64" ]; then
patch < $SNAPCRAFT_PART_SRC/sizeof_time_t_cross_compile_val.patch
fi
mv $CRAFT_PART_SRC/scons-option-cache .scons-option-cache
patch < $CRAFT_PART_SRC/set_ioctl.patch
patch < $CRAFT_PART_SRC/chrony_sock_path.patch
override-build: |
# section to build gpsd
cd $CRAFT_PART_BUILD/gpsd-3.20
scons sysroot=/ prefix=$CRAFT_PART_INSTALL
scons install
override-prime: |
craftctl default
cd $CRAFT_PRIME
tar -cf $CRAFT_PROJECT_DIR/gpsd_3.20.tar .
mkdir -p $CRAFT_PROJECT_DIR/../../../out
mv $CRAFT_PROJECT_DIR/gpsd_3.20.tar $CRAFT_PROJECT_DIR/../../../out/
build-packages:
- dpkg-dev
- devscripts
- scons
- dkms:${CRAFT_TARGET_ARCH}
- libncurses-dev:${CRAFT_TARGET_ARCH}
- libssl-dev:${CRAFT_TARGET_ARCH}
- libelf-dev:${CRAFT_TARGET_ARCH}
- libudev-dev:${CRAFT_TARGET_ARCH}
- libpci-dev:${CRAFT_TARGET_ARCH}
- libiberty-dev:${CRAFT_TARGET_ARCH}
- libbluetooth-dev:${CRAFT_TARGET_ARCH}
- libtinfo-dev:${CRAFT_TARGET_ARCH}
- libusb-1.0-0-dev:${CRAFT_TARGET_ARCH}
- libdbus-1-dev:${CRAFT_TARGET_ARCH}
snapcraft-p2.yaml
name: mygpsd
base: core22
version: '0.1'
summary: Construct gpsd tar archive with serial patch
description: |
Construct gpsd tar archive with serial patch
grade: devel
confinement: devmode
architectures:
- build-on: [arm64, amd64]
build-for: arm64
parts:
gpsd-tar:
source: $SNAPCRAFT_PROJECT_DIR/location_patches
plugin: nil
build-environment:
- CFLAGS: "-I$SNAPCRAFT_PROJECT_DIR/../../../src/system/core/include \
-I$SNAPCRAFT_PROJECT_DIR/../../../kernel-headers/usr/include/ \
-I/usr/lib/aarch64-linux-gnu/dbus-1.0/include"
- CPPFLAGS: "-I$SNAPCRAFT_PROJECT_DIR/../../../src/system/core/include \
-I/usr/lib/aarch64-linux-gnu/dbus-1.0/include"
- LDFLAGS: "-L/usr/local/lib/ \
-L/usr/lib/aarch64-linux-gnu"
override-pull: |
craftctl default
cd $CRAFT_PART_SRC
echo "Creating gpsd tar archive..."
# section to fetch gpsd source and apply patch
if [ ! -d "gpsd-3.22" ]; then
apt-get -qq source gpsd:${CRAFT_TARGET_ARCH}=3.22-4
fi
cd gpsd-3.22
mv $CRAFT_PART_SRC/scons-option-cache .scons-option-cache
override-build: |
# section to build gpsd
cd $CRAFT_PART_BUILD/gpsd-3.22
scons sysroot=/ prefix=$CRAFT_PART_INSTALL
scons install
override-prime: |
craftctl default
cd $CRAFT_PRIME
tar -cf $CRAFT_PROJECT_DIR/gpsd_3.22.tar .
mkdir -p $CRAFT_PROJECT_DIR/../../../out
mv $CRAFT_PROJECT_DIR/gpsd_3.22.tar $CRAFT_PROJECT_DIR/../../../out/
build-packages:
- dpkg-dev
- devscripts
- scons
- dkms:${CRAFT_TARGET_ARCH}
- libncurses-dev:${CRAFT_TARGET_ARCH}
- libssl-dev:${CRAFT_TARGET_ARCH}
- libelf-dev:${CRAFT_TARGET_ARCH}
- libudev-dev:${CRAFT_TARGET_ARCH}
- libpci-dev:${CRAFT_TARGET_ARCH}
- libiberty-dev:${CRAFT_TARGET_ARCH}
- libbluetooth-dev:${CRAFT_TARGET_ARCH}
- libtinfo-dev:${CRAFT_TARGET_ARCH}
- libusb-1.0-0-dev:${CRAFT_TARGET_ARCH}
- libdbus-1-dev:${CRAFT_TARGET_ARCH}