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

Build failure with SwiftPM package with spaces in directory name on Linux #333

Open
cmcgee1024 opened this issue Mar 21, 2025 · 2 comments

Comments

@cmcgee1024
Copy link
Member

When building a SwiftPM package on a path with spaces in it there is a build failure on Linux.

Run this command from a swift-package manager Linux development environment:

swift run swift-build -v --build-system=swiftbuild --package-path=Fixtures/Miscellaneous/Spaces\ Fixture

It's expected that this should pass as it does for similar packages without spaces in the package path.

Instead, we get an error from clang:

info: Link Module Name 1_Module.o (aarch64)
    cd /swiftpm/Fixtures/Miscellaneous/Spaces\ Fixture
    /usr/bin/clang -target aarch64-unknown-linux-gnu -r --sysroot / -O0 -L/swiftpm/Fixtures/Miscellaneous/Spaces\ Fixture/.build/aarch64-unknown-linux-gnu/Intermediates.noindex/EagerLinkingTBDs/Debug-linux -L/swiftpm/Fixtures/Miscellaneous/Spaces\ Fixture/.build/aarch64-unknown-linux-gnu/Products/Debug-linux -L/usr/lib @/swiftpm/Fixtures/Miscellaneous/Spaces\ Fixture/.build/aarch64-unknown-linux-gnu/Intermediates.noindex/Spaces\ Fixture.build/Debug-linux/Module\ Name\ 1_Module.build/Objects-normal/aarch64/Module\ Name\ 1_Module.LinkFileList -nostdlib -rdynamic -o /swiftpm/Fixtures/Miscellaneous/Spaces\ Fixture/.build/aarch64-unknown-linux-gnu/Products/Debug-linux/Module\ Name\ 1_Module.o
error: unknown No such file or directory: '/swiftpm/Fixtures/Miscellaneous/Spaces' []
error: unknown No such file or directory: 'Fixture/.build/aarch64-unknown-linux-gnu/Intermediates.noindex/Spaces' []
error: unknown No such file or directory: 'Fixture.build/Debug-linux/Module' []
error: unknown No such file or directory: 'Name' []
error: unknown No such file or directory: '1_Module.build/Objects-normal/aarch64/Modules/Module_Name_1.o' []
error: unknown No such file or directory: '/swiftpm/Fixtures/Miscellaneous/Spaces' []
error: unknown No such file or directory: 'Fixture/.build/aarch64-unknown-linux-gnu/Intermediates.noindex/Spaces' []
info: Compile main.swift (aarch64)
    cd /swiftpm/Fixtures/Miscellaneous/Spaces\ Fixture

error: unknown No such file or directory: 'Fixture.build/Debug-linux/Module' []
error: unknown No such file or directory: 'Name' []
error: unknown No such file or directory: '1_Module.build/Objects-normal/aarch64/Foo.o' []
info: clang: error: no such file or directory: '/swiftpm/Fixtures/Miscellaneous/Spaces'
clang: error: no such file or directory: 'Fixture/.build/aarch64-unknown-linux-gnu/Intermediates.noindex/Spaces'
clang: error: no such file or directory: 'Fixture.build/Debug-linux/Module'
clang: error: no such file or directory: 'Name'
clang: error: no such file or directory: '1_Module.build/Objects-normal/aarch64/Modules/Module_Name_1.o'
clang: error: no such file or directory: '/swiftpm/Fixtures/Miscellaneous/Spaces'
clang: error: no such file or directory: 'Fixture/.build/aarch64-unknown-linux-gnu/Intermediates.noindex/Spaces'
clang: error: no such file or directory: 'Fixture.build/Debug-linux/Module'
clang: error: no such file or directory: 'Name'
clang: error: no such file or directory: '1_Module.build/Objects-normal/aarch64/Foo.o'
error: Build failed
@cmcgee1024
Copy link
Member Author

This appears to be caused by the way that the link file list is being set up for clang. It's interpreting the space as a file name delimiter.

@cmcgee1024
Copy link
Member Author

Clang on linux expects shell escaping for each line of the file list file. See the following section of code where the file list file is generated:

// ld64 reads lines from the file using fgets, without doing any other processing.

This comment:

// ld64 reads lines from the file using fgets, without doing any other processing.

It only applies to a specific linker, ld64. If clang, or other linkers are interpreting this file then some might have other conventions. For example, clang will directly interpret the list with @, but if the file is sent to the linker via an -Xlinker flag then the linker will read the file. It is currently unknown what binutils ld, and lld-link.exe will do in these cases.

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

1 participant