17 ms·
Cargo-style dependency management for C, C++ and other languages with Meson
- fluffy87 6y agoDoes it have an equivalent of build.rs ?
- vlovich123 6y agoCargo in terms of ease-of-use but not in terms of scale. You only get the packages that Meson (or the community?) has written build scripts for. By my count that's ~144 packages [1]. That's nowhere near as pervasive as Cargo given that basically any Rust project published will use Cargo vs C/C++ that has a mix of CMake & autoconf (largely standard for OSS) & BUCK/Bazel for Facebook/Google-influenced (potentially multi-language) codebases. That's also not including all the IDE-specific or platform-specific workspaces (Visual Studio, Xcode, gradle NDK builds, etc). It's a nice thought but you have to be confident every 3rd party project you use is one whose parallel build you'll maintain as it updates. That's the strength of Cargo - it's the way to write Rust code & the maintenance is done by upstream for everyone. Additionally Cargo's strength isn't just it's packaging & publishing system. Having a single Rust compiler that everyone uses on all platforms is powerful. C++ might get there eventually with clang but the ecosystem of libraries will need to support that as a baseline. Currently there's too many compiler or platform-specific hacks that are done to regularize the environment a bit whereas Rust generally does all of that under the hood for you (i.e. try writing any cross-platform BSD socket code - it's a total shitshow that basically results in Winsock & all other POSIX OSes basically different net stacks). Rust also comes with a very deep standard library for I/O, path manipulation etc whereas the C++ equivalents for all of this are still surprisingly lacking even in C++20 (especially on the network side). [1] Based on manually counting the packages listed here https://wrapdb.mesonbuild.com/ https://wrapdb.mesonbuild.com/
- rapsey 6y agoWhen using Rust libs you also have some faith that the lib will not have some sort of memory corruption and introduce instability to your app. This is why C/C++ can never have the Rust crate system, no matter how user friendly the package manager.
- identity0 6y ago?? You're telling me C++ devs don't use libraries?
- rapsey 6y agoTo the degree of Rust no.
- self_awareness 6y agoIt's probably because of the complication of adding a library dependency in C++. If the ecosystem would use a Cargo-like management, I think C++ would have as much libraries, eagerly used, as Rust.
- Cloudef 6y agoOne could leverage something like Arch PKGBUILDs or nix recipes to create C/C++ "package manager". C/C++ libraries aren't really hard, all you need is "root directory" with the common {/include,/lib} layout. For C you could even have binary libraries, but for C++ binary libraries are gonna be quite a problem, because there's no ABI compatiblity and even different compiler flags can cause ABI incompatibility.
- oblio 6y ago> One could One could, but no one has. That's the whole discussion, there are multiple partial implementations with limited adoption.
- Cloudef 6y agoMSYS2 actually has one based on pacman and PKGBUILDs. I remember unofficial vita SDK going similar route as well. Probably there's tons of similar solutions but not marketed well enough.
- otabdeveloper4 6y agoHaving multiple compiler implementations is a strength, not a weakness. As long as Rust is not standardized and documented only by the implementation's code it will never be a serious language.
- aprdm 6y agoWhat is a serious language? Is being used in companies like Amazon to deliver runtimes used by a considerable % of the internet not serious?
- papaf 6y agoWhat is a serious language? I would call C a serious language. Its running your laptop, your phone, your car, the airplane you took on holiday, the fighter planes that protect your airspace, your washing machine, and if you are unfortunate enough to get seriously ill it will probably be running on the medical equipment that keeps you alive. One of the reasons it is serious is because it is standardized and multiple implementations exist.
- aprdm 6y agoI do wonder what other languages you consider serious apart from C. You could use similar examples for a lot of other languages, C isn't the only language used to keep our civilization alive. I did a fair bit of development in C, and developed hard real time systems in VHDL that did involve life & death, but, wouldn't call any language used in the industry generating value as a non serious language...
- papaf 6y agoI do wonder what other languages you consider serious apart from C. Off the top of my head I thought C++ and Ada. However, you mention VHDL which I agree with and somebody else pointed out Javascript which is also a good point. The Javascript example (along with C++) make the point that serious computer languages are not necessarily great languages. I would argue that Rust is not a serious language (at the moment [1]) because its still young, there is no specification and if anything happens to the one implementation it would be a disaster. Despite C being a null pointer minefield, if someone was to sue a developer the argument could be made that it is an industry standard. In the less likely event that a Rust program hurt somebody what are you going to say? [1] https://users.rust-lang.org/t/is-there-a-plan-to-get-a-formal-rust-language-specification-at-some-point/21622/8 https://users.rust-lang.org/t/is-there-a-plan-to-get-a-forma...
- papaf 6y agoRust also comes with a very deep standard library for I/O, path manipulation etc whereas the C++ equivalents for all of this are still surprisingly lacking even in C++20 (especially on the network side). I agree with this point and cross-platform development is painful in C and C++. However, one of the reasons people use C and C++ is because of platform specific development. It turns out the platforms themselves are written in C. For example, the "very deep standard library" for Rust can't do DNS TXT queries. On Linux, I run 'man res_query' [1] and get the documentation. Notice the Synopsis, that's C/C++ and the Linux specific code I write can use that. Rust can also call these functions but there is an impedance mismatch between the safe world of standard rust and the unsafe calls to the system -- I imagine that a crate is a available to ease the pain of the 'unsigned char *answer'. I am not making this comment to belittle Rust, I actually think it is a good and safe alternative to C++. However, there is decades of system development behind the C/C++ ecosystem and coming onto a C/C++ thread (about a package manager) and calling things a "shitshow" is not going to win people over. [1] https://man7.org/linux/man-pages/man3/res_query.3.html https://man7.org/linux/man-pages/man3/res_query.3.html
- bschwindHN 6y agoOne of the great things about Rust is you can write platform-specific code for each platform and then package it all up into one interface so anyone can trivially use it. They get the simplicity of one interface and the performance of platform-specific code. Though I haven't used it personally, it seems like the trust-dns project is one such example: https://github.com/bluejekyll/trust-dns https://github.com/bluejekyll/trust-dns
- platinumrad 6y agoYou can do that in literally any language.
- bschwindHN 6y agoYep, but Rust makes it very easy to package and distribute libraries with Cargo, while maintaining performance on the level of C. I was mostly replying to this: > However, one of the reasons people use C and C++ is because of platform specific development. It turns out the platforms themselves are written in C.
- einpoklum 6y ago> Having a single Rust compiler that everyone uses on all platforms is powerful. It's also quite problematic, in that this tends to create a lot of reliance on non-standardized compiler behavior and quirks. > C++ might get there eventually with clang I sure hope not! (and I appreciate clang). It's important and useful for there to be several compilers. Plus, if any compiler becomes the single standard one, then it definitely needs to be strongly "copyleft"ed, e.g. with a GNU GPL license. Otherwise agree with the problems you identified.
- ansible 6y ago> It's also quite problematic, in that this tends to create a lot of reliance on non-standardized compiler behavior and quirks. While that may be a problem in other communities, with Rust there is a general aversion to undefined behavior. It is my belief that there will be more community pressure to fix quirks and such, and not depend upon them in general.
- einpoklum 6y ago> with Rust there is a general aversion to undefined behavior. Ah, but it will be defined behavior - just implicitly defined.
- Cloudef 6y agoUgh.. Meson and CMake, don't know how they did it, but they manage to be even worse than autotools.
- self_awareness 6y agoI don't think anything can be worse than autotools. Well, maybe a collection of shell scripts to do the actual build. Wait a minute...
- dxuh 6y agoI really don't think Meson and CMake should be mentioned in the same breath here. I would be glad to know what you think makes Meson so bad.
- Cloudef 6y agoThere's many problems with meson and cmake, but as for meson. Meson is the kind of build system that makes using tools hard as it forces certain workflow to you. It detects the compiler and tries to be too clever what you can do with it and what you can't. For example recent mishap was that it detected emscripten compiler and didn't allow me to use it as non cross-compiler and so on. There's no way to build static libs, if the project hardcodes shared library building. The codebase is also pretty nuts, I welcome you to go read it. (GNU) Makefiles with some standard variables and pkg-config are still the king. Cmake and meson can work okay for very simple projects, but other than that I'd recommend always using native build system for each platform, or going Makefile + mingw route (if you need windows builds). Using native build system eventually saves you time and headache, especially when these "portable build file generators" don't support some feature you absolutely need, or doesn't allow you to put that command line flag in one of the tools that gets executed under the hood. CMake also absolutely sucks at finding system dependencies when everyone uses those "FindFooBar.cmake" files with hardcoded search paths and what not, instead of using pkg-config. This forces many packagers to hack the projects build system, because the project would otherwise link to wrong library, or not find the library at all. With pkg-config the distributions can provide the correct paths and flags when linking against something. Autotools, while slow and generates tons of shell script that's compatible with all sort of ancient shells and platforms, still manages to offer a standard interface to packagers and fine tune exactly how things get linked, how things get configured and where stuff gets installed. Autotools in general is less headache to packagers than meson or cmake.
- aprdm 6y agoI tried to do a simple web app with C++ recently.. nothing against the language but trying to decide which framework to use and then trying to integrate them to my project and build took me a couple of days, ultimately I gave up and did the same in python in 30 minutes. I don't understand how such a popular language can have such a weak story in dependency management and integration with third party libraries. Even something that should be simple like using grpc / protocol buffers in C++ took me way more than I was intending, plus my final CMake file ended up looking extremely hacky with some other dependencies... IMO C++ needs something akin to the rust book (https://www.rust-lang.org/learn https://www.rust-lang.org/learn) or the python official docs (https://docs.python.org/3/ https://docs.python.org/3/) and a built in dependency manager. Every C++ project Make/CMake seems to end up like its own unique dumpster of fire that is non trivial to add dependencies to...
- dxuh 6y agoTo be fair Google libraries are famously hard to build and integrate. It doesn't help that they use their own build system, though it seems gRPC can be built with CMake now. It's a good number of years since I did it last, but integrating gRPC was one of the worst experiences I ever had integrating a dependency (on Windows at least).
- qppo 6y agoHistorically the dependency management tool for C++ is the system's package manager, and/or a shell configure/provision script. I don't see any value add to a "built in" dependency management tool to C++. Not as in it isn't a useful thing to have, just that it can't solve the big problem which is that most C++ projects would never support it. There's also the fact that long dependency chains are frowned upon in many C++ code bases.
- aprdm 6y agoWhat about supporting multiple versions of libraries at a computer? They all support it: npm, rvm, virtualenv, cargo, golang, python, maven and etc. A very common use case is to use some newer version of something than what shipped with the OS but at the same time you don't want to potentially cause instability in the OS... Or you know, developing multiple projects w/ different versions from a single OS. Also in case I really want to do it, I have to go to some obscure website download some payload and read some build instructions to see how to best integrate to my messy CMake/Make system... All of it could literally be replaced by something akin to cppvenv create myproject cppvenv --depend-on grpc-1.40 zeromq json cppvenv build
- mcraealex16 6y agoMaybe it's just my experience, or lack of it, with cpp but everything feels hacky. With rust it just feels right. The websites like docs.rs and crates.io are amazing and there's no equal in cpp.
- dxuh 6y agoEverything is big and old, so there are multiple ways to do it and making them work with the old ways is sometimes trouble. If you wait a couple of years Rust will be like that too. cppreference.com is good and hast almost everything you need.
- oblio 6y ago> If you wait a couple of years Rust will be like that too. Debatable. It's also a matter of design choice. Much like Perl, C++ chose to "include everything, be everything to everyone". Almost no modern language does that, if you look around, every modern language is focused and for almost every choice has at least a recommendation if not an enforced choice. This makes for much better design. I don't think there is a living C++ developer that knows all of C++, it's impossible. I'd be shocked if Stroustrup knows all of it.
- pierrebai 6y agoI'm going to agree with your parent poster. Just wait a few years. I'd even claim that having deprecated bits is a sign of acceptability and industry trust: the language is used widely enough to have grown multiple implementations of multiples features. Sure, it might now be features Rust currently has, it will be technology X or programming trend Y that will appear down the line and which will be implemented by multiple teams.
- pjmlp 6y agoC++ is 40 years old by now, C is reaching 60, almost the same age as COBOL (about 10 years younger). Stroustrup does assume not to know everything, just like Ken Thompson won't know everything about C17. Wait until Rust reaches their age, actually enjoys multiple commercial implementations, assuming it does survive that long, and those still alive will say the same words about Rust.
- eqvinox 6y agoHonestly, C and C++ libraries being annoying to deal with is a Windows-created problem. POSIX systems have pkg-config as the de-facto standard way to find installed (or non-installed, if done correctly) libraries, and all common build systems (including autoconf, CMake, Meson, ...) support this. Meanwhile on Windows you're left with a pile of unpacked library directories somewhere on your disk and everyone does their own thing and it's a clusterf*ck of build system twiddling. And the worst part is that this bleeds over into POSIX systems when Windows-created libraries make a jump over and don't know to stick to the conventions.
- sto_hristo 6y agoBut the inherent problem is still the inability to deal with dependencies in a standard and portable way. As you said - pkg-config is standard on POSIX, but the world is bigger than this.
- arximboldi 6y agoThis is so true. It is always Windows people trying to bend libraries to make them easy to "install" for them. On Unix installing libraries system-wide was never too much of a hassle, and now with Nix you can have reproducible distinct development environments for each project. I hate that sadly a lot of the projects I work on must also work on Windows, but I'd just hire a Windows person simply to deal with their build system stuff.
- pjmlp 6y agoTry having the fun to install something on e.g. Aix.
- oblio 6y agoYeah, but the thing is, even on POSIX stuff, even without Windows-created libraries, how do you: package-manager install bleeding-edge-library and have it just work? Keep in mind, I don't want to use an entire bleeding edge OS in order to easily get 1 bleeding edge library. Also, how do I do it on another POSIX OS, in a standard way for my development flow?
- notmadnomad 6y agoI thought this was what Conan did. Am I missing something?
- Game_Ender 6y agoI think Conan [1] has wider support in the C++ community. It definitely does not match the Cargo toolchain for integrated ease of use, but it does support CMake directly. 1 - https://conan.io/ https://conan.io/
- junon 6y agoNever again with Meson. The developer is a jerk and has dogmatic views on prpoject structure that do not match reality.
- quietbritishjim 6y agoI know this is slightly annoying knee-jerk reaction but it would be remiss not to mention vcpkg [1] whenever C++ dependencies are brought up. In practice vcpkg has by far the most packages of any C++ package manager. For example, it's unusual to find any one of opencv, grpc and QT5 for Windows, Linux and Mac in any other C++ package manager, let alone all three. Unfortunately I'm not enough of an expert on the alternatives to make a proper comparison, but it seems to me that vcpkg works better with whatever build system the packages natively prefer to be built with (e.g. although vcpkg is CMake-based it can build Visual Studio projects on Windows and make-based libraries on Linux) whereas following links in the OP's article takes me to a zip file full of meson.build files that seem to have been written from scratch for the library. Using the library's own build system directly seems like a much more managable long-term solution. Also, vcpkg's policy of putting all the ports into its git repository, while it does have disadvantages, does make it very clear everything that vcpkg is doing and needs to know to build something (e.g. [2] for grpc). Edit: A partial comparison of vcpkg with Meson WrapDB and Conan Centre: * Meson WrapDB lists just under 145 packages, although some of them appear to be empty (e.g. grpc, libtiff). As mentioned above, it seems that you need to re-implement the whole build system for a library in Meson for it to be included. I found that the package data is on github e.g. for spdlog [3] * Conan Centre lists 583 packages, so it seems like a much better choice than Meson. The way to specify different configurations look awkward to me - they mix up decisions that you probably want to share across your dependencies (e.g. platform, static vs dynamic) with library-specific stuff; but maybe I just don't understand them properly. * vcpkg has 1509 ports, including several quite tricky ones like grpc on Windows and QT as mentioned above. The configuration stuff is split over places in a way that makes sense to me: triplet files contain global options like static vs dynamic and even cross compile options, the portfile itself contains any package-specific tweaks, and feature packages allow extra features in ports (e.g. I can vcpkg install opencv[eigen3] to mean "include eigen3 support in opencv3", which would also update the list of transitive dependencies). [1] https://github.com/microsoft/vcpkg https://github.com/microsoft/vcpkg [2] https://github.com/microsoft/vcpkg/tree/master/ports/grpc https://github.com/microsoft/vcpkg/tree/master/ports/grpc [3] https://github.com/mesonbuild/spdlog/tree/1.8.0 https://github.com/mesonbuild/spdlog/tree/1.8.0
- virtualritz 6y ago
- pornel 6y agoThe best thing about Cargo is not that it's the best build system (feature-wise it's rather basic), but that there's nothing else for Rust. Projects never have to argue whether Cargo is better than Mergo or Ronan or Rustfiles or their grandad's bash script. All the tooling knows how to build any project. Every editor knows where to look for files. https://docs.rs https://docs.rs can generate documentation for 40000 different projects using the same build command.
- jnxx 6y agoWhat's also good is that one can combine cargo with Guix as an OS/multi-language package manager, for example when other tools or C libraries (say, alsa-lib) are needed. Guix provides currently 15,000 packages including many rust packages (https://guix.gnu.org/packages/R/page/21/ https://guix.gnu.org/packages/R/page/21/ ), and uses of course cargo for building rust packages. The reason why I think this is the right way to do it is because in big , quickly-moving projects, the only comfortable way out of dependency hell is to use a Linux distribution with checked-to-work dependencies, or one is damned to the task of building a distribution oneself, and a checked distribution of packages is precisely what Guix provides. Because own, or project-specific package recipes, which contain dependency and build instructions, can just be added to the public package definitions (https://guix.gnu.org/blog/2018/a-packaging-tutorial-for-guix/ https://guix.gnu.org/blog/2018/a-packaging-tutorial-for-guix...), this allows to deterministically and hermetically build multi-language projects on top of a very solid base. And for testing with another version of a C dependency (say, alsa-lib 1.1.9), one just needs a branch with another version number in the build recipe.
- choeger 6y agoThat sounds about fantastic. Is there a non-root way to build and a way to install at least some of the packages in my $HOME? Because as a developer I need to work with different branches. edit: How does it handle python wheels and other non-source language-specific packages?
- jnxx 6y ago
- wocram 6y agoSurely nixpkgs is a better choice for c and cross-language dependency management at this point. As long as you're not on windows.
- moth-fuzz 6y agomy only problems with meson wrap today are its lack of packages, and the fact that it's source-only. Actually, I tried to use SDL_image and while the page for the package exists on wrapdb[0], it has no versions listed and so building with SDL_image fails. Source builds on windows for SDL2 fail because it presumes a UNIX-style build and fails looking for 'unistd.h'. I've found the real 'one true solution' for my needs to be conan + meson. Conan includes a build script that supplies pkg-config files to Meson for dependency handling, and with conan you can use the gigantic repository of packages along with bincrafters for an even gigantic-er repository of packages. I have not yet found a package I needed that wasn't on either conan center or bincrafters. And on Linux I can download the source to build if I really want to, but on Windows I'm happy just downloading the binary .lib files. And it's so easy to use. cd build && conan install .. && conan build .. is all you need to download and compile everything. Before this setup I used vcpkg with cmake and I'm never going back to that. Yet before vcpkg I used ExternalContent, which I would also never go back to. Ergonomics are extremely important with this kind of thing. I think that's why cargo is a huge hit in this space. 0. https://wrapdb.mesonbuild.com/sdl2_image https://wrapdb.mesonbuild.com/sdl2_image
- baby 6y ago`Cargo` and `go` are the reasons I don't want to work with other languages that don't have good default tooling for dependency management, formatting code, linting, etc.