Giter Site home page Giter Site logo

Yams without Foundation? about yams HOT 9 OPEN

t089 avatar t089 commented on August 16, 2024
Yams without Foundation?

from yams.

Comments (9)

jpsim avatar jpsim commented on August 16, 2024 1

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.

t089 avatar t089 commented on August 16, 2024

🤔 Bad timing, maybe there is something brewing at the fruit company.
https://twitter.com/ktosopl/status/1601145297077686272?s=46&t=C2w1wZhSOLAErfvayJ24KQ

from yams.

jpsim avatar jpsim commented on August 16, 2024

As an example, a simple "Hello World" Swift binary compiled with swift build -c release --static-swift-stdlib on swift:5.7.1 weighs in at 7.6M. Adding the Yams dependency increases the binary size to 50M.

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.

t089 avatar t089 commented on August 16, 2024

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.

t089 avatar t089 commented on August 16, 2024

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.

jpsim avatar jpsim commented on August 16, 2024

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.

jpsim avatar jpsim commented on August 16, 2024

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.

jpsim avatar jpsim commented on August 16, 2024

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.

t089 avatar t089 commented on August 16, 2024

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 as String?

Probably yes. The alternative to Data usually is a simple [UInt8].

from yams.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.