changeset 847:85d69fa69faa

add: util to build projects more streamlined
author Sam <sam@basx.dev>
date Sun, 03 Dec 2023 01:02:42 +0700
parents d4f4cc238379
children 42c680897aab
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