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

Adopt the static linux sdk #196

Merged
merged 9 commits into from
Jan 8, 2025
Merged

Conversation

cmcgee1024
Copy link
Member

@cmcgee1024 cmcgee1024 commented Dec 26, 2024

With the Static Linux SDK swiftly can be compiled on a particular
Linux and processor architecture and the binary can run on a very
wide variety of versions and distributions. This eliminates the need
to build swiftly on "older" Linux distributions to produce a binary
that runs on the "newer" ones>

Bump the version of swift-tools-support-core so that it compiles
successfully in a Static SDK environment with Musl.

Fix the readLine function to add a newline to the prompt so that it
prints it out before waiting on user input on stdin.

Update the build-swiftly-release tool. First, detect the version of
swift so that the matching version of the Static SDK is downloaded
and installed into the toolchain. Use the Musl that is inside it to
configure and compile libarchive along with a special must-clang
wrapper script that sets the correct compile options to use Musl
instead of the system's glibc. Finally, build the swiftly binary with
the Static SDK / Musl linking it together with the Musl compiled
libarchive.

Deprecate the old flag that would decide between RHEL UBI9
or Amazon Linux 2 as the required release building platform and
eliminate the supported Linux check.

@cmcgee1024
Copy link
Member Author

@swift-ci test macOS

Remove supported linux distribution check and deprecate command-line flag
@cmcgee1024 cmcgee1024 marked this pull request as ready for review December 27, 2024 17:22
@cmcgee1024
Copy link
Member Author

@swift-ci test macOS

@@ -45,7 +45,7 @@ public protocol InputProvider {
public var inputProvider: (any InputProvider)?

public func readLine(prompt: String) -> String? {
print(prompt, terminator: ": ")
print(prompt, terminator: ": \n")

Choose a reason for hiding this comment

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

So does the user input then get output on a new line? So the stdout would look like:

Yes or No: 
No   <-- this is my user input

?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's correct.

Something that I noticed with the switch to musl instead of libc is that the prompt doesn't get printed to stdout before the user types their answer, which is super confusing. Adding the line terminator seems to force the buffer to get flushed and printed to the screen. This is a mitigation for that behaviour. I'm not really sure why it happens and whether there's some kind of a bug in the stack, or if the bug was that it worked before.

@@ -13,6 +23,7 @@ public struct Error: LocalizedError {
}

public func runProgramEnv(_ args: String..., quiet: Bool = false, env: [String: String]?) throws {
print("\(args.joined(separator: " "))")

Choose a reason for hiding this comment

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

do we want to print this if quiet == False?

(same question below)

throw Error(message: "Swift release \(swiftVersion) has no Static SDK offering")
}

try runProgram(swift, "sdk", "install", "https://download.swift.org/swift-\(swiftVersion)-release/static-sdk/swift-\(swiftVersion)-RELEASE/swift-\(swiftVersion)-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz", "--checksum", sdkPlatform.checksum ?? "deadbeef")

Choose a reason for hiding this comment

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

the Static Linux SDK will always have this .0.0.1 version identifier? Just want to make sure this doesn't break if that format changes

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a good point. I'll ask around about the version compatibility story.

Copy link
Member Author

Choose a reason for hiding this comment

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

It appears that this version is expected to change only very rarely, if ever.

// Statically link standard libraries for maximum portability of the swiftly binary
try runProgram(swift, "build", "--product=swiftly", "--pkg-config-path=\(pkgConfigPath)/lib/pkgconfig", "--static-swift-stdlib", "--configuration=release")
try runProgram(swift, "build", "--swift-sdk", "\(arch)-swift-linux-musl", "--product=swiftly", "--pkg-config-path=\(pkgConfigPath)/lib/pkgconfig", "--static-swift-stdlib", "--configuration=release")
try runProgram(swift, "sdk", "remove", sdkName)

Choose a reason for hiding this comment

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

Could this inadvertently remove the linux SDK from a users machine even if they didn't want it to? As in they already had the static sdk installed, built swiftly, and now their SDK is gone and maybe they didn't expect that?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't expect that users should run the release script on their own machine. It should be some kind of builder where keeping the SDK around could cause problems for future builds. It's unfortunate that SDK's can't just be referenced with a file path.

@cmcgee1024
Copy link
Member Author

@swift-ci test macOS

@cmcgee1024 cmcgee1024 merged commit acd2139 into swiftlang:main Jan 8, 2025
21 checks passed
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.

2 participants