diff options
| author | ruki <[email protected]> | 2021-02-18 00:55:41 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-02-18 00:55:41 +0800 |
| commit | 7398de24ff14782768cbd72882aa18ebd36717ea (patch) | |
| tree | c7b5c1126c8d1e8927fef68155c3ddf524e7eb12 | |
| parent | 46e0f6a1adda408052ba5b87c244cedaae5f1d00 (diff) | |
add export_all rule
| -rw-r--r-- | tests/projects/c/shared_library/src/foo.c (renamed from tests/projects/c/shared_library/src/interface.c) | 2 | ||||
| -rw-r--r-- | tests/projects/c/shared_library/src/foo.h (renamed from tests/projects/c/shared_library/src/interface.h) | 7 | ||||
| -rw-r--r-- | tests/projects/c/shared_library/src/test.c | 2 | ||||
| -rw-r--r-- | tests/projects/c/shared_library/test.lua | 3 | ||||
| -rw-r--r-- | tests/projects/c/shared_library/xmake.lua | 8 | ||||
| -rw-r--r-- | tests/projects/c/shared_library_export_all/src/foo.c | 6 | ||||
| -rw-r--r-- | tests/projects/c/shared_library_export_all/src/foo.h | 9 | ||||
| -rw-r--r-- | tests/projects/c/shared_library_export_all/src/main.c | 8 | ||||
| -rw-r--r-- | tests/projects/c/shared_library_export_all/test.lua | 3 | ||||
| -rw-r--r-- | tests/projects/c/shared_library_export_all/xmake.lua | 13 | ||||
| -rw-r--r-- | xmake/rules/utils/symbols/export_all/export_all.lua | 30 |
11 files changed, 74 insertions, 17 deletions
diff --git a/tests/projects/c/shared_library/src/interface.c b/tests/projects/c/shared_library/src/foo.c index 598d07560..08054d059 100644 --- a/tests/projects/c/shared_library/src/interface.c +++ b/tests/projects/c/shared_library/src/foo.c @@ -1,4 +1,4 @@ -#include "interface.h" +#include "foo.h" int add(int a, int b) { diff --git a/tests/projects/c/shared_library/src/interface.h b/tests/projects/c/shared_library/src/foo.h index ef24ba3ce..073fb68d7 100644 --- a/tests/projects/c/shared_library/src/interface.h +++ b/tests/projects/c/shared_library/src/foo.h @@ -10,13 +10,6 @@ extern "C" { # define __export #endif -/*! calculate add(a, b) - * - * @param a the first argument - * @param b the second argument - * - * @return the result - */ __export int add(int a, int b); #ifdef __cplusplus diff --git a/tests/projects/c/shared_library/src/test.c b/tests/projects/c/shared_library/src/test.c index 9505a2f75..1e52e7a81 100644 --- a/tests/projects/c/shared_library/src/test.c +++ b/tests/projects/c/shared_library/src/test.c @@ -1,4 +1,4 @@ -#include "interface.h" +#include "foo.h" #include <stdio.h> int main(int argc, char** argv) diff --git a/tests/projects/c/shared_library/test.lua b/tests/projects/c/shared_library/test.lua index b76241be2..b57362078 100644 --- a/tests/projects/c/shared_library/test.lua +++ b/tests/projects/c/shared_library/test.lua @@ -1,6 +1,3 @@ --- main entry function main(t) - - -- build project t:build() end diff --git a/tests/projects/c/shared_library/xmake.lua b/tests/projects/c/shared_library/xmake.lua index 6507658c6..664e2d4eb 100644 --- a/tests/projects/c/shared_library/xmake.lua +++ b/tests/projects/c/shared_library/xmake.lua @@ -1,12 +1,12 @@ add_rules("mode.release", "mode.debug") -target("shared_library_c") +target("foo") set_kind("shared") - add_files("src/interface.c") + add_files("src/foo.c") target("test") set_kind("binary") - add_deps("shared_library_c") - add_files("src/test.c") + add_deps("foo") + add_files("src/main.c") diff --git a/tests/projects/c/shared_library_export_all/src/foo.c b/tests/projects/c/shared_library_export_all/src/foo.c new file mode 100644 index 000000000..08054d059 --- /dev/null +++ b/tests/projects/c/shared_library_export_all/src/foo.c @@ -0,0 +1,6 @@ +#include "foo.h" + +int add(int a, int b) +{ + return a + b; +} diff --git a/tests/projects/c/shared_library_export_all/src/foo.h b/tests/projects/c/shared_library_export_all/src/foo.h new file mode 100644 index 000000000..d2506bca9 --- /dev/null +++ b/tests/projects/c/shared_library_export_all/src/foo.h @@ -0,0 +1,9 @@ +#ifdef __cplusplus +extern "C" { +#endif + +int add(int a, int b); + +#ifdef __cplusplus +} +#endif diff --git a/tests/projects/c/shared_library_export_all/src/main.c b/tests/projects/c/shared_library_export_all/src/main.c new file mode 100644 index 000000000..1e52e7a81 --- /dev/null +++ b/tests/projects/c/shared_library_export_all/src/main.c @@ -0,0 +1,8 @@ +#include "foo.h" +#include <stdio.h> + +int main(int argc, char** argv) +{ + printf("add(1, 2) = %d\n", add(1, 2)); + return 0; +} diff --git a/tests/projects/c/shared_library_export_all/test.lua b/tests/projects/c/shared_library_export_all/test.lua new file mode 100644 index 000000000..b57362078 --- /dev/null +++ b/tests/projects/c/shared_library_export_all/test.lua @@ -0,0 +1,3 @@ +function main(t) + t:build() +end diff --git a/tests/projects/c/shared_library_export_all/xmake.lua b/tests/projects/c/shared_library_export_all/xmake.lua new file mode 100644 index 000000000..f618fe2c9 --- /dev/null +++ b/tests/projects/c/shared_library_export_all/xmake.lua @@ -0,0 +1,13 @@ +add_rules("mode.release", "mode.debug") + +target("foo") + set_kind("shared") + add_files("src/foo.c") + add_rules("utils.symbols.export_all") + +target("test") + set_kind("binary") + add_deps("foo") + add_files("src/main.c") + + diff --git a/xmake/rules/utils/symbols/export_all/export_all.lua b/xmake/rules/utils/symbols/export_all/export_all.lua index 9d815090c..15566fa04 100644 --- a/xmake/rules/utils/symbols/export_all/export_all.lua +++ b/xmake/rules/utils/symbols/export_all/export_all.lua @@ -25,6 +25,34 @@ import("core.tool.toolchain") -- export all symbols for dynamic library function main (target) -- @note it only supports windows/dll now - assert(target:is_plat("windows") and target:kind() == "shared", 'rule("utils.symbols.export_all"): only support windows/dll now') + assert(target:kind() == "shared", 'rule("utils.symbols.export_all"): only for shared target!') + if not target:is_plat("windows") then + return + end + -- get dumpbin + local msvc = toolchain.load("msvc", {plat = target:plat(), arch = target:arch()}) + local dumpbin = assert(find_tool("dumpbin", {envs = msvc:runenvs()}), "dumpbin not found!") + + -- export all symbols + local allsymbols_filepath = path.join(target:autogendir(), "rules", "symbols", "export_all.def") + local allsymbols_file = io.open(allsymbols_filepath, 'w') + allsymbols_file:print("EXPORTS") + for _, objectfile in ipairs(target:objectfiles()) do + local objectsymbols = os.iorunv(dumpbin.program, {"/symbols", "/nologo", objectfile}) + if objectsymbols then + for _, line in ipairs(objectsymbols:split('\n', {plain = true})) do + -- 008 00000000 SECT3 notype () External | add + if line:find("External") then + local symbol = line:match(".*External%s+| (.*)") + if symbol then + symbol = symbol:trim() + allsymbols_file:print("%s", symbol) + end + end + end + end + end + allsymbols_file:close() + target:add("shflags", "/def:" .. allsymbols_filepath, {force = true}) end |
