Repository navigation
Conversation
Signed-off-by: Ikeh Chukwuka <mrikehchukwuka@gmail.com>
|
Thanks! My main concern is that this runs the compiler a second time just to get the dependencies. It would be better to get them from the real compile: -MMD for GCC/Clang (the .d files land next to the objects), and /sourceDependencies for cl.exe, keeping /showIncludes as a fallback for clang-cl. A test in test/ that includes a header from a cpp! block would be nice. |
|
thank you, that makes sense, so i'll rework it the way you suggested. since the part i still need to work out is finding the i'll add the test too. |
this is a follow-up to #118, which made cargo rerun the build script when a rust file with
cpp!macros changes. headers included from those macros and sources added withConfig::filestill aren't tracked, though, so editing one of them keeps the old generated library until something else triggers a rerun. that's why the docs told users to printcargo:rerun-if-changedfor them by hand.with this change (after compiling), cpp_build asks the compiler which files the generated
cpp_closures.cppand everyConfig::filesource read, and printscargo:rerun-if-changedfor each one. how it asks depends on the compiler:-MM -MT cpp_build_deps, and cpp_build parses the make-style output, which leaves out system headers because of-MM./Zs /showIncludes, which only checks the syntax and prints aNote: including file:line for each header. since it can't leave out system headers on its own, cpp_build skips the ones under theINCLUDEdirectories. it also setsVSLANG=1033so that output stays in english, as rustc and cc already do, and passes sources other than.cwith-Tp, like cc does for.cc, so cl.exe doesn't mistake them for object files./Zs /showIncludes:user, which leaves out system headers by itself. cpp_build recognises clang-cl by its file name, because cc'sis_like_clang_clisn't in the older cc versions cpp_build still supports.files in
OUT_DIRare skipped, paths inside the package stay relative, and a file that several sources include is only printed once. paths that don't exist are never printed, because cargo would rerun the build script on every build for them. and as with #118, nothing is printed whencargo_metadata(false)is set, and if the compiler can't list the files, the behaviour is the same as today.a few notes on my work here:
/sourceDependenciesfirst, but it lowercases every path, which breaks the relative paths and theOUT_DIRcheck, while/showIncludeskeeps paths as they are.cc::Buildbefore converting it withFromaren't tracked, because cc only lists them throughget_files, which needs cc 1.0.89. the docs now say to add them withConfig::fileinstead.SDKSettings.jsonas a dependency even with-MM, and i left it in, since an sdk update should rerun the build.for testing, there are unit tests for both output formats and for splitting
INCLUDE. i also wrote a script that builds a throwaway crate with a nested header, a header outside the crate, a header in a non-ascii folder, aConfig::filesource that shares a header, and a header behind#ifdef, and then edits each one. i ran it in a workflow on my fork on linux (gcc, clang), macos (apple clang) and windows (cl.exe, visual studio's clang-cl, mingw gcc), and every edit rebuilt with the new value, no-op builds stayed fresh, and editing the#ifdef-ed header didn't rerun anything. for comparison, the released 0.5.12 from crates.io kept printing the old values after every edit, because its build script never reran. the same workflow also passed the test suite on stable and 1.71 on all three systems, andccache g++worked locally too.