-
Notifications
You must be signed in to change notification settings - Fork 146
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
Yams without Foundation? #358
Comments
🤔 Bad timing, maybe there is something brewing at the fruit company. |
Yikes, that's a pretty heavy dependency. Why do you need the statically compile the Swift stdlib if you're running it on what appears to be a Docker image with Swift installed? On macOS, a simple |
Usually, we build on docker swift:5.7 but then deploy on a distroless image which has no (swift) runtime dependencies pre-installed to make the final image as small as possible. |
ok that makes sense. I hacked up a proof-of-concept to remove Foundation here: https://github.com/jpsim/Yams/compare/jp-no-foundation It removes a ton of useful features from Yams, but it gets the following compiling without Foundation: import Yams
let yaml = """
a: 0
b: 1.2
c: [1, 2, 3]
d:
- a
- b
- c
"""
dump(try Yams.load(yaml: yaml)!) And it builds and runs on Linux $ docker run -it -v `pwd`:`pwd` -w `pwd` swift:latest swift run -c release
Building for production...
Build complete! (0.20s)
▿ 4 key/value pairs
▿ (2 elements)
▿ key: AnyHashable("a")
- value: "a"
- value: 0
▿ (2 elements)
▿ key: AnyHashable("d")
- value: "d"
▿ value: 3 elements
- "a"
- "b"
- "c"
▿ (2 elements)
▿ key: AnyHashable("b")
- value: "b"
- value: 1.2
▿ (2 elements)
▿ key: AnyHashable("c")
- value: "c"
▿ value: 3 elements
- 1
- 2
- 3 There are linker errors when passing But his demonstrates that the core functionality of Yams should be usable without the Foundation dependency. |
Nice, that's already a great start. I think you also removed the entire |
Yes, I removed most of what wasn't needed for my simple |
Re-added let bandYAML = """
members:
- name: John Coltrane
age: 27
- name: Miles Davis
age: 23
"""
struct Person: Codable {
let name: String
let age: Int
}
struct Band: Codable {
let members: [Person]
}
let band = try YAMLDecoder().decode(Band.self, from: bandYAML)
dump(band) $ docker run -it -v `pwd`:`pwd` -w `pwd` swift:latest swift run -c release
Building for production...
Build complete! (0.19s)
▿ 4 key/value pairs
▿ (2 elements)
▿ key: AnyHashable("b")
- value: "b"
- value: 1.2
▿ (2 elements)
▿ key: AnyHashable("d")
- value: "d"
▿ value: 3 elements
- "a"
- "b"
- "c"
▿ (2 elements)
▿ key: AnyHashable("a")
- value: "a"
- value: 0
▿ (2 elements)
▿ key: AnyHashable("c")
- value: "c"
▿ value: 3 elements
- 1
- 2
- 3
▿ yams_cli.Band
▿ members: 2 elements
▿ yams_cli.Person
- name: "John Coltrane"
- age: 27
▿ yams_cli.Person
- name: "Miles Davis"
- age: 23 |
It's definitely possible to do this for real, not just as a proof-of-concept demo, it's just a matter of refactoring and time. Also some questions around what to do for Foundation types. Should |
That's really cool. I think it would be a great initiative.
Probably yes. The alternative to |
The state of Foundation on non Apple platforms continues to be less than ideal and brings the additional burden of increased binary size and memory footprint. Many libraries take effort the factor out their Foundation dependency in a separate module (eg. karwa/swift-url, apple/swift-nio, discussion swift-server/async-http-client, ...).
As an example, a simple "Hello World" Swift binary compiled with
swift build -c release --static-swift-stdlib
onswift:5.7.1
weighs in at7.6M
. Adding theYams
dependency increases the binary size to50M
.Of course, not relying on Foundation is not trivial, but would be good to at least map out what would need to be done to make it happen.
The text was updated successfully, but these errors were encountered: