← 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

Fixed ${pcfiledir} handling via snapcraft#5157 (0a7f753ac) for Core20/Core22 and craft-parts#977 (b4a09d95) for Core24+.

Resolution: closed resolved

Reason: Both resolving PRs were merged: snapcraft#5157 at 0a7f753ac and craft-parts#977 at b4a09d95. Together they preserve relocatable pkg-config prefixes beginning with ${pcfiledir}.

Evaluated by: mr-cal-bot

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
stealth/space-bunny-alpha — closed resolved Fixed ${pcfiledir} handling via snapcraft#5157 (0a7f753ac) for Core20/Core22 and craft-parts#977 (b4a09d95) for Core24+.
stealth/space-bunny-alpha — closed resolved Fixed ${pcfiledir} handling in pkg-config files: snapcraft#5157 covers Core20/Core22 and craft-parts#977 covers Core24+, preserving relocatable paths instead of prepending the stage directory.
stealth/space-bunny-alpha — closed resolved Fixed relocatable pkg-config handling: Snapcraft PR #5157 (0a7f753ac) covers Core20/22, and craft-parts PR #977 (b4a09d95) covers Core24+, preserving ${pcfiledir} prefixes.
stealth/space-bunny-alpha — closed resolved Fixed ${pcfiledir} handling: merged Snapcraft PR #5157 for Core20/Core22 and craft-parts PR #977 for Core24+, preventing stage paths from being prepended to relocatable pkgconfig files.
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.

Update history

No update history recorded yet.

Related work

Related issues

Issue Project State Summary Similarity
#1604472 snapcraft changing pkgconfig .pc prefix is creating conflicts between parts snapcraft (launchpad) closed Resolved conflicting pkg-config prefix rewriting through snapcore/snapcraft PR #676, which a maintainer linked as the issue's resolution.
77%
#977 fix: Honor the ${pcfiledir} entries in pkgconfig craft-parts merged Merged as b4a09d95, preserving ${pcfiledir}-based prefixes so relocatable pkg-config files remain valid; released in Craft Parts 2.4.1.
74%
#251 repo: fix_pkg_config removes prefixes from staged snap's .pc files. craft-parts merged Merged in craft-parts#251 via 7c8140f4 (commit 359d377a), stripping staged build paths from .pc prefixes before applying the new prefix, addressing LP #1916281.
74%
#1548232 Snapcraft messes with include path precedence in unhealthy ways snapcraft (launchpad) closed Include-path precedence was corrected by pkg-config work in canonical/snapcraft#429 (commit a117bd273), with a regression test added.
72%
#3848 repo: fix_pkg_config removes prefixes from staged snap's .pc files. snapcraft merged Merged in snapcraft#3848 as commit 2dadaa6da, fixing fix_pkg_config to remove build-stage prefixes from staged snaps' pkg-config .pc files.
71%
#1916281 pkgconfig files end up with double `/root/stage` in prefix snapcraft (launchpad) closed Fixed by snapcraft PR #3848 (commit 2dadaa6da), which removes staged-snap prefixes from .pc files; the reporter confirmed that Snapcraft 7.1.1 on stable fixes it.
70%