Skip to content

Compile and Run the Manifest on Windows #2363

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

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Sources/PackageLoading/ManifestLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,11 @@ public final class ManifestLoader: ManifestLoaderProtocol {
}
#endif
cmd += [resources.swiftCompiler.pathString]
// The interpreter doesn't work on Windows yet, so instead
// we compile and run it on Windows
#if !os(Windows)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you know if it'll be available soon? I think we should break this into cleaner functions for compiling vs interpreting and then always select the compiling one for windows.

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 don't think anyone is working on it at the moment. I can split them out though, that makes sense to me.

Copy link
Member

Choose a reason for hiding this comment

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

Using #if os(Windows) for this means the code is likely to break as others do refactoring an Darwin/Linux. Can it instead be some global Bool whose default value differs on Windows, but which will allow us to test the behavior on Darwin/Linux as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

That's the plan (see my first comment).

cmd += ["--driver-mode=swift"]
#endif
cmd += bootstrapArgs()
cmd += verbosity.ccArgs
cmd += ["-L", runtimePath, "-lPackageDescription"]
Expand All @@ -438,7 +442,35 @@ public final class ManifestLoader: ManifestLoaderProtocol {
}

cmd += [manifestPath.pathString]
#if os(Windows)
try withTemporaryFile { file in
cmd += ["-o", "\(file.path).exe"]

try Process.popen(arguments: cmd)

let compileResult = try Process.popen(arguments: cmd)
let compileOutput = try (compileResult.utf8Output() + compileResult.utf8stderrOutput()).spm_chuzzle()
manifestParseResult.compilerOutput = compileOutput

// Return now if there was an error.
if compileResult.exitStatus != .terminated(code: 0) {
return
}

// Pass the fd in arguments.
cmd = ["\(file.path).exe", "-fileno", "1"]

// Run the command.
let result = try Process.popen(arguments: cmd)
manifestParseResult.parsedManifest =
try (result.utf8Output() + result.utf8stderrOutput()).spm_chuzzle()

// Return now if there was an error.
if result.exitStatus != .terminated(code: 0) {
return
}
}
#else
// Create and open a temporary file to write json to.
try withTemporaryFile { file in
// Pass the fd in arguments.
Expand Down Expand Up @@ -470,6 +502,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
}
manifestParseResult.parsedManifest = json
}
#endif
}

var manifestParseResult = ManifestParseResult()
Expand Down Expand Up @@ -563,6 +596,10 @@ public final class ManifestLoader: ManifestLoaderProtocol {
#endif
if let sdkRoot = resources.sdkRoot ?? self.sdkRoot() {
cmd += ["-sdk", sdkRoot.pathString]
#if os(Windows)
cmd += ["-resource-dir", sdkRoot.pathString + "\\usr\\lib\\swift"]
cmd += ["-L", sdkRoot.pathString + "\\usr\\lib\\swift\\windows"]
#endif
}
cmd += ["-package-description-version", manifestVersion.description]
return cmd
Expand Down