Skip to content

Linux: static libc + arm64 build #6015

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
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

bradleymackey
Copy link
Contributor

@bradleymackey bradleymackey commented Mar 8, 2025

  • Linux builds with Docker are now built using the static Linux SDK from Apple, which statically links Musl into the swiftlint binary.
  • Unfortunately, SwiftLint is inherently dependent on shared libraries, so it's not possible at the moment to produce a fully statically linked build. Hosts will need to ensure they have Swift runtime dependencies available. Alternatively, they can run SwiftLint from a Docker container, which bundles all the required runtime dependencies.
    • The aim of this change is to statically link libc (reducing the burden on the host environment to have exactly the correct glibc version).
  • Add an ARM64 build to the build artifacts and include this in linux release arifacts and the cross-platform artifact bundle.
    • The artifact paths of the original amd64 binary are unaffected, and the new arm64 binary is named swiftlint_arm64, located in the same directory as the amd64 binary.

@bradleymackey bradleymackey changed the title Linux: static builds + arm64 build Linux: static libc + arm64 build Mar 8, 2025
Copy link
Collaborator

@SimplyDanny SimplyDanny left a comment

Choose a reason for hiding this comment

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

Looking forward to this!

To test the build you could make the docker.yml workflow trigger in pull requests.

Comment on lines +79 to +82
strip artifacts/linux_amd64/usr/bin/swiftformat
mv artifacts/linux_amd64/usr/bin/swiftlint artifacts/usr/bin/swiftlint_linux_amd64
aarch64-linux-gnu-strip artifacts/linux_arm64/usr/bin/swiftformat
mv artifacts/linux_arm64/usr/bin/swiftlint artifacts/usr/bin/swiftlint_linux_arm64
Copy link
Collaborator

Choose a reason for hiding this comment

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

This refers to swiftformat. Not sure if the paths to the binaries are correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops! I'll double check all these

if: contains(env.OUTPUT_TYPE, 'local')
uses: actions/upload-artifact@v4
with:
name: swiftlint_linux_amd64
path: artifacts/usr/bin/swiftlint_linux_amd64
if-no-files-found: error
retention-days: 2
- name: Upload ARM64 binary artifact
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you can upload both files at once in only a single step.

COPY --from=builder /usr/lib/swift/linux/libswiftDispatch.so /usr/lib
COPY --from=builder /usr/lib/swift/linux/libswiftGlibc.so /usr/lib
COPY --from=builder /usr/lib/swift/linux/libswiftSynchronization.so /usr/lib
COPY --from=builder /usr/lib/swift/linux/libswiftSwiftOnoneSupport.so /usr/lib
Copy link
Collaborator

Choose a reason for hiding this comment

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

These runtime dependencies are not copied anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Still playing around here, most of these likely will need to still get copied into the container.

cp -f "$(LICENSE_PATH)" "$(ARTIFACT_BUNDLE_PATH)"
(cd "$(TEMPORARY_FOLDER)"; zip -yr - "SwiftLintBinary.artifactbundle") > "./SwiftLintBinary.artifactbundle.zip"

zip_linux: docker_image $(SWIFTLINT_EXECUTABLE_LINUX_AMD64)
zip_linux: docker_image $(SWIFTLINT_EXECUTABLE_LINUX_AMD64) $(SWIFTLINT_EXECUTABLE_LINUX_ARM64)
$(eval TMP_FOLDER := $(shell mktemp -d))
cp -f $(SWIFTLINT_EXECUTABLE_LINUX_AMD64) "$(TMP_FOLDER)/swiftlint"
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should probably rename this to swiftlint_amd64 once everything works.

--product swiftlint
--configuration release
-Xlinker -S
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are the other linker options not needed anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also still playing around here. The main issue I'm having at the moment is getting libc statically linked while keeping the other dependencies dynamically linked. --swift-sdk is seemingly always producing a fully statically linked binary.

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