@@ -31,14 +31,33 @@ import("support")
31
31
import (" .mapper" )
32
32
import (" .builder" , {inherit = true })
33
33
34
+ function _get_bmifile (target , module )
35
+ local has_reduced_bmi = support .get_modulesreducedbmiflag (target )
36
+ local has_two_phases = target :policy (" build.c++.modules.two_phases" )
37
+ local incremental_optimizations = target :policy (" build.c++.modules.incremental_optimizations" )
38
+ -- llvm have currently a bug which prevent to emit reduced bmi when using two phase compilation
39
+ -- local add_reduced_flag = has_reduced_bmi and (not has_two_phases or incremental_optimizations)
40
+ local add_reduced_flag = not has_two_phases and has_reduced_bmi
41
+ local bmifile = module .bmifile
42
+
43
+ if has_two_phases and add_reduced_flag then
44
+ bmifile = path .join (path .directory (module .bmifile ), " reduced." .. path .filename (module .bmifile ))
45
+ end
46
+
47
+ return bmifile , add_reduced_flag
48
+ end
49
+
34
50
function _make_modulebuildflags (target , module , opt )
35
51
assert (not module .headerunit )
52
+
53
+ local modules_reduced_bmi_flag = support .get_modulesreducedbmiflag (target )
54
+ local has_two_phases = target :policy (" build.c++.modules.two_phases" )
36
55
local flags
37
- local two_phases = target :policy (" build.c++.modules.two_phases" )
38
56
if opt .bmi then
39
57
local module_outputflag = support .get_moduleoutputflag (target )
40
58
41
59
flags = {" -x" , " c++-module" }
60
+
42
61
if not opt .objectfile then
43
62
table.insert (flags , " --precompile" )
44
63
if target :has_tool (" cxx" , " clang_cl" ) then
@@ -49,10 +68,16 @@ function _make_modulebuildflags(target, module, opt)
49
68
if std then
50
69
table .join2 (flags , {" -Wno-include-angled-in-module-purview" , " -Wno-reserved-module-identifier" , " -Wno-deprecated-declarations" })
51
70
end
52
- table.insert (flags , module_outputflag .. module .bmifile )
71
+
72
+ local bmifile , add_reduced_flag = _get_bmifile (target , module )
73
+ if add_reduced_flag then
74
+ table.insert (flags , modules_reduced_bmi_flag )
75
+ end
76
+
77
+ table.insert (flags , module_outputflag .. bmifile )
53
78
else
54
79
flags = {}
55
- if not two_phases or not module .bmifile then
80
+ if not has_two_phases or not module .bmifile then
56
81
flags = {" -x" , " c++" }
57
82
end
58
83
local std = (module .name == " std" or module .name == " std.compat" )
@@ -200,7 +225,8 @@ function _get_requiresflags(target, module)
200
225
local dep_module = mapper .get (target , required )
201
226
assert (dep_module , " module dependency %s required for %s not found" , required , name )
202
227
203
- local mapflag = dep_module .headerunit and modulefileflag .. dep_module .bmifile or format (" %s%s=%s" , modulefileflag , required , dep_module .bmifile )
228
+ local dep_bmifile , _ = dep .headerunit and dep_module .bmifile or _get_bmifile (target , dep_module )
229
+ local mapflag = dep_module .headerunit and modulefileflag .. dep_bmifile or format (" %s%s=%s" , modulefileflag , required , dep_bmifile )
204
230
table.insert (requiresflags , mapflag )
205
231
206
232
-- append deps
0 commit comments