Repository navigation
Conversation
Signed-off-by: Ikeh Chukwuka <mrikehchukwuka@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #115, related to #84.
since cc 1.0.74 (rust-lang/cc-rs@019603a),
cc::Buildprintscargo:rerun-if-env-changedlines by default. once a build script prints anyrerun-ifline, cargo stops rerunning it when other files in the package change (cargo docs), so an edited or newcpp!macro is never extracted again, and the build fails with "This cpp! macro is not found in the library's rust-cpp metadata" untilcargo clean.with this change the parser records every file it reads, and
Config::buildprints acargo:rerun-if-changedline for each one. modules turned off with#[cfg(feature = ...)]aren't listed, because the parser never reads them and cargo reruns the build script anyway when features change. a file is recorded before it's read, so fixing a file that failed to parse also reruns the build script. the paths stay relative, which cargo resolves from the package root, and the lines usecargo:rather thancargo::to keep the 1.71 msrv. nothing is printed aftercargo_metadata(false), as theXXXcomment in that method asked for, andccprints norerun-iflines in that case either, so cargo's default rescan still applies. the docs forcargo_metadata,From<cc::Build>and the build script section of thecppcrate now explain this.to reproduce, take a crate whose
build.rsonly callscpp_build::build("src/lib.rs"), runcargo test, change thecpp!block insrc/value.rsfromreturn 1;toreturn 2;, and runcargo testagain withoutcargo clean. with cpp_build 0.5.12 the second run fails with the metadata error. with this branch it passes, and the build script prints:i also checked these cases with scratch crates, building twice without
cargo clean:cpp!macrocpp!macro to a module that had nonecpp!macrocpp!macrobuild("lib.rs")cargo_metadata(false)with hand-written link linestest_source_fileschecks the recorded files for each module layout the parser follows, which are an adjacentfoo.rs,foo/mod.rs, a file module declared inside an inline module,#[path], and a feature-disabled module.there are a few things this doesn't cover. headers included from
cpp!macros and files added withConfig::file()still don't rerun the build script, the same as now, because only the compiler knows which headers it opened, so i'd like to handle them in a separate pr using the compiler's dependency output. with cc 1.0.73 or older, cargo's default rescan used to pick up header edits, and these lines turn that rescan off, which newer cc versions already do. acc::Buildpassed throughFromwithcargo_metadata(false)already set can't be detected, so the docs ask forConfig::cargo_metadata(false)as well. the build script, and so the C++ compile, now reruns on every edit to a parsed file, which is how it behaved before cc 1.0.74. a build script that rewrites one of the parsed files on every run will now rerun on every build, because cargo sees that file as newer each time. the build script can avoid this by only writing the file when its contents actually change.your comment on #115 mentions an option.
cargo_metadata(false)turns this off, but if you'd rather have a separateConfigmethod, i can add one.(for context, i ran into this while working on the rust foundation's overloading-macros experiment, which uses cpp (rustfoundation/overloading-macros#61). we worked around it there by adding a
rerun-if-changedline to its build script (rustfoundation/overloading-macros#63), and a reviewer there suggested working on a fix upstream here.)