mirror of
https://gitcode.com/JianFeeeee/LuaCangjia_api.git
synced 2026-09-21 01:18:10 +00:00
优化编译脚本,保证bundle顺利通过
This commit is contained in:
22
build.cj
22
build.cj
@ -4,19 +4,16 @@ import std.process.*
|
|||||||
import std.fs.*
|
import std.fs.*
|
||||||
import std.core.*
|
import std.core.*
|
||||||
|
|
||||||
// 构建前钩子:编译 C 库
|
func buildCLib(): Int64 {
|
||||||
func stagePreBuild(): Int64 {
|
|
||||||
let root_dir = Path(".")
|
let root_dir = Path(".")
|
||||||
let lib_dir = root_dir.join("lib")
|
let lib_dir = root_dir.join("lib")
|
||||||
let build_dir = lib_dir.join("build")
|
let build_dir = lib_dir.join("build")
|
||||||
|
|
||||||
// 1. 确保 lib 目录存在
|
|
||||||
if (!exists(lib_dir)) {
|
if (!exists(lib_dir)) {
|
||||||
println("Error: lib directory not found at ${lib_dir}")
|
println("Error: lib directory not found at ${lib_dir}")
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 创建构建目录 - 使用 try 表达式
|
|
||||||
if (!exists(build_dir)) {
|
if (!exists(build_dir)) {
|
||||||
try {
|
try {
|
||||||
Directory.create(build_dir, recursive: true)
|
Directory.create(build_dir, recursive: true)
|
||||||
@ -26,7 +23,6 @@ func stagePreBuild(): Int64 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 执行 cmake 配置
|
|
||||||
println("Configuring C library with CMake...")
|
println("Configuring C library with CMake...")
|
||||||
let cmake_exit = execute(
|
let cmake_exit = execute(
|
||||||
"cmake",
|
"cmake",
|
||||||
@ -44,7 +40,6 @@ func stagePreBuild(): Int64 {
|
|||||||
return cmake_exit
|
return cmake_exit
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. 执行构建
|
|
||||||
println("Building C library...")
|
println("Building C library...")
|
||||||
let build_exit = execute(
|
let build_exit = execute(
|
||||||
"cmake",
|
"cmake",
|
||||||
@ -64,26 +59,32 @@ func stagePreBuild(): Int64 {
|
|||||||
|
|
||||||
println("C library compiled successfully at: ${build_dir}")
|
println("C library compiled successfully at: ${build_dir}")
|
||||||
|
|
||||||
// 5. 可选:安装到输出目录
|
|
||||||
let output_dir = root_dir.join("liboutput")
|
let output_dir = root_dir.join("liboutput")
|
||||||
if (!exists(output_dir)) {
|
if (!exists(output_dir)) {
|
||||||
try {
|
try {
|
||||||
Directory.create(output_dir, recursive: true)
|
Directory.create(output_dir, recursive: true)
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
// 忽略创建错误
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构建后钩子
|
func stagePreBuild(): Int64 {
|
||||||
|
println("Pre-build: compiling C library...")
|
||||||
|
buildCLib()
|
||||||
|
}
|
||||||
|
|
||||||
|
func stagePreTest(): Int64 {
|
||||||
|
println("Pre-test: compiling C library...")
|
||||||
|
buildCLib()
|
||||||
|
}
|
||||||
|
|
||||||
func stagePostBuild(): Int64 {
|
func stagePostBuild(): Int64 {
|
||||||
println("Post-build: C library integration complete")
|
println("Post-build: C library integration complete")
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清理前钩子
|
|
||||||
func stagePreClean(): Int64 {
|
func stagePreClean(): Int64 {
|
||||||
let build_dir = Path(".").join("lib").join("build")
|
let build_dir = Path(".").join("lib").join("build")
|
||||||
if (exists(build_dir)) {
|
if (exists(build_dir)) {
|
||||||
@ -104,6 +105,7 @@ main(args: Array<String>): Int64 {
|
|||||||
|
|
||||||
match (args[0]) {
|
match (args[0]) {
|
||||||
case "pre-build" => stagePreBuild()
|
case "pre-build" => stagePreBuild()
|
||||||
|
case "pre-test" => stagePreTest()
|
||||||
case "post-build" => stagePostBuild()
|
case "post-build" => stagePostBuild()
|
||||||
case "pre-clean" => stagePreClean()
|
case "pre-clean" => stagePreClean()
|
||||||
case _ => 0
|
case _ => 0
|
||||||
|
|||||||
@ -1,10 +1,13 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "luarunner"
|
name = "luarunner"
|
||||||
version = "0.0.1"
|
version = "0.1.1"
|
||||||
description = "Lite and High performance LuaRunner"
|
description = "Lite and High performance LuaRunner"
|
||||||
cjc-version = "1.1.0"
|
cjc-version = "1.1.0"
|
||||||
license = "LGPL-3.0-or-later"
|
license = "LGPL-3.0-or-later"
|
||||||
output-type ="dynamic"
|
output-type ="dynamic"
|
||||||
|
repository = "https://gitcode.com/JianFeeeee/LuaCangjia_api.git"
|
||||||
|
homepage = "https://atomgit.com/JianFeeeee/LuaCangjia_api"
|
||||||
|
include = ["src","lib","build.cj"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user