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

Swift / C build error related to missing definition of fds_bits. #69311

Open
fibrechannelscsi opened this issue Oct 20, 2023 · 2 comments
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c interop Feature: Interoperability with C clang importer Area → compiler: The clang importer

Comments

@fibrechannelscsi
Copy link
Contributor

Description
A build error occurs with a missing definition of fds_bits in certain cases. The error message generted is:

/usr/include/aarch64-linux-gnu/sys/select.h:64:15: error: '(anonymous struct)::fds_bits' from module 'Clibgraphviz' is not present in definition of 'fd_set' in module 'CDispatch'
    __fd_mask fds_bits[__FD_SETSIZE / __NFDBITS];
              ^
/usr/include/aarch64-linux-gnu/sys/select.h:59:9: note: definition has no member 'fds_bits'
typedef struct
        ^
error: fatalError

Steps to reproduce
This reproducer is a minimized version of GraphViz, available here:
https://github.com/SwiftDocOrg/GraphViz
This is not to say that there is an issue with GraphViz itself, but rather, the process to build it.

This reproducer requires five files. The directory tree looks like this:

./Sources/Clibgraphviz/gvc.h
./Sources/Clibgraphviz/arith.h
./Sources/Clibgraphviz/module.modulemap
./Sources/GraphViz/Renderer.swift
./Package.swift

Listing for Sources/Clibgraphviz/gvc.h:

#include "types.h"
#include <signal.h>

Listing for Sources/Clibgraphviz/arith.h:

#define _GNU_SOURCE 1

Listing for Sources/Clibgraphviz/module.modulemap:

module Clibgraphviz [system] {
header "arith.h"
header "gvc.h"
}

Listing for Sources/GraphViz/Renderer.swift:

import Dispatch; import Clibgraphviz

Listing for Package.swift:

// swift-tools-version:5.8
import PackageDescription
let package = Package(name: "GraphViz",
    products: [.library(name: "GraphViz", targets: ["GraphViz"])],
    targets: [.systemLibrary(name: "Clibgraphviz", pkgConfig: "libcgraph")] + [.target(name: "GraphViz", dependencies: ["Clibgraphviz"])]
)

The error only occurs when performing a clean build, namely:
swift package clean; swift build

Performing two or more builds after a clean, like so:
swift build; swift build
causes the build to succed after the second invocation.

Expected behavior
The compilation via swift build should succeed on the first invocation.

Environment

  • Swift compiler version info: 2023-07-10a, 2023-10-15a
  • Xcode version info: N/A
  • Deployment target: Ubuntu 20, ARM64, inside a Docker container.
@fibrechannelscsi fibrechannelscsi added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Oct 20, 2023
@fibrechannelscsi fibrechannelscsi changed the title Swift / C++ build error related to missing definition of fds_bits. Swift / C build error related to missing definition of fds_bits. Oct 20, 2023
@MaxDesiatov MaxDesiatov added clang importer Area → compiler: The clang importer c interop Feature: Interoperability with C and removed triage needed This issue needs more specific labels labels Oct 20, 2023
@YOCKOW
Copy link
Collaborator

YOCKOW commented Dec 11, 2023

I've run into the same issue with ImageMagick.
Sorry, but it occurred in my private repository, so I can only paste some build logs...

/usr/include/x86_64-linux-gnu/sys/select.h:67:15: error: '(anonymous struct)::__fds_bits' from module 'CDispatch' is not present in definition of 'fd_set' in module 'CImageMagick'
    __fd_mask __fds_bits[__FD_SETSIZE / __NFDBITS];
              ^
/usr/include/x86_64-linux-gnu/sys/select.h:59:9: note: definition has no member '__fds_bits'
typedef struct

In my experiences (Ubuntu 22.04):

  • Swift 5.9 + ImageMagick 6.9.11 👉 ✅ OK
  • Swift 5.9.1 + ImageMagick 6.9.11 👉 ❌ Ugh
  • Swift 5.9 + ImageMagick 7.1.1 👉 ✅ OK
  • Swift 5.9.1 + ImageMagick 7.1.1 👉 ✅ OK

I'm not sure why these differences happen.

@YOCKOW
Copy link
Collaborator

YOCKOW commented Dec 12, 2023

I created a reproducer repository named SwiftFdsBitsIssue69311.
I found only #define _GNU_SOURCE 1 and #include <sys/types.h> are necessary to reproduce this issue: https://github.com/YOCKOW/SwiftFdsBitsIssue69311/blob/main/Sources/CModule/header.h

There are just 25 commits from 5.9 to 5.9.1. There must be some hints...🧐
Edit: Confirmed this happens even in Swift 5.9...
May be related to #64251

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c interop Feature: Interoperability with C clang importer Area → compiler: The clang importer
Projects
None yet
Development

No branches or pull requests

3 participants