Skip to content

Commit 2271f68

Browse files
authored
Merge pull request #2851 from daniel-grumberg/binary-library-artifacts-amends
Binary library artifacts amends
2 parents f5ad687 + aa82059 commit 2271f68

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

proposals/0482-swiftpm-static-library-binary-target-non-apple-platforms.md

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010

1111
## Introduction
1212

13-
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).
13+
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).
1414
However, currently SwiftPM supports linking against binary dependencies on Apple platforms only.
15-
This proposal aims to make it possible to provide static library dependencies exposing a C interface on non-Apple platforms.
16-
17-
Swift-evolution thread:
15+
This proposal aims to make it possible to provide static library dependencies exposing a C interface on non-Apple platforms that depend only on the standard C library.
16+
The scope of this proposal is C libraries only, distributing Swift libraries has additional challenges (see [Future directions](#future-directions).
1817

1918
## Motivation
2019

@@ -41,8 +40,10 @@ The artifact manifest would encode the following information for each variant:
4140
* Enough information to be able to use the library's API in the packages source code,
4241
i.e., headers and module maps for libraries exporting a C-based interface.
4342

44-
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.
43+
Additionally, 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.
4544
Such a tool would ensure that people do not accidentally distribute artifacts that require dependencies that are not met on the various deployment platforms.
45+
However when an artifact isn't widely consumed and all dependent packages are known,
46+
artifact vendors can provide artifacts with dependencies on other C libraries provided that each client target depends explicitly on all required dependencies of the artifact.
4647

4748
## Detailed design
4849

@@ -62,42 +63,49 @@ The artifact manifest JSON format for a static library is described below:
6263
"variants": [
6364
{
6465
"path": "<relative-path-to-library-file>",
65-
"headerPaths": ["<relative-path-to-header-directory-1>, ...],
66-
"moduleMapPath": "<path-to-module-map>",
6766
"supportedTriples": ["<triple1>", ... ],
67+
"staticLibraryMetadata": {
68+
"headerPaths": ["<relative-path-to-header-directory-1>, ...],
69+
"moduleMapPath": "<path-to-module-map>"
70+
}
6871
},
6972
...
7073
]
7174
},
7275
...
7376
}
7477
}
78+
7579
```
7680

7781
The additions are:
7882

7983
* The `staticLibrary` artifact `type` that indicates this binary artifact is not an executable but rather a static library to link against.
8084
* The `headerPaths` field specifies directory paths relative to the root of the artifact bundle that contain the header interfaces to the static library.
8185
These are forwarded along to the swift compiler (or the C compiler) using the usual search path arguments.
82-
Each of these directories can optionally contain a `module.modulemap` file that will be used for importing the API into Swift code.
83-
* The optional `moduleMapPath` field specifies a custom module map to use if the header paths do not contain the module definitions or to provide custom overrides.
86+
* The optional `moduleMapPath` field specifies the path relative to the root of the artifact bundle that contains a custom module map to use if the header paths do not contain the module definitions or to provide custom overrides.
87+
This field is required if the library's API is to be imported into Swift code.
8488

8589
As with executable binary artifacts, the `path` field represents the relative path to the binary from the root of the artifact bundle,
8690
and the `supportedTriples` field provides information about the target triples supported by this variant.
8791

8892
An example artifact might look like:
93+
8994
```json
9095
{
9196
"schemaVersion": "1.0",
9297
"artifacts": {
93-
"my-artifact": {
98+
"example": {
9499
"type": "staticLibrary",
95100
"version": "1.0.0",
96101
"variants": [
97102
{
98-
"path": "artifact.a",
99-
"headerPaths": ["include"],
100-
"supportedTriples": ["aarch64-unknown-linux-gnu"]
103+
"path": "libExample.a",
104+
"supportedTriples": ["aarch64-unknown-linux-gnu"],
105+
"staticLibraryMetadata": {
106+
"headerPaths": ["include"],
107+
"moduleMapPath": "include/example.modulemap"
108+
}
101109
}
102110
]
103111
}
@@ -123,7 +131,7 @@ The tool would then check that the referenced symbols list is a subset of the se
123131
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.
124132
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.
125133
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.
126-
This strategy as been succesfully employed in the Python community with [`manylinux`](https://peps.python.org/pep-0513/).
134+
This strategy as been successfully employed in the Python community with [`manylinux`](https://peps.python.org/pep-0513/).
127135

128136
## Security
129137

0 commit comments

Comments
 (0)