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

Fix swift-system to work on Windows. #158

Merged
merged 7 commits into from May 8, 2024
Merged

Conversation

al45tair
Copy link
Contributor

The swift-system tests were not passing, for various reasons, mostly to do with path related confusion.

As part of this, add a function to create a temporary directory, as that was one of the problems.

Also add Windows support for pipe() and ftruncate(), which was missing.

rdar://125087707

@al45tair
Copy link
Contributor Author

@swift-ci Please test

@al45tair
Copy link
Contributor Author

@swift-ci Please test Windows platform

@al45tair
Copy link
Contributor Author

I guess we don't test Windows for swift-system. We should.

Sources/System/FilePath/FilePathParsing.swift Show resolved Hide resolved
Sources/System/FilePath/FilePathTemp.swift Outdated Show resolved Hide resolved
Sources/System/Internals/Mocking.swift Outdated Show resolved Hide resolved
Sources/System/Internals/Mocking.swift Outdated Show resolved Hide resolved
Sources/System/Internals/Syscalls.swift Show resolved Hide resolved
Sources/System/Internals/Syscalls.swift Show resolved Hide resolved
Sources/System/Internals/WindowsSyscallAdapters.swift Outdated Show resolved Hide resolved
Sources/System/Internals/WindowsSyscallAdapters.swift Outdated Show resolved Hide resolved
@al45tair
Copy link
Contributor Author

@swift-ci Please test

@lorentey lorentey requested a review from glessard March 20, 2024 21:16
Copy link
Member

@lorentey lorentey left a comment

Choose a reason for hiding this comment

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

Yay for the FilePath fixes! 🎉 Thanks 👍

I have lots of grumpy comments about the additions. swift-system was never intended to be a POSIX emulation package, and I really dislike that it's being pushed to become that. (I don't think we have the means to do a good job of that, even if it was a good idea, which I don't think it is.) This package isn't for building cross-platform abstraction layers -- that's Foundation's job.

Sources/System/ErrnoWindows.swift Outdated Show resolved Hide resolved
Sources/System/FilePath/FilePathTemp.swift Outdated Show resolved Hide resolved
Sources/System/FilePath/FilePathTemp.swift Outdated Show resolved Hide resolved
Sources/System/FilePath/FilePathTemp.swift Outdated Show resolved Hide resolved
Sources/System/Internals/WindowsSyscallAdapters.swift Outdated Show resolved Hide resolved
Sources/System/FilePath/FilePathTemp.swift Outdated Show resolved Hide resolved
Sources/System/FilePath/FilePathTemp.swift Outdated Show resolved Hide resolved
Sources/System/FilePath/FilePathTemp.swift Show resolved Hide resolved
Sources/System/FilePath/FilePathTemp.swift Show resolved Hide resolved
@al45tair al45tair force-pushed the eng/PR-125087707 branch 2 times, most recently from 5818960 to b45ea64 Compare March 26, 2024 17:12
@al45tair
Copy link
Contributor Author

@swift-ci Please test

1 similar comment
@al45tair
Copy link
Contributor Author

al45tair commented Apr 8, 2024

@swift-ci Please test

@al45tair al45tair marked this pull request as ready for review April 8, 2024 16:42
@al45tair
Copy link
Contributor Author

@swift-ci Please test

al45tair and others added 7 commits May 8, 2024 16:09
The swift-system tests were not passing, for various reasons, mostly
to do with path related confusion.

As part of this, add a function to create a temporary directory, as that
was one of the problems.

Also add Windows support for pipe() and ftruncate(), which was missing.

rdar://125087707
It seems we can get the temporary directory from confstr().

rdar://125087707
Use idiomatic Swift notation, not `Optional<Bool>`.

Prefer Win32 APIs to UCRT APIs.

rdar://125087707
This adds support for mapping POSIX-style mode bits to Windows ACLs when
calling `open()` or `mkdir()`.

rdar://125087707
Broke `FilePathTemp.swift` into separate files for POSIX and
Windows.

Added tests for permissions code on Windows.

Added leading underscores to some function names.

Made some other functions `fileprivate`.

rdar://125087707
Swift ends up with OpaquePointer instead of a typed pointer.

rdar://125087707
@al45tair
Copy link
Contributor Author

al45tair commented May 8, 2024

Rebased as some WASI stuff landed that conflicted.

@al45tair
Copy link
Contributor Author

al45tair commented May 8, 2024

@swift-ci Please test Linux platform

@al45tair
Copy link
Contributor Author

al45tair commented May 8, 2024

@swift-ci Please test macOS platform

@al45tair al45tair merged commit 027c936 into apple:main May 8, 2024
2 checks passed
/// Creates a temporary directory with a name based on the given `basename`,
/// executes `body`, passing in the path of the created directory, then
/// deletes the directory and all of its contents before returning.
public func withTemporaryFilePath<R>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Make sure that any API additions go through some kind of review, ideally on the forums. At the very least, a dedicated PR that highlights it's an API addition PR as opposed to just a bug-fix PR for Windows.

For this function, would a static method on FilePath work instead of a global? E.g. FilePath.withTemporaryPath { ... }.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it would. My only reservation is that (to me) things like FilePath.withTemporaryPath read like a function that constructs and returns a FilePath from some kind of TemporaryPath thing. This isn't the same as e.g. Array's withUnsafeBytes, because that's called on an instance rather than on the type itself. Maybe that's just because I'm used to ObjC. It's obvious from the arguments that it takes a closure, of course.

I only needed this for the tests, so for now I think the thing to do is to make this non-public (I'll raise a PR to fix that). I'll check through to make sure I didn't leak any other new API and do the same there.

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.

None yet

4 participants