twostraws / SwiftGD

A simple Swift wrapper for libgd
MIT License
457 stars 71 forks source link

Build error after adding support of Avif files on Linux #44

Open mczachurski opened 2 months ago

mczachurski commented 2 months ago

After merging PR #42 there is an error during build on Ubuntu Docker (in Vapor application). Seems like there is missing something in Linux connected with gdImageCreateFromAvifPtr.

#18 94.04 /build/.build/checkouts/SwiftGD/Sources/SwiftGD/Format.swift:225:88: error: cannot find 'gdImageCreateFromAvifPtr' in scope
#18 94.04      fileprivate let importFunction: (Int32, UnsafeMutableRawPointer) -> gdImagePtr? = gdImageCreateFromAvifPtr
#18 94.04                                                                                        ^~~~~~~~~~~~~~~~~~~~~~~~
#18 94.04 /build/.build/checkouts/SwiftGD/Sources/SwiftGD/Format.swift:228:110: error: cannot find 'gdImageAvifPtr' in scope
#18 94.04      fileprivate let exportFunction: (gdImagePtr, UnsafeMutablePointer<Int32>) -> UnsafeMutableRawPointer? = gdImageAvifPtr
#18 94.04                                                                                                              ^~~~~~~~~~~~~~
#18 94.04 error: fatalError
#18 ERROR: process "/bin/sh -c swift build -c release --static-swift-stdlib" did not complete successfully: exit code: 1
------
 > [build  7/14] RUN swift build -c release --static-swift-stdlib:
92.36 [103/1418] Compiling CVaporBcrypt blf.c
93.21 [105/1420] Compiling _NIOBase64 Base64.swift
94.04 [106/1421] Compiling SwiftGD Color.swift
94.04 /build/.build/checkouts/SwiftGD/Sources/SwiftGD/Format.swift:225:88: error: cannot find 'gdImageCreateFromAvifPtr' in scope
94.04      fileprivate let importFunction: (Int32, UnsafeMutableRawPointer) -> gdImagePtr? = gdImageCreateFromAvifPtr
94.04                                                                                        ^~~~~~~~~~~~~~~~~~~~~~~~
94.04 /build/.build/checkouts/SwiftGD/Sources/SwiftGD/Format.swift:228:110: error: cannot find 'gdImageAvifPtr' in scope
94.04      fileprivate let exportFunction: (gdImagePtr, UnsafeMutablePointer<Int32>) -> UnsafeMutableRawPointer? = gdImageAvifPtr
94.04                                                                                                              ^~~~~~~~~~~~~~
94.04 error: fatalError

My Dockerfile:

FROM swift:5.10-jammy as build

# Install OS updates and, if needed, sqlite3
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
    && apt-get -q update \
    && apt-get -q dist-upgrade -y \
    && apt-get install -y libgd-dev \
    && rm -rf /var/lib/apt/lists/*

# Set up a build area
WORKDIR /build

# Copy entire repo into container
COPY . .

# Clean the packages cache.
RUN swift package clean

# Build everything, with optimizations
RUN swift build -c release --static-swift-stdlib

Probably can be also reproduced on regular Ubuntu (not Docker), but I have no way to check it.

mczachurski commented 1 month ago

The issue is that AVIF and HEIF support was added to libGD starting from version 2.3.2 (https://libgd.github.io/). This version of the library is included in Ubuntu 24.04, whereas Ubuntu 22.04 uses libGD version 2.3.0.

Therefore, it would be beneficial to update the README file to include information about this requirement.