From 0a52676ff3de5b302eb4fa85ed8440ae14281318 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 30 Jun 2021 13:01:16 +0200 Subject: Move symbol exporting .def file rule to bin.def module, add support for MinGW The bin.def module is automatically loaded by the c and cxx modules for the *-win32-msvc target architecture. This allows automatically exporting all symbols for all Windows targets using the following setup (showing for cxx in this example): lib{foo}: libul{foo}: {hxx cxx}{**} ... lib{foo}: def{foo}: include = ($cxx.target.system == 'win32-msvc') def{foo}: libul{foo} if ($cxx.target.system == 'mingw32') cxx.loptions += -Wl,--export-all-symbols That is, we use the .def file generation for MSVC and the built-in support (--export-all-symbols) for MinGW. But it is also possible to use the .def file generation for MinGW. In this case we need to explicitly load the bin.def module (which should be done after loading c or cxx) and using the following setup: using bin.def # In root.build. lib{foo}: libul{foo}: {hxx cxx}{**} ... lib{foo}: def{foo}: include = ($cxx.target.class == 'windows') def{foo}: libul{foo} --- libbuild2/bin/init.cxx | 50 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 16 deletions(-) (limited to 'libbuild2/bin/init.cxx') diff --git a/libbuild2/bin/init.cxx b/libbuild2/bin/init.cxx index 7d1f171..02321c2 100644 --- a/libbuild2/bin/init.cxx +++ b/libbuild2/bin/init.cxx @@ -939,21 +939,6 @@ namespace build2 } } - // Register .def file rule. - // - if (lid == "msvc" || lid == "msvc-lld") - { - // If we are using link.exe, then we can access dumpbin via the - // link.exe /DUMP option. But for lld-link we need llvm-nm. - // - if (lid == "msvc-lld") - load_module (rs, bs, "bin.nm.config", loc, extra.hints); - - bs.insert_rule (perform_update_id, "bin.def", def_); - bs.insert_rule (perform_clean_id, "bin.def", def_); - bs.insert_rule (configure_update_id, "bin.def", def_); - } - return true; } @@ -1092,7 +1077,8 @@ namespace build2 // // Use the target to decide on the default nm name. Note that in case // of win32-msvc this is insufficient and we fallback to the linker - // type (if available) to decide between dumpbin and llvm-nm. + // type (if available) to decide between dumpbin and llvm-nm (with + // fallback to dumpbin). // // Finally note that the dumpbin.exe functionality is available via // link.exe /DUMP. @@ -1164,6 +1150,37 @@ namespace build2 return true; } + bool + def_init (scope& rs, + scope& bs, + const location& loc, + bool, + bool, + module_init_extra& extra) + { + tracer trace ("bin::def_init"); + l5 ([&]{trace << "for " << bs;}); + + // Make sure the bin core is loaded (def{} target type). We also load + // nm.config unless we are using MSVC link.exe and can access dumpbin + // via its /DUMP option. + // + const string* lid (cast_null (rs["bin.ld.id"])); + + load_module (rs, bs, "bin", loc, extra.hints); + + if (lid == nullptr || *lid != "msvc") + load_module (rs, bs, "bin.nm.config", loc, extra.hints); + + // Register the def{} rule. + // + bs.insert_rule (perform_update_id, "bin.def", def_); + bs.insert_rule (perform_clean_id, "bin.def", def_); + bs.insert_rule (configure_update_id, "bin.def", def_); + + return true; + } + static const module_functions mod_functions[] = { // NOTE: don't forget to also update the documentation in init.hxx if @@ -1180,6 +1197,7 @@ namespace build2 {"bin.rc", nullptr, rc_init}, {"bin.nm.config", nullptr, nm_config_init}, {"bin.nm", nullptr, nm_init}, + {"bin.def", nullptr, def_init}, {nullptr, nullptr, nullptr} }; -- cgit v1.1