mirror of
https://gitcode.com/JianFeeeee/LuaCangjia_api.git
synced 2026-09-19 16:42:48 +00:00
113 lines
2.6 KiB
Plaintext
113 lines
2.6 KiB
Plaintext
package my_project
|
|
|
|
import std.process.*
|
|
import std.fs.*
|
|
import std.core.*
|
|
|
|
func buildCLib(): Int64 {
|
|
let root_dir = Path(".")
|
|
let lib_dir = root_dir.join("lib")
|
|
let build_dir = lib_dir.join("build")
|
|
|
|
if (!exists(lib_dir)) {
|
|
println("Error: lib directory not found at ${lib_dir}")
|
|
return 1
|
|
}
|
|
|
|
if (!exists(build_dir)) {
|
|
try {
|
|
Directory.create(build_dir, recursive: true)
|
|
} catch (e: Exception) {
|
|
println("Error: Cannot create build directory")
|
|
return 1
|
|
}
|
|
}
|
|
|
|
println("Configuring C library with CMake...")
|
|
let cmake_exit = execute(
|
|
"cmake",
|
|
["-S", lib_dir.toString(), "-B", build_dir.toString()],
|
|
workingDirectory: None,
|
|
environment: None,
|
|
stdIn: Inherit,
|
|
stdOut: Inherit,
|
|
stdErr: Inherit,
|
|
timeout: None
|
|
)
|
|
|
|
if (cmake_exit != 0) {
|
|
println("CMake configuration failed! Exit code: ${cmake_exit}")
|
|
return cmake_exit
|
|
}
|
|
|
|
println("Building C library...")
|
|
let build_exit = execute(
|
|
"cmake",
|
|
["--build", build_dir.toString(), "--parallel"],
|
|
workingDirectory: None,
|
|
environment: None,
|
|
stdIn: Inherit,
|
|
stdOut: Inherit,
|
|
stdErr: Inherit,
|
|
timeout: None
|
|
)
|
|
|
|
if (build_exit != 0) {
|
|
println("Build failed! Exit code: ${build_exit}")
|
|
return build_exit
|
|
}
|
|
|
|
println("C library compiled successfully at: ${build_dir}")
|
|
|
|
let output_dir = root_dir.join("liboutput")
|
|
if (!exists(output_dir)) {
|
|
try {
|
|
Directory.create(output_dir, recursive: true)
|
|
} catch (_: Exception) {
|
|
}
|
|
}
|
|
|
|
0
|
|
}
|
|
|
|
func stagePreBuild(): Int64 {
|
|
println("Pre-build: compiling C library...")
|
|
buildCLib()
|
|
}
|
|
|
|
func stagePreTest(): Int64 {
|
|
println("Pre-test: compiling C library...")
|
|
buildCLib()
|
|
}
|
|
|
|
func stagePostBuild(): Int64 {
|
|
println("Post-build: C library integration complete")
|
|
0
|
|
}
|
|
|
|
func stagePreClean(): Int64 {
|
|
let build_dir = Path(".").join("lib").join("build")
|
|
if (exists(build_dir)) {
|
|
try {
|
|
remove(build_dir, recursive: true)
|
|
println("Cleaned C library build directory")
|
|
} catch (_: Exception) {
|
|
println("Warning: Failed to clean build directory")
|
|
}
|
|
}
|
|
0
|
|
}
|
|
|
|
main(args: Array<String>): Int64 {
|
|
if (args.size == 0) {
|
|
return 0
|
|
}
|
|
|
|
match (args[0]) {
|
|
case "pre-build" => stagePreBuild()
|
|
case "pre-test" => stagePreTest()
|
|
case "post-build" => stagePostBuild()
|
|
case "pre-clean" => stagePreClean()
|
|
case _ => 0
|
|
}
|
|
} |