From 1958b829f22e3b69d4c4c23662e0d1c7c4d2e62b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 24 Jun 2017 11:43:45 +0200 Subject: Make VC compatible with 'export module M;' by fixing up preprocessed output --- build2/cc/compile.cxx | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'build2/cc/compile.cxx') diff --git a/build2/cc/compile.cxx b/build2/cc/compile.cxx index eddd465..9b8f31b 100644 --- a/build2/cc/compile.cxx +++ b/build2/cc/compile.cxx @@ -2398,7 +2398,37 @@ namespace build2 // implementation units. // if (cid == compiler_id::msvc && src.is_a (*x_mod)) - tu.mod.iface = true; + { + // It's quite painful to guard the export with an #if/#endif so + // if it is present, "fixup" the (temporary) preprocessed output + // by getting rid of the keyword. + // + // Note: when removing this also remember to remove the test. + // + if (tu.mod.iface) + { + // We can only fixup a temporary file. + // + if (!ps) + fail (relative (src)) << "fixup requires preprocessor"; + + // Stomp out the export keyword with spaces. We are using + // std::fstream since our fdstream does not yet support + // seeking. + // + fstream os (psrc.path ().string (), + fstream::out | fstream::in); + + auto pos (static_cast (p.export_pos)); + + if (!os.is_open () || + !os.seekp (pos) || + !os.write (" ", 6)) + fail << "unable to overwrite preprocessor output"; + } + else + tu.mod.iface = true; + } return tu; } -- cgit v1.1