summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-03-02 22:44:22 +0800
committerruki <[email protected]>2022-03-02 22:44:22 +0800
commitb68ec3a3564e6fa261a45e01c6d590d49219600f (patch)
tree993e4ab6a0a261d9437aa38b5d9d80a1ba30da1d
parenta76408793027b1aca6b8938a51e5d121bb42084b (diff)
export list
-rw-r--r--tests/projects/c/shared_library_export_all/xmake.lua2
-rw-r--r--tests/projects/c/shared_library_export_list/src/foo.c14
-rw-r--r--tests/projects/c/shared_library_export_list/src/foo.h9
-rw-r--r--tests/projects/c/shared_library_export_list/src/main.c8
-rw-r--r--tests/projects/c/shared_library_export_list/test.lua3
-rw-r--r--tests/projects/c/shared_library_export_list/xmake.lua15
-rw-r--r--xmake/rules/c++/modules/build_modules/msvc.lua2
-rw-r--r--xmake/rules/utils/symbols/export_list/xmake.lua72
8 files changed, 123 insertions, 2 deletions
diff --git a/tests/projects/c/shared_library_export_all/xmake.lua b/tests/projects/c/shared_library_export_all/xmake.lua
index 6466a16fc..2797d2024 100644
--- a/tests/projects/c/shared_library_export_all/xmake.lua
+++ b/tests/projects/c/shared_library_export_all/xmake.lua
@@ -3,7 +3,7 @@ add_rules("mode.release", "mode.debug")
target("foo")
set_kind("shared")
add_files("src/foo.c", "src/bar.cpp")
- add_rules("utils.symbols.export_all", {class = true})
+ add_rules("utils.symbols.export_all", {export_classes = true})
target("test")
set_kind("binary")
diff --git a/tests/projects/c/shared_library_export_list/src/foo.c b/tests/projects/c/shared_library_export_list/src/foo.c
new file mode 100644
index 000000000..e068c1983
--- /dev/null
+++ b/tests/projects/c/shared_library_export_list/src/foo.c
@@ -0,0 +1,14 @@
+#include "foo.h"
+#include <stdio.h>
+
+void stub() {
+ printf("stub\n");
+}
+
+int sub(int a, int b) {
+ return a - b;
+}
+
+int add(int a, int b) {
+ return a + b;
+}
diff --git a/tests/projects/c/shared_library_export_list/src/foo.h b/tests/projects/c/shared_library_export_list/src/foo.h
new file mode 100644
index 000000000..d2506bca9
--- /dev/null
+++ b/tests/projects/c/shared_library_export_list/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_list/src/main.c b/tests/projects/c/shared_library_export_list/src/main.c
new file mode 100644
index 000000000..1e52e7a81
--- /dev/null
+++ b/tests/projects/c/shared_library_export_list/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_list/test.lua b/tests/projects/c/shared_library_export_list/test.lua
new file mode 100644
index 000000000..b57362078
--- /dev/null
+++ b/tests/projects/c/shared_library_export_list/test.lua
@@ -0,0 +1,3 @@
+function main(t)
+ t:build()
+end
diff --git a/tests/projects/c/shared_library_export_list/xmake.lua b/tests/projects/c/shared_library_export_list/xmake.lua
new file mode 100644
index 000000000..7e856130f
--- /dev/null
+++ b/tests/projects/c/shared_library_export_list/xmake.lua
@@ -0,0 +1,15 @@
+add_rules("mode.release", "mode.debug")
+
+target("foo")
+ set_kind("shared")
+ add_files("src/foo.c")
+ add_rules("utils.symbols.export_list", {symbols = {
+ "add",
+ "sub"}})
+
+target("test")
+ set_kind("binary")
+ add_deps("foo")
+ add_files("src/main.c")
+
+
diff --git a/xmake/rules/c++/modules/build_modules/msvc.lua b/xmake/rules/c++/modules/build_modules/msvc.lua
index dfaf56b41..cb81effd7 100644
--- a/xmake/rules/c++/modules/build_modules/msvc.lua
+++ b/xmake/rules/c++/modules/build_modules/msvc.lua
@@ -43,7 +43,7 @@ function load_parent(target, opt)
local sourcebatches = dep:sourcebatches()
if sourcebatches and sourcebatches["c++.build.modules"] then
local cachedir = path.join(dep:autogendir(), "rules", "modules", "cache")
- target:add("cxxflags", {"/ifcSearchDir", cachedir}, {force = true, expand = true})
+ target:add("cxxflags", {"/ifcSearchDir", cachedir}, {force = true, expand = false})
end
end
end
diff --git a/xmake/rules/utils/symbols/export_list/xmake.lua b/xmake/rules/utils/symbols/export_list/xmake.lua
new file mode 100644
index 000000000..a8fe2133a
--- /dev/null
+++ b/xmake/rules/utils/symbols/export_list/xmake.lua
@@ -0,0 +1,72 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file xmake.lua
+--
+
+-- export the given symbols list
+rule("utils.symbols.export_list")
+ on_config(function (target)
+ assert(target:is_shared(), 'rule("utils.symbols.export_list"): only for shared target(%s)!', target:name())
+ local exportfile
+ local exportkind
+ local exportsymbols = target:extraconf("rules", "utils.symbols.export_list", "symbols")
+ assert(exportsymbols and #exportsymbols > 0, 'rule("utils.symbols.export_list"): no exported symbols!')
+ if target:has_tool("ld", "link") then
+ exportkind = "def"
+ exportfile = path.join(target:autogendir(), "rules", "symbols", "export_list.def")
+ target:add("shflags", "/def:" .. exportfile, {force = true})
+ elseif target:is_plat("macosx", "iphoneos", "watchos", "appletvos") then
+ exportkind = "apple"
+ exportfile = path.join(target:autogendir(), "rules", "symbols", "export_list.txt")
+ target:add("shflags", {"-Wl,-exported_symbols_list", exportfile}, {force = true, expand = false})
+ elseif target:has_tool("ld", "gcc", "gxx", "clang", "clangxx") or
+ target:has_tool("sh", "gcc", "gxx", "clang", "clangxx") then
+ exportkind = "ver"
+ exportfile = path.join(target:autogendir(), "rules", "symbols", "export_list.map")
+ target:add("shflags", "-Wl,--version-script=" .. exportfile, {force = true})
+ elseif target:has_tool("ld", "dmd") or target:has_tool("sh", "dmd") then
+ exportkind = "ver"
+ exportfile = path.join(target:autogendir(), "rules", "symbols", "export_list.map")
+ target:add("shflags", "-L--version-script=" .. exportfile, {force = true})
+ elseif target:has_tool("ld", "ld") or target:has_tool("sh", "ld") then
+ exportkind = "ver"
+ exportfile = path.join(target:autogendir(), "rules", "symbols", "export_list.map")
+ target:add("shflags", "--version-script=" .. exportfile, {force = true})
+ end
+ if exportfile and exportkind then
+ if exportkind == "ver" then
+ io.writefile(exportfile, ([[{
+ global:
+ %s
+
+ local:
+ *;
+};]]):format(table.concat(exportsymbols, ";\n ") .. ";"))
+ elseif exportkind == "apple" then
+ io.writefile(exportfile, table.concat(exportsymbols, "\n"))
+ elseif exportkind == "def" then
+ local file = io.open(exportfile, 'w')
+ file:print("EXPORTS")
+ for _, symbol in ipairs(exportsymbols) do
+ file:print("%s", symbol)
+ end
+ file:close()
+ end
+ end
+ end)
+