SwiftFormat icon indicating copy to clipboard operation
SwiftFormat copied to clipboard

Windows Support

Open MarkKoz opened this issue 4 years ago • 9 comments

I can't build this on Windows because glibc (used by CommandLineTool) isn't available. Is it feasible to make this support Windows? Does UCRT adequately fill in the shoes of glibc in this case? It seems like all Swift auto-formatting tools are either incompatible with Windows or unmaintained :(

MarkKoz avatar Aug 18 '21 04:08 MarkKoz

@MarkKoz I don't have a Windows machine to test on. I'd love to add Windows support though - if it's something you'd be interested in trying to make happen, I'd be happy to assist.

nicklockwood avatar Aug 18 '21 09:08 nicklockwood

#if os(macOS)
    import Darwin.POSIX
#elseif os(Windows)
    import ucrt
#else
    import Glibc
#endif

seems to work. I've been using the tool for a few hours without issues. All the tests pass too, though I don't think any of the tests specifically cover the TTY check. I'm not sure how I could manually test that either.

I get a bunch of LNK4217 warnings (no idea why) and a warning about isatty being deprecated:

SwiftFormat-master\CommandLineTool\main.swift:61:27: warning: 'isatty' is deprecated: The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _isatty. See online help for details.
private let stderrIsTTY = isatty(STDERR_FILENO) != 0

CI could be set up to include a Windows runner, but it seems like your CI is in the middle of a migration right now. It might be tricky to do this setup step in CI though, since the instructions state to do that through a specific shell that sets up VS-specific environment variables.

MarkKoz avatar Aug 18 '21 16:08 MarkKoz

it seems like your CI is in the middle of a migration right now

I'm not sure what you mean by this? I moved from Travis to GitHub actions a few weeks ago, but AFAIK that migration is complete.

nicklockwood avatar Aug 18 '21 20:08 nicklockwood

Thought the build was failing, but that's just the coverage step.

MarkKoz avatar Aug 18 '21 21:08 MarkKoz

The cache is hard-coded to /var/tmp, but this isn't an appropriate directory on Windows. I think a good place would be the local AppData directory.

MarkKoz avatar Aug 20 '21 15:08 MarkKoz

@MarkKoz are you still interested in pursuing this?

nicklockwood avatar Mar 07 '22 10:03 nicklockwood

Yes.

MarkKoz avatar Mar 07 '22 19:03 MarkKoz

Any news on Windows support?

insinfo avatar Oct 08 '23 22:10 insinfo

@insinfo SwiftFormat builds for Windows, and there are Windows binaries included on the releases page. As far as I know they should work?

nicklockwood avatar Oct 09 '23 06:10 nicklockwood