You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Swift continues to grow as a cross-platform language supporting a wide variety of use cases from [programming embedded device](https://www.swift.org/blog/embedded-swift-examples/) to [server-side development](https://www.swift.org/documentation/server/) across a multitude of [operating systems](https://www.swift.org/documentation/articles/static-linux-getting-started.html).
23
23
However, currently SwiftPM supports linking against binary dependencies on Apple platforms only.
24
-
This proposal aims to make it possible to provide static library dependencies on non-Apple platforms.
24
+
This proposal aims to make it possible to provide static library dependencies exposing a C interface on non-Apple platforms.
25
25
26
26
Swift-evolution thread:
27
27
@@ -37,7 +37,7 @@ In the current version of SwiftPM, binary targets support the following:
37
37
38
38
We aim here to bring a subset of the XCFramework capabilities to non-Apple platforms in a safe way.
39
39
40
-
While this proposal is specifically focused on binary static library dependencies without unresolved external symbols on non-Apple platforms,
40
+
While this proposal is specifically focused on binary static library dependencies without unexpected unresolved external symbols on non-Apple platforms,
41
41
it tries to do so in a way that will not prevent broader future support for static libraries and dynamically linked libraries.
42
42
43
43
## Proposed solution
@@ -50,7 +50,7 @@ The artifact manifest would encode the following information for each variant:
50
50
* Enough information to be able to use the library's API in the packages source code,
51
51
i.e., headers and module maps for libraries exporting a C-based interface.
52
52
53
-
Additionnaly, we propose the addition of an auditing tool that can validate the library artifact is safe to use across the platforms supported by the Swift project.
53
+
Additionnaly, we propose the addition of an auditing tool that can validate the library artifact is safe to use across the Linux-based platforms supported by the Swift project.
54
54
Such a tool would ensure that people do not accidentally distribute artifacts that require dependencies that are not met on the various deployment platforms.
55
55
56
56
## Detailed design
@@ -120,13 +120,20 @@ Without proper auditing it would be very easy to provide binary static library a
120
120
121
121
We propose the introduction of a new tool that can validate the "safety" of a binary library artifact across the platforms it supports and the corresponding runtime environment.
122
122
123
-
In this proposal we restrict ourselves to static libraries that do not have any external dependencies.
123
+
In this proposal we restrict ourselves to static libraries that do not have any external dependencies beyond the C standard library and runtime.
124
124
To achieve this we need to be able to detect validate this property across the three object file formats used in static libraries on our supported platforms: [Mach-O](https://developer.apple.com/library/archive/documentation/Performance/Conceptual/CodeFootprint/Articles/MachOOverview.html#//apple_ref/doc/uid/20001860-BAJGJEJC) on Apple platforms, [ELF](https://refspecs.linuxfoundation.org/elf/elf.pdf) on Linux-based platforms, and [COFF](https://learn.microsoft.com/en-us/windows/win32/debug/pe-format) on Windows.
125
125
All three formats express references to external symbols as _relocations_ which reside in a single section of each object file.
126
126
127
-
The tool would scan every object file in the static library and construct a complete list of symbols defined and referenced across the entire library.
127
+
We propose adding the `llvm-objdump` to the toolchain to provide the capability to inspect relocations across all three supported object file formats. The tool would use `llvm-objdump` every object file in the static library and construct a complete list of symbols defined and referenced across the entire library.
128
+
Additionally, the tool would construct a simple C compiler invocation to derive to generate a default linker invocation.
129
+
This would be used to derive the libraries linked by default in a C program, these libraries would then be scanned to contribute to the list of defined symbols.
128
130
The tool would then check that the referenced symbols list is a subset of the set of defined symbols and emit an error otherwise.
129
131
132
+
This would be sufficient to guarantee that all symbols from the static library would be available at runtime for statically linked executables or for ones running on the build host.
133
+
To ensure maximum runtime compatibility we would also provide a Linux-based Docker image that uses the oldest supported `glibc` for a given Swift version.
134
+
As `glibc` is backwards compatible, a container running the audit on a given static library would ensure that the version of `glibc` on any runtime platform would be compatible with the binary artifact.
135
+
This strategy as been succesfully employed in the Python community with [`manylinux`](https://peps.python.org/pep-0513/).
136
+
130
137
## Security
131
138
132
139
This proposal brings the security implications outlined in [SE-0272](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0272-swiftpm-binary-dependencies.md#security) to non-Apple platforms,
@@ -139,19 +146,16 @@ No current package should be affected by this change since this is only an addit
139
146
140
147
## Future directions
141
148
142
-
### Extend binary compatibility guarantees
149
+
### Support Swift static libraries
143
150
144
-
This proposal makes no guarantees regarding the availability of symbols in the runtime environment and therefore the auditing tool validates that all referenced symbols in the binary dependency are already resolved.
145
-
In the future we would like to provide more exhaustive guarantees about core system libraries and symbols that are guaranteed to be present on supported runtime environments, e.g. `libc.so`.
146
-
This is very similar to the [`manylinux`](https://peps.python.org/pep-0513/) effort in the Python community, but the standardization effort would need to extend to Apple platforms and Windows platforms.
147
-
Specifically we would extend the auditing tool to allow unresolved external symbols to symbols that are known to exist.
151
+
To do this we would extend the static library binary artifact manifest to provide a `.swiftinterface` file that can be consumed by the Swift compiler to import the Swift APIs.
152
+
Additionally we would extend the auditing tool to validate the usage of Swift standard library and runtime symbols, e.g., from `libSwiftCore`.
148
153
149
-
### Support Swift static libraries (needs fact checking)
154
+
### Extend binary compatibility guarantees
150
155
151
-
Today Swift static libraries can not be fully statically linked.
152
-
However, once binary compatibility guarantees are extended to include Swift SDK symbols,
153
-
static libraries exposing a purely Swift API should be supported.
154
-
To do this we would extend the static library binary artifact manifest to provide a `.swiftinterface` file that can be consumed by the Swift compiler.
156
+
This proposal limits itself to providing facilities for binary compatibility only with the C standard library and runtime.
157
+
In the future we could provide a system to allow binary artifact distributors to specify additional linkage dependencies for their binary artifacts.
158
+
These would be used to customize the operation of the audit tool and perform automatic linking of them in any client target that depends on the binary artifact, in the same way [CMake](https://cmake.org/cmake/help/v4.0/prop_tgt/INTERFACE_LINK_LIBRARIES.html) propagates link dependencies transitively.
155
159
156
160
### Add support for dynamically linked dependencies
0 commit comments