changeset 386:31f8ecc6644c

add: util to build projects more streamlined
author Sam <sam@basx.dev>
date Sun, 03 Dec 2023 01:02:42 +0700
parents c27281f8e0ce
children cbd59b758ef6
files semicongine/build.nim
diffstat 1 files changed, 40 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/semicongine/build.nim	Sun Dec 03 01:02:42 2023 +0700
@@ -0,0 +1,40 @@
+import std/strformat
+import std/os
+
+proc semicongine_build*(buildType: string, bundleType: string, resourceRoot="resources", builddir="./build"): string =
+  switch("experimental", "strictEffects")
+  switch("experimental", "strictFuncs")
+  switch("define", "nimPreviewHashRef")
+
+
+  var platformDir = "unkown"
+  if defined(linux):
+    switch("define", "VK_USE_PLATFORM_XLIB_KHR")
+    platformDir = "linux"
+  if defined(windows):
+    switch("define", "VK_USE_PLATFORM_WIN32_KHR")
+    platformDir = "windows"
+
+  var outdir = builddir / buildType / platformDir / projectName()
+  switch("outdir", outdir)
+  setCommand "c"
+  rmDir(outdir)
+  mkDir(outdir)
+  let resourcedir = joinPath(projectDir(), resourceRoot)
+  if os.dirExists(resourcedir):
+    let outdir_resources = joinPath(outdir, resourceRoot)
+    if bundleType == "dir":
+      cpDir(resourcedir, outdir_resources)
+    elif bundleType == "zip":
+      mkDir(outdir_resources)
+      for resource in listDirs(resourcedir):
+        let
+          oldcwd = getCurrentDir()
+          outputfile = joinPath(outdir_resources, resource.splitPath().tail & ".zip")
+        cd(resource)
+        if defined(linux):
+          exec &"zip -r {outputfile} ."
+        elif defined(windows):
+          exec &"powershell Compress-Archive * {outputfile}"
+        cd(oldcwd)
+  return outdir