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

Draft: Swift version management, Docker multi-stage build #41

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

josefdolezal
Copy link
Collaborator

While implementing #38, I sometime struggled with steps necessary to make the app build. I'd like to pitch developer experience improvement using swiftenv for toolchain management.


The problem

The current toolchain management is hard to understand and error-prone when managing multiple versions. The configuration of supported swift versions is spread across multiple places (build scripts, Vapor app, frontend and Docker) making maintenance real challenge.

The solution

  • Offload swift toolchain management to swiftenv
  • Use installed toolchains (swiftenv versions) as the source of truth for BE and FE (using new /api/versions endpoint)
  • Drop per-toolchain OnlinePlayground in favour of Swift 5 ABI (build once, link everywhere™️)
  • (Unrelated) Use slim container for app deployment
    • Uses Docker multi-stage build (stripping final image from system swift version, node, ..)

Let me know if it sounds interesting to you and we can coordinate to finish this PR.

cmd += ["-L", projectDirectoryPath.appending(components: "OnlinePlayground", "OnlinePlayground-\(toolchain.rawValue)", ".build", "debug").pathString]
#else
cmd += ["-I", projectDirectoryPath.appending(components: "OnlinePlayground", "OnlinePlayground-\(toolchain.rawValue)", ".build", "release").pathString]
cmd += ["-L", projectDirectoryPath.appending(components: "OnlinePlayground", "OnlinePlayground-\(toolchain.rawValue)", ".build", "release").pathString]
Copy link
Owner

Choose a reason for hiding this comment

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

can't get rid of that. The OnlinePlayground-* is a helper module that is injected into each user source, and it has to work with the selected version of the swiftc - effectively need to build it with every and each supported toolchain for compatibility (less important in swift5, but it was crucial in swift 4 and 5 coexistence)

Here it's precompiled per toolchain.

what would be solution to have it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Aaah, my bad, the part with linking OnlinePlayground explicitly is missing here.

The idea is to pre-build the helper with Swift 5+, then link pre-build binary with user's code. The pre-build libs are located in lib directory (could optionally contain third party .frameworks on macOS). This approach drops support of Swift 4 (due to lack of ABI), but makes the system easier to understand and maintain.

If we wanted to maintain per-toolchain compilation independent on Swift version, then we could use docker images. The server app would only be responsible for starting containers and collecting its output - compilation and execution would happen in the container.

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

2 participants