C dependencies


(Drew Crawford) #1

I noticed the README for the package manager seems to take a strong view of source distribution:

Packages are distributed and consumed as source code, rather than pre-compiled binaries.
Although it requires additional computational resources, this approach guarantees that developers can adopt new features on platforms they support, without being reliant on vendors to supply updated dependencies. This also has the advantage of allowing tools to do things like automated testing and API analysis of package dependencies.

I maintain a lot of Swift software with C dependencies. For example, I develop Swift frameworks that ship with libsodium statically linked. AFAIK the new Foundation will have various C dynamic and static dependencies. Etc.

What is the vision for distributing this software with the package manager?

1. Will it barf if the user does not have the C dependencies already installed on their machine?
    1a. What about iOS, where there is no concept of this? Can I not build iOS libraries using the package manager?
2. Are all binary packages forbidden? Is there any mechanism like homebrew's bottles for distributing software that is arcane to compile?
3. Can I write a script that tries to resolve various C dependencies my project needs to link with?
4. Is it a design goal to distribute Foundation via the package manager?


(Daniel Dunbar) #2

I would say that our main goals are two fold:
1. Support a great development experience for building projects from source, where we build everything into the sandbox for that project. We would like to eventually support being able to build more complex dependencies (like external C projects) as part of a package build.
2. Leave deployment and installation of packages to system package managers (i.e., someone else).

As a good example of #1, it would be awesome if in the future that even a project like the Swift compiler itself -- with its complicated dependency tree and build process -- could be configured and built with the package manager.

The goals here are mostly oriented around how do we give the best possible developer experience for constructing source code. I strongly believe that the "container" / "sandbox" model is the right way to go in order to build tools which give reproducible results, allow for easy sharing and deployment, and encourage modular development. If you look at how easy and portable it is to install projects with complex dependencies in ecosystems like Python + virtualenv, that is the kind of environment we want for Swift and eventually for the C family dependencies.

Goal #2 of trying to stay out of the system package manager business (installing built software) is more out of trying to maintain a clear focus and emphasis than anything else. We already have a ton of work to do on the package manager even within that scope, so it just makes sense for now to leave this problem to existing projects better suited to the task.

FWIW, I am working on a proposal for our initial support for *building* C family sources as part of Swift packages. Depending on exactly how complicated your dependencies are (and if you give me pointers to the full tree I would be interested in checking them out as test cases), this feature may be enough that you could in theory get your Swift package to also build the necessary C libraries (with some adaption work). Stay tuned...

I noticed the README for the package manager seems to take a strong view of source distribution:

Packages are distributed and consumed as source code, rather than pre-compiled binaries.
Although it requires additional computational resources, this approach guarantees that developers can adopt new features on platforms they support, without being reliant on vendors to supply updated dependencies. This also has the advantage of allowing tools to do things like automated testing and API analysis of package dependencies.

I maintain a lot of Swift software with C dependencies. For example, I develop Swift frameworks that ship with libsodium statically linked. AFAIK the new Foundation will have various C dynamic and static dependencies. Etc.

What is the vision for distributing this software with the package manager?

1. Will it barf if the user does not have the C dependencies already installed on their machine?
   1a. What about iOS, where there is no concept of this? Can I not build iOS libraries using the package manager?

Yes, it would barf. We are open to improving the reliability of the "system modules" mechanism to be more robust. We do need to support interoperating with installed libraries, and it would be great to make this as smooth as possible.

2. Are all binary packages forbidden? Is there any mechanism like homebrew's bottles for distributing software that is arcane to compile?

We don't have such a mechanism, and as I said the goal of the package manager is to build your project, not distribute it as installable packages. I can imagine adding mechanisms to *help you create* an easily installable product, but I think the actual installation of that product should be left to other tools.

3. Can I write a script that tries to resolve various C dependencies my project needs to link with?

Not currently. What exactly are you envisioning here?

4. Is it a design goal to distribute Foundation via the package manager?

I'm not sure what you mean. Foundation itself is a special case, it is something we consider part of the Swift corelibs and will ship with the Swift compiler.

We *would* like to be able to build the Foundation project with the package manager, but there are a lot of things that need to get sorted out before that can happen.

HTH,
- Daniel

···

On Dec 12, 2015, at 5:04 AM, Drew Crawford via swift-build-dev <swift-build-dev@swift.org> wrote:

_______________________________________________
swift-build-dev mailing list
swift-build-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-build-dev


(Drew Crawford) #3

1. Support a great development experience for building projects from source, where we build everything into the sandbox for that project. We would like to eventually support being able to build more complex dependencies (like external C projects) as part of a package build.
2. Leave deployment and installation of packages to system package managers (i.e., someone else).

Okay, this is good information. The output of the package manager is a .a (or .so, .dylib, Mach-O executable, etc.) and it is your job to install that to a path on your system, or not. This seems like a good model. I might suggest updating the README in some way that explains this.

This is actually vaguely analogous to Rust's cargo, so I would suggest looking there for design concepts, as they are quite a bit further ahead of us on this problem.

If you look at how easy and portable it is to install projects with complex dependencies in ecosystems like Python + virtualenv, that is the kind of environment we want for Swift and eventually for the C family dependencies.

I'm (sadly) intimately familiar. It is not really all that easy, primarily because of binary hell, as anyone who has googled how to install pycairo can attest. I really want to do better on this problem than Python does.

Here's a concrete question: how would we advise a hypothetical swiftcairo project to package themselves in the package manager? Should they:

1. Call out to a shell script that does `brew install cairo` on OSX, `apt-get install cairo` on Debian, etc.
2. Print some error telling them to come back when they've installed cairo somewhere on their system. Good luck, kid
3. Write a shell script that downloads and builds cairo from source including all its dependencies
4. Create a tree in the swift package manager like

swiftcairo <-- cairo <-------pixman
                     <-------freetype
                     <-------fontconfig
                     <-------libpng
                     <-------glib
  Where each of these "packages" are mostly a shell script that runs a lot of `curl -O` `tar xf` `configure` `make` etc.
5. Do we try and second-guess what libpng's autotools want to do? (Bad, bad, idea. Build the way libpng decided to build, don't try to guess based on the arrangement of .c files in a folder)
6. Other ideas?

A vision for the pathological case like Cairo will illuminate the simpler cases. IMO it would be nice if "depends: swiftcairo" would 'just work', but that may be out of scope.

(and if you give me pointers to the full tree I would be interested in checking them out as test cases), this feature may be enough that you could in theory get your Swift package to also build the necessary C libraries (with some adaption work). Stay tuned...

NaOH <https://code.sealedabstract.com/drewcrawford/NaOH> is a good test case. It's a framework that statically links libsodium. My current (terrible) workflow is:

1. Download libsodium-xx.tar.gz <https://github.com/jedisct1/libsodium/releases> from GitHub
2. ./configure && make
3. Move binaries + .h around to where Xcode can find them
4. Check into source control
5. Build

Would love to automate this and get it building with the package manager. There's actually been an issue open <https://code.sealedabstract.com/drewcrawford/NaOH/issues/1> since pretty much day 1 to get this working. That is the problem that motivated me to post.

···

On Dec 12, 2015, at 11:02 AM, Daniel Dunbar <daniel_dunbar@apple.com> wrote:

I would say that our main goals are two fold:
1. Support a great development experience for building projects from source, where we build everything into the sandbox for that project. We would like to eventually support being able to build more complex dependencies (like external C projects) as part of a package build.
2. Leave deployment and installation of packages to system package managers (i.e., someone else).

As a good example of #1, it would be awesome if in the future that even a project like the Swift compiler itself -- with its complicated dependency tree and build process -- could be configured and built with the package manager.

The goals here are mostly oriented around how do we give the best possible developer experience for constructing source code. I strongly believe that the "container" / "sandbox" model is the right way to go in order to build tools which give reproducible results, allow for easy sharing and deployment, and encourage modular development. If you look at how easy and portable it is to install projects with complex dependencies in ecosystems like Python + virtualenv, that is the kind of environment we want for Swift and eventually for the C family dependencies.

Goal #2 of trying to stay out of the system package manager business (installing built software) is more out of trying to maintain a clear focus and emphasis than anything else. We already have a ton of work to do on the package manager even within that scope, so it just makes sense for now to leave this problem to existing projects better suited to the task.

FWIW, I am working on a proposal for our initial support for *building* C family sources as part of Swift packages. Depending on exactly how complicated your dependencies are (and if you give me pointers to the full tree I would be interested in checking them out as test cases), this feature may be enough that you could in theory get your Swift package to also build the necessary C libraries (with some adaption work). Stay tuned...

On Dec 12, 2015, at 5:04 AM, Drew Crawford via swift-build-dev <swift-build-dev@swift.org> wrote:

I noticed the README for the package manager seems to take a strong view of source distribution:

Packages are distributed and consumed as source code, rather than pre-compiled binaries.
Although it requires additional computational resources, this approach guarantees that developers can adopt new features on platforms they support, without being reliant on vendors to supply updated dependencies. This also has the advantage of allowing tools to do things like automated testing and API analysis of package dependencies.

I maintain a lot of Swift software with C dependencies. For example, I develop Swift frameworks that ship with libsodium statically linked. AFAIK the new Foundation will have various C dynamic and static dependencies. Etc.

What is the vision for distributing this software with the package manager?

1. Will it barf if the user does not have the C dependencies already installed on their machine?
  1a. What about iOS, where there is no concept of this? Can I not build iOS libraries using the package manager?

Yes, it would barf. We are open to improving the reliability of the "system modules" mechanism to be more robust. We do need to support interoperating with installed libraries, and it would be great to make this as smooth as possible.

2. Are all binary packages forbidden? Is there any mechanism like homebrew's bottles for distributing software that is arcane to compile?

We don't have such a mechanism, and as I said the goal of the package manager is to build your project, not distribute it as installable packages. I can imagine adding mechanisms to *help you create* an easily installable product, but I think the actual installation of that product should be left to other tools.

3. Can I write a script that tries to resolve various C dependencies my project needs to link with?

Not currently. What exactly are you envisioning here?

4. Is it a design goal to distribute Foundation via the package manager?

I'm not sure what you mean. Foundation itself is a special case, it is something we consider part of the Swift corelibs and will ship with the Swift compiler.

We *would* like to be able to build the Foundation project with the package manager, but there are a lot of things that need to get sorted out before that can happen.

HTH,
- Daniel

_______________________________________________
swift-build-dev mailing list
swift-build-dev@swift.org <mailto:swift-build-dev@swift.org>
https://lists.swift.org/mailman/listinfo/swift-build-dev


(Daniel Dunbar) #4

1. Support a great development experience for building projects from source, where we build everything into the sandbox for that project. We would like to eventually support being able to build more complex dependencies (like external C projects) as part of a package build.
2. Leave deployment and installation of packages to system package managers (i.e., someone else).

Okay, this is good information. The output of the package manager is a .a (or .so, .dylib, Mach-O executable, etc.) and it is your job to install that to a path on your system, or not. This seems like a good model. I might suggest updating the README in some way that explains this.

Good point, we don't really have any docs on the output. I don't have time to tackle this currently, but if patches here would be welcome. I believe Max also has some plans to make the build products more obvious (not hidden in the .build dir), the current system hasn't really been "designed" yet.

This is actually vaguely analogous to Rust's cargo, so I would suggest looking there for design concepts, as they are quite a bit further ahead of us on this problem.

Yup. I can't say I've had the time to seriously study cargo and the state of its ecosystem, but I am aware of it. I'd appreciate pointers if there are specific things you are thinking about.

If you look at how easy and portable it is to install projects with complex dependencies in ecosystems like Python + virtualenv, that is the kind of environment we want for Swift and eventually for the C family dependencies.

I'm (sadly) intimately familiar. It is not really all that easy, primarily because of binary hell, as anyone who has googled how to install pycairo can attest. I really want to do better on this problem than Python does.

I think it depends on the project. For web stacks it can be awesome to pull down a dependency tree w/ C extensions for PostgreSQL, Redis, etc. and a lot of stuff "just works". For more complicated C projects I agree it isn't a slam dunk.

Here's a concrete question: how would we advise a hypothetical swiftcairo project to package themselves in the package manager? Should they:

Well, we don't really support any of these features yet so our current advisement would be "we need to design this feature". :slight_smile:

1. Call out to a shell script that does `brew install cairo` on OSX, `apt-get install cairo` on Debian, etc.

Currently, this is the only supported thing. But I want to do better than this...

2. Print some error telling them to come back when they've installed cairo somewhere on their system. Good luck, kid
3. Write a shell script that downloads and builds cairo from source including all its dependencies
4. Create a tree in the swift package manager like

swiftcairo <-- cairo <-------pixman
                     <-------freetype
                     <-------fontconfig
                     <-------libpng
                     <-------glib
  Where each of these "packages" are mostly a shell script that runs a lot of `curl -O` `tar xf` `configure` `make` etc.
5. Do we try and second-guess what libpng's autotools want to do? (Bad, bad, idea. Build the way libpng decided to build, don't try to guess based on the arrangement of .c files in a folder)
6. Other ideas?

A vision for the pathological case like Cairo will illuminate the simpler cases. IMO it would be nice if "depends: swiftcairo" would 'just work', but that may be out of scope.

My proposal is:

1. We include some native support for C/C++ libraries. This should be "well designed", but ideally would scale up to supporting very support complex projects (like `swiftc`). I care about this part deeply because there is a lot of awesome stuff I want to do in llbuild + clang, and that depends on being able to get the project onto those tools. We will by necessity need to start with a small limited scope and feature creep our way forward.

2. We provide an adaption mechanism, to allow projects that can't yet be built by #1 to still integrate directly into the ecosystem. This can take two forms:

2.a. For projects which *could* conform to #1, but the only problem is the upstream project doesn't want to change (or hasn't yet), then we could support an adaption mechanism which just took in the upstream project and overlayed the appropriate Package.swift definitions that we need to use to build it. This means that swiftpm + llbuild would have a full understanding of the build process, which is the ideal scenario for the ensuring a good user experience.

2.b. For projects which are just "too complicated" to do #2.a, we would allow a form of your #3 (a shell script which downloads and builds). The way I envision this working is that:
- I'd like to avoid the script actually downloading anything, I think we should still try and use our model for pulling the sources. This may mean someone maintains a tagged version of an adaptor package that includes the source of the upstream project + the adaptor pieces.
- We would require a very strict interface between that script and the rest of the package manager. Essentially, we would provide the script with its inputs, and we would expect it to produce, as an output, the exact kind of build layout that we ourselves would have done for project in case #2.a. In practice, those scripts would usually look something like " configure && make && ... move the built products around a bunch to conform to the expected layout ...". We would run the script in appropriate dependency order, then ingest / audit all of the outputs, and from then on it would integrate just like #2.a.

We need to be very careful about doing #2.b in a way that doesn't restrict our ability to evolve...

One thing I would like to call out is that I don't feel like we need to directly support the total amount of complexity that exists in the world w.r.t. C family projects. I want use to help make the world more sane by coming up with sensible conventions and models for C family projects, and then apply pressure in other places to reduce unnecessary complexity or to converge on semi-standard solutions. I outlined a bit more of my philosophy here in:
  https://lists.swift.org/pipermail/swift-build-dev/Week-of-Mon-20151130/000027.html

(and if you give me pointers to the full tree I would be interested in checking them out as test cases), this feature may be enough that you could in theory get your Swift package to also build the necessary C libraries (with some adaption work). Stay tuned...

NaOH <https://code.sealedabstract.com/drewcrawford/NaOH> is a good test case. It's a framework that statically links libsodium. My current (terrible) workflow is:

1. Download libsodium-xx.tar.gz <https://github.com/jedisct1/libsodium/releases> from GitHub
2. ./configure && make
3. Move binaries + .h around to where Xcode can find them
4. Check into source control
5. Build

Would love to automate this and get it building with the package manager. There's actually been an issue open <https://code.sealedabstract.com/drewcrawford/NaOH/issues/1> since pretty much day 1 to get this working. That is the problem that motivated me to post.

Cool, thanks for the pointer I will check it out.

- Daniel

···

On Dec 12, 2015, at 3:46 PM, Drew Crawford <drew@sealedabstract.com> wrote:

On Dec 12, 2015, at 11:02 AM, Daniel Dunbar <daniel_dunbar@apple.com <mailto:daniel_dunbar@apple.com>> wrote:

I would say that our main goals are two fold:
1. Support a great development experience for building projects from source, where we build everything into the sandbox for that project. We would like to eventually support being able to build more complex dependencies (like external C projects) as part of a package build.
2. Leave deployment and installation of packages to system package managers (i.e., someone else).

As a good example of #1, it would be awesome if in the future that even a project like the Swift compiler itself -- with its complicated dependency tree and build process -- could be configured and built with the package manager.

The goals here are mostly oriented around how do we give the best possible developer experience for constructing source code. I strongly believe that the "container" / "sandbox" model is the right way to go in order to build tools which give reproducible results, allow for easy sharing and deployment, and encourage modular development. If you look at how easy and portable it is to install projects with complex dependencies in ecosystems like Python + virtualenv, that is the kind of environment we want for Swift and eventually for the C family dependencies.

Goal #2 of trying to stay out of the system package manager business (installing built software) is more out of trying to maintain a clear focus and emphasis than anything else. We already have a ton of work to do on the package manager even within that scope, so it just makes sense for now to leave this problem to existing projects better suited to the task.

FWIW, I am working on a proposal for our initial support for *building* C family sources as part of Swift packages. Depending on exactly how complicated your dependencies are (and if you give me pointers to the full tree I would be interested in checking them out as test cases), this feature may be enough that you could in theory get your Swift package to also build the necessary C libraries (with some adaption work). Stay tuned...

On Dec 12, 2015, at 5:04 AM, Drew Crawford via swift-build-dev <swift-build-dev@swift.org <mailto:swift-build-dev@swift.org>> wrote:

I noticed the README for the package manager seems to take a strong view of source distribution:

Packages are distributed and consumed as source code, rather than pre-compiled binaries.
Although it requires additional computational resources, this approach guarantees that developers can adopt new features on platforms they support, without being reliant on vendors to supply updated dependencies. This also has the advantage of allowing tools to do things like automated testing and API analysis of package dependencies.

I maintain a lot of Swift software with C dependencies. For example, I develop Swift frameworks that ship with libsodium statically linked. AFAIK the new Foundation will have various C dynamic and static dependencies. Etc.

What is the vision for distributing this software with the package manager?

1. Will it barf if the user does not have the C dependencies already installed on their machine?
  1a. What about iOS, where there is no concept of this? Can I not build iOS libraries using the package manager?

Yes, it would barf. We are open to improving the reliability of the "system modules" mechanism to be more robust. We do need to support interoperating with installed libraries, and it would be great to make this as smooth as possible.

2. Are all binary packages forbidden? Is there any mechanism like homebrew's bottles for distributing software that is arcane to compile?

We don't have such a mechanism, and as I said the goal of the package manager is to build your project, not distribute it as installable packages. I can imagine adding mechanisms to *help you create* an easily installable product, but I think the actual installation of that product should be left to other tools.

3. Can I write a script that tries to resolve various C dependencies my project needs to link with?

Not currently. What exactly are you envisioning here?

4. Is it a design goal to distribute Foundation via the package manager?

I'm not sure what you mean. Foundation itself is a special case, it is something we consider part of the Swift corelibs and will ship with the Swift compiler.

We *would* like to be able to build the Foundation project with the package manager, but there are a lot of things that need to get sorted out before that can happen.

HTH,
- Daniel

_______________________________________________
swift-build-dev mailing list
swift-build-dev@swift.org <mailto:swift-build-dev@swift.org>
https://lists.swift.org/mailman/listinfo/swift-build-dev


(Drew Crawford) #5

Yup. I can't say I've had the time to seriously study cargo and the state of its ecosystem, but I am aware of it. I'd appreciate pointers if there are specific things you are thinking about.

Well, the bullet list of learning from cargo:

Enforce a consistent file structure on sourcecode (which we do)
Consider using [swift] as a scripting language for external builds rather than bash
swift as manifest seems more powerful than is strictly necessary, but I do see some advantages too
Let the user choose static link, dynamic link, debug, release, --with-openssl, --target=iOS, etc. at the CLI
Have a synonym for "make check"
Have a .lock file that records the dependency revs actually used
Do something sane when the dependency repository is a git URL to an autotools project

I would +1 most of your proposal (prefer llbuild, scripting escape hatch, tagged sources, etc.) but I forsee a potential problem on this point:

One of my personal beliefs is that part of the reason software packaging & integration has historically been so messy is because no one has been able to be a "force for change" and cause projects to adapt. For C/C++/Obj-C projects, there are a lot of "unnecessary" variations in the project structure which add complexity for very little overall gain.

While this is true, this seems like an https://xkcd.com/927/ kind of statement. I think this project has the potential for moral authority (or "force for change" as you put it), but the exact magnitude of the moral authority is unknown and I estimate it lower than perhaps you do.

I think swift-pm derives its moral authority from two facts:

That it's an official, swift.org <http://swift.org/> project, like Rust's cargo, go get, etc.
That people want a build system for Linux now and so they have to rethink their packaging anyway

However these two facts are only relevant for **swift** projects. That is to say, libpng already builds on Linux and is not actively shopping for a new build system. Nor do they care about packaging with the Approved Method™ from swift.org <http://swift.org/>, a language they do not even use. And when push comes to shove, swift projects need libpng more badly than they need the Approved Packaging Method™.

tl;dr it is actually the C dependencies here which have the moral authority. Any conflict between what swift-pm wants and what libpng wants will be resolved in favor of libpng. You cannot tell swift developers to go apply pressure to libpng to switch build systems; we lack standing.

Well, we don't really support any of these features yet so our current advisement would be "we need to design this feature". :slight_smile:

Well yes, but in the context of the above, I'm suggesting that the C dependency story and courting libpng etc (if that is in fact important) is more important than nearly any other problem. I can live for a few months without unit tests, configuration options, build environment isolation, versioning, etc. I can PR those as I need them, it is mostly obvious what is the right patch to write, from the README alone.

I can't build without libsodium. I can't build without libpng. So forget about months, I can't get ten minutes into being a user even on one platform without making a decision on how to build C dependencies. And it is much less obvious what the right thing to PR here is.

I think it is potentially something like your 2b, but it seems presently underspecified ("We need to be very careful about doing #2.b in a way that doesn't restrict our ability to evolve") and I'm uncertain if there's anything concrete that can be done to get it into an implementable state.

···

On Dec 13, 2015, at 1:55 PM, Daniel Dunbar <daniel_dunbar@apple.com> wrote:

On Dec 12, 2015, at 3:46 PM, Drew Crawford <drew@sealedabstract.com <mailto:drew@sealedabstract.com>> wrote:

1. Support a great development experience for building projects from source, where we build everything into the sandbox for that project. We would like to eventually support being able to build more complex dependencies (like external C projects) as part of a package build.
2. Leave deployment and installation of packages to system package managers (i.e., someone else).

Okay, this is good information. The output of the package manager is a .a (or .so, .dylib, Mach-O executable, etc.) and it is your job to install that to a path on your system, or not. This seems like a good model. I might suggest updating the README in some way that explains this.

Good point, we don't really have any docs on the output. I don't have time to tackle this currently, but if patches here would be welcome. I believe Max also has some plans to make the build products more obvious (not hidden in the .build dir), the current system hasn't really been "designed" yet.

This is actually vaguely analogous to Rust's cargo, so I would suggest looking there for design concepts, as they are quite a bit further ahead of us on this problem.

Yup. I can't say I've had the time to seriously study cargo and the state of its ecosystem, but I am aware of it. I'd appreciate pointers if there are specific things you are thinking about.

If you look at how easy and portable it is to install projects with complex dependencies in ecosystems like Python + virtualenv, that is the kind of environment we want for Swift and eventually for the C family dependencies.

I'm (sadly) intimately familiar. It is not really all that easy, primarily because of binary hell, as anyone who has googled how to install pycairo can attest. I really want to do better on this problem than Python does.

I think it depends on the project. For web stacks it can be awesome to pull down a dependency tree w/ C extensions for PostgreSQL, Redis, etc. and a lot of stuff "just works". For more complicated C projects I agree it isn't a slam dunk.

Here's a concrete question: how would we advise a hypothetical swiftcairo project to package themselves in the package manager? Should they:

Well, we don't really support any of these features yet so our current advisement would be "we need to design this feature". :slight_smile:

1. Call out to a shell script that does `brew install cairo` on OSX, `apt-get install cairo` on Debian, etc.

Currently, this is the only supported thing. But I want to do better than this...

2. Print some error telling them to come back when they've installed cairo somewhere on their system. Good luck, kid
3. Write a shell script that downloads and builds cairo from source including all its dependencies
4. Create a tree in the swift package manager like

swiftcairo <-- cairo <-------pixman
                     <-------freetype
                     <-------fontconfig
                     <-------libpng
                     <-------glib
  Where each of these "packages" are mostly a shell script that runs a lot of `curl -O` `tar xf` `configure` `make` etc.
5. Do we try and second-guess what libpng's autotools want to do? (Bad, bad, idea. Build the way libpng decided to build, don't try to guess based on the arrangement of .c files in a folder)
6. Other ideas?

A vision for the pathological case like Cairo will illuminate the simpler cases. IMO it would be nice if "depends: swiftcairo" would 'just work', but that may be out of scope.

My proposal is:

1. We include some native support for C/C++ libraries. This should be "well designed", but ideally would scale up to supporting very support complex projects (like `swiftc`). I care about this part deeply because there is a lot of awesome stuff I want to do in llbuild + clang, and that depends on being able to get the project onto those tools. We will by necessity need to start with a small limited scope and feature creep our way forward.

2. We provide an adaption mechanism, to allow projects that can't yet be built by #1 to still integrate directly into the ecosystem. This can take two forms:

2.a. For projects which *could* conform to #1, but the only problem is the upstream project doesn't want to change (or hasn't yet), then we could support an adaption mechanism which just took in the upstream project and overlayed the appropriate Package.swift definitions that we need to use to build it. This means that swiftpm + llbuild would have a full understanding of the build process, which is the ideal scenario for the ensuring a good user experience.

2.b. For projects which are just "too complicated" to do #2.a, we would allow a form of your #3 (a shell script which downloads and builds). The way I envision this working is that:
- I'd like to avoid the script actually downloading anything, I think we should still try and use our model for pulling the sources. This may mean someone maintains a tagged version of an adaptor package that includes the source of the upstream project + the adaptor pieces.
- We would require a very strict interface between that script and the rest of the package manager. Essentially, we would provide the script with its inputs, and we would expect it to produce, as an output, the exact kind of build layout that we ourselves would have done for project in case #2.a. In practice, those scripts would usually look something like " configure && make && ... move the built products around a bunch to conform to the expected layout ...". We would run the script in appropriate dependency order, then ingest / audit all of the outputs, and from then on it would integrate just like #2.a.

We need to be very careful about doing #2.b in a way that doesn't restrict our ability to evolve...

One thing I would like to call out is that I don't feel like we need to directly support the total amount of complexity that exists in the world w.r.t. C family projects. I want use to help make the world more sane by coming up with sensible conventions and models for C family projects, and then apply pressure in other places to reduce unnecessary complexity or to converge on semi-standard solutions. I outlined a bit more of my philosophy here in:
  https://lists.swift.org/pipermail/swift-build-dev/Week-of-Mon-20151130/000027.html

(and if you give me pointers to the full tree I would be interested in checking them out as test cases), this feature may be enough that you could in theory get your Swift package to also build the necessary C libraries (with some adaption work). Stay tuned...

NaOH <https://code.sealedabstract.com/drewcrawford/NaOH> is a good test case. It's a framework that statically links libsodium. My current (terrible) workflow is:

1. Download libsodium-xx.tar.gz <https://github.com/jedisct1/libsodium/releases> from GitHub
2. ./configure && make
3. Move binaries + .h around to where Xcode can find them
4. Check into source control
5. Build

Would love to automate this and get it building with the package manager. There's actually been an issue open <https://code.sealedabstract.com/drewcrawford/NaOH/issues/1> since pretty much day 1 to get this working. That is the problem that motivated me to post.

Cool, thanks for the pointer I will check it out.

- Daniel

On Dec 12, 2015, at 11:02 AM, Daniel Dunbar <daniel_dunbar@apple.com <mailto:daniel_dunbar@apple.com>> wrote:

I would say that our main goals are two fold:
1. Support a great development experience for building projects from source, where we build everything into the sandbox for that project. We would like to eventually support being able to build more complex dependencies (like external C projects) as part of a package build.
2. Leave deployment and installation of packages to system package managers (i.e., someone else).

As a good example of #1, it would be awesome if in the future that even a project like the Swift compiler itself -- with its complicated dependency tree and build process -- could be configured and built with the package manager.

The goals here are mostly oriented around how do we give the best possible developer experience for constructing source code. I strongly believe that the "container" / "sandbox" model is the right way to go in order to build tools which give reproducible results, allow for easy sharing and deployment, and encourage modular development. If you look at how easy and portable it is to install projects with complex dependencies in ecosystems like Python + virtualenv, that is the kind of environment we want for Swift and eventually for the C family dependencies.

Goal #2 of trying to stay out of the system package manager business (installing built software) is more out of trying to maintain a clear focus and emphasis than anything else. We already have a ton of work to do on the package manager even within that scope, so it just makes sense for now to leave this problem to existing projects better suited to the task.

FWIW, I am working on a proposal for our initial support for *building* C family sources as part of Swift packages. Depending on exactly how complicated your dependencies are (and if you give me pointers to the full tree I would be interested in checking them out as test cases), this feature may be enough that you could in theory get your Swift package to also build the necessary C libraries (with some adaption work). Stay tuned...

On Dec 12, 2015, at 5:04 AM, Drew Crawford via swift-build-dev <swift-build-dev@swift.org <mailto:swift-build-dev@swift.org>> wrote:

I noticed the README for the package manager seems to take a strong view of source distribution:

Packages are distributed and consumed as source code, rather than pre-compiled binaries.
Although it requires additional computational resources, this approach guarantees that developers can adopt new features on platforms they support, without being reliant on vendors to supply updated dependencies. This also has the advantage of allowing tools to do things like automated testing and API analysis of package dependencies.

I maintain a lot of Swift software with C dependencies. For example, I develop Swift frameworks that ship with libsodium statically linked. AFAIK the new Foundation will have various C dynamic and static dependencies. Etc.

What is the vision for distributing this software with the package manager?

1. Will it barf if the user does not have the C dependencies already installed on their machine?
  1a. What about iOS, where there is no concept of this? Can I not build iOS libraries using the package manager?

Yes, it would barf. We are open to improving the reliability of the "system modules" mechanism to be more robust. We do need to support interoperating with installed libraries, and it would be great to make this as smooth as possible.

2. Are all binary packages forbidden? Is there any mechanism like homebrew's bottles for distributing software that is arcane to compile?

We don't have such a mechanism, and as I said the goal of the package manager is to build your project, not distribute it as installable packages. I can imagine adding mechanisms to *help you create* an easily installable product, but I think the actual installation of that product should be left to other tools.

3. Can I write a script that tries to resolve various C dependencies my project needs to link with?

Not currently. What exactly are you envisioning here?

4. Is it a design goal to distribute Foundation via the package manager?

I'm not sure what you mean. Foundation itself is a special case, it is something we consider part of the Swift corelibs and will ship with the Swift compiler.

We *would* like to be able to build the Foundation project with the package manager, but there are a lot of things that need to get sorted out before that can happen.

HTH,
- Daniel

_______________________________________________
swift-build-dev mailing list
swift-build-dev@swift.org <mailto:swift-build-dev@swift.org>
https://lists.swift.org/mailman/listinfo/swift-build-dev


(Daniel Dunbar) #6

Yup. I can't say I've had the time to seriously study cargo and the state of its ecosystem, but I am aware of it. I'd appreciate pointers if there are specific things you are thinking about.

Well, the bullet list of learning from cargo:

Enforce a consistent file structure on sourcecode (which we do)
Consider using [swift] as a scripting language for external builds rather than bash
swift as manifest seems more powerful than is strictly necessary, but I do see some advantages too

I can see how this might be useful, but don't really see what it buys you if that just turns around and calls something as open ended as configure. Can you say more about why this is a good thing?

Let the user choose static link, dynamic link, debug, release, --with-openssl, --target=iOS, etc. at the CLI

Yup, Max and I have talked about this, I assume things like this will come eventually. I agree cargo's system here looks pretty well done, although I would also like to know more about how it is working in practice.

Have a synonym for "make check"

Part of current testing proposal.

Have a .lock file that records the dependency revs actually used

Yup, this is part of the plan.

Do something sane when the dependency repository is a git URL to an auto tools project

I'm less interested in trying to do something automatic here. If someone comes up with something that "just works" in a huge % of cases once the rest of things are designed I would gladly take it. If it doesn't "just work" most of the time, I would much rather force someone to write the adaptor package if it means that all consumers get a more robust development experience, that seems like a better tradeoff.

I would +1 most of your proposal (prefer llbuild, scripting escape hatch, tagged sources, etc.) but I forsee a potential problem on this point:

One of my personal beliefs is that part of the reason software packaging & integration has historically been so messy is because no one has been able to be a "force for change" and cause projects to adapt. For C/C++/Obj-C projects, there are a lot of "unnecessary" variations in the project structure which add complexity for very little overall gain.

While this is true, this seems like an https://xkcd.com/927/ kind of statement. I think this project has the potential for moral authority (or "force for change" as you put it), but the exact magnitude of the moral authority is unknown and I estimate it lower than perhaps you do.

I think swift-pm derives its moral authority from two facts:

That it's an official, swift.org <http://swift.org/> project, like Rust's cargo, go get, etc.
That people want a build system for Linux now and so they have to rethink their packaging anyway

However these two facts are only relevant for **swift** projects. That is to say, libpng already builds on Linux and is not actively shopping for a new build system. Nor do they care about packaging with the Approved Method™ from swift.org <http://swift.org/>, a language they do not even use. And when push comes to shove, swift projects need libpng more badly than they need the Approved Packaging Method™.

tl;dr it is actually the C dependencies here which have the moral authority. Any conflict between what swift-pm wants and what libpng wants will be resolved in favor of libpng. You cannot tell swift developers to go apply pressure to libpng to switch build systems; we lack standing.

I am generally a believer in "if you build it *better*, they will come". My goals here are not to encourage change by being a moral authority, but by simply providing a better solution to real problems than already exists, even for projects that don't care about Swift.

I've been a C/C++ developer a lot longer than I have been a Swift developer, and I think it is a real active pain point in those communities that there is no easy way to glue packages together. So what I am really shooting for here is a system that is so good, its worth it for a project like libpng to support just so that it is easier for their C clients to use.

Well, we don't really support any of these features yet so our current advisement would be "we need to design this feature". :slight_smile:

Well yes, but in the context of the above, I'm suggesting that the C dependency story and courting libpng etc (if that is in fact important) is more important than nearly any other problem. I can live for a few months without unit tests, configuration options, build environment isolation, versioning, etc. I can PR those as I need them, it is mostly obvious what is the right patch to write, from the README alone.

I can't build without libsodium. I can't build without libpng. So forget about months, I can't get ten minutes into being a user even on one platform without making a decision on how to build C dependencies. And it is much less obvious what the right thing to PR here is.

Well, for now the answer is that you have to install your C dependencies with a system package manager and then use the modules maps feature. We know there are issues even with that approach (like the portability of the module maps), and that seems like one area to tackle with individual PRs and more focused design discussions. If there are specific issues blocking this approach for "just getting it working" lets discuss that separately.

I agree this is important and will be actively working on this area, starting with a proposal for building C family sources which are part of the package. That should go some way to supporting more integration with C based stuff, and will also hopefully start to clarify what 2.b would look like.

- Daniel

···

On Dec 13, 2015, at 3:05 PM, Drew Crawford <drew@sealedabstract.com> wrote:

I think it is potentially something like your 2b, but it seems presently underspecified ("We need to be very careful about doing #2.b in a way that doesn't restrict our ability to evolve") and I'm uncertain if there's anything concrete that can be done to get it into an implementable state.

On Dec 13, 2015, at 1:55 PM, Daniel Dunbar <daniel_dunbar@apple.com <mailto:daniel_dunbar@apple.com>> wrote:

On Dec 12, 2015, at 3:46 PM, Drew Crawford <drew@sealedabstract.com <mailto:drew@sealedabstract.com>> wrote:

1. Support a great development experience for building projects from source, where we build everything into the sandbox for that project. We would like to eventually support being able to build more complex dependencies (like external C projects) as part of a package build.
2. Leave deployment and installation of packages to system package managers (i.e., someone else).

Okay, this is good information. The output of the package manager is a .a (or .so, .dylib, Mach-O executable, etc.) and it is your job to install that to a path on your system, or not. This seems like a good model. I might suggest updating the README in some way that explains this.

Good point, we don't really have any docs on the output. I don't have time to tackle this currently, but if patches here would be welcome. I believe Max also has some plans to make the build products more obvious (not hidden in the .build dir), the current system hasn't really been "designed" yet.

This is actually vaguely analogous to Rust's cargo, so I would suggest looking there for design concepts, as they are quite a bit further ahead of us on this problem.

Yup. I can't say I've had the time to seriously study cargo and the state of its ecosystem, but I am aware of it. I'd appreciate pointers if there are specific things you are thinking about.

If you look at how easy and portable it is to install projects with complex dependencies in ecosystems like Python + virtualenv, that is the kind of environment we want for Swift and eventually for the C family dependencies.

I'm (sadly) intimately familiar. It is not really all that easy, primarily because of binary hell, as anyone who has googled how to install pycairo can attest. I really want to do better on this problem than Python does.

I think it depends on the project. For web stacks it can be awesome to pull down a dependency tree w/ C extensions for PostgreSQL, Redis, etc. and a lot of stuff "just works". For more complicated C projects I agree it isn't a slam dunk.

Here's a concrete question: how would we advise a hypothetical swiftcairo project to package themselves in the package manager? Should they:

Well, we don't really support any of these features yet so our current advisement would be "we need to design this feature". :slight_smile:

1. Call out to a shell script that does `brew install cairo` on OSX, `apt-get install cairo` on Debian, etc.

Currently, this is the only supported thing. But I want to do better than this...

2. Print some error telling them to come back when they've installed cairo somewhere on their system. Good luck, kid
3. Write a shell script that downloads and builds cairo from source including all its dependencies
4. Create a tree in the swift package manager like

swiftcairo <-- cairo <-------pixman
                     <-------freetype
                     <-------fontconfig
                     <-------libpng
                     <-------glib
  Where each of these "packages" are mostly a shell script that runs a lot of `curl -O` `tar xf` `configure` `make` etc.
5. Do we try and second-guess what libpng's autotools want to do? (Bad, bad, idea. Build the way libpng decided to build, don't try to guess based on the arrangement of .c files in a folder)
6. Other ideas?

A vision for the pathological case like Cairo will illuminate the simpler cases. IMO it would be nice if "depends: swiftcairo" would 'just work', but that may be out of scope.

My proposal is:

1. We include some native support for C/C++ libraries. This should be "well designed", but ideally would scale up to supporting very support complex projects (like `swiftc`). I care about this part deeply because there is a lot of awesome stuff I want to do in llbuild + clang, and that depends on being able to get the project onto those tools. We will by necessity need to start with a small limited scope and feature creep our way forward.

2. We provide an adaption mechanism, to allow projects that can't yet be built by #1 to still integrate directly into the ecosystem. This can take two forms:

2.a. For projects which *could* conform to #1, but the only problem is the upstream project doesn't want to change (or hasn't yet), then we could support an adaption mechanism which just took in the upstream project and overlayed the appropriate Package.swift definitions that we need to use to build it. This means that swiftpm + llbuild would have a full understanding of the build process, which is the ideal scenario for the ensuring a good user experience.

2.b. For projects which are just "too complicated" to do #2.a, we would allow a form of your #3 (a shell script which downloads and builds). The way I envision this working is that:
- I'd like to avoid the script actually downloading anything, I think we should still try and use our model for pulling the sources. This may mean someone maintains a tagged version of an adaptor package that includes the source of the upstream project + the adaptor pieces.
- We would require a very strict interface between that script and the rest of the package manager. Essentially, we would provide the script with its inputs, and we would expect it to produce, as an output, the exact kind of build layout that we ourselves would have done for project in case #2.a. In practice, those scripts would usually look something like " configure && make && ... move the built products around a bunch to conform to the expected layout ...". We would run the script in appropriate dependency order, then ingest / audit all of the outputs, and from then on it would integrate just like #2.a.

We need to be very careful about doing #2.b in a way that doesn't restrict our ability to evolve...

One thing I would like to call out is that I don't feel like we need to directly support the total amount of complexity that exists in the world w.r.t. C family projects. I want use to help make the world more sane by coming up with sensible conventions and models for C family projects, and then apply pressure in other places to reduce unnecessary complexity or to converge on semi-standard solutions. I outlined a bit more of my philosophy here in:
  https://lists.swift.org/pipermail/swift-build-dev/Week-of-Mon-20151130/000027.html

(and if you give me pointers to the full tree I would be interested in checking them out as test cases), this feature may be enough that you could in theory get your Swift package to also build the necessary C libraries (with some adaption work). Stay tuned...

NaOH <https://code.sealedabstract.com/drewcrawford/NaOH> is a good test case. It's a framework that statically links libsodium. My current (terrible) workflow is:

1. Download libsodium-xx.tar.gz <https://github.com/jedisct1/libsodium/releases> from GitHub
2. ./configure && make
3. Move binaries + .h around to where Xcode can find them
4. Check into source control
5. Build

Would love to automate this and get it building with the package manager. There's actually been an issue open <https://code.sealedabstract.com/drewcrawford/NaOH/issues/1> since pretty much day 1 to get this working. That is the problem that motivated me to post.

Cool, thanks for the pointer I will check it out.

- Daniel

On Dec 12, 2015, at 11:02 AM, Daniel Dunbar <daniel_dunbar@apple.com <mailto:daniel_dunbar@apple.com>> wrote:

I would say that our main goals are two fold:
1. Support a great development experience for building projects from source, where we build everything into the sandbox for that project. We would like to eventually support being able to build more complex dependencies (like external C projects) as part of a package build.
2. Leave deployment and installation of packages to system package managers (i.e., someone else).

As a good example of #1, it would be awesome if in the future that even a project like the Swift compiler itself -- with its complicated dependency tree and build process -- could be configured and built with the package manager.

The goals here are mostly oriented around how do we give the best possible developer experience for constructing source code. I strongly believe that the "container" / "sandbox" model is the right way to go in order to build tools which give reproducible results, allow for easy sharing and deployment, and encourage modular development. If you look at how easy and portable it is to install projects with complex dependencies in ecosystems like Python + virtualenv, that is the kind of environment we want for Swift and eventually for the C family dependencies.

Goal #2 of trying to stay out of the system package manager business (installing built software) is more out of trying to maintain a clear focus and emphasis than anything else. We already have a ton of work to do on the package manager even within that scope, so it just makes sense for now to leave this problem to existing projects better suited to the task.

FWIW, I am working on a proposal for our initial support for *building* C family sources as part of Swift packages. Depending on exactly how complicated your dependencies are (and if you give me pointers to the full tree I would be interested in checking them out as test cases), this feature may be enough that you could in theory get your Swift package to also build the necessary C libraries (with some adaption work). Stay tuned...

On Dec 12, 2015, at 5:04 AM, Drew Crawford via swift-build-dev <swift-build-dev@swift.org <mailto:swift-build-dev@swift.org>> wrote:

I noticed the README for the package manager seems to take a strong view of source distribution:

Packages are distributed and consumed as source code, rather than pre-compiled binaries.
Although it requires additional computational resources, this approach guarantees that developers can adopt new features on platforms they support, without being reliant on vendors to supply updated dependencies. This also has the advantage of allowing tools to do things like automated testing and API analysis of package dependencies.

I maintain a lot of Swift software with C dependencies. For example, I develop Swift frameworks that ship with libsodium statically linked. AFAIK the new Foundation will have various C dynamic and static dependencies. Etc.

What is the vision for distributing this software with the package manager?

1. Will it barf if the user does not have the C dependencies already installed on their machine?
  1a. What about iOS, where there is no concept of this? Can I not build iOS libraries using the package manager?

Yes, it would barf. We are open to improving the reliability of the "system modules" mechanism to be more robust. We do need to support interoperating with installed libraries, and it would be great to make this as smooth as possible.

2. Are all binary packages forbidden? Is there any mechanism like homebrew's bottles for distributing software that is arcane to compile?

We don't have such a mechanism, and as I said the goal of the package manager is to build your project, not distribute it as installable packages. I can imagine adding mechanisms to *help you create* an easily installable product, but I think the actual installation of that product should be left to other tools.

3. Can I write a script that tries to resolve various C dependencies my project needs to link with?

Not currently. What exactly are you envisioning here?

4. Is it a design goal to distribute Foundation via the package manager?

I'm not sure what you mean. Foundation itself is a special case, it is something we consider part of the Swift corelibs and will ship with the Swift compiler.

We *would* like to be able to build the Foundation project with the package manager, but there are a lot of things that need to get sorted out before that can happen.

HTH,
- Daniel

_______________________________________________
swift-build-dev mailing list
swift-build-dev@swift.org <mailto:swift-build-dev@swift.org>
https://lists.swift.org/mailman/listinfo/swift-build-dev


(Drew Crawford) #7

I can see how this might be useful, but don't really see what it buys you if that just turns around and calls something as open ended as configure. Can you say more about why this is a good thing?

I think the premise is that structured formats are useful for a lot of problems. One example, the README has some interesting ideas about automatically checking license compatibility. This presumes the license of a package can be statically inferred. If the package metadata are defined in a Turing-complete language then that gets hard. If it is YAML or something the problem is much easier.

The idea of someone defining their license as a function evaluation seems rather silly, but if it is legal then someone will do it. I also forsee security problems with this approach. Somebody who wants to write a swift-packages.org <http://swift-packages.org/> search engine is about to find their life very painful.

Calling out to a real program seems more appropriate for a "so, you actually want to build this software" scenario rather than questions of basic metadata like the examples that appear in this documentation <https://github.com/apple/swift-package-manager/blob/master/Documentation/Package.swift.md>.

I am generally a believer in "if you build it *better*, they will come". My goals here are not to encourage change by being a moral authority, but by simply providing a better solution to real problems than already exists, even for projects that don't care about Swift.

This argument concerns me. What evidence would you cite that this actually works?

My frame of reference is e.g., Carthage (which IMO is better than CocoaPods), Ninja / CMake (which IMO are better than autotools). It is my observation that the better build systems are dwarfed by the popular ones.

Further, I have some experience lobbying random projects to move to an obviously better buildsystem. Historically it's always bit of a bikeshed, and generally a complete waste of time. Is your experience here different?

I don't like it; I wish I lived in a world where the best build tool wins. But the evidence suggests I might not live in that world, so I find arguments of the form "we will win because we have the best tool" concerning.

If there are specific issues blocking this approach for "just getting it working" lets discuss that separately.

I'm going to open separate discussions as I run into problems. But the preview is: I need to run a prebuild script of some kind in order to even get started. I may just end up PRing something, since the discussion here seems to be wandering away from that part of the problem.