Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upmetabuild: semantic build scripts for Cargo #2196
Conversation
joshtriplett
added
the
T-cargo
label
Oct 31, 2017
SimonSapin
reviewed
Oct 31, 2017
``` | ||
|
||
Note that the `metabuild` functions intentionally take no parameters; they | ||
should obtain any parameters they need from `Cargo.toml`. Various crates to |
This comment has been minimized.
This comment has been minimized.
SimonSapin
Oct 31, 2017
Contributor
I assume this refers to http://doc.crates.io/manifest.html#the-metadata-table-optional ? It’d be nice for the RFC to provide an example fn metabuild()
implementation that does so.
This comment has been minimized.
This comment has been minimized.
kryptan
commented
Oct 31, 2017
Why combine multiple build dependencies into a single executable instead of compiling and executing them one by one? While uncommon, it may cause problems because they enable different features on dependent crates or depend on different versions of the same *-sys crate.
After reading the RFC I still don't understand how build systems would use this. How would a build system get information about all the |
joshtriplett
added some commits
Oct 31, 2017
This comment has been minimized.
This comment has been minimized.
That's a reasonable point. At the very least, I can mention that as an alternative. (Done.)
I'd expect Cargo to resolve the build-dependencies once, not once per script, so I don't expect this to differ.
To give one of many examples: I expect to have a metabuild script that finds native libraries, using pkg-config at first and eventually using a wide variety of mechanisms. Such a script would get the information about what library to find from |
This comment has been minimized.
This comment has been minimized.
Please don't require crates to parse Cargo.toml. I've done it in cargo-deb and it's been a bad experience and cargo-deb is still subtly buggy because of it. At very least provide them basic key/value config, which could still be read from Cargo.toml, but by Cargo itself.
|
This comment has been minimized.
This comment has been minimized.
Do you expect the metabuild crates to be build-system specific like I wonder where platform-specific quirks should go. For example libjpeg-turbo uses autotools on non-Windows (and explicitly does not support them on Windows) and cmake on Windows. Is that supposed to be encoded in Cargo.toml? |
This comment has been minimized.
This comment has been minimized.
I expect that we'll very quickly end up with a canonical crate that parses (Also, I thought I'd seen a standard crate for doing that parsing already, but I can't seem to find it.)
Environment variables don't provide arbitrary data structures. How would you represent the following in environment variables? [package.metadata.pkg-config]
testdata = "4"
testlib = { version = "1", feature = "test-feature" }
testmore = { version = "2", feature = "another-test-feature" }
Potentially either. At first, the former; later on, we'll also end up with things that detect and run multiple build systems, similar to debhelper's
Does it support cmake on non-Windows? I don't think the |
This comment has been minimized.
This comment has been minimized.
No. At least on macOS the cmake build requires several tweaks to work. There are plans to make cmake work cross-platform, but the project lacks the funds to execute it. |
This comment has been minimized.
This comment has been minimized.
I mean build scripts currently already use ad-hoc env vars (like this) with whatever formats they need. I expect they would merely continue to do what they did previously instead of switching to more complex solution of parsing cargo.toml. BTW, can a -sys crate be its own metabuild crate? Libraries like llvm or libpng have their own unique like-pkg-config-but-not-compatible-with-pkg-config solutions. Or should clang-sys depend on clang-metabuild? |
This comment has been minimized.
This comment has been minimized.
bbatha
commented
Nov 1, 2017
•
Even if they have to be separate cargo workspaces plus private crates (#1977) make this pattern painless, and I'd argue that it guides you to structure your code better. |
This comment has been minimized.
This comment has been minimized.
I certainly hope not; those environment variables are not in any way standardized. By contrast, I wonder if we could standardize a single crate to invoke anything that looks like
If you still need custom code, I'd suggest keeping your Also, libpng has a pkg-config script, at least in the packages I have. |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
I don't really get this RFC. It seems to allow a crate to specify a different method of building for its dependencies, but it's not clear to me how/why this is related to "declarative" build scripts -- in fact, as far as I can see it's largely unrelated to this concept. Maybe the Motivation section could start with a motivating real-worldish example of what the problem is with today's cargo? |
This comment has been minimized.
This comment has been minimized.
Yes. For instance:
I fully expect this to remain an unstable cargo feature for a while. |
This comment has been minimized.
This comment has been minimized.
@djc This RFC makes it much easier to replace the |
This comment has been minimized.
This comment has been minimized.
@joshtriplett what about converting this into an eRFC instead? Then we'd have a second discussion before stabilisation which I think would be a very good idea. |
This comment has been minimized.
This comment has been minimized.
@est31 I feel that an eRFC seems more appropriate for the case where we want to identify the problem but have no concrete solution proposal, or only the skeleton of a solution. In this case, the RFC proposes a specific concrete solution for experimentation, so I don't think that the eRFC process applies. However, I added some text to the RFC explicitly acknowledging that the interface may change in the course of experimentation, prior to stabilization. (This seems like the standard practice for any unstable feature; it can always change prior to stabilization.) |
This comment has been minimized.
This comment has been minimized.
lukesutton
commented
Nov 7, 2017
I love the idea of this feature. I could absolutely see myself using it. Here is a motivating example. For a web application, I might wish to perform some preprocessing — compile SASS, resize images etc. — as part of the build. Currently I use a custom build script, but that involves lots of boiler plate. It would be great if instead I could break these tasks up into separate crates. It would also give me the option of specifying config in This would also allow for things like 'helper' image processing crates on crates.io. For my use case here, another solution is to just add these 'helper' crates build-dependencies and configure and call into them in a custom |
This comment has been minimized.
This comment has been minimized.
In case of web oriented build scripts there was already a battle between declarative configuration-driven Grunt and program-driven Gulp, and Gulp has won. Declarative approach worked nicely only in insufficiently simple cases and wasn't powerful enough to seamlessly combine multiple tools together (e.g. you end up configuring two or more tools individually, each using their own configuration DSL, just so they happen to hit the same set of temporary files to meet in the middle, which is non obvious and fragile) OTOH Gulp's approach is very similar to build.rs using external crates, and has proven useful and manageable even in large and complex projects. |
This comment has been minimized.
This comment has been minimized.
raphaelcohn
commented
Nov 16, 2017
As the maintainer of Libertine Linux, a fully reproducible, build-from-source distro, and the author of a comprehensive multi-package tool swaddle, I'm looking for an easier way to cross-compile Rust code that uses third party dependencies (ie compiled C libraries) than the current morass of various In essence, simply the ability to specify a list of dependencies and locations is what I want. If that means I can have a way to replace a crate's build.rs with my own, that'd be sweet. It'd also be nice if eventually crates split Rust codegen (eg via bindgen) from libc compilation. @lukesutton You might like my upcoming static webserver cordial. |
This comment has been minimized.
This comment has been minimized.
Following up on this, what's the next step here? In one of the @rust-lang/cargo meetings, it seemed like there was general approval of the concept here. What would it take to move this forward? |
This comment has been minimized.
This comment has been minimized.
The mechanism proposed here seems vaguely related to the custom test frameworks proposal - in the way that we want to execute code from a dependency in a compile-time context. I'm not sure whether that has any significance - I can't imagine some unified mechanism. |
ashleygwilliams
referenced this pull request
Mar 27, 2018
Open
rfc: make cargo install extensible #2376
This comment has been minimized.
This comment has been minimized.
@nrc I can't imagine a unified mechanism either. And if there is, I think we could treat that as part of the implementation, not the RFC. |
This comment has been minimized.
This comment has been minimized.
We discussed this today in the Cargo meeting at the Rust All-Hands. Part of the conclusion was that it would make sense to go forward with a minimal experimental implementation of metabuild, enough to allow the ecosystem to experiment with metabuild crates. We can iterate later on both the interface between cargo and metabuild crates, and on the implementations of common functionality needed in metabuild crates (e.g. |
This comment has been minimized.
This comment has been minimized.
Thanks @joshtriplett for the summary! We're excited to start experimenting in this area, and it's important to allow that experimentation to happen early in the year, with hopes that at least some parts of the ecosystem impact will be known prior to the 2018 edition. As such: @rfcbot fcp merge |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Mar 29, 2018
•
Team member @aturon has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Mar 29, 2018
|
rfcbot
removed
the
proposed-final-comment-period
label
Mar 29, 2018
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Apr 8, 2018
The final comment period is now complete. |
Centril
referenced this pull request
Apr 9, 2018
Open
Tracking issue for RFC 2196, "metabuild: semantic build scripts for Cargo" #49803
Centril
merged commit c09e805
into
rust-lang:master
Apr 9, 2018
This comment has been minimized.
This comment has been minimized.
Huzzah! Tracking issue: rust-lang/rust#49803 |
joshtriplett commentedOct 31, 2017
•
edited by Centril
Introduce a mechanism for Cargo crates to make use of declarative build scripts, obtained from one or more of their dependencies rather than via a
build.rs
file. This allows us to experimentat with declarative build scripts in the crates.io ecosystem.With this mechanism, crates can specify
metabuild = ["somecrate", "anothercrate"]
in theirCargo.toml
, and they'll automatically end up with a build script that invokessomecrate::metabuild()
andanothercrate::metabuild()
. Likely providers of crates for use with metabuild would include pkg-config (and more general native-library finders), parser generators, binding generators, other code generators, and anything else that would ordinarily say "add this to yourbuild.rs
" in its README.Rendered
Tracking issue