Skip to content

Commit

Permalink
Rollup merge of rust-lang#93969 - bjorn3:codegen_backend_dep_info, r=…
Browse files Browse the repository at this point in the history
…pnkfelix

Only add codegen backend to dep info if -Zbinary-dep-depinfo is used

I am currently migrating the cg_clif build system from using a binary linked to the codegen backend as rustc replacement to passing `-Zcodegen-backend` instead. Without this PR this would force cargo to rebuild the sysroot on any change to the codegen backend even if I explicitly specify that I want it to be preserved, which would make development of cg_clif a lot slower. If you still want to have changes to the codegen backend invalidate the cargo build cache you can explicitly specify `-Zbinary-dep-depinfo`.

cc `@eddyb` as the codegen backend was initially added to the depinfo for rust-gpu.
  • Loading branch information
Dylan-DPC authored Apr 16, 2022
2 parents bb1a03c + 147e5da commit 7b8df43
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
12 changes: 8 additions & 4 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,11 +629,15 @@ fn write_out_deps(
});
files.extend(extra_tracked_files);

if let Some(ref backend) = sess.opts.debugging_opts.codegen_backend {
files.push(backend.to_string());
}

if sess.binary_dep_depinfo() {
if let Some(ref backend) = sess.opts.debugging_opts.codegen_backend {
if backend.contains('.') {
// If the backend name contain a `.`, it is the path to an external dynamic
// library. If not, it is not a path.
files.push(backend.to_string());
}
}

boxed_resolver.borrow_mut().access(|resolver| {
for cnum in resolver.cstore().crates_untracked() {
let source = resolver.cstore().crate_source_untracked(cnum);
Expand Down
19 changes: 17 additions & 2 deletions src/test/run-make-fulldeps/hotplug_codegen_backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,25 @@ include ../tools.mk

# ignore-stage1

# This test both exists as a check that -Zcodegen-backend is capable of loading external codegen
# backends and that this external codegen backend is only included in the dep info if
# -Zbinary-dep-depinfo is used.

all:
/bin/echo || exit 0 # This test requires /bin/echo to exist
$(RUSTC) the_backend.rs --crate-name the_backend --crate-type dylib \
-o $(TMPDIR)/the_backend.dylib

$(RUSTC) some_crate.rs --crate-name some_crate --crate-type lib -o $(TMPDIR)/some_crate \
-Z codegen-backend=$(TMPDIR)/the_backend.dylib -Z unstable-options \
--emit link,dep-info
grep -x "This has been \"compiled\" successfully." $(TMPDIR)/libsome_crate.rlib
# don't declare a dependency on the codegen backend if -Zbinary-dep-depinfo isn't used.
grep -v "the_backend.dylib" $(TMPDIR)/some_crate.d

$(RUSTC) some_crate.rs --crate-name some_crate --crate-type lib -o $(TMPDIR)/some_crate \
-Z codegen-backend=$(TMPDIR)/the_backend.dylib -Z unstable-options
grep -x "This has been \"compiled\" successfully." $(TMPDIR)/some_crate
-Z codegen-backend=$(TMPDIR)/the_backend.dylib -Z unstable-options \
--emit link,dep-info -Zbinary-dep-depinfo
grep -x "This has been \"compiled\" successfully." $(TMPDIR)/libsome_crate.rlib
# but declare a dependency on the codegen backend if -Zbinary-dep-depinfo it used.
grep "the_backend.dylib" $(TMPDIR)/some_crate.d

0 comments on commit 7b8df43

Please sign in to comment.