summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-04-02 23:11:14 +0800
committerruki <[email protected]>2024-04-02 23:11:14 +0800
commitdf720af04206d1ea5d481542575c9d10c42753ec (patch)
treeb6057e803eb4832a898cb0288d798dfe71f90c17
parent693842d3e756953da273db9037264362a33b4812 (diff)
add autogen with native module
-rw-r--r--tests/projects/other/autogen_module/.gitignore8
-rw-r--r--tests/projects/other/autogen_module/modules/autogen/.gitignore8
-rw-r--r--tests/projects/other/autogen_module/modules/autogen/src/main.cpp29
-rw-r--r--tests/projects/other/autogen_module/modules/autogen/xmake.lua6
-rw-r--r--tests/projects/other/autogen_module/src/data.in1
-rw-r--r--tests/projects/other/autogen_module/src/main.cpp10
-rw-r--r--tests/projects/other/autogen_module/test.lua3
-rw-r--r--tests/projects/other/autogen_module/xmake.lua32
8 files changed, 97 insertions, 0 deletions
diff --git a/tests/projects/other/autogen_module/.gitignore b/tests/projects/other/autogen_module/.gitignore
new file mode 100644
index 000000000..152105761
--- /dev/null
+++ b/tests/projects/other/autogen_module/.gitignore
@@ -0,0 +1,8 @@
+# Xmake cache
+.xmake/
+build/
+
+# MacOS Cache
+.DS_Store
+
+
diff --git a/tests/projects/other/autogen_module/modules/autogen/.gitignore b/tests/projects/other/autogen_module/modules/autogen/.gitignore
new file mode 100644
index 000000000..152105761
--- /dev/null
+++ b/tests/projects/other/autogen_module/modules/autogen/.gitignore
@@ -0,0 +1,8 @@
+# Xmake cache
+.xmake/
+build/
+
+# MacOS Cache
+.DS_Store
+
+
diff --git a/tests/projects/other/autogen_module/modules/autogen/src/main.cpp b/tests/projects/other/autogen_module/modules/autogen/src/main.cpp
new file mode 100644
index 000000000..c5150cdbd
--- /dev/null
+++ b/tests/projects/other/autogen_module/modules/autogen/src/main.cpp
@@ -0,0 +1,29 @@
+#include <iostream>
+#include <fstream>
+#include <vector>
+
+using namespace std;
+
+int main(int argc, char** argv) {
+ ifstream src_file(argv[1], ios::in | ios::binary);
+ if (!src_file) {
+ return 1;
+ }
+ vector<char> buffer(istreambuf_iterator<char>(src_file), {});
+ src_file.close();
+
+ ofstream dst_file(argv[2], ios::out);
+ if (!dst_file) {
+ return 1;
+ }
+
+ dst_file << "unsigned char g_codegen_data[] = {";
+ for (auto byte : buffer) {
+ dst_file << "0x" << hex << (int)(unsigned char)byte << ",";
+ }
+ dst_file << "0};" << endl;
+ dst_file.close();
+ return 0;
+}
+
+
diff --git a/tests/projects/other/autogen_module/modules/autogen/xmake.lua b/tests/projects/other/autogen_module/modules/autogen/xmake.lua
new file mode 100644
index 000000000..677da3e2d
--- /dev/null
+++ b/tests/projects/other/autogen_module/modules/autogen/xmake.lua
@@ -0,0 +1,6 @@
+add_rules("mode.debug", "mode.release")
+
+target("generate")
+ add_rules("module.binary")
+ add_files("src/*.cpp")
+ set_languages("c++11")
diff --git a/tests/projects/other/autogen_module/src/data.in b/tests/projects/other/autogen_module/src/data.in
new file mode 100644
index 000000000..a04238969
--- /dev/null
+++ b/tests/projects/other/autogen_module/src/data.in
@@ -0,0 +1 @@
+hello world!
diff --git a/tests/projects/other/autogen_module/src/main.cpp b/tests/projects/other/autogen_module/src/main.cpp
new file mode 100644
index 000000000..3241308f7
--- /dev/null
+++ b/tests/projects/other/autogen_module/src/main.cpp
@@ -0,0 +1,10 @@
+#include <iostream>
+
+using namespace std;
+
+extern unsigned char g_codegen_data[];
+
+int main(int argc, char** argv) {
+ cout << (const char*)g_codegen_data << endl;
+ return 0;
+}
diff --git a/tests/projects/other/autogen_module/test.lua b/tests/projects/other/autogen_module/test.lua
new file mode 100644
index 000000000..b57362078
--- /dev/null
+++ b/tests/projects/other/autogen_module/test.lua
@@ -0,0 +1,3 @@
+function main(t)
+ t:build()
+end
diff --git a/tests/projects/other/autogen_module/xmake.lua b/tests/projects/other/autogen_module/xmake.lua
new file mode 100644
index 000000000..c5b194d2e
--- /dev/null
+++ b/tests/projects/other/autogen_module/xmake.lua
@@ -0,0 +1,32 @@
+add_rules("mode.debug", "mode.release")
+
+add_moduledirs("modules")
+
+rule("autogen")
+ set_extensions(".in")
+ before_build_file(function (target, sourcefile, opt)
+ import("utils.progress")
+ import("core.project.depend")
+ import("core.tool.compiler")
+ import("autogen")
+
+ local sourcefile_cx = path.join(target:autogendir(), "rules", "autogen", path.basename(sourcefile) .. ".cpp")
+ local objectfile = target:objectfile(sourcefile_cx)
+ table.insert(target:objectfiles(), objectfile)
+
+ depend.on_changed(function ()
+ progress.show(opt.progress, "${color.build.object}compiling.autogen %s", sourcefile)
+ os.mkdir(path.directory(sourcefile_cx))
+ autogen.generate(sourcefile, sourcefile_cx)
+ compiler.compile(sourcefile_cx, objectfile, {target = target})
+ end, {dependfile = target:dependfile(objectfile),
+ files = sourcefile,
+ changed = target:is_rebuilt()})
+ end)
+
+target("test")
+ set_kind("binary")
+ add_rules("autogen")
+ add_files("src/main.cpp")
+ add_files("src/*.in")
+