Building recent snapshot fails on Arch Linux

Gist updated

Interesting, so it seems that syscall.h is not getting included at all. What happens if you add a #include <syscall.h> to ForSwiftFoundationOnly.h at L68?

As I mentioned above I tried to move out syscall.h include right after features.h but I got another error. But let my try that again.

Line 68 starts with #define AT_STATX_SYNC_AS_STAT ... in the following block

#if __GLIBC_PREREQ(2, 28) == 0
// required for statx() system call, glibc >=2.28 wraps the kernel function
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/stat.h>
#include <linux/fs.h>
#define AT_STATX_SYNC_AS_STAT   0x0000  /* - Do whatever stat() does */
#endif //__GLIBC_PREREQ(2. 28)

Ok, I did it. Gist updated with the result.

Sorry, I was looking at a different version. You should add that outside, right after the #include <features.h>.

I’ll be away for a couple of days. Once I’m back I’ll run the build and update the gist again.

I'm back. Here's the result:

[14/103][ 13%][0.246s] Building C object CoreFoundati...oreFoundation.dir/Collections.subproj/CFBasicHash.c.
FAILED: CoreFoundation/CMakeFiles/CoreFoundation.dir/Collections.subproj/CFBasicHash.c.o
/home/segabor/Workspace/swift-dev/build/buildbot_linux/llvm-linux-x86_64/bin/clang -DCF_BUILDING_CF -DDEPLOYMENT_RUNTIME_SWIFT -DHAVE_SCHED_GETAFFINITY -DU_SHOW_DRAFT_API -D_GNU_SOURCE -I/home/segabor/Workspace/swift-dev/swift-corelibs-foundation/CoreFoundation -I/usr/include/libxml2 -I/home/segabor/Workspace/swift-dev/build/buildbot_linux/libicu-linux-x86_64/tmp_install/include -I/home/segabor/Workspace/swift-dev/swift-corelibs-libdispatch -I/home/segabor/Workspace/swift-dev/build/buildbot_linux/libdispatch-linux-x86_64/tests -isystem /home/segabor/Workspace/swift-dev/swift-corelibs-libdispatch/src/BlocksRuntime -O3 -DNDEBUG -fPIC -F /home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64 -I /home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64/CoreFoundation.framework/PrivateHeaders -include /home/segabor/Workspace/swift-dev/swift-corelibs-foundation/CoreFoundation/Base.subproj/CoreFoundation_Prefix.h -fblocks -fconstant-cfstrings -fdollars-in-identifiers -fexceptions -fno-common -fcf-runtime-abi=swift -Wno-shorten-64-to-32 -Wno-deprecated-declarations -Wno-unreachable-code -Wno-conditional-uninitialized -Wno-unused-variable -Wno-int-conversion -Wno-unused-function -Wno-microsoft-enum-forward-reference -pthread -std=gnu99 -MD -MT CoreFoundation/CMakeFiles/CoreFoundation.dir/Collections.subproj/CFBasicHash.c.o -MF CoreFoundation/CMakeFiles/CoreFoundation.dir/Collections.subproj/CFBasicHash.c.o.d -o CoreFoundation/CMakeFiles/CoreFoundation.dir/Collections.subproj/CFBasicHash.c.o -c /home/segabor/Workspace/swift-dev/swift-corelibs-foundation/CoreFoundation/Collections.subproj/CFBasicHash.c
In file included from /home/segabor/Workspace/swift-dev/swift-corelibs-foundation/CoreFoundation/Collections.subproj/CFBasicHash.c:11:
In file included from /home/segabor/Workspace/swift-dev/swift-corelibs-foundation/CoreFoundation/Collections.subproj/CFBasicHash.h:12:
In file included from /home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64/CoreFoundation.framework/PrivateHeaders/CFInternal.h:156:
/home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64/CoreFoundation.framework/Headers/ForSwiftFoundationOnly.h:541:85: warning: declaration of 'struct statx' will not be visible outside of this function [-Wvisibility]
_statx(int dfd, const char *filename, unsigned int flags, unsigned int mask, struct statx *buffer) {
^
/home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64/CoreFoundation.framework/Headers/ForSwiftFoundationOnly.h:550:18: error: variable has incomplete type 'struct statx'
struct statx statx_buffer = {0};
^
/home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64/CoreFoundation.framework/Headers/ForSwiftFoundationOnly.h:550:12: note: forward declaration of 'struct statx'
struct statx statx_buffer = {0};
^
/home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64/CoreFoundation.framework/Headers/ForSwiftFoundationOnly.h:553:91: error: use of undeclared identifier 'STATX_ALL'
ssize_t ret = _statx(AT_FDCWD, filename, AT_SYMLINK_NOFOLLOW | AT_STATX_SYNC_AS_STAT, STATX_ALL, &statx_buffer);
^
/home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64/CoreFoundation.framework/Headers/ForSwiftFoundationOnly.h:571:37: error: use of undeclared identifier 'STATX_BTIME'
if (statx_buffer.stx_mask & STATX_BTIME) {
^
1 warning and 3 errors generated.
ninja: build stopped: subcommand failed.
./swift/utils/build-script: fatal error: command terminated with a non-zero exit status 1, aborting
./swift/utils/build-script: fatal error: command terminated with a non-zero exit status 1, aborting

What version of glibc are you using? I think that you need 2.28 or newer.

It's 2.29-1.

Could you verify that statx.h was included? -H to clang should show the include hierarchy.

Well if you can point out where to put that flag. With the latest modification build stops here:

cd /home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64 && /home/segabor/Workspace/swift-dev/build/buildbot_linux/swift-linux-x86_64/bin/swiftc -emit-library -incremental -j 12 -module-name Foundation -module-link-name Foundation -emit-module-path /home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64/swift/Foundation.swiftmodule -DDEPLOYMENT_RUNTIME_SWIFT -DDEPLOYMENT_ENABLE_LIBDISPATCH -I /home/segabor/Workspace/swift-dev/build/buildbot_linux/libicu-linux-x86_64/tmp_install/include -I /home/segabor/Workspace/swift-dev/swift-corelibs-libdispatch -I /home/segabor/Workspace/swift-dev/build/buildbot_linux/libdispatch-linux-x86_64/src/swift -Xcc -fblocks -enable-testing -O -Xcc -F/home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64 -output-file-map /home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64/Foundation.dir/output-file-map.json /home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64/CoreFoundation/libCoreFoundation.a -l/usr/lib/libxml2.so -ldl -lm -ldispatch /home/segabor/Workspace/swift-dev/build/buildbot_linux/swift-linux-x86_64/lib/swift/linux/x86_64/libicuucswift.so /home/segabor/Workspace/swift-dev/build/buildbot_linux/swift-linux-x86_64/lib/swift/linux/x86_64/libicui18nswift.so /usr/lib/libxml2.so -L /home/segabor/Workspace/swift-dev/build/buildbot_linux/libdispatch-linux-x86_64 -L /home/segabor/Workspace/swift-dev/build/buildbot_linux/libdispatch-linux-x86_64/src -ldispatch -lswiftDispatch -Xlinker -rpath -Xlinker /home/segabor/Workspace/swift-dev/build/buildbot_linux/libdispatch-linux-x86_64/src /home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64/libuuid.a -Xlinker -rpath -Xlinker "\$ORIGIN"         -o /home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64/Foundation.dir/libFoundation.so @/home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64/Foundation.dir/Foundation.rsp
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "Headers/CoreFoundation.h"
         ^
/home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64/CoreFoundation.framework/Headers/CoreFoundation.h:101:10: note: in file included from /home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64/CoreFoundation.framework/Headers/CoreFoundation.h:101:
#include <CoreFoundation/ForSwiftFoundationOnly.h>
         ^
/home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64/CoreFoundation.framework/Headers/ForSwiftFoundationOnly.h:550:18: error: variable has incomplete type 'struct statx'
    struct statx statx_buffer = {0};
                 ^
/home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64/CoreFoundation.framework/Headers/ForSwiftFoundationOnly.h:550:12: note: forward declaration of 'struct statx'
    struct statx statx_buffer = {0};
           ^
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "Headers/CoreFoundation.h"
         ^
/home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64/CoreFoundation.framework/Headers/CoreFoundation.h:101:10: note: in file included from /home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64/CoreFoundation.framework/Headers/CoreFoundation.h:101:
#include <CoreFoundation/ForSwiftFoundationOnly.h>
         ^
/home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64/CoreFoundation.framework/Headers/ForSwiftFoundationOnly.h:553:68: error: use of undeclared identifier 'AT_STATX_SYNC_AS_STAT'
    ssize_t ret = _statx(AT_FDCWD, filename, AT_SYMLINK_NOFOLLOW | AT_STATX_SYNC_AS_STAT, STATX_ALL, &statx_buffer);
                                                                   ^
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "Headers/CoreFoundation.h"
         ^
/home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64/CoreFoundation.framework/Headers/CoreFoundation.h:101:10: note: in file included from /home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64/CoreFoundation.framework/Headers/CoreFoundation.h:101:
#include <CoreFoundation/ForSwiftFoundationOnly.h>
         ^
/home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64/CoreFoundation.framework/Headers/ForSwiftFoundationOnly.h:553:91: error: use of undeclared identifier 'STATX_ALL'
    ssize_t ret = _statx(AT_FDCWD, filename, AT_SYMLINK_NOFOLLOW | AT_STATX_SYNC_AS_STAT, STATX_ALL, &statx_buffer);
                                                                                          ^
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "Headers/CoreFoundation.h"
         ^
/home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64/CoreFoundation.framework/Headers/CoreFoundation.h:101:10: note: in file included from /home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64/CoreFoundation.framework/Headers/CoreFoundation.h:101:
#include <CoreFoundation/ForSwiftFoundationOnly.h>
         ^
/home/segabor/Workspace/swift-dev/build/buildbot_linux/foundation-linux-x86_64/CoreFoundation.framework/Headers/ForSwiftFoundationOnly.h:571:37: error: use of undeclared identifier 'STATX_BTIME'
        if (statx_buffer.stx_mask & STATX_BTIME) {
                                    ^
/home/segabor/Workspace/swift-dev/swift-corelibs-foundation/Foundation/Bridging.swift:13:8: error: could not build C module 'CoreFoundation'
import CoreFoundation
       ^
ninja: build stopped: subcommand failed.
./swift/utils/build-script: fatal error: command terminated with a non-zero exit status 1, aborting
./swift/utils/build-script: fatal error: command terminated with a non-zero exit status 1, aborting

Let me include the current change what makes trouble now:

diff --git a/CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h b/CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h
index 5dc221de..18d70b51 100644
--- a/CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h
+++ b/CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h
@@ -60,12 +60,12 @@
 #include <sys/syscall.h>
 #elif TARGET_OS_LINUX
 #include <features.h>
+#include <sys/syscall.h>
+#include <sys/stat.h>
 
 #if __GLIBC_PREREQ(2, 28) == 0
 // required for statx() system call, glibc >=2.28 wraps the kernel function
-#include <sys/syscall.h>
 #include <sys/types.h>
-#include <sys/stat.h>
 #include <linux/stat.h>
 #include <linux/fs.h>
 #define AT_STATX_SYNC_AS_STAT   0x0000  /* - Do whatever stat() does */

Thanks again for your help.

The flag would go on the compiler invocation (at the end is fine). I believe that a needed header (statx.h) is not being included.

swiftc does not seem to accept -E parameter even supplied with -Xcc.

You shouldn't be passing that to swiftc. The file being compiled is C code, you should be looking at the clang invocation.

Understood. But at this point swiftc is trying to do something with ForSwiftFoundationOnly.h and I cannot pass the wanted flag downward hoping that clang catches it.
This is getting me really frustrated. So far I was able to build snapshots but now I'm stuck.
What I don't get that "official" AUR package can build 5.0.1 release (although it has REPL issues).

Sorry, without actually being able to look at the details, the best I can do is suggest hints at how to investigate this. I don't run arch and don't have easy access to an environment to reproduce this issue. I think that you are missing a #include <sys/statx.h> after the inclusion of <sys/stat.h>. But, I do not have a way to verify the header location nor if it fixes anything.

Good news! Don't ask me what has changed but 5.1-DEVELOPMENT-SNAPSHOT-2019-06-21-a successfully built right away. Also tab completion bug in REPL is resolved in this version.

I can use swift on my Linux desktop again! Happy-happy me :slightly_smiling_face: