summaryrefslogtreecommitdiff
path: root/tests/projects
diff options
context:
space:
mode:
authorririyeye <[email protected]>2026-04-23 10:39:33 +0800
committerririyeye <[email protected]>2026-04-23 10:39:33 +0800
commit7b2c43757d8d51997087f14d24716e384db21b1d (patch)
tree548f05262f7d51974fd7cd1090dac728d9a3962f /tests/projects
parentc110d46d8cbb7ce929a98c58fc43668431f9fbe8 (diff)
test add linux driver cross compile example
Add a minimal platform.linux.module sample that documents custom linux headers/builddir usage for cross toolchains and verifies the new cross-build workflow. Made-with: Cursor
Diffstat (limited to 'tests/projects')
-rw-r--r--tests/projects/linux/driver/hello_cross/src/add.c4
-rw-r--r--tests/projects/linux/driver/hello_cross/src/add.h2
-rw-r--r--tests/projects/linux/driver/hello_cross/src/hello.c22
-rw-r--r--tests/projects/linux/driver/hello_cross/xmake.lua21
4 files changed, 49 insertions, 0 deletions
diff --git a/tests/projects/linux/driver/hello_cross/src/add.c b/tests/projects/linux/driver/hello_cross/src/add.c
new file mode 100644
index 000000000..72c39a6e4
--- /dev/null
+++ b/tests/projects/linux/driver/hello_cross/src/add.c
@@ -0,0 +1,4 @@
+#include "add.h"
+int add(int a, int b) {
+ return a + b;
+}
diff --git a/tests/projects/linux/driver/hello_cross/src/add.h b/tests/projects/linux/driver/hello_cross/src/add.h
new file mode 100644
index 000000000..ba2df6926
--- /dev/null
+++ b/tests/projects/linux/driver/hello_cross/src/add.h
@@ -0,0 +1,2 @@
+#pragma once
+int add(int a, int b);
diff --git a/tests/projects/linux/driver/hello_cross/src/hello.c b/tests/projects/linux/driver/hello_cross/src/hello.c
new file mode 100644
index 000000000..c32e48f61
--- /dev/null
+++ b/tests/projects/linux/driver/hello_cross/src/hello.c
@@ -0,0 +1,22 @@
+#include <linux/init.h>
+#include <linux/module.h>
+#include "add.h"
+
+MODULE_LICENSE("Dual BSD/GPL");
+MODULE_AUTHOR("Ruki");
+MODULE_DESCRIPTION("A simple Hello World Module");
+MODULE_ALIAS("a simplest module");
+
+static int hello_init(void)
+{
+ printk(KERN_INFO "Hello World: %d\n", add(1, 2));
+ return 0;
+}
+
+static void hello_exit(void)
+{
+ printk(KERN_INFO "Goodbye World\n");
+}
+
+module_init(hello_init);
+module_exit(hello_exit);
diff --git a/tests/projects/linux/driver/hello_cross/xmake.lua b/tests/projects/linux/driver/hello_cross/xmake.lua
new file mode 100644
index 000000000..c5372de0b
--- /dev/null
+++ b/tests/projects/linux/driver/hello_cross/xmake.lua
@@ -0,0 +1,21 @@
+set_plat("linux")
+
+option("linux-headers", {showmenu = true, description = "Set kernel headers/source tree path."})
+option("linux-builddir", {showmenu = true, description = "Set kernel build/output tree path."})
+
+-- Example:
+-- xmake f -p linux -a arm64 --cc=/path/to/aarch64-linux-gnu-gcc \
+-- --ld=/path/to/aarch64-linux-gnu-ld \
+-- --linux-headers=/path/to/linux \
+-- --linux-builddir=/path/to/linux-out
+
+target("hello")
+ add_rules("platform.linux.module")
+ add_files("src/*.c")
+ set_license("GPL-2.0")
+ if has_config("linux-headers") then
+ set_values("linux.driver.linux-headers", get_config("linux-headers"))
+ end
+ if has_config("linux-builddir") then
+ set_values("linux.driver.linux-builddir", get_config("linux-builddir"))
+ end