Skip to content

Changes to support building with Musl#2595

Merged
Lukasa merged 2 commits intoapple:mainfrom
al45tair:musl-support
Nov 29, 2023
Merged

Changes to support building with Musl#2595
Lukasa merged 2 commits intoapple:mainfrom
al45tair:musl-support

Conversation

@al45tair
Copy link
Copy Markdown
Contributor

@al45tair al45tair commented Nov 16, 2023

Various changes to allow building NIO for a Linux system that is using Musl instead of Glibc.

Motivation:

We would like to be able to build NIO on top of Musl, as well as the usual Glibc.

Modifications:

Define _GNU_SOURCE in the Package.swift rather than in shim.c (this is required because _GNU_SOURCE affects modular headers).

Add an import for Musl to IO.swift.

Add code to disable SIGPIPE to SocketProtocols.swift.

Remove types from a pile of functions in System.swift; Swift will use the correct type automatically (except in cases where there are multiple versions of a function, e.g. ioctl(), in which case we need to be explicit which one we mean).

Result:

NIO should build against Musl.

Copy link
Copy Markdown
Member

@dnadoba dnadoba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but would like someone else to take another look as well

@dnadoba
Copy link
Copy Markdown
Member

dnadoba commented Nov 16, 2023

@swift-server-bot add to allowlist

Copy link
Copy Markdown
Member

@FranzBusch FranzBusch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment thread Package.swift
dependencies: []
dependencies: [],
cSettings: [
.define("_GNU_SOURCE"),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we confident we're allowed to do this? Previously this has appeared to conflict with Swift's glibc module, which was declared without this definition.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm. Well, we're definitely not safe just #defineing it in a source file, because with modular includes you have to define it on the command line (or it won't affect the modularized headers). If it doesn't work with the Glibc module, that would be… bad.

@FranzBusch
Copy link
Copy Markdown
Member

The CI seems to be failing with

17:09:30 /tmp/.swift-nio-syscall-wrappers-sh-test_6C5iKP/syscallwrapper/Sources/CNIOLinux/shim.c:22:2: error: You must define _GNU_SOURCE
17:09:30 #error You must define _GNU_SOURCE

This might just be a problem for the syscall wrapper tests. @al45tair you mind taking a look?

@al45tair
Copy link
Copy Markdown
Contributor Author

Will do. I also need to have another look at the System.swift stuff; I think maybe we do need the types there (I've just had a compiler crash that looks suspiciously like it might be related to that code; obviously it shouldn't crash, but I started thinking that maybe the types are there to force the compiler to pick the underlying system functions rather than ones in the respective overlay).

@al45tair
Copy link
Copy Markdown
Contributor Author

Update: the crash wasn't that problem (it was another problem, in a different dependency), and everything seems to work without the type information being mentioned explicitly.

@al45tair
Copy link
Copy Markdown
Contributor Author

The CI seems to be failing with

17:09:30 /tmp/.swift-nio-syscall-wrappers-sh-test_6C5iKP/syscallwrapper/Sources/CNIOLinux/shim.c:22:2: error: You must define _GNU_SOURCE
17:09:30 #error You must define _GNU_SOURCE

This might just be a problem for the syscall wrapper tests. @al45tair you mind taking a look?

I think I have a fix for that. Seems there are some extra Package.swifts hiding in the integration tests' shell scripts.

Define `_GNU_SOURCE` in the `Package.swift` rather than in `shim.c`
(this is required because `_GNU_SOURCE` affects modular headers).

Add an import for Musl to IO.swift.

Add code to disable `SIGPIPE` to `SocketProtocols.swift`.

Remove types from a pile of functions in `System.swift`; Swift will
use the correct type automatically (except in cases where there are
multiple versions of a function, e.g. `ioctl()`, in which case we
need to be explicit which one we mean).
A couple of the integration tests grab code and build it outside of the
normal `Package.swift`, so they needed fixing to define `_GNU_SOURCE`
themselves.
@al45tair
Copy link
Copy Markdown
Contributor Author

@swift-server-bot test this please

@Lukasa Lukasa added the 🔨 semver/patch No public API change. label Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants