aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/bin/init.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2021-06-30 13:01:16 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2021-06-30 13:01:16 +0200
commit0a52676ff3de5b302eb4fa85ed8440ae14281318 (patch)
tree897f2d8435eb3140ee5e56fe817cb63cdff7fdcd /libbuild2/bin/init.cxx
parent195de65a84864cf5931325eeb2356f7d98155055 (diff)
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}
Diffstat (limited to 'libbuild2/bin/init.cxx')
-rw-r--r--libbuild2/bin/init.cxx50
1 files changed, 34 insertions, 16 deletions
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<def> (perform_update_id, "bin.def", def_);
- bs.insert_rule<def> (perform_clean_id, "bin.def", def_);
- bs.insert_rule<def> (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<string> (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<def> (perform_update_id, "bin.def", def_);
+ bs.insert_rule<def> (perform_clean_id, "bin.def", def_);
+ bs.insert_rule<def> (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}
};