[SR-14796] The new swift-driver doesn't pass the '-sdk /' flag correctly to the ClangImporter -sysroot #57145
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
transfer candidate
The issue may belong in another repository
Environment
Fedora Core 33 x86_64
Additional Detail from JIRA
md5: 8027fdac6ea6c52cc590c901f8d3aba3
Issue Description:
I came across this bug when trying to build the trunk standalone stdlib with the latest official trunk snapshot build for centos8 on Fedora x86_64. It fails because it passes in
-sdk / -resource-dir build/Ninja-Release/swift-linux-x86_64/lib/swift
when building the stdlib, which then can't find basic libc headers likesys/types.h
.I'm able to reproduce by trying to build this simple test file:
import Foundation
let fm = FileManager.default
let path = NSTemporaryDirectory() + "testdir(NSUUID().uuidString)"
print("creating temporary directory (path)")
try fm.createDirectory(atPath: path, withIntermediateDirectories: false, attributes: nil)
try? fm.removeItem(atPath: path)
print("removed temporary directory (path)")
If I add the
-Xfrontend -dump-clang-diagnostics
flag to check the ClangImporter flags, I get> ./swift-DEVELOPMENT-SNAPSHOT-2021-06-12-a-centos8/usr/bin/swiftc check.swift -Xfrontend -dump-clang-diagnostics
'clang' '-fsyntax-only' '-fblocks' '-D__swift__=50500' '-fretain-comments-from-system-headers' '-isystem' '/home/butta/src/swift-DEVELOPMENT-SNAPSHOT-2021-06-12-a-centos8/usr/lib/swift' '-fPIC' '-fmodules' '-Xclang' '-fmodule-feature' '-Xclang' 'swift' '-Werror=non-modular-include-in-framework-module' '-x' 'c' '-std=gnu11' '-fmodule-map-file=/home/butta/src/swift-DEVELOPMENT-SNAPSHOT-2021-06-12-a-centos8/usr/lib/swift/linux/x86_64/glibc.modulemap' '-Xclang' '-nostdsysteminc' '-fmodules-validate-system-headers' '-Xclang' '-fmodule-format=obj' '-fapinotes-modules' '-fapinotes-swift-version=5' '-iapinotes-modules' '/home/butta/src/swift-DEVELOPMENT-SNAPSHOT-2021-06-12-a-centos8/usr/lib/swift/apinotes' '-target' 'x86_64-unknown-linux-gnu' '<swift-imported-modules>' '-resource-dir' '/home/butta/src/swift-DEVELOPMENT-SNAPSHOT-2021-06-12-a-centos8/usr/lib/swift/clang' '-fansi-escape-codes' '-working-directory' '/home/butta/src'
and that builds fine. If I add the two flags above, it fails:
> ./swift-DEVELOPMENT-SNAPSHOT-2021-06-12-a-centos8/usr/bin/swiftc check.swift -sdk / -resource-dir swift-DEVELOPMENT-SNAPSHOT-2021-06-12-a-centos8/usr/lib/swift -Xfrontend -dump-clang-diagnostics
warning: Could not read SDKSettings.json for SDK at: /home/butta/src
'clang' '-fsyntax-only' '-fblocks' '-D__swift__=50500' '-fretain-comments-from-system-headers' '-isystem' 'swift-DEVELOPMENT-SNAPSHOT-2021-06-12-a-centos8/usr/lib/swift' '-fPIC' '-fmodules' '-Xclang' '-fmodule-feature' '-Xclang' 'swift' '-Werror=non-modular-include-in-framework-module' '-x' 'c' '-std=gnu11' '-fmodule-map-file=swift-DEVELOPMENT-SNAPSHOT-2021-06-12-a-centos8/usr/lib/swift/linux/x86_64/glibc.modulemap' '--sysroot' '/home/butta/src' '-fmodules-validate-system-headers' '-Xclang' '-fmodule-format=obj' '-fapinotes-modules' '-fapinotes-swift-version=5' '-iapinotes-modules' 'swift-DEVELOPMENT-SNAPSHOT-2021-06-12-a-centos8/usr/lib/swift/apinotes' '-target' 'x86_64-unknown-linux-gnu' '<swift-imported-modules>' '-resource-dir' 'swift-DEVELOPMENT-SNAPSHOT-2021-06-12-a-centos8/usr/lib/swift/clang' '-fansi-escape-codes' '-working-directory' '/home/butta/src'
While building module 'CoreFoundation':
In file included from <module-includes>:1:
/home/butta/src/swift-DEVELOPMENT-SNAPSHOT-2021-06-12-a-centos8/usr/lib/swift/CoreFoundation/CoreFoundation.h:25:10: fatal error: 'sys/types.h' file not found
This same failing command works fine when run with the latest official build of the Swift 5.4.1 toolchain for centos8, but fails with the latest official Swift 5.5 snapshot build too. Comparing the working 5.4.1 command, I see that it is correctly passing
--sysroot /-
to the ClangImporter whereas the trunk and 5.5 snapshot builds incorrectly pass the working directory, ie-sysroot /home/butta/src
above.What gets even stranger is that I tried building the exact same tag from source on Fedora and I could not reproduce the problem, implying this is an issue with how the official builds are produced on the CI. Maybe something changed recently in the C++ toolchain used to build the Swift compiler on the CI or with how the build is prepared?
I've put together a pull on the Github Actions CI to demonstrate the same behavior on Ubuntu 20.04, so this is not specific to my Fedora environment. Note how everything works fine with the official Swift 5.4.1 build, that they have pre-installed on the CI.
@shahmishal, maybe you know what's going on here.
The text was updated successfully, but these errors were encountered: