From b4036cd8ddae7d3c2d9177fc58415d3f8c57ee80 Mon Sep 17 00:00:00 2001 From: ChestnutYueyue <952134128@qq.com> Date: Tue, 10 Feb 2026 20:46:53 +0800 Subject: [PATCH] =?UTF-8?q?feat(build):=20=E4=B8=BA=E7=A4=BA=E4=BE=8B?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=B7=BB=E5=8A=A0=E6=89=93=E5=8C=85=E6=97=B6?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=A4=8D=E5=88=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为 push_box、hello_world、collision_demo 和 spatial_index_demo 示例项目添加以下功能: 1. 构建后生成 NRO 文件并打印日志 2. 打包时将 NRO 文件复制到 package 目录 3. 改进资源复制逻辑,支持子目录递归复制 4. 打包时将资源文件复制到 package 目录 --- examples/collision_demo/xmake.lua | 35 ++++++++++++++++++++++++-- examples/hello_world/xmake.lua | 36 ++++++++++++++++++++++++--- examples/push_box/xmake.lua | 35 ++++++++++++++++++++++++-- examples/spatial_index_demo/xmake.lua | 35 ++++++++++++++++++++++++-- 4 files changed, 132 insertions(+), 9 deletions(-) diff --git a/examples/collision_demo/xmake.lua b/examples/collision_demo/xmake.lua index b8c0665..f67e244 100644 --- a/examples/collision_demo/xmake.lua +++ b/examples/collision_demo/xmake.lua @@ -20,6 +20,7 @@ target("collision_demo") set_toolchains("switch") set_targetdir("../../build/examples/collision_demo") + -- 构建后生成 NRO 文件 after_build(function (target) local devkitPro = os.getenv("DEVKITPRO") or "C:/devkitPro" local elf_file = target:targetfile() @@ -37,6 +38,17 @@ target("collision_demo") else os.vrunv(elf2nro, {elf_file, nro_file, "--nacp=" .. nacp_file}) end + print("Generated NRO: " .. nro_file) + end + end) + + -- 打包时将 NRO 文件复制到 package 目录 + after_package(function (target) + local nro_file = path.join(target:targetdir(), "collision_demo.nro") + local package_dir = target:packagedir() + if os.isfile(nro_file) and package_dir then + os.cp(nro_file, package_dir) + print("Copied NRO to package: " .. package_dir) end end) @@ -46,20 +58,39 @@ target("collision_demo") set_targetdir("../../build/examples/collision_demo") add_ldflags("-mwindows", {force = true}) - -- 复制资源 + -- 复制资源到输出目录 after_build(function (target) local romfs = path.join(example_dir, "romfs") if os.isdir(romfs) then local target_dir = path.directory(target:targetfile()) local assets_dir = path.join(target_dir, "assets") + + -- 创建 assets 目录 if not os.isdir(assets_dir) then os.mkdir(assets_dir) end - os.cp(path.join(romfs, "assets/*"), assets_dir) + + -- 复制所有资源文件(包括子目录) + os.cp(path.join(romfs, "assets/**"), assets_dir) print("Copied assets from " .. romfs .. " to " .. assets_dir) else print("Warning: romfs directory not found at " .. romfs) end end) + + -- 打包时将资源复制到 package 目录 + after_package(function (target) + local target_dir = path.directory(target:targetfile()) + local assets_dir = path.join(target_dir, "assets") + local package_dir = target:packagedir() + if os.isdir(assets_dir) and package_dir then + local package_assets = path.join(package_dir, "assets") + if not os.isdir(package_assets) then + os.mkdir(package_assets) + end + os.cp(path.join(assets_dir, "**"), package_assets) + print("Copied assets to package: " .. package_assets) + end + end) end target_end() diff --git a/examples/hello_world/xmake.lua b/examples/hello_world/xmake.lua index 2d7991c..bde16e8 100644 --- a/examples/hello_world/xmake.lua +++ b/examples/hello_world/xmake.lua @@ -20,7 +20,7 @@ target("hello_world") set_toolchains("switch") set_targetdir("../../build/examples/hello_world") - -- 生成 NRO + -- 构建后生成 NRO 文件 after_build(function (target) local devkitPro = os.getenv("DEVKITPRO") or "C:/devkitPro" local elf_file = target:targetfile() @@ -38,6 +38,17 @@ target("hello_world") else os.vrunv(elf2nro, {elf_file, nro_file, "--nacp=" .. nacp_file}) end + print("Generated NRO: " .. nro_file) + end + end) + + -- 打包时将 NRO 文件复制到 package 目录 + after_package(function (target) + local nro_file = path.join(target:targetdir(), "hello_world.nro") + local package_dir = target:packagedir() + if os.isfile(nro_file) and package_dir then + os.cp(nro_file, package_dir) + print("Copied NRO to package: " .. package_dir) end end) @@ -47,20 +58,39 @@ target("hello_world") set_targetdir("../../build/examples/hello_world") add_ldflags("-mwindows", {force = true}) - -- 复制资源 + -- 复制资源到输出目录 after_build(function (target) local romfs = path.join(example_dir, "romfs") if os.isdir(romfs) then local target_dir = path.directory(target:targetfile()) local assets_dir = path.join(target_dir, "assets") + + -- 创建 assets 目录 if not os.isdir(assets_dir) then os.mkdir(assets_dir) end - os.cp(path.join(romfs, "assets/*"), assets_dir) + + -- 复制所有资源文件(包括子目录) + os.cp(path.join(romfs, "assets/**"), assets_dir) print("Copied assets from " .. romfs .. " to " .. assets_dir) else print("Warning: romfs directory not found at " .. romfs) end end) + + -- 打包时将资源复制到 package 目录 + after_package(function (target) + local target_dir = path.directory(target:targetfile()) + local assets_dir = path.join(target_dir, "assets") + local package_dir = target:packagedir() + if os.isdir(assets_dir) and package_dir then + local package_assets = path.join(package_dir, "assets") + if not os.isdir(package_assets) then + os.mkdir(package_assets) + end + os.cp(path.join(assets_dir, "**"), package_assets) + print("Copied assets to package: " .. package_assets) + end + end) end target_end() diff --git a/examples/push_box/xmake.lua b/examples/push_box/xmake.lua index 4e22790..b56576d 100644 --- a/examples/push_box/xmake.lua +++ b/examples/push_box/xmake.lua @@ -20,6 +20,7 @@ target("push_box") set_toolchains("switch") set_targetdir("../../build/examples/push_box") + -- 构建后生成 NRO 文件 after_build(function (target) local devkitPro = os.getenv("DEVKITPRO") or "C:/devkitPro" local elf_file = target:targetfile() @@ -37,6 +38,17 @@ target("push_box") else os.vrunv(elf2nro, {elf_file, nro_file, "--nacp=" .. nacp_file}) end + print("Generated NRO: " .. nro_file) + end + end) + + -- 打包时将 NRO 文件复制到 package 目录 + after_package(function (target) + local nro_file = path.join(target:targetdir(), "push_box.nro") + local package_dir = target:packagedir() + if os.isfile(nro_file) and package_dir then + os.cp(nro_file, package_dir) + print("Copied NRO to package: " .. package_dir) end end) @@ -46,20 +58,39 @@ target("push_box") set_targetdir("../../build/examples/push_box") add_ldflags("-mwindows", {force = true}) - -- 复制资源 + -- 复制资源到输出目录 after_build(function (target) local romfs = path.join(example_dir, "romfs") if os.isdir(romfs) then local target_dir = path.directory(target:targetfile()) local assets_dir = path.join(target_dir, "assets") + + -- 创建 assets 目录 if not os.isdir(assets_dir) then os.mkdir(assets_dir) end - os.cp(path.join(romfs, "assets/*"), assets_dir) + + -- 复制所有资源文件(包括子目录) + os.cp(path.join(romfs, "assets/**"), assets_dir) print("Copied assets from " .. romfs .. " to " .. assets_dir) else print("Warning: romfs directory not found at " .. romfs) end end) + + -- 打包时将资源复制到 package 目录 + after_package(function (target) + local target_dir = path.directory(target:targetfile()) + local assets_dir = path.join(target_dir, "assets") + local package_dir = target:packagedir() + if os.isdir(assets_dir) and package_dir then + local package_assets = path.join(package_dir, "assets") + if not os.isdir(package_assets) then + os.mkdir(package_assets) + end + os.cp(path.join(assets_dir, "**"), package_assets) + print("Copied assets to package: " .. package_assets) + end + end) end target_end() diff --git a/examples/spatial_index_demo/xmake.lua b/examples/spatial_index_demo/xmake.lua index 6916886..f16751f 100644 --- a/examples/spatial_index_demo/xmake.lua +++ b/examples/spatial_index_demo/xmake.lua @@ -20,6 +20,7 @@ target("spatial_index_demo") set_toolchains("switch") set_targetdir("../../build/examples/spatial_index_demo") + -- 构建后生成 NRO 文件 after_build(function (target) local devkitPro = os.getenv("DEVKITPRO") or "C:/devkitPro" local elf_file = target:targetfile() @@ -37,6 +38,17 @@ target("spatial_index_demo") else os.vrunv(elf2nro, {elf_file, nro_file, "--nacp=" .. nacp_file}) end + print("Generated NRO: " .. nro_file) + end + end) + + -- 打包时将 NRO 文件复制到 package 目录 + after_package(function (target) + local nro_file = path.join(target:targetdir(), "spatial_index_demo.nro") + local package_dir = target:packagedir() + if os.isfile(nro_file) and package_dir then + os.cp(nro_file, package_dir) + print("Copied NRO to package: " .. package_dir) end end) @@ -46,20 +58,39 @@ target("spatial_index_demo") set_targetdir("../../build/examples/spatial_index_demo") add_ldflags("-mwindows", {force = true}) - -- 复制资源 + -- 复制资源到输出目录 after_build(function (target) local romfs = path.join(example_dir, "romfs") if os.isdir(romfs) then local target_dir = path.directory(target:targetfile()) local assets_dir = path.join(target_dir, "assets") + + -- 创建 assets 目录 if not os.isdir(assets_dir) then os.mkdir(assets_dir) end - os.cp(path.join(romfs, "assets/*"), assets_dir) + + -- 复制所有资源文件(包括子目录) + os.cp(path.join(romfs, "assets/**"), assets_dir) print("Copied assets from " .. romfs .. " to " .. assets_dir) else print("Warning: romfs directory not found at " .. romfs) end end) + + -- 打包时将资源复制到 package 目录 + after_package(function (target) + local target_dir = path.directory(target:targetfile()) + local assets_dir = path.join(target_dir, "assets") + local package_dir = target:packagedir() + if os.isdir(assets_dir) and package_dir then + local package_assets = path.join(package_dir, "assets") + if not os.isdir(package_assets) then + os.mkdir(package_assets) + end + os.cp(path.join(assets_dir, "**"), package_assets) + print("Copied assets to package: " .. package_assets) + end + end) end target_end()