Skip to content

Commit

Permalink
Strip @foo.modmap command-file from the command line
Browse files Browse the repository at this point in the history
CMake 3.28 adds a modmap command file to the command line that it
writes into compile_commands.json but the file does not actually
exist outside of cmake compiling. This means the command line in
the compile_commands.json fails with an error about the missing
file:
```
error: no such file or directory: '@sus/CMakeFiles/subspace_unittests.dir/mem/addressof_unittest.cc.o.modmap'
```

To work around this we can strip out the use of the modmap command-file
for now. This will break compilation later when C++ 20 modules are being
used though. CMake will need to find a way to provide a command line in
the compile_commands.json file which can actually be used by other tools
to reproduce the compilation step.

CMake discussion: https://discourse.cmake.org/t/how-to-control-the-location-of-the-c-20-binary-module-interface-bmi-output-directory/7968/13
Fixes #437
  • Loading branch information
danakj committed Dec 19, 2023
1 parent e69c82f commit b431afc
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions subdoc/lib/run.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,27 @@ sus::Result<Database, DiagnosticResults> run_files(
args.push_back("-DSUBDOC");
}

// As of CMake version 3.28, the compile_commands.json includes "C++ 20
// modules support". Unfortuantely, this means that CMake injects a command-
// file into the compile command which is supposed to provide the mapping
// from module name to BMI file. However the mapping file does not actually
// exist outside of CMake doing compilation, so the compile_commands.json is
// a bit of a lie, and running the command contained within it will fail if
// subdoc tries to executate it verbatim, due to the mapping file not
// existing.
//
// So we drop the `@foo.modmap` argument from each command line for now to
// work around this problem introduced by CMake. Once code actually uses
// modules however, the mappings provided by the modmap file will be
// required to executate the compilation. And we will need to figure out
// some other way to provide them or force CMake to write the modmap files
// outside of compilation.
//
// See https://github.com/chromium/subspace/issues/437.
std::erase_if(args, [](const auto& a) {
return a.starts_with("@") && a.ends_with(".modmap");
});

return std::move(args);
};
tool.appendArgumentsAdjuster(adj);
Expand Down

0 comments on commit b431afc

Please sign in to comment.