Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sergio-costas opened this issue Nov 27, 2024 · 10 comments · May be fixed by #5157 or canonical/craft-parts#977
Open

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

sergio-costas opened this issue Nov 27, 2024 · 10 comments · May be fixed by #5157 or canonical/craft-parts#977

Comments

@sergio-costas
Copy link
Contributor

sergio-costas commented Nov 27, 2024

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 #5157 fixes Core20 and Core22 snaps, and canonical/craft-parts#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}/../../..
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

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

@frenchwr
Copy link

frenchwr commented Dec 3, 2024

Just a note that this bug is affecting the GIMP snap as described here: snapcrafters/gimp#300

There is a workaround in the PR to hard-code the librsvg header file search path in the build-environment section of a part that is impacted by this bug.

@sergio-costas
Copy link
Contributor Author

sergio-costas commented Dec 3, 2024

I prepared a patch for gnome-46-2404-sdk which should fix the problem ubuntu/gnome-sdk#264 but it's just a workaround until this is fixed in snapcraft.

@mr-cal
Copy link
Collaborator

mr-cal commented Jan 15, 2025

I tried to do a patch #5157 but didn't work.

Hey @sergio-costas,

Do you have any ideas to why #5157 didn't work?

@sergio-costas
Copy link
Contributor Author

@mr-cal No idea, but I modified the entry of this bug to include a test YAML file, that shows the problem and allows to know if it has been fixed.

@sergio-costas
Copy link
Contributor Author

I've been doing some extra tests and adding debugging messages. Building the test snap, in the parts/librsvg/install/usr/lib/x86_64-linux-gnu/pkgconfig/librsvg-2.0.pc file, the contents are the expected ones (prefix=${pcfiledir}/../../..), and in stage/usr/lib/x86_64-linux-gnu/pkgconfig/librsvg-2.0.pc, the contents have been replaced with prefix=/root/stage${pcfiledir}/../../... The odd thing is that the only function that seems to be able to modify that, fix_pkg_config... seems to not be called... never... I added several log.warning, but none of them do appear in the logs...

@sergio-costas
Copy link
Contributor Author

I suspect that the replacement is being done in other of the *craft projects code... I'll try to find it.

@mr-cal
Copy link
Collaborator

mr-cal commented Jan 16, 2025

(updated)

Ah yes, it's here for core22 and core24 snaps: https://github.com/canonical/craft-parts/blob/2a7578ed4f588b8a4d04aebc54a45ec5a4e2540f/craft_parts/packages/normalize.py#L160

I was looking at the bug report for gimp, which uses core20. In gimp's case, #5157 is correct to modify snapcraft_legacy.

@sergio-costas
Copy link
Contributor Author

Ok, so both this patch, and another for craft-parts are required to fix this, isn't it?

@mr-cal
Copy link
Collaborator

mr-cal commented Jan 16, 2025

Correct

@sergio-costas
Copy link
Contributor Author

Ok, changed #5157 to ready, and added canonical/craft-parts#977

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants