Comments (9)
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 --static-swift-stdlib
though, so that would need to be sorted out.
But his demonstrates that the core functionality of Yams should be usable without the Foundation dependency.
from yams.
🤔 Bad timing, maybe there is something brewing at the fruit company.
https://twitter.com/ktosopl/status/1601145297077686272?s=46&t=C2w1wZhSOLAErfvayJ24KQ
from yams.
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
.
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 import Yams; print(try Yams.load(yaml: "a: 0")!)
CLI executable is 920 KB when built for release for arm64.
from yams.
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?
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.
from yams.
Nice, that's already a great start. I think you also removed the entire Codable
support, that seems like a big loss and sth we should look into maybe. I will check it out in more details as well.
from yams.
Nice, that's already a great start. I think you also removed the entire
Codable
support, that seems like a big loss and sth we should look into maybe. I will check it out in more details as well.
Yes, I removed most of what wasn't needed for my simple Yams.load(yaml:)
demo. It's a proof-of-concept and not something meant to be seriously considered, I just wanted to show that the core Yams functionality doesn't strictly require Foundation.
from yams.
Re-added YAMLDecoder
:
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
from yams.
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 Date
, UUID
& Data
just be parsed as String
?
from yams.
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.
That's really cool. I think it would be a great initiative.
Also some questions around what to do for Foundation types. Should
Date
,UUID
&Data
just be parsed asString
?
Probably yes. The alternative to Data
usually is a simple [UInt8]
.
from yams.
Related Issues (20)
- Array / Sequence single-line flow style format encoding option? HOT 2
- Can't seem to build or import Yams (Xcode 13.2.1) HOT 2
- Add options to force using quotes for strings encoding HOT 2
- Ordered Map support HOT 1
- Error parsing markdown "code" backticks at end of line
- Compatible with SwiftyJSON
- Decode class with inheritance
- Re-enable Jazzy CI job
- Re-enable Windows SwiftPM CI jobs
- The problem with encoding floating points HOT 1
- Documentation generation fails in Swift Package Index HOT 2
- Failure to represent empty dictionary
- How does Yams serialize enum cases?
- Emojis get escaped when serializing HOT 1
- Empty keys cannot be decoded
- Strings with newlines should be encoded as multiline literals HOT 1
- Serialize loss tag HOT 1
- Yams should fail if there are duplicate keys in a mapping
- Failed to debug project with LLDB in SPM
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yams.