← Back to issue list

Snapcraft doesn't honor ${pcfiledir} in pkgconfig files

View original Github issue

Metadata

Project
snapcraft
Number
#5158
Type
issue
State
closed
Author
sergio-costas
Labels
Created
Updated
Closed

Current evaluation

Resolved by merging snapcraft#5157 for Core20/Core22 and craft-parts#977 for Core24+. The patches stop Snapcraft from incorrectly prepending build paths to the ${pcfiledir} variable in pkgconfig files, preserving relocatable paths.

Suggested action:

No scores available.

Issue body

### Bug Description Pkgconfig defines the ${pcfiledir} variable as "the path of the .pc file". It is designed to allow to create relocatable .pc files. For example, the .pc file for librsvg library version 2.59.1 begins with: ``` prefix=${pcfiledir}/../../.. ``` Since the file is stored at `/usr/lib/x86_64-linux-gnu/pkg-config`, the result is that `prefix` is `/usr`. Unfortunately, snapcraft doesn't honor it, and prepends the $CRAFT_STAGE path during build, which breaks it. When the `prefix` begins with `${pcfiledir}`, it should be kept unmodified. Patch https://github.com/canonical/snapcraft/pull/5157 fixes Core20 and Core22 snaps, and https://github.com/canonical/craft-parts/pull/977 fixes Core24 and newer. ### To Reproduce Just downloading the current stable version of gnome-46-2404 shows it. ### Environment Using LXD on Ubuntu 24.10. ### snapcraft.yaml Building this test snap shows the problem. After build, unsquash the snap file and check the file `squashfs-root/usr/lib/x86_64-linux-gnu/pkgconfig/librsvg-2.0.pc`. * wrong value: prefix=/root/stage${pcfiledir}/../../.. * right value: prefix=${pcfiledir}/../../.. ```yaml name: test-pcfiledir version: 1.0 summary: Tests pcfiledir statement preservation description: | This is a test for the ${pcfiledir} statement in pkgconfig files. After build, unsquash the snap file and check the file `squashfs-root/usr/lib/x86_64-linux-gnu/pkgconfig/librsvg-2.0.pc`. * wrong value: prefix=/root/stage${pcfiledir}/../../.. * right value: prefix=${pcfiledir}/../../.. confinement: strict grade: stable base: core24 # if the base is changed, the BUILDENV part must be updated parts: librsvg: source: https://gitlab.gnome.org/GNOME/librsvg.git #source-tag: '2.59.1' # they left the odd->unstable even->stable scheme, and now tags are stable # ext:updatesnap # version-format: # no-9x-revisions: true source-depth: 1 plugin: meson meson-parameters: - --prefix=/usr - -Doptimization=3 - -Ddebug=true - -Dintrospection=enabled - -Dvala=enabled - -Dpixbuf=enabled - -Dpixbuf-loader=enabled - -Ddocs=disabled - -Dtests=false build-environment: - ACLOCAL_PATH: $CRAFT_STAGE/usr/share/aclocal - XDG_DATA_DIRS: $CRAFT_STAGE/usr/share:/usr/share - LD_LIBRARY_PATH: "$CRAFT_STAGE/usr/lib:\ $CRAFT_STAGE/usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR\ ${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" - PKG_CONFIG_PATH: "$CRAFT_STAGE/usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR/pkgconfig:\ $CRAFT_STAGE/usr/lib/pkgconfig:\ $CRAFT_STAGE/usr/share/pkgconfig\ ${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}" - CRAFT_EXT_CORE_LEVEL: core24 build-packages: - meson - cmake - libcairo2-dev - libharfbuzz-dev - libxml2-dev - libpango1.0-dev - gobject-introspection - ninja-build - libssl-dev - curl - valac - libgdk-pixbuf-2.0-dev override-pull: | craftctl default # cargo version in .deb is too old curl https://sh.rustup.rs -sSf > cargo.sh sh ./cargo.sh -y export PATH=$PATH:$HOME/.cargo/bin ~/.cargo/bin/cargo install cargo-c cp ~/.cargo/bin/* /usr/local/bin ``` ### Relevant log output ```shell This is the generated .pc file prefix=/root/stage${pcfiledir}/../../.. includedir=${prefix}/include libdir=${prefix}/lib/x86_64-linux-gnu Name: librsvg Description: library that renders svg files Version: 2.59.1 Requires: cairo >= 1.18.0, cairo-gobject >= 1.18.0, cairo-png >= 1.18.0, freetype2 >= 20.0.14, gdk-pixbuf-2.0 >= 2.20, gio-2.0 >= 2.24.0, glib-2.0 >= 2.50.0, harfbuzz >= 2.0.0, libxml-2.0 >= 2.9.0, pangocairo >= 1.50.0, pangoft2 >= 1.50.0, gmodule-2.0 >= 2.50.0 Libs: -L${libdir} -lrsvg-2 Libs.private: -lm Cflags: -I${includedir}/librsvg-2.0 ``` ### Additional context _No response_

Evaluation history

Date Model Scores Action Summary
qwen/qwen3.6-35b-a3b Resolved by merging snapcraft#5157 for Core20/Core22 and craft-parts#977 for Core24+. The patches stop Snapcraft from incorrectly prepending build paths to the ${pcfiledir} variable in pkgconfig files, preserving relocatable paths.
qwen/qwen3.6-35b-a3b Resolved by merging snapcraft#5157 and craft-parts#977. Snapcraft now correctly preserves the ${pcfiledir} variable in pkgconfig files instead of prepending the stage path, fixing relocatable package builds for Core20 through Core24+.
qwen3.6-35b-a3b-mtp-q6 Fixed via snapcraft#5157 and craft-parts#977. These patches preserve ${pcfiledir} in pkgconfig files for Core20/22 and Core24+ bases. Issue closed after the craft-parts PR was merged.
qwen3.6-35b-a3b-mtp-q6 Resolved by merging snapcraft#5157 and craft-parts#977. These changes prevent snapcraft from incorrectly prepending build paths to the ${pcfiledir} variable in pkgconfig files, fixing relocatable .pc handling for Core20/22 and Core24+ bases.

Update history

No update history recorded yet.

Related issues

No related issues found above the similarity threshold.