@@ -1839,6 +1839,21 @@ std::string emit_ninja_string(const BuildPlan& plan, std::string* placements,
18391839 append (std::format (" rspfile_content ={}{}\n " ,
18401840 msvcDeps ? " " + std::string (kUtf8ByteOrderMark ) : " " , payload));
18411841 };
1842+ // Keep ordinary compile edges inside the same admission controller as the
1843+ // detached GCC path. The compiler command remains argv-based; only the
1844+ // existing shell-free depfile filter is moved into the wrapper.
1845+ const bool memoryAdmission = plan.memoryCompilerCap > 0
1846+ && plan.memoryBaselineBytes != 0 ;
1847+ auto admission_prefix = [&]() {
1848+ return std::format (" $mcpp compile-admit --sem .mcpp-sched --cap {}"
1849+ " --mem-baseline {} --mem-threshold {}" ,
1850+ plan.memoryCompilerCap , plan.memoryBaselineBytes ,
1851+ plan.memoryThresholdPercent );
1852+ };
1853+ auto admission_dep = [&]() {
1854+ return needsGnuModuleFilter
1855+ ? std::string (" --dep-raw $out.d.raw --dep-out $out.d" ) : std::string{};
1856+ };
18421857
18431858 // Tell the driver, every time, that this TU is a module interface.
18441859 //
@@ -1957,26 +1972,39 @@ std::string emit_ninja_string(const BuildPlan& plan, std::string* placements,
19571972 append (" rule cxx_precompile\n " );
19581973 if constexpr (mcpp::platform::is_windows) {
19591974 const std::string payload = " $local_includes" ;
1960- append (std::format (
1961- " command = {}$cxx{} $cxxflags $unit_cxxflags{}{} {}$in {}$out\n " ,
1962- win_depfile_filter, rsp_ref (payload), traits.bmiOnlyFlags ,
1963- module_src_flags, mmd_flag, dial.outputObjPrefix ));
1975+ if (memoryAdmission)
1976+ append (std::format (
1977+ " command = {} -- $cxx{} $cxxflags $unit_cxxflags{}{} {}$in {}$out\n " ,
1978+ admission_prefix (), rsp_ref (payload), traits.bmiOnlyFlags ,
1979+ module_src_flags, mmd_flag, dial.outputObjPrefix ));
1980+ else
1981+ append (std::format (
1982+ " command = {}$cxx{} $cxxflags $unit_cxxflags{}{} {}$in {}$out\n " ,
1983+ win_depfile_filter, rsp_ref (payload), traits.bmiOnlyFlags ,
1984+ module_src_flags, mmd_flag, dial.outputObjPrefix ));
19641985 append_rspfile (payload);
19651986 append_cxx_deps ();
19661987 } else {
19671988 // Same bak / bmi-equal / restore dance as cxx_module, and for the
19681989 // same reason: ninja's `restat` compares the output's MTIME, and a
19691990 // compiler that rewrites a byte-identical BMI still moves it. What
19701991 // suppresses the cascade is putting the old file back.
1971- append (std::format (
1972- " command = "
1973- " if [ -f \" $out\" ]; then cp -p \" $out\" \" $out.bak\" ; fi && "
1974- " $cxx $local_includes $cxxflags $unit_cxxflags{}{} {}$in {}$out && "
1975- " if [ -f \" $out.bak\" ] && $mcpp bmi-equal \" $out\" \" $out.bak\" ; then "
1976- " mv \" $out.bak\" \" $out\" ; "
1977- " else rm -f \" $out.bak\" ; fi\n " ,
1978- traits.bmiOnlyFlags , module_src_flags, mmd_flag,
1979- dial.outputObjPrefix ));
1992+ if (memoryAdmission)
1993+ append (std::format (" command = {}{} -- $cxx $local_includes"
1994+ " $cxxflags $unit_cxxflags{}{} {}$in {}$out\n " ,
1995+ admission_prefix (), admission_dep (),
1996+ traits.bmiOnlyFlags , module_src_flags, mmd_flag,
1997+ dial.outputObjPrefix ));
1998+ else
1999+ append (std::format (
2000+ " command = "
2001+ " if [ -f \" $out\" ]; then cp -p \" $out\" \" $out.bak\" ; fi && "
2002+ " $cxx $local_includes $cxxflags $unit_cxxflags{}{} {}$in {}$out && "
2003+ " if [ -f \" $out.bak\" ] && $mcpp bmi-equal \" $out\" \" $out.bak\" ; then "
2004+ " mv \" $out.bak\" \" $out\" ; "
2005+ " else rm -f \" $out.bak\" ; fi\n " ,
2006+ traits.bmiOnlyFlags , module_src_flags, mmd_flag,
2007+ dial.outputObjPrefix ));
19802008 append_cxx_deps ();
19812009 }
19822010 append (" description = BMI $out\n " );
@@ -1989,15 +2017,26 @@ std::string emit_ninja_string(const BuildPlan& plan, std::string* placements,
19892017 append (" rule cxx_module_object\n " );
19902018 if constexpr (mcpp::platform::is_windows) {
19912019 const std::string payload = " $local_includes" ;
1992- append (std::format (" command = {}$cxx{} $cxxflags $unit_cxxflags{} {}{}\n " ,
1993- win_depfile_filter, rsp_ref (payload), module_src_flags,
1994- mmd_flag, compile_tail));
2020+ if (memoryAdmission)
2021+ append (std::format (" command = {}{} -- $cxx{} $cxxflags $unit_cxxflags{} {}{}\n " ,
2022+ admission_prefix (), admission_dep (), rsp_ref (payload),
2023+ module_src_flags, mmd_flag, compile_tail));
2024+ else
2025+ append (std::format (" command = {}$cxx{} $cxxflags $unit_cxxflags{} {}{}\n " ,
2026+ win_depfile_filter, rsp_ref (payload), module_src_flags,
2027+ mmd_flag, compile_tail));
19952028 append_rspfile (payload);
19962029 append_cxx_deps ();
19972030 } else {
1998- append (std::format (
1999- " command = $cxx $local_includes $cxxflags $unit_cxxflags{} {}{}{}\n " ,
2000- module_src_flags, mmd_flag, compile_tail, mmd_filter));
2031+ if (memoryAdmission)
2032+ append (std::format (" command = {}{} -- $cxx $local_includes"
2033+ " $cxxflags $unit_cxxflags{} {}{}\n " ,
2034+ admission_prefix (), admission_dep (),
2035+ module_src_flags, mmd_flag, compile_tail));
2036+ else
2037+ append (std::format (
2038+ " command = $cxx $local_includes $cxxflags $unit_cxxflags{} {}{}{}\n " ,
2039+ module_src_flags, mmd_flag, compile_tail, mmd_filter));
20012040 append_cxx_deps ();
20022041 }
20032042 append (" description = OBJ $out\n " );
@@ -2007,14 +2046,24 @@ std::string emit_ninja_string(const BuildPlan& plan, std::string* placements,
20072046 append (" rule cxx_object\n " );
20082047 if constexpr (mcpp::platform::is_windows) {
20092048 const std::string payload = " $local_includes" ;
2010- append (std::format (" command = {}$cxx{} $cxxflags $unit_cxxflags {}{}\n " ,
2011- win_depfile_filter, rsp_ref (payload), mmd_flag,
2012- compile_tail));
2049+ if (memoryAdmission)
2050+ append (std::format (" command = {}{} -- $cxx{} $cxxflags $unit_cxxflags {}{}\n " ,
2051+ admission_prefix (), admission_dep (), rsp_ref (payload),
2052+ mmd_flag, compile_tail));
2053+ else
2054+ append (std::format (" command = {}$cxx{} $cxxflags $unit_cxxflags {}{}\n " ,
2055+ win_depfile_filter, rsp_ref (payload), mmd_flag, compile_tail));
20132056 append_rspfile (payload);
20142057 } else {
2015- append (std::format (
2016- " command = $cxx $local_includes $cxxflags $unit_cxxflags {}{}{}\n " ,
2017- mmd_flag, compile_tail, mmd_filter));
2058+ if (memoryAdmission)
2059+ append (std::format (" command = {}{} -- $cxx $local_includes"
2060+ " $cxxflags $unit_cxxflags {}{}\n " ,
2061+ admission_prefix (), admission_dep (),
2062+ mmd_flag, compile_tail));
2063+ else
2064+ append (std::format (
2065+ " command = $cxx $local_includes $cxxflags $unit_cxxflags {}{}{}\n " ,
2066+ mmd_flag, compile_tail, mmd_filter));
20182067 }
20192068 append (" description = OBJ $out\n " );
20202069 append_cxx_deps ();
@@ -2025,8 +2074,13 @@ std::string emit_ninja_string(const BuildPlan& plan, std::string* placements,
20252074 if (need_c_rule) {
20262075 append (" rule c_object\n " );
20272076 const std::string payload = " $local_includes" ;
2028- append (std::format (" command = $cc{} $cflags $unit_cflags {}{}\n " ,
2029- rsp_ref (payload), c_mmd_flag, compile_tail));
2077+ if (memoryAdmission)
2078+ append (std::format (" command = {} -- $cc{} $cflags $unit_cflags {}{}\n " ,
2079+ admission_prefix (), rsp_ref (payload), c_mmd_flag,
2080+ compile_tail));
2081+ else
2082+ append (std::format (" command = $cc{} $cflags $unit_cflags {}{}\n " ,
2083+ rsp_ref (payload), c_mmd_flag, compile_tail));
20302084 append_rspfile (payload);
20312085 append (" description = CC $out\n " );
20322086 append_cxx_deps ();
0 commit comments