aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2023-11-15 14:01:53 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2023-11-15 14:01:53 +0200
commit279384475749326570fa0ac38b57764322d30c73 (patch)
treec8033cb70830181947fbbaba7d3204dfc1890850
parent19d918eb4a5fcc732b23de510bf59a9ea4f7c2e7 (diff)
Switch from two-step module compilation to -fmodule-output for Clang
-rw-r--r--libbuild2/cc/compile-rule.cxx35
1 files changed, 35 insertions, 0 deletions
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<string, 2> header_args; // Header unit options storage.
small_vector<string, 2> 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 ());