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 upAllow build scripts to specify dependencies #2134
Conversation
rust-highfive
assigned
huonw
Nov 11, 2015
This comment has been minimized.
This comment has been minimized.
rust-highfive
commented
Nov 11, 2015
|
r? @huonw (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
rust-highfive
assigned
brson
and unassigned
huonw
Nov 11, 2015
This comment has been minimized.
This comment has been minimized.
|
This looks legit to me. |
This comment has been minimized.
This comment has been minimized.
|
What's the motivation for the directory case (I don't see it in the linked issue)? Are there other build systems that do this? I don't see tests for it, and it's admittedly buggy. Can it be excluded? |
This comment has been minimized.
This comment has been minimized.
briansmith
commented
Nov 11, 2015
|
Note that the build.rs script can do multiple things that each have independent dependencies. For example, one part of the build script might build a C library to be linked in, and another part might take a data file and generate Rust code from it. I don't use the Also, this feature seems dangerous as currently specified, as far as optimizing the build. In most cases, it would be better to be able to specify patterns of files that, if they are changed, do NOT cause a rebuild to be needed, with cargo by default assuming that any change does require the build script to get re-run. In particular, I expect it would be common for people to forget to manually update the list of dependencies as their build.rs dependencies change; the feature should be designed to do the safest thing when that happens. |
This comment has been minimized.
This comment has been minimized.
|
The directory case was motivated by my own intentions which is that I have a bunch of crates with vendored C source code and I was hoping to not reimplement walking the entire directory tree and printing all paths in those cases. That being said I would be fine leaving it out for now and just not traversing and looking at the mtime of the directory itself (which just won't be meaningful information). You're probably right about just not including something that's already broken. Yeah I would expect the case where multiple things are being done that Cargo would have to be informed about the union of the two and then the build script itself would have to worry about each individually (or just run I would also expect any build dependencies (e.g. |
alexcrichton
force-pushed the
alexcrichton:build-script-input
branch
from
8d2ad53
to
b920858
Nov 11, 2015
alexcrichton
force-pushed the
alexcrichton:build-script-input
branch
from
b920858
to
7c97c5b
Nov 11, 2015
This comment has been minimized.
This comment has been minimized.
|
Updated with clarification of docs and removal of directory traversal |
tomaka
referenced this pull request
Nov 11, 2015
Merged
Remove support for the "image" library #1337
This comment has been minimized.
This comment has been minimized.
|
My pocket-resources crate lists all the files in a directory and includes all them with |
This comment has been minimized.
This comment has been minimized.
|
@Tomata Is that a suitable replacement for the directory feature, or are you suggesting the directory feature is needed because of what you are doing? |
This comment has been minimized.
This comment has been minimized.
|
Uh, @tomaka, sorry tomata. |
This comment has been minimized.
This comment has been minimized.
|
It's an illustration of how the directory feature could be useful. All my game projects contain a However you could reasonably argue that it's my crate that has a bad design and that should be changed, just like using |
This comment has been minimized.
This comment has been minimized.
|
Yeah I can see where directories can be useful from time to time, but @brson's point about depending on a directory being a little "inherently broken" (e.g. doesn't track file deletions) is pretty convincing to me that it shouldn't happen just yet. It's reasonably easy enough to traverse a directory in Rust and just print out all the files as well, so I'm fine with a "v1" of this just being that you have to manually print out files in a directory. I don't really expect every crate with a build script to start using this feature. Many build-dependency libraries will likely start working with this but there it's easy enough to implement traversal once and call it a day. |
This comment has been minimized.
This comment has been minimized.
|
If a build script doesn't print And if so, how do you write a build script that has no dependency at all? Do you have to use a hack like |
This comment has been minimized.
This comment has been minimized.
|
Yeah the current behavior is used if nothing is printed, and I guess some dummy file like that could be used yeah (or perhaps some directory in the source folder). A new directive could perhaps be added for "no input files" at some point in the future. |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
By "dependencies" this means file dependencies, not |
This comment has been minimized.
This comment has been minimized.
|
Indeed! Should perhaps consider a better PR title... |
This comment has been minimized.
This comment has been minimized.
|
ping r? @brson |
This comment has been minimized.
This comment has been minimized.
|
@bors r+ |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Dec 4, 2015
This comment has been minimized.
This comment has been minimized.
|
|
alexcrichton commentedNov 11, 2015
Currently Cargo is quite conservative in how it determines whether a build
script should be run. The heuristic used is "did any file in the project
directory change", but this is almost always guaranteed to be too coarse
grained in situations like:
few times as possible. Being able to inform Cargo about precisely when a build
script should be run should provide more robust support here.
crate root. Sometimes a dependency could be elsewhere in a repository and
scripts need a method of informing Cargo about this (as currently these
compiles don't happen then they should).
This commit adds this support in build scripts via a new
rerun-if-changeddirective which can be printed to standard output (using the standard Cargo
metadata format). The value for this key is a path relative to the crate root,
and Cargo will only look at these paths when determining whether to rerun the
build script. Any other file changes will not trigger the build script to be
rerun.
Currently the printed paths may either be a file or a directory, and a directory
is deeply traversed. The heuristic for trigger a rerun is detecting whether any
input file has been modified since the build script was last run (determined by
looking at the modification time of the output file of the build script). This
current implementation means that if you depend on a directory and then delete a
file within it the build script won't be rerun, but this is already the case and
can perhaps be patched up later.
Future extensions could possibly include the usage of glob patterns in build
script paths like the
includeandexcludefeatures ofCargo.toml, butthese should be backwards compatible to add in the future.
Closes #1162