Skip to content

Fix FreeBSD build#293

Merged
glessard merged 5 commits intoapple:mainfrom
kkebo:fix-freebsd
Feb 6, 2026
Merged

Fix FreeBSD build#293
glessard merged 5 commits intoapple:mainfrom
kkebo:fix-freebsd

Conversation

@kkebo
Copy link
Contributor

@kkebo kkebo commented Jan 27, 2026

fixes #294, fixes #295

This PR fixes swift build and swift test on FreeBSD.

$ swift build
[1/1] Planning build
Building for debugging...
[1/1] Write swift-version-2B7A02F0DA2902A5.txt
Build complete! (0.14s)
$ swift test
Building for debugging...                                                                                                                                                              
[5/5] Compiling SystemTests StatTests.swift                                                                                                                                            
Build complete! (1.84s)                                                                                                                                                                
Test Suite 'All tests' started at 2026-01-28 00:02:35.756                                                                                                                              
Test Suite 'debug.xctest' started at 2026-01-28 00:02:35.758
...
Test Suite 'debug.xctest' passed at 2026-01-28 00:02:37.857
         Executed 52 tests, with 0 failures (0 unexpected) in 2.099 (2.099) seconds
Test Suite 'All tests' passed at 2026-01-28 00:02:37.857
         Executed 52 tests, with 0 failures (0 unexpected) in 2.099 (2.099) seconds
◇ Test run started.
↳ Testing Library Version: 6.3-dev (98430f2d6cb8d81)
↳ Target Platform: x86_64-unknown-freebsd
◇ Suite "Stat" started.
◇ Suite "FileMode" started.
◇ Test basics() started.
◇ Test times() started.
◇ Test permissions() started.
◇ Test followSymlinkInits() started.
◇ Test invalidInput() started.
◇ Test basics() started.
◇ Test flags() started.
✔ Test invalidInput() passed after 0.001 seconds.
✔ Test basics() passed after 0.001 seconds.
✔ Suite "FileMode" passed after 0.001 seconds.
✔ Test flags() passed after 0.003 seconds.
✔ Test basics() passed after 0.004 seconds.
✔ Test permissions() passed after 0.004 seconds.
✔ Test followSymlinkInits() passed after 0.004 seconds.
✔ Test times() passed after 0.043 seconds.
✔ Suite "Stat" passed after 0.044 seconds.
✔ Test run with 7 tests in 2 suites passed after 0.044 seconds.

Environment:

$ uname -a
FreeBSD Coconut-rhinoceros-beetle 15.0-RELEASE-p1 FreeBSD 15.0-RELEASE-p1 releng/15.0-n280999-7bceec30b351 GENERIC amd64
$ swift --version
Swift version 6.3-dev (LLVM b58b2a34d509492, Swift cf535d8b998d09b)
Target: x86_64-unknown-freebsd14.3
Build config: +assertions

Swift toolchain is from forums.swift.org/t/swift-on-freebsd-preview/83064.

@jrflat
Copy link
Contributor

jrflat commented Jan 27, 2026

@swift-ci please test


flags.insert(userSettableFlags)
try #require(fchflags(fd.rawValue, flags.rawValue) == 0, "\(Errno.current)")
try #require(fchflags(fd.rawValue, UInt(flags.rawValue)) == 0, "\(Errno.current)")
Copy link
Contributor

Choose a reason for hiding this comment

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

On macOS: - error: cannot convert value of type 'UInt' to expected argument type '__uint32_t' (aka 'UInt32')
We need a different fix for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Below is the type of FileFlags.rawValue:

extension CInterop {
  // ...
  #if SYSTEM_PACKAGE_DARWIN || os(FreeBSD) || os(OpenBSD)
  public typealias FileFlags = UInt32
  #endif
}

What was the error that led you to cast it to UInt? Perhaps you could compare it to UInt32.zero instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll fix this after I open an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about this solution?

91bd99f

@glessard
Copy link
Contributor

@kkebo could you open an issue that contains the build errors that prompted this change? Thank you.

@kkebo
Copy link
Contributor Author

kkebo commented Jan 28, 2026

@glessard I created issues: #294 and #295.

@glessard
Copy link
Contributor

glessard commented Feb 2, 2026

@swift-ci please test

}

#if os(FreeBSD)
// Helper functions for FreeBSD
Copy link
Contributor

@glessard glessard Feb 2, 2026

Choose a reason for hiding this comment

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

It would be fine to have the correct direct call to fchflags inside an #if statement in the test case itself. Adding a helper function likely obscures what we're doing.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd also be fine with using numericCast(_:).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand your concerns, but if someone adds new fchflags() invocations, they may forget to #if statements for FreeBSD. To prevent that, I added a helper function.

However, I removed that function. Instead, I added some comments to clarify the reason for using integer casting.

043bda4

flags.insert(userSettableFlags)
try #require(fchflags(fd.rawValue, flags.rawValue) == 0, "\(Errno.current)")
// On FreeBSD, the second argument of `fchflags` requires `UInt` instead of`UInt32`.
try #require(fchflags(fd.rawValue, .init(flags.rawValue)) == 0, "\(Errno.current)")
Copy link
Contributor

Choose a reason for hiding this comment

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

In the fullness of time, the right solution will be to have a proper wrapper of chflags and fchflags that take a FileFlags parameter. This is good in the meantime.

@glessard
Copy link
Contributor

glessard commented Feb 6, 2026

@swift-ci please test

@glessard glessard merged commit 71db29e into apple:main Feb 6, 2026
47 checks passed
@glessard
Copy link
Contributor

glessard commented Feb 6, 2026

Thanks @kkebo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

swift test fails on FreeBSD swift build fails on FreeBSD

3 participants