Open swift-ci opened 3 years ago
Comment by Helge Heß (JIRA)
I think this is the problematic call:
/private/tmp/ubuntu/cross-toolchain/swift.xctoolchain/usr/bin/swift \
-frontend -c \
-primary-file /private/tmp/ubuntu/my-test-app/Sources/my-test-app/main.swift \
-emit-module-path /private/tmp/ubuntu/my-test-app/.build/x86_64-unknown-linux/debug/my_test_app.build/main~partial.swiftmodule \
-emit-module-doc-path /private/tmp/ubuntu/my-test-app/.build/x86_64-unknown-linux/debug/my_test_app.build/main~partial.swiftdoc \
-emit-module-source-info-path /private/tmp/ubuntu/my-test-app/.build/x86_64-unknown-linux/debug/my_test_app.build/main~partial.swiftsourceinfo \
-emit-dependencies-path /private/tmp/ubuntu/my-test-app/.build/x86_64-unknown-linux/debug/my_test_app.build/main.d \
-emit-reference-dependencies-path /private/tmp/ubuntu/my-test-app/.build/x86_64-unknown-linux/debug/my_test_app.build/main.swiftdeps \
-target x86_64-unknown-linux -disable-objc-interop \
-sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk \
-I /private/tmp/ubuntu/my-test-app/.build/x86_64-unknown-linux/debug \
-color-diagnostics -enable-testing -g \
-module-cache-path /private/tmp/ubuntu/my-test-app/.build/x86_64-unknown-linux/debug/ModuleCache \
-swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -enable-anonymous-context-mangled-names \
-module-name my_test_app \
-o /private/tmp/ubuntu/my-test-app/.build/x86_64-unknown-linux/debug/my_test_app.build/main.swift.o \
-index-store-path /private/tmp/ubuntu/my-test-app/.build/x86_64-unknown-linux/debug/index/store \
-index-system-modules
Specifically the `-sdk /Applications/Xcode.app/..../MacOSX1.15.sdk`, all the rest seems to be good.
Comment by Helge Heß (JIRA)
Steps to reproduce (no Docker or anything required, just a regular Swift install).
First make sure that the `clang_package_url` in the [`build_ubuntu_cross_compilation_toolchain`](https://github.com/apple/swift-package-manager/blob/master/Utilities/build_ubuntu_cross_compilation_toolchain) has a `https` URL, not `http`. Otherwise straight forward:
curl -o ~/Downloads/swift-5.2.4-RELEASE-ubuntu16.04.tar.gz \
https://swift.org/builds/swift-5.2.4-release/ubuntu1604/swift-5.2.4-RELEASE/swift-5.2.4-RELEASE-ubuntu16.04.tar.gz
curl -o ~/Downloads/swift-5.2.4-RELEASE-osx.pkg \
https://swift.org/builds/swift-5.2.4-release/xcode/swift-5.2.4-RELEASE/swift-5.2.4-RELEASE-osx.pkg
./build_ubuntu_cross_compilation_toolchain /tmp \
~/Downloads/swift-5.2.4-RELEASE-osx.pkg \
~/Downloads/swift-5.2.4-RELEASE-ubuntu16.04.tar.gz
mkdir my-test-app && cd my-test-app && swift package init --type=executable
swift build --destination /tmp/cross-toolchain/ubuntu-xenial-destination.json
Comment by Helge Heß (JIRA)
Some more research on this.
Actually the call outputting the `main.swift.o` seems to be good, it produces:
.build/x86_64-unknown-linux/debug/my_test_app.build/main.swift.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped
The next call is the one producing the `my_test_app.swiftmodule`, no idea whether that is OK.
But the subsequent call which produces `my_test_app.swiftmodule.o` emits a Mach-O:
/tmp/cross-toolchain/swift.xctoolchain/usr/bin/swiftc \
-modulewrap /Users/helge/Dropbox/dev/Tests/awstoolchain/my-test-app/.build/x86_64-unknown-linux/debug/my_test_app.swiftmodule \
-o /Users/helge/Dropbox/dev/Tests/awstoolchain/my-test-app/.build/x86_64-unknown-linux/debug/my_test_app.build/my_test_app.swiftmodule.o
Gives:
.build/x86_64-unknown-linux/debug/my_test_app.build/my_test_app.swiftmodule.o: Mach-O 64-bit object x86_64
which the subsequent linking step can't process:
<unknown>:0: error: error opening input file '/.build/x86_64-unknown-linux/debug/my_test_app.build/my_test_app.swiftmodule.o' (Don't know how to extract from object fileformat)
Comment by Helge Heß (JIRA)
Adding
-target x86_64-unknown-linux
to the `-modulewrap` call seems to fix the issue. (the linking one)
The linking itself fails, but that may be a different issue:
$ /tmp/cross-toolchain/swift.xctoolchain/usr/bin/swiftc -use-ld=lld -tools-directory /tmp/cross-toolchain/swift.xctoolchain/usr/bin -L /Users/helge/Dropbox/dev/Tests/awstoolchain/my-test-app/.build/x86_64-unknown-linux/debug -o /Users/helge/Dropbox/dev/Tests/awstoolchain/my-test-app/.build/x86_64-unknown-linux/debug/my-test-app -module-name my_test_app -emit-executable -Xlinker '-rpath=$ORIGIN' @/Users/helge/Dropbox/dev/Tests/awstoolchain/my-test-app/.build/x86_64-unknown-linux/debug/my-test-app.product/Objects.LinkFileList -target x86_64-unknown-linux -L /private/tmp/cross-toolchain/swift.xctoolchain/usr/lib
/tmp/cross-toolchain/swift.xctoolchain/usr/bin/ld.lld: error: cannot open Scrt1.o: No such file or directory
...
The missing crt .o files live in `ubuntu-xenial.sdk/usr/lib/x86_64-linux-gnu`, the missing libgcc etc in `ubuntu-xenial.sdk/usr/lib/gcc/x86_64-linux-gnu/5`. By adding the latter to `-L` I can get rid of the libgcc linker errors, but `-L` of course doesn't help with the `.o` files.
Comment by Helge Heß (JIRA)
The modulewrap invocation (missing the target) seems to be fixed in 5.3. Would be nice to know when this was first b0rked.
There are still the linking errors though.
Comment by Helge Heß (JIRA)
To fix the linking errors, usr/lib/swift and swift_static also (or only?) need to be copied into the target toolchain as well (the script only copies them into the host toolchain, maybe they have been looked up there before).
In addition (and I think this is just a hack-a-round to the original bug), the SDK must be explicitly passed in the `extra-swiftc-flags`, like so (thanks go to @drexin):
"extra-swiftc-flags": [
"-use-ld=lld",
"-tools-directory", "${BUILD_DIR}/${CROSS_TOOLCHAIN_NAME}/$xc_tc_name/usr/bin",
"-sdk", "${BUILD_DIR}/${CROSS_TOOLCHAIN_NAME}/$linux_sdk_name"
],
(note that the JSON already has a proper "sdk" property, which presumably is supposed to do this automatically - that the extra works might be pure luck [override the macOS sdk in the lookup sequence])
Environment
10.15.6, Xcode 11.6 zMBP20:\~ helge$ swift --version Apple Swift version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53) Target: x86_64-apple-darwin19.6.0Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Package Manager | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 5d012d9d70763762258577c97106148bIssue Description:
The `build_ubuntu_cross_compilation_toolchain` included in SPM runs through, but the resulting toolchain doesn't work anymore when compiling the (empty) example app.
I think the issue is that the SDK is not picked up:
and indeed, that .o file is a Mach-O, not an ELF one: