From 279384475749326570fa0ac38b57764322d30c73 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 15 Nov 2023 14:01:53 +0200 Subject: Switch from two-step module compilation to -fmodule-output for Clang --- libbuild2/cc/compile-rule.cxx | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'libbuild2/cc/compile-rule.cxx') diff --git a/libbuild2/cc/compile-rule.cxx b/libbuild2/cc/compile-rule.cxx index 7abd23d..82282eb 100644 --- a/libbuild2/cc/compile-rule.cxx +++ b/libbuild2/cc/compile-rule.cxx @@ -7123,7 +7123,9 @@ namespace build2 small_vector header_args; // Header unit options storage. small_vector module_args; // Module options storage. +#if 0 size_t out_i (0); // Index of the -o option. +#endif switch (cclass) { @@ -7451,9 +7453,11 @@ namespace build2 append_header_options (env, args, header_args, a, t, md, md.dd); append_module_options (env, args, module_args, a, t, md, md.dd); +#if 0 // Note: the order of the following options is relied upon below. // out_i = args.size (); // Index of the -o option. +#endif if (ut == unit_type::module_intf || ut == unit_type::module_intf_part || @@ -7493,8 +7497,12 @@ namespace build2 } case compiler_type::clang: { + assert (ut != unit_type::module_header); + relm = relative (tp); + // @@ TMP: cleanup (see also the second invocation below). +#if 0 args.push_back ("-o"); args.push_back (relm.string ().c_str ()); args.push_back ("--precompile"); @@ -7506,6 +7514,29 @@ namespace build2 args.push_back ("-Xclang"); args.push_back ("-fmodules-embed-all-files"); +#else + // Without this option Clang's .pcm will reference source + // files. In our case this file may be transient (.ii). Plus, + // it won't play nice with distributed compilation. + // + args.push_back ("-Xclang"); + args.push_back ("-fmodules-embed-all-files"); + + if (relo.empty ()) + { + args.push_back ("-o"); + args.push_back (relm.string ().c_str ()); + args.push_back ("--precompile"); + } + else + { + out1 = "-fmodule-output=" + relm.string (); + args.push_back (out1.c_str ()); + args.push_back ("-o"); + args.push_back (relo.string ().c_str ()); + args.push_back ("-c"); + } +#endif break; } case compiler_type::msvc: @@ -7738,6 +7769,9 @@ namespace build2 if (ptmp && verb >= 3) md.psrc.temporary = true; + // @@ TMP: cleanup (see also --precompile option above and out_i). + // +#if 0 // Clang's module compilation requires two separate compiler // invocations. // @@ -7800,6 +7834,7 @@ namespace build2 rm.cancel (); } } +#endif timestamp now (system_clock::now ()); -- cgit v1.1