[swift-build-dev] C dependencies
Drew Crawford
drew at sealedabstract.com
Sun Dec 13 17:05:24 CST 2015
> 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/ <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". :)
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 at apple.com> wrote:
>
>>
>> On Dec 12, 2015, at 3:46 PM, Drew Crawford <drew at sealedabstract.com <mailto:drew at 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". :)
>
>> 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 <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 at apple.com <mailto:daniel_dunbar at 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 at swift.org <mailto:swift-build-dev at 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 at swift.org <mailto:swift-build-dev at swift.org>
>>>> https://lists.swift.org/mailman/listinfo/swift-build-dev <https://lists.swift.org/mailman/listinfo/swift-build-dev>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-build-dev/attachments/20151213/3ff51648/attachment.html>
More information about the swift-build-dev
mailing list