summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-12-23 22:37:46 +0800
committerruki <[email protected]>2021-12-23 22:37:46 +0800
commit95b63301dd11e16b5039aa9c10cda77e8ddc1036 (patch)
tree369d853039549d1548b577dcec1155bcdda1c69d
parent65e93fa30d57ad5823cbfbb7b70df621a5cce4fa (diff)
add soabi for swig.python
-rw-r--r--tests/projects/swig/python_c_with_soabi/src/example.c14
-rw-r--r--tests/projects/swig/python_c_with_soabi/src/example.i11
-rw-r--r--tests/projects/swig/python_c_with_soabi/xmake.lua8
-rw-r--r--xmake/rules/swig/xmake.lua17
4 files changed, 48 insertions, 2 deletions
diff --git a/tests/projects/swig/python_c_with_soabi/src/example.c b/tests/projects/swig/python_c_with_soabi/src/example.c
new file mode 100644
index 000000000..b0ddc9c26
--- /dev/null
+++ b/tests/projects/swig/python_c_with_soabi/src/example.c
@@ -0,0 +1,14 @@
+double My_variable = 3.0;
+
+/* Compute factorial of n */
+int fact(int n) {
+ if (n <= 1)
+ return 1;
+ else
+ return n*fact(n-1);
+}
+
+/* Compute n mod m */
+int my_mod(int n, int m) {
+ return(n % m);
+}
diff --git a/tests/projects/swig/python_c_with_soabi/src/example.i b/tests/projects/swig/python_c_with_soabi/src/example.i
new file mode 100644
index 000000000..34193edc7
--- /dev/null
+++ b/tests/projects/swig/python_c_with_soabi/src/example.i
@@ -0,0 +1,11 @@
+%module example
+%{
+/* Put headers and other declarations here */
+extern double My_variable;
+extern int fact(int);
+extern int my_mod(int n, int m);
+%}
+
+extern double My_variable;
+extern int fact(int);
+extern int my_mod(int n, int m);
diff --git a/tests/projects/swig/python_c_with_soabi/xmake.lua b/tests/projects/swig/python_c_with_soabi/xmake.lua
new file mode 100644
index 000000000..81dd49926
--- /dev/null
+++ b/tests/projects/swig/python_c_with_soabi/xmake.lua
@@ -0,0 +1,8 @@
+add_rules("mode.release", "mode.debug")
+add_requires("python 3.x")
+
+target("example")
+ add_rules("swig.c", {moduletype = "python", soabi = true})
+ add_files("src/example.i", {scriptdir = "share"})
+ add_files("src/example.c")
+ add_packages("python")
diff --git a/xmake/rules/swig/xmake.lua b/xmake/rules/swig/xmake.lua
index 29b2673a2..c0387a940 100644
--- a/xmake/rules/swig/xmake.lua
+++ b/xmake/rules/swig/xmake.lua
@@ -30,8 +30,21 @@ rule("swig.base")
local moduletype = target:extraconf("rules", "swig.c", "moduletype") or target:extraconf("rules", "swig.cpp", "moduletype")
if moduletype == "python" then
target:set("prefixname", "_")
- if target:is_plat("windows") then
- target:set("extension", ".pyd")
+ local soabi = target:extraconf("rules", "swig.c", "soabi") or target:extraconf("rules", "swig.cpp", "soabi")
+ if soabi then
+ import("lib.detect.find_tool")
+ local python = assert(find_tool("python3"), "python not found!")
+ local result = try { function() return os.iorunv(python.program, {"-c", "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))"}) end}
+ if result then
+ result = result:trim()
+ if result ~= "None" then
+ target:set("extension", result)
+ end
+ end
+ else
+ if target:is_plat("windows") then
+ target:set("extension", ".pyd")
+ end
end
elseif moduletype == "lua" then
target:set("prefixname", "")