Skip to content

Commit 8d0f918

Browse files
committed
[C++20] [Modules] Offer -fmodules-embed-all-files option
See https://discourse.llvm.org/t/rfc-modules-should-we-embed-sources-to-the-bmi/81029 for details. Close #72383
1 parent 812c96e commit 8d0f918

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

clang/docs/StandardCPlusPlusModules.rst

+34
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,33 @@ Currently, Clang accepts the above example, though it may produce surprising
462462
results if the debugging code depends on consistent use of ``NDEBUG`` in other
463463
translation units.
464464

465+
Source Files Consistency
466+
^^^^^^^^^^^^^^^^^^^^^^^^
467+
468+
Clang may open the input files (*) of a BMI during the compilation. It implies that
469+
when we consume a BMI, all the input files need to be present with the same path
470+
and the same contents.
471+
472+
To overcome the requirements and simplify cases like distributed builds and sandboxed
473+
builds, users can use ``-fmodules-embed-all-files`` flag to embed all input files
474+
into the BMI so that clang won't ask to open the corresponding file on disk.
475+
476+
Input files (*): The source files that took part in the compilation of the BMI.
477+
For example,
478+
479+
.. code-block:: c++
480+
481+
// M.cppm
482+
module;
483+
#include "foo.h"
484+
export module M;
485+
486+
// foo.h
487+
#pragma once
488+
#include "bar.h"
489+
490+
The ``M.cppm``, ``foo.h`` and ``bar.h`` are input files for the BMI of ``M.cppm``.
491+
465492
Object definition consistency
466493
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
467494

@@ -484,6 +511,13 @@ fragment is disabled by default. These checks can be enabled by specifying
484511
and you encounter incorrect or missing diagnostics, please report them via the
485512
`community issue tracker <https://github.com/llvm/llvm-project/issues/>`_.
486513

514+
Privacy Issue
515+
-------------
516+
517+
BMIs are not and should not be treated as an information hiding mechanism.
518+
They should always be assumed to contain all the information that was used to
519+
create them, in a recoverable form.
520+
487521
ABI Impacts
488522
-----------
489523

clang/include/clang/Driver/Options.td

+6-4
Original file line numberDiff line numberDiff line change
@@ -3162,6 +3162,12 @@ def modules_reduced_bmi : Flag<["-"], "fexperimental-modules-reduced-bmi">,
31623162
HelpText<"Generate the reduced BMI">,
31633163
MarshallingInfoFlag<FrontendOpts<"GenReducedBMI">>;
31643164

3165+
def fmodules_embed_all_files : Joined<["-"], "fmodules-embed-all-files">,
3166+
Visibility<[ClangOption, CC1Option, CLOption]>,
3167+
HelpText<"Embed the contents of all files read by this compilation into "
3168+
"the produced module file.">,
3169+
MarshallingInfoFlag<FrontendOpts<"ModulesEmbedAllFiles">>;
3170+
31653171
def fmodules_prune_interval : Joined<["-"], "fmodules-prune-interval=">, Group<i_Group>,
31663172
Visibility<[ClangOption, CC1Option]>, MetaVarName<"<seconds>">,
31673173
HelpText<"Specify the interval (in seconds) between attempts to prune the module cache">,
@@ -7656,10 +7662,6 @@ def fmodules_embed_file_EQ : Joined<["-"], "fmodules-embed-file=">,
76567662
HelpText<"Embed the contents of the specified file into the module file "
76577663
"being compiled.">,
76587664
MarshallingInfoStringVector<FrontendOpts<"ModulesEmbedFiles">>;
7659-
def fmodules_embed_all_files : Joined<["-"], "fmodules-embed-all-files">,
7660-
HelpText<"Embed the contents of all files read by this compilation into "
7661-
"the produced module file.">,
7662-
MarshallingInfoFlag<FrontendOpts<"ModulesEmbedAllFiles">>;
76637665
defm fimplicit_modules_use_lock : BoolOption<"f", "implicit-modules-use-lock",
76647666
FrontendOpts<"BuildingImplicitModuleUsesLock">, DefaultTrue,
76657667
NegFlag<SetFalse>,

clang/lib/Driver/ToolChains/Clang.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -4214,6 +4214,9 @@ static bool RenderModulesOptions(Compilation &C, const Driver &D,
42144214
Args.ClaimAllArgs(options::OPT_fmodule_output_EQ);
42154215
}
42164216

4217+
if (Args.hasArg(options::OPT_fmodules_embed_all_files))
4218+
CmdArgs.push_back("-fmodules-embed-all-files");
4219+
42174220
return HaveModules;
42184221
}
42194222

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// RUN: %clang -std=c++20 %s -fmodules-embed-all-files -### 2>&1 | FileCheck %s
2+
// CHECK: -fmodules-embed-all-files

0 commit comments

Comments
 (0)