Repository navigation
cpp_build: track C++ headers and Config::file sources - #119
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. |
Signed-off-by: Ikeh Chukwuka <mrikehchukwuka@gmail.com>
|
i pushed the rework. gcc and clang now compile with i did try scanning that's the cc bump i mentioned i'd check with you on. the minimum goes from 1.0.38 to 1.6, and since cc 1.6 still builds on rust 1.65, cpp's msrv stays at 1.71. does that work for you? for cl.exe, i kept the i also added a test in the checks on my fork pass across linux, macos, and windows with g++, clang++, cl.exe, clang-cl, and mingw g++. the two macos test jobs never picked up a runner from github, though the macos scenario itself passed. |
|
Bumping msrv is no problem |
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, cpp_build finds out which files the generated
cpp_closures.cppand every other source it compiles read, and printscargo:rerun-if-changedfor each one. how it finds out depends on the compiler:-MMD -MT cpp_build_depsadded, which writes a make-style.dfile next to each object, and cpp_build parses those after the build.-MMDleaves out system headers./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.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:
.dfiles, cpp_build needs the object paths. cc 1.6 addedtry_create_archiveandtry_emit_link_directives, which is alltry_compiledoes after compiling the objects, so cpp_build callstry_compile_intermediatesand those two itself and keeps the paths. that raises the minimum cc from 1.0.38 to 1.6, which still builds on rust 1.65, so cpp's msrv stays at 1.71./sourceDependenciesfirst, but it lowercases the header paths, which breaks the relative paths and theOUT_DIRcheck, while/showIncludeskeeps paths as they are. clang-cl ignores/sourceDependenciesanyway, so both msvc compilers share the/showIncludespass.cc::Buildbefore converting it withFromare tracked now too, so the docs no longer ask users to add them withConfig::file.for testing, there are unit tests for both output formats and for splitting
INCLUDE, and a test intest/with acpp!block that includes a nested header. 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, a source added to thecc::Buildbefore the conversion, 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 linux and windows, but github never gave the macos test jobs a runner.ccache g++worked locally too.