annotate semicongine/build.nim @ 391:68198310770b

add: function to zip directories, usefull when creating dists
author Sam <sam@basx.dev>
date Wed, 06 Dec 2023 00:37:34 +0700
parents 1727bec9ca2f
children ff751cbe66e3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
386
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
1 import std/strformat
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
2 import std/os
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
3
388
405bb1fb52b8 add: import-helpers for nimscripts
Sam <sam@basx.dev>
parents: 387
diff changeset
4 import ./core/audiotypes
405bb1fb52b8 add: import-helpers for nimscripts
Sam <sam@basx.dev>
parents: 387
diff changeset
5
391
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
6 proc semicongine_outdir*(buildname: string, builddir="./build"): string =
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
7 var platformDir = "unkown"
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
8 if defined(linux):
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
9 switch("define", "VK_USE_PLATFORM_XLIB_KHR")
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
10 platformDir = "linux"
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
11 if defined(windows):
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
12 switch("define", "VK_USE_PLATFORM_WIN32_KHR")
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
13 platformDir = "windows"
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
14
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
15 return builddir / buildname / platformDir / projectName()
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
16
387
cbd59b758ef6 fix: move switches into our engine-build-func
Sam <sam@basx.dev>
parents: 386
diff changeset
17 proc semicongine_build*(buildname: string, bundleType: string, resourceRoot: string, builddir="./build"): string =
386
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
18 switch("experimental", "strictEffects")
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
19 switch("experimental", "strictFuncs")
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
20 switch("define", "nimPreviewHashRef")
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
21
387
cbd59b758ef6 fix: move switches into our engine-build-func
Sam <sam@basx.dev>
parents: 386
diff changeset
22 switch("define", &"BUNDLETYPE={bundleType}")
cbd59b758ef6 fix: move switches into our engine-build-func
Sam <sam@basx.dev>
parents: 386
diff changeset
23 switch("define", &"RESOURCEROOT={resourceRoot}")
386
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
24
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
25 var platformDir = "unkown"
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
26 if defined(linux):
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
27 switch("define", "VK_USE_PLATFORM_XLIB_KHR")
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
28 platformDir = "linux"
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
29 if defined(windows):
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
30 switch("define", "VK_USE_PLATFORM_WIN32_KHR")
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
31 platformDir = "windows"
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
32
387
cbd59b758ef6 fix: move switches into our engine-build-func
Sam <sam@basx.dev>
parents: 386
diff changeset
33 var outdir = builddir / buildname / platformDir / projectName()
386
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
34 switch("outdir", outdir)
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
35 setCommand "c"
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
36 rmDir(outdir)
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
37 mkDir(outdir)
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
38 let resourcedir = joinPath(projectDir(), resourceRoot)
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
39 if os.dirExists(resourcedir):
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
40 let outdir_resources = joinPath(outdir, resourceRoot)
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
41 if bundleType == "dir":
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
42 cpDir(resourcedir, outdir_resources)
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
43 elif bundleType == "zip":
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
44 mkDir(outdir_resources)
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
45 for resource in listDirs(resourcedir):
391
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
46 let outputfile = joinPath(outdir_resources, resource.splitPath().tail & ".zip")
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
47 withdir resource:
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
48 if defined(linux):
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
49 exec &"zip -r {outputfile} ."
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
50 elif defined(windows):
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
51 exec &"powershell Compress-Archive * {outputfile}"
386
31f8ecc6644c add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff changeset
52 return outdir
391
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
53
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
54 proc semicongine_zip*(dir: string) =
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
55 withdir dir.parentDir:
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
56 if defined(linux):
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
57 exec &"zip -r {dir.lastPathPart} ."
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
58 elif defined(windows):
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
59 exec &"powershell Compress-Archive * {dir.lastPathPart}"
68198310770b add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents: 390
diff changeset
60