diff --git a/src/dds/toolchain/from_dds.cpp b/src/dds/toolchain/from_dds.cpp index 3562ce6c..16eecad6 100644 --- a/src/dds/toolchain/from_dds.cpp +++ b/src/dds/toolchain/from_dds.cpp @@ -306,11 +306,34 @@ toolchain dds::parse_toolchain_dds(const lm::pair_list& pairs, strv context) { return cxx_ver_iter->second; }; - auto get_flags = [&](language lang) -> string_seq { + auto get_link_flags = [&]() -> string_seq { string_seq ret; - if (flags) { - extend(ret, *flags); + if (is_msvc) { + strv rt_lib = "/MT"; + if (do_optimize.value_or(false)) { + extend(ret, {"/O2"}); + } + if (do_debug.value_or(false)) { + extend(ret, {"/Z7", "/DEBUG"}); + rt_lib = "/MTd"; + } + ret.emplace_back(rt_lib); + } else if (is_gnu_like) { + if (do_optimize.value_or(false)) { + extend(ret, {"-O2"}); + } + if (do_debug.value_or(false)) { + extend(ret, {"-g"}); + } } + if (link_flags) { + extend(ret, *link_flags); + } + return ret; + }; + + auto get_flags = [&](language lang) -> string_seq { + string_seq ret; if (lang == language::cxx && cxx_flags) { extend(ret, *cxx_flags); } @@ -329,11 +352,11 @@ toolchain dds::parse_toolchain_dds(const lm::pair_list& pairs, strv context) { extend(ret, {"/O2"}); } if (do_debug.has_value() && *do_debug) { - extend(ret, {"/Z7", "/DEBUG", "/MTd"}); + extend(ret, {"/Z7", "/DEBUG"}); rt_lib = "/MTd"; } ret.emplace_back(rt_lib); - extend(ret, {"/nologo", "", "/c", "", "/permissive-", "/Fo"}); + extend(ret, {"/nologo", "", "/permissive-", "/c", "", "/Fo"}); if (lang == language::cxx) { extend(ret, {"/EHsc"}); } @@ -353,6 +376,9 @@ toolchain dds::parse_toolchain_dds(const lm::pair_list& pairs, strv context) { "", "-o"}); } + if (flags) { + extend(ret, *flags); + } return ret; }; @@ -485,9 +511,7 @@ toolchain dds::parse_toolchain_dds(const lm::pair_list& pairs, strv context) { assert(false && "No link-exe command"); std::terminate(); } - if (link_flags) { - extend(ret, *link_flags); - } + extend(ret, get_link_flags()); return ret; }); diff --git a/src/dds/toolchain/from_dds.test.cpp b/src/dds/toolchain/from_dds.test.cpp index 7b76c0fb..c4d7fe94 100644 --- a/src/dds/toolchain/from_dds.test.cpp +++ b/src/dds/toolchain/from_dds.test.cpp @@ -76,6 +76,34 @@ void run_tests() { "ar rcs stuff.a foo.o bar.o", "g++ -fPIC -fdiagnostics-color foo.o bar.a -pthread -lstdc++fs -omeow.exe"); + check_tc_compile( + "Compiler-ID: GNU\nDebug: True", + "g++ -g -fPIC -fdiagnostics-color -pthread -c foo.cpp -ofoo.o", + "g++ -g -fPIC -fdiagnostics-color -pthread -Wall -Wextra -Wpedantic -Wconversion " + "-c foo.cpp -ofoo.o", + "ar rcs stuff.a foo.o bar.o", + "g++ -fPIC -fdiagnostics-color foo.o bar.a -pthread -lstdc++fs -omeow.exe -g"); + + check_tc_compile( + "Compiler-ID: GNU\nDebug: True\nOptimize: True", + "g++ -O2 -g -fPIC -fdiagnostics-color -pthread -c foo.cpp -ofoo.o", + "g++ -O2 -g -fPIC -fdiagnostics-color -pthread -Wall -Wextra -Wpedantic -Wconversion " + "-c foo.cpp -ofoo.o", + "ar rcs stuff.a foo.o bar.o", + "g++ -fPIC -fdiagnostics-color foo.o bar.a -pthread -lstdc++fs -omeow.exe -O2 -g"); + + check_tc_compile("Compiler-ID: MSVC", + "cl.exe /MT /nologo /permissive- /c foo.cpp /Fofoo.o /EHsc", + "cl.exe /MT /nologo /W4 /permissive- /c foo.cpp /Fofoo.o /EHsc", + "lib /nologo /OUT:stuff.a foo.o bar.o", + "cl.exe /nologo /EHsc foo.o bar.a /Femeow.exe /MT"); + + check_tc_compile("Compiler-ID: MSVC\nDebug: True", + "cl.exe /Z7 /DEBUG /MTd /nologo /permissive- /c foo.cpp /Fofoo.o /EHsc", + "cl.exe /Z7 /DEBUG /MTd /nologo /W4 /permissive- /c foo.cpp /Fofoo.o /EHsc", + "lib /nologo /OUT:stuff.a foo.o bar.o", + "cl.exe /nologo /EHsc foo.o bar.a /Femeow.exe /Z7 /DEBUG /MTd"); + auto tc = dds::parse_toolchain_dds(R"( Compiler-ID: GNU )"); diff --git a/tools/ci.py b/tools/ci.py index 56e9b383..15de9b4e 100644 --- a/tools/ci.py +++ b/tools/ci.py @@ -124,6 +124,7 @@ def main(argv: Sequence[str]) -> int: '--durations=10', f'--basetemp={paths.BUILD_DIR / "_tmp"}', '-n4', + 'tests/', ])