Swift build failure on AUR package

I am aware that this is a non-official package, but would appreciate any help.

This is the build error:

--- bootstrap: note: building stage1
Compiling libc.c
Compiling Swift Module 'PackageDescription4' (10 sources)
clang-8: warning: argument unused during compilation: '-fmodules-cache-path=/home/pacman/aur/swift-language/src/build/Ninja-ReleaseAssert/swiftpm-linux-x86_64/.bootstrap/ModuleCache' [-Wunused-command-line-argument]
Linking clibc
Compiling Swift Module 'SPMLibc' (1 sources)
Linking SPMLibc
Compiling Swift Module 'Basic' (40 sources)
Linking PackageDescription4
/home/pacman/aur/swift-language/src/swiftpm/Sources/Basic/Process.swift:328:59: error: value of optional type 'UnsafeMutablePointer<Int8>?' must be unwrapped to a value of type 'UnsafeMutablePointer<Int8>'
        posix_spawn_file_actions_addopen(&fileActions, 0, devNull, O_RDONLY, 0)
                                                          ^
/home/pacman/aur/swift-language/src/swiftpm/Sources/Basic/Process.swift:328:59: note: coalesce using '??' to provide a default when the optional value contains 'nil'
        posix_spawn_file_actions_addopen(&fileActions, 0, devNull, O_RDONLY, 0)
                                                          ^
                                                                  ?? <#default value#>
/home/pacman/aur/swift-language/src/swiftpm/Sources/Basic/Process.swift:328:59: note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
        posix_spawn_file_actions_addopen(&fileActions, 0, devNull, O_RDONLY, 0)
                                                          ^
                                                                 !
/home/pacman/aur/swift-language/src/swiftpm/Sources/Basic/Process.swift:351:54: error: value of optional type 'UnsafeMutablePointer<Int8>?' must be unwrapped to a value of type 'UnsafeMutablePointer<Int8>'
        let rv = posix_spawnp(&processID, argv.cArray[0], &fileActions, &attributes, argv.cArray, env.cArray)
                                                     ^
/home/pacman/aur/swift-language/src/swiftpm/Sources/Basic/Process.swift:351:54: note: coalesce using '??' to provide a default when the optional value contains 'nil'
        let rv = posix_spawnp(&processID, argv.cArray[0], &fileActions, &attributes, argv.cArray, env.cArray)
                                                     ^
                                                         ?? <#default value#>
/home/pacman/aur/swift-language/src/swiftpm/Sources/Basic/Process.swift:351:54: note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
        let rv = posix_spawnp(&processID, argv.cArray[0], &fileActions, &attributes, argv.cArray, env.cArray)
                                                     ^
                                                        !
--- bootstrap: error: build failed with exit status 1
./utils/build-script: fatal error: command terminated with a non-zero exit status 1, aborting
==> ERROR: A failure occurred in build().
    Aborting...

Here's the PKGBUILD:

# Maintainer: Michael Hansen <zrax0111 gmail com>

pkgbase=swift-language
pkgname=(swift swift-lldb)
_swiftver=5.1-RELEASE
pkgver=${_swiftver//-RELEASE/}
pkgrel=1
pkgdesc="The Swift programming language and debugger"
arch=('i686' 'x86_64')
url="http://swift.org/"
license=('apache')
depends=('python2' 'libutil-linux' 'icu' 'libbsd' 'libedit' 'libxml2'
         'sqlite' 'ncurses' 'libblocksruntime')
makedepends=('git' 'cmake' 'ninja' 'swig3' 'clang>=5.0' 'python2-six' 'perl'
             'python2-sphinx' 'python2-requests' 'rsync')

source=(
    "swift-${_swiftver}.tar.gz::https://github.com/apple/swift/archive/swift-${_swiftver}.tar.gz"
    "swift-llvm-${_swiftver}.tar.gz::https://github.com/apple/swift-llvm/archive/swift-${_swiftver}.tar.gz"
    "swift-clang-${_swiftver}.tar.gz::https://github.com/apple/swift-clang/archive/swift-${_swiftver}.tar.gz"
    "swift-clang-tools-extra-${_swiftver}.tar.gz::https://github.com/apple/swift-clang-tools-extra/archive/swift-${_swiftver}.tar.gz"
    "swift-libcxx-${_swiftver}.tar.gz::https://github.com/apple/swift-libcxx/archive/swift-${_swiftver}.tar.gz"
    "swift-lldb-${_swiftver}.tar.gz::https://github.com/apple/swift-lldb/archive/swift-${_swiftver}.tar.gz"
    "swift-cmark-${_swiftver}.tar.gz::https://github.com/apple/swift-cmark/archive/swift-${_swiftver}.tar.gz"
    "swift-llbuild-${_swiftver}.tar.gz::https://github.com/apple/swift-llbuild/archive/swift-${_swiftver}.tar.gz"
    "swift-package-manager-${_swiftver}.tar.gz::https://github.com/apple/swift-package-manager/archive/swift-${_swiftver}.tar.gz"
    "swift-corelibs-xctest-${_swiftver}.tar.gz::https://github.com/apple/swift-corelibs-xctest/archive/swift-${_swiftver}.tar.gz"
    "swift-corelibs-foundation-${_swiftver}.tar.gz::https://github.com/apple/swift-corelibs-foundation/archive/swift-${_swiftver}.tar.gz"
    "swift-corelibs-libdispatch-${_swiftver}.tar.gz::https://github.com/apple/swift-corelibs-libdispatch/archive/swift-${_swiftver}.tar.gz"
    "swift-compiler-rt-${_swiftver}.tar.gz::https://github.com/apple/swift-compiler-rt/archive/swift-${_swiftver}.tar.gz"
    "swift-integration-tests-${_swiftver}.tar.gz::https://github.com/apple/swift-integration-tests/archive/swift-${_swiftver}.tar.gz"
    "glibc-includes.patch"
    "repl_swift-dl.patch"
)
sha256sums=('04cbf97859cc691840a2c18354329e12f051226758b99f4a025d0bcca99ed4df'
            '3ed973401d62a9610c8d9be8afbb28d04f50340a773be48af6965033e80e0411'
            '3d704763df8e17af5559839484c29681c19e16e9801734c33cd4e12ffaba6cdf'
            'f1f383106fd3589bc9566225015cfa88e671231f9e8695773f0012a93f9853c6'
            'cf5a1dfe5d6fbfaaa26bc4b98c2033c48c513d06b9a1d5ae7180871d144caa0c'
            'ca01ed89c886565155cd55129fa1d27d7486df031a409b2709f90937d4f81349'
            'f0c6fdb8a81a9d422fbc47dc9e6408556b25198f50a0fddcb3aeccdaff56bcfd'
            'cbd228619d1172f7f6d38983f0419226baa1cfbecc6afac891856fcb46ba4920'
            '830d79d777841c28c6b270083c3fd305bc1ba736086ad9790dee1673a23a6aee'
            'adaaec994d18067a49596b0720b0c163da3a1915f20a619221834292b0e2af68'
            '9176e1334e2b8b6715c4d071be1337554438096b9f29d62f90aecfb5230148fa'
            'da24d299eecc10e7d4b40a24e0700ca2f73da622795ecf6f4a5da4d33c486662'
            'f2eb728ce1d4be21bb0e8bf7e099b6654a45ce8ff8dee6050e868822d7bbcd95'
            'faad37015993a8713d10fd281e17d8bf308196c8cc4ecc45dc962e22141718cf'
            '6a94de9adbdc4182b297e0011a68c9387fd25864dcb4386654218c8c530032c2'
            '0b2dcb80d9f5cd987a6750b88dc71823980c47dcc711a993e71a496fd73d4e5e')

prepare() {
    # Use python2 where appropriate
    find "$srcdir" -type f -print0 | \
         xargs -0 sed -i 's|/usr/bin/env python$|&2|;s|/usr/bin/python$|&2|'
    find "$srcdir/swift-lldb-swift-${_swiftver}" -name Makefile -print0 | \
         xargs -0 sed -i 's|python-config|python2-config|g'
    sed -i '/^cmake_minimum_required/a set(Python_ADDITIONAL_VERSIONS 2.7)' \
         "$srcdir/swift-swift-${_swiftver}/CMakeLists.txt"
    sed -i '/^cmake_minimum_required/a set(Python_ADDITIONAL_VERSIONS 2.7)' \
         "$srcdir/swift-lldb-swift-${_swiftver}/CMakeLists.txt"
    sed -i 's/\<python\>/&2/' \
         "$srcdir/swift-swift-${_swiftver}/utils/build-script-impl"

    # Use directory names which build-script expects
    for sdir in llvm clang clang-tools-extra libcxx lldb cmark llbuild \
                compiler-rt
    do
        rm -rf ${sdir}
        mv swift-${sdir}-swift-${_swiftver} ${sdir}
    done
    for sdir in corelibs-xctest corelibs-foundation corelibs-libdispatch \
                integration-tests
    do
        rm -rf ${sdir}
        mv swift-${sdir}-swift-${_swiftver} swift-${sdir}
    done
    rm -rf swift swiftpm
    mv swift-swift-${_swiftver} swift
    mv swift-package-manager-swift-${_swiftver} swiftpm

    # Fix wrong glibc include paths in glibc module map
    ( cd swift && patch -p1 -i "$srcdir/glibc-includes.patch" )

    # repl_swift requires -ldl
    ( cd lldb && patch -p1 -i "$srcdir/repl_swift-dl.patch" )
}

_common_build_params=(
    --install-prefix=/usr
    --lldb
    --llbuild
    --swiftpm
    --xctest
    --foundation
    --libdispatch
    --extra-cmake-options="-DSWIG_EXECUTABLE=/usr/bin/swig-3"
)

_build_script_wrapper() {
    export SWIFT_SOURCE_ROOT="$srcdir"
    ./utils/build-script "$@"
}

build() {
    cd "$srcdir/swift"

    export PATH="$PATH:/usr/bin/core_perl"
    _build_script_wrapper -R "${_common_build_params[@]}"
}

check() {
    cd "$srcdir/swift"

    # Fix the lldb swig binding's import path (matches Arch LLDB package)
    # Need to do this here as well as the install since the test suite
    # uses the lldb python bindings directly from the build dir
    sed -i "/import_module('_lldb')/s/_lldb/lldb.&/" \
        "${srcdir}/build/Ninja-ReleaseAssert/lldb-linux-${CARCH}/lib/python2.7/site-packages/lldb/__init__.py"

    _build_script_wrapper -R -t
}

package_swift() {
    pkgdesc='The Swift programming language compiler and tools'
    provides=('swift-language')
    conflicts=('swift-language-git' 'swift-git' 'swift-bin')
    optdepends=('swift-lldb: Swift REPL and debugger')

    cd "$srcdir/swift"

    _build_script_wrapper -R "${_common_build_params[@]}" \
        --install-destdir="$pkgdir" \
        --install-llbuild --install-swiftpm --install-xctest \
        --install-foundation --install-libdispatch

    cd "$srcdir/build/Ninja-ReleaseAssert"

    # Some projects' install targets don't work correctly :(
    (
        cd swift-linux-$CARCH
        install -m755 bin/swift bin/swift-{demangle,ide-test} "$pkgdir/usr/bin"
        ln -s swift "$pkgdir/usr/bin/swiftc"
        ln -s swift "$pkgdir/usr/bin/swift-autolink-extract"

        install -m644 lib/libsourcekitdInProc.so "$pkgdir/usr/lib"

        install -dm755 "$pkgdir/usr/share/man/man1"
        install -m644 docs/tools/swift.1 "$pkgdir/usr/share/man/man1"

        umask 0022
        cp -rL lib/swift/{clang,linux,shims} "$pkgdir/usr/lib/swift/"
    )

    # License file
    install -dm755 "$pkgdir/usr/share/licenses/swift"
    install -m644 "$srcdir/swift/LICENSE.txt" "$pkgdir/usr/share/licenses/swift"
}

package_swift-lldb() {
    pkgdesc='The Swift programming language debugger (LLDB) and REPL'
    depends=('swift' 'python2-six')
    provides=('lldb')
    conflicts=('lldb')
    options=('!strip')  # Don't strip repl_swift -- we need its symbols

    cd "$srcdir/swift"

    _build_script_wrapper -R "${_common_build_params[@]}" \
        --install-destdir="$pkgdir" \
        --install-lldb

    # Fix the lldb swig binding's import path (matches Arch LLDB package)
    # We have to do this again because the build-script recreates the "bad"
    # version of the source file.
    sed -i "/import_module('_lldb')/s/_lldb/lldb.&/" \
        "${pkgdir}/usr/lib/python2.7/site-packages/lldb/__init__.py"

    # This should be provided from python2-six
    rm "$pkgdir/usr/lib/python2.7/site-packages/six.py"
    rm "$pkgdir/usr/lib/python2.7/site-packages/six.pyc"
}

Thank you for reading,
Guido.

I ran into similar issues when building SPM natively on Android, which I had to work around by passing in some preprocessor definitions. In this case, my guess is that some C types are off because of the glibc patch you're using, which I guess is to make sure x86 works?

I've been building and testing these Swift repos from unpatched source on Arch x86_64 for most of this year without a problem, including the 5.1 source release, maybe try building without that patch and see what happens. Either way, the problem seems to be that the Swift compiler's clang importer is getting C types from headers that this Swift module doesn't expect.

Sorry, after actually looking at your errors (rather than assuming that such type errors are caused by the same reason as Android), those are actually Swift variables that it seems to be getting the types wrong for, which could be a compiler bug. I think I've seen similar flakiness before, might go away on a clean rebuild, ie it's usually not reproducible.

I still think that glibc patch is old and may not be needed anymore, or at the very least you should look into modifying the CMake build scripts instead so that it isn't needed, but it probably isn't the cause of these errors as I guessed.

Looks like my first guess was right after all, try that patch and see if it fixes the build for you.

Terms of Service

Privacy Policy

Cookie Policy