From 957552c7a85b4a1b50c7192b12813b618348ad99 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 14 Nov 2023 11:03:41 +0200 Subject: Fix module sidebuild logic for Clang --- libbuild2/cc/compile-rule.cxx | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'libbuild2/cc/compile-rule.cxx') diff --git a/libbuild2/cc/compile-rule.cxx b/libbuild2/cc/compile-rule.cxx index aefcc30..7abd23d 100644 --- a/libbuild2/cc/compile-rule.cxx +++ b/libbuild2/cc/compile-rule.cxx @@ -7074,7 +7074,8 @@ namespace build2 // If we are building a module interface or partition, then the target // is bmi*{} and it may have an ad hoc obj*{} member. For header units // there is no obj*{} (see the corresponding add_adhoc_member() call in - // apply()). + // apply()). For named modules there may be no obj*{} if this is a + // sidebuild (obj*{} is already in the library binary). // path relm; path relo; @@ -7237,7 +7238,7 @@ namespace build2 // Note also that what we are doing here appears to be incompatible // with PCH (/Y* options) and /Gm (minimal rebuild). // - // @@ MOD: TODO deal with absent relo. + // @@ MOD: TODO deal with absent relo (sidebuild). // if (find_options ({"/Zi", "/ZI", "-Zi", "-ZI"}, args)) { @@ -7492,8 +7493,6 @@ namespace build2 } case compiler_type::clang: { - // @@ MOD TODO: deal with absent relo. - relm = relative (tp); args.push_back ("-o"); @@ -7501,7 +7500,7 @@ namespace build2 args.push_back ("--precompile"); // Without this option Clang's .pcm will reference source - // files. In our case this file may be transient (.ii). Plus, + // files. In our case this file may be transient (.ii). Plus, // it won't play nice with distributed compilation. // args.push_back ("-Xclang"); @@ -7742,16 +7741,23 @@ namespace build2 // Clang's module compilation requires two separate compiler // invocations. // - // @@ MODPART: Clang (all of this is probably outdated). + // Note that if relo is empty, then there is no need for an object file + // (sidebuild). // - if (ctype == compiler_type::clang && - (ut == unit_type::module_intf || - ut == unit_type::module_intf_part || - ut == unit_type::module_impl_part)) + if (ctype == compiler_type::clang && + (ut == unit_type::module_intf || + ut == unit_type::module_intf_part || + ut == unit_type::module_impl_part) && + !relo.empty ()) { // Adjust the command line. First discard everything after -o then // build the new "tail". // + // Note that Clang will warn about unused command line options like + // -I. Feels like it's easier to just suppress the warning than to + // recreate the command line from scratch. Hopefully this will go away + // once we switch to -fmodule-output. + // args.resize (out_i + 1); args.push_back (relo.string ().c_str ()); // Produce .o. args.push_back ("-c"); // By compiling .pcm. -- cgit v1.1