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

Unable to build cross-architecture linux project #191

Open
dscreve opened this issue Mar 2, 2025 · 5 comments
Open

Unable to build cross-architecture linux project #191

dscreve opened this issue Mar 2, 2025 · 5 comments

Comments

@dscreve
Copy link

dscreve commented Mar 2, 2025

On x86-64 Linux, I tried to compile aarch64 linux binary.

I have created an aarch64 sdk that I have build on a Mac, and copy on x86-64 linux build system.

Then, I completely:

$>swift build -Xswiftc '-disable-round-trip-debug-types' --swift-sdk 6.0.3-bookworm-arm64

And I have link error :

error: link command failed with exit code 1 (use -v to see invocation)
ld.lld: error: /home/dscreve/.swiftpm/swift-sdks/6.0.3-bookworm-arm64.artifactbundle/6.0.3-bookworm-arm64/aarch64-unknown-linux-gnu/ubuntu-jammy.sdk/lib/aarch64-linux-gnu/Scrt1.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/.swiftpm/swift-sdks/6.0.3-bookworm-arm64.artifactbundle/6.0.3-bookworm-arm64/aarch64-unknown-linux-gnu/ubuntu-jammy.sdk/lib/aarch64-linux-gnu/crti.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/.swiftpm/swift-sdks/6.0.3-bookworm-arm64.artifactbundle/6.0.3-bookworm-arm64/aarch64-unknown-linux-gnu/ubuntu-jammy.sdk/lib/gcc/aarch64-linux-gnu/12/crtbeginS.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/.swiftpm/swift-sdks/6.0.3-bookworm-arm64.artifactbundle/6.0.3-bookworm-arm64/aarch64-unknown-linux-gnu/ubuntu-jammy.sdk/usr/lib/swift/linux/aarch64/swiftrt.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/AdjacentPairs.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/Algorithms.swiftmodule.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/Chain.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/Chunked.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/Combinations.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/Compacted.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/Cycle.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/EitherSequence.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/FirstNonNil.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/FlattenCollection.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/Grouped.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/Indexed.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/Intersperse.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/Joined.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/Keyed.swift.o is incompatible with elf64-x86-64
ld.lld: error: /home/dscreve/CypheringBackEndServer/.build/aarch64-unknown-linux-gnu/debug/Algorithms.build/MinMax.swift.o is incompatible with elf64-x86-64

@xtremekforever
Copy link
Contributor

What did you invoke to generate the aarch64 SDK? It almost looks like you created an SDK for x86_64 but with an arm64 image.

@dscreve
Copy link
Author

dscreve commented Mar 2, 2025

swiftTarget="aarch64-unknown-linux-gnu"
swift run swift-sdk-generator make-linux-sdk --with-docker --from-container-image dlta-swift-docker-arm64 --target ${swiftTarget} --sdk-name 6.0.3-bookworm-arm64

DockerFile:
FROM swift:6.0.3-bookworm

RUN apt update && apt -y install openssl libssl-dev pkg-config && apt -y clean

$>docker build --platform linux/arm64 -t dlta-swift-docker-arm64 -f dockerFile .

Note : SDK has been created on a Mac with M1 processor, and compilation is performed on linux x86-64 system targeting linux aarch64.

@xtremekforever
Copy link
Contributor

This looks like it is caused by your other ticket #192 . I saw these exact errors on my system when I tried to link openssl using a .systemLibrary with the pkgConfig directive. It's like swiftpm is trying to link x86_64 and aarch64 together, which is incompatible. Try my suggest on #192 and see if it also fixes this ticket.

@MaxDesiatov @euanh do you guys have any idea why using pkgConfig on a .systemLibrary would cause Swift PM to look for libraries on the host instead of the target? Maybe a use case that hasn't been covered/handled, or a bug?

@dscreve
Copy link
Author

dscreve commented Mar 2, 2025

This works fine.

@euanh
Copy link
Contributor

euanh commented Mar 6, 2025

@MaxDesiatov @euanh do you guys have any idea why using pkgConfig on a .systemLibrary would cause Swift PM to look for libraries on the host instead of the target? Maybe a use case that hasn't been covered/handled, or a bug?

This is swiftlang/swift-package-manager#7409. It's currently necessary to set PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH to point to the SDK root directory.

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

No branches or pull requests

3 participants