Open Bug 1342532 Opened 7 years ago Updated 2 years ago

use dependency files generated by cargo so we don't have to run it for every build

Categories

(Firefox Build System :: General, defect)

defect

Tracking

(Not tracked)

People

(Reporter: ted, Unassigned)

References

Details

cargo got a `--dep-info` option just recently:
https://github.com/rust-lang/cargo/pull/3557

We should use it once we require a new-enough Rust compiler. I guess we could optionally enable it by checking the cargo version.

It would behoove us to at least write a patch and try it out to make sure that it does what we need. If not we can get fixes landed and we won't have to wait as long for it to hit stable.
Oh FWIW there's no flag needed (the implementation changed from the PR title), Cargo will just always emit the dep-info file.

I believe if Cargo is currently generating target/debug/libfoo.a there'll be a dep file (for path dependencies) at target/debug/libfoo.d. Sorry I meant to cc you on that bug, but please let me know if anything is missing out of that file!
Oh, great!
Summary: Pass `--dep-info` to cargo to get a dependency file so we don't have to run it for every build → use dependency files generated by cargo so we don't have to run it for every build
In light of that this should just be a matter of sticking an `-include whatever.d` line in rules.mk somewhere, then getting rid of the `force-cargo-*-build` targets. However, since the dep file is the output file with the extension replaced, this is probably a PITA to do in rules.mk, so we should maybe just write this out in the recursive make backend, since it has all the info it needs to do this.

I guess the simplest place to actually generate the dep file name would be in the {RustLibrary,BaseRustProgram} classes themselves:
https://dxr.mozilla.org/mozilla-central/rev/aff336ac161daa3ea350e59a288963edbd58ed39/python/mozbuild/mozbuild/frontend/data.py#539
https://dxr.mozilla.org/mozilla-central/rev/aff336ac161daa3ea350e59a288963edbd58ed39/python/mozbuild/mozbuild/frontend/data.py#447

We're already generating the output filename from the base name + extension there, so we could simply add another line like `self.depfile = ...`.

Then in the recursive make backend, when we handle Rust libraries / programs:
https://dxr.mozilla.org/mozilla-central/rev/aff336ac161daa3ea350e59a288963edbd58ed39/python/mozbuild/mozbuild/backend/recursivemake.py#1102
https://dxr.mozilla.org/mozilla-central/rev/aff336ac161daa3ea350e59a288963edbd58ed39/python/mozbuild/mozbuild/backend/recursivemake.py#1248

we could add a line like: `backend_file.write('-include %s\n' % (obj.depfile, ))`.

Then, finally, we would replace `force-cargo-library-build` with `$(RUST_LIBRARY_FILE)` here:
https://dxr.mozilla.org/mozilla-central/rev/aff336ac161daa3ea350e59a288963edbd58ed39/config/rules.mk#986

and remove the now-extraneous dependency below it, and then do the same for the other `force-cargo-*-build` targets.

I guess if we rip out the force-building behavior we'd need to require Rust 1.18 (bug 1370874).
Product: Core → Firefox Build System
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.