I'm building a Swift application for a custom ARM64 Linux distribution and encountering a runtime error after changing from a POSIX-standard filesystem layout to a custom directory structure.
Environment
- Platform: ARM64 Linux (custom distribution)
- Swift SDK:
aarch64-swift-linux-musl
- Build Configuration: Static linking with musl
- Target: Custom embedded system
Build Command
swift build \ -c release \ --scratch-path $SRC_DIR/workbench/build \ --swift-sdk aarch64-swift-linux-musl \ --static-swift-stdlib
Binary Verification
The binary appears correctly built as static:
$ file workbench workbench: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, BuildID[sha1]=fb50f07fe80fed49d38daceb2840c2acc7268012, with debug_info, not stripped $ ldd workbench not a dynamic executable
Filesystem Layout Change
Working layout (POSIX standard):
/bin, /sbin, /var, /proc, /sys, /etc, /usr, /lib64
New layout (custom - causing issues):
/Applications /System/Binary /System/Processes /System/Boot /System/Settings /Settings /Boot /Station
Error Message
Unable to obtain Swift runtime path
What Changed
The application worked perfectly on the standard POSIX filesystem layout. After migrating to our custom directory structure (moving from /bin
, /sbin
, etc. to /Applications
, /System/Binary
, etc.), the same statically-linked binary now fails with the runtime path error.
Questions
-
Why would a statically-linked Swift binary need to resolve runtime paths? I expected static linking to embed everything needed.
-
Does Swift runtime have hardcoded assumptions about standard POSIX paths like
/usr/lib
,/lib
, etc.? -
Are there build flags or environment variables to override Swift's runtime path detection for custom filesystem layouts?
-
Could this be related to the Swift runtime trying to access
/proc
or other standard directories that don't exist in our custom layout? -> moved to/System/Processes
?
What I've Tried
- Verified the binary is truly statically linked
- Confirmed all Swift stdlib is statically linked with
--static-swift-stdlib
- The only change between working and non-working versions was the filesystem directory structure (I think, try to analyse the git history of my team, but only kernel options are added)
Additional Context
This is for an embedded system project where we need a custom filesystem layout for organizational reasons. The Swift application serves as a terminal interface (TUI) for system management.
Any insights into Swift's runtime path resolution mechanism or workarounds for custom filesystem layouts would be greatly appreciated!
Thank you,
Kris