comparison config.nims @ 213:b5d9410a8184

add: resource packaging and loading for different resource types, simplify build commands, update readme
author Sam <sam@basx.dev>
date Wed, 10 May 2023 22:36:59 +0700
parents 81fab407a479
children f1f35e9f5335
comparison
equal deleted inserted replaced
212:77755701bf49 213:b5d9410a8184
6 const DEBUG = "debug" 6 const DEBUG = "debug"
7 const RELEASE = "release" 7 const RELEASE = "release"
8 const LINUX = "linux" 8 const LINUX = "linux"
9 const WINDOWS = "windows" 9 const WINDOWS = "windows"
10 10
11 proc compilerFlags() = 11 const BUNDLETYPE* {.strdefine.}: string = "dir" # dir, zip, exe
12 const RESOURCEROOT* {.strdefine.}: string = "resources"
13
14 task build, "build":
12 switch("path", "src") 15 switch("path", "src")
13 switch("mm", "orc") 16 switch("mm", "orc")
14 switch("experimental", "strictEffects") 17 switch("experimental", "strictEffects")
15 switch("threads", "on") 18 switch("threads", "on")
19 var buildType = DEBUG
20 var platformDir = ""
16 if defined(linux): 21 if defined(linux):
17 switch("define", "VK_USE_PLATFORM_XLIB_KHR") 22 switch("define", "VK_USE_PLATFORM_XLIB_KHR")
23 platformDir = LINUX
18 if defined(windows): 24 if defined(windows):
19 switch("define", "VK_USE_PLATFORM_WIN32_KHR") 25 switch("define", "VK_USE_PLATFORM_WIN32_KHR")
26 platformDir = WINDOWS
27 if defined(release):
28 switch("app", "gui")
29 buildType = RELEASE
30 else:
31 switch("debugger", "native")
20 32
33 var outdir = getCurrentDir() / BUILDBASE / buildType / platformDir / projectName()
34 switch("outdir", outdir)
35 setCommand "c"
36 rmDir(outdir)
37 mkDir(outdir)
38 let resourcedir = joinPath(projectDir(), RESOURCEROOT)
39 if existsDir(resourcedir):
40 let outdir_resources = joinPath(outdir, RESOURCEROOT)
41 if BUNDLETYPE == "dir":
42 cpDir(resourcedir, outdir_resources)
43 elif BUNDLETYPE == "zip":
44 mkDir(outdir_resources)
45 for resource in listDirs(resourcedir):
46 let
47 oldcwd = getCurrentDir()
48 outputfile = joinPath(outdir_resources, resource.splitPath().tail & ".zip")
49 inputfile = resource.splitPath().tail
50 cd(resource)
51 if defined(linux):
52 exec &"zip -r {outputfile} ."
53 elif defined(windows):
54 # TODO: test this
55 exec &"powershell Compress-Archive {inputfile} {outputfile}"
56 cd(oldcwd)
21 57
22 proc compilerFlagsDebug() = 58 task build_all_debug, "build all examples for debug":
23 switch("debugger", "native")
24
25 proc compilerFlagsRelease() =
26 switch("define", "release")
27 switch("app", "gui")
28
29 task single_linux_debug, "build linux debug":
30 compilerFlags()
31 compilerFlagsDebug()
32 switch("outdir", BUILDBASE / DEBUG / LINUX)
33 setCommand "c"
34 mkDir(BUILDBASE / DEBUG / LINUX)
35
36 task single_linux_release, "build linux release":
37 compilerFlags()
38 compilerFlagsRelease()
39 switch("outdir", BUILDBASE / RELEASE / LINUX)
40 setCommand "c"
41 mkDir(BUILDBASE / RELEASE / LINUX)
42
43 task single_windows_debug, "build windows debug":
44 compilerFlags()
45 compilerFlagsDebug()
46 switch("outdir", BUILDBASE & "/" & DEBUG & "/" & WINDOWS)
47 setCommand "c"
48 mkDir(BUILDBASE & "/" & DEBUG & "/" & WINDOWS)
49
50 task single_windows_release, "build windows release":
51 compilerFlags()
52 compilerFlagsRelease()
53 switch("outdir", BUILDBASE & "/" & RELEASE & "/" & WINDOWS)
54 setCommand "c"
55 mkDir(BUILDBASE & "/" & RELEASE & "/" & WINDOWS)
56
57 task build_all_linux_debug, "build all examples with linux/debug":
58 for file in listFiles("examples"): 59 for file in listFiles("examples"):
59 if file.endsWith(".nim"): 60 if file.endsWith(".nim"):
60 selfExec(&"single_linux_debug {file}") 61 exec(&"nim build {file}")
61 62
62 task build_all_linux_release, "build all examples with linux/release": 63 task build_all_release, "build all examples for release":
63 for file in listFiles("examples"): 64 for file in listFiles("examples"):
64 if file.endsWith(".nim"): 65 if file.endsWith(".nim"):
65 selfExec(&"single_linux_release {file}") 66 exec(&"nim build -d:release {file}")
66
67 task build_all_windows_debug, "build all examples with windows/debug":
68 for file in listFiles("examples"):
69 if file.endsWith(".nim"):
70 exec(&"nim single_windows_debug --define:mingw {file}")
71
72 task build_all_windows_release, "build all examples with windows/release":
73 for file in listFiles("examples"):
74 if file.endsWith(".nim"):
75 exec(&"nim single_windows_release --define:mingw {file}")
76
77 task build_all_debug, "build all examples with */debug":
78 build_all_linux_debugTask()
79 build_all_windows_debugTask()
80
81 task build_all_release, "build all examples with */release":
82 build_all_linux_releaseTask()
83 build_all_windows_releaseTask()
84
85 task build_all_linux, "build all examples with linux/*":
86 build_all_linux_debugTask()
87 build_all_linux_releaseTask()
88
89 task build_all_windows, "build all examples with windows/*":
90 build_all_windows_debugTask()
91 build_all_windows_releaseTask()
92
93 task build_all, "build all examples":
94 build_all_linuxTask()
95 build_all_windowsTask()
96 67
97 task clean, "remove all build files": 68 task clean, "remove all build files":
98 exec(&"rm -rf {BUILDBASE}") 69 exec(&"rm -rf {BUILDBASE}")
99 70
100 task publish, "publish all build": 71 task publish, "publish all build":
114 exec &"cd {dirname} && unzip *.zip" 85 exec &"cd {dirname} && unzip *.zip"
115 exec &"mv {dirname}/bin/glslangValidator examples/" 86 exec &"mv {dirname}/bin/glslangValidator examples/"
116 exec &"rm -rf {dirname}" 87 exec &"rm -rf {dirname}"
117 88
118 task glslangValidator_exe, "Download glslangValidator.exe (required for windows compilation)": 89 task glslangValidator_exe, "Download glslangValidator.exe (required for windows compilation)":
90 # TODO: make this work on windows
119 let dirname = "/tmp/glslang_download" 91 let dirname = "/tmp/glslang_download"
120 exec &"mkdir -p {dirname}" 92 exec &"mkdir -p {dirname}"
121 exec &"cd {dirname} && wget https://github.com/KhronosGroup/glslang/releases/download/master-tot/glslang-master-windows-x64-Release.zip" 93 exec &"cd {dirname} && wget https://github.com/KhronosGroup/glslang/releases/download/master-tot/glslang-master-windows-x64-Release.zip"
122 exec &"cd {dirname} && unzip *.zip" 94 exec &"cd {dirname} && unzip *.zip"
123 exec &"mv {dirname}/bin/glslangValidator.exe examples/" 95 exec &"mv {dirname}/bin/glslangValidator.exe examples/"
142 mkDir "src/semicongine/core/" 114 mkDir "src/semicongine/core/"
143 cpFile "src/vulkan_api/output/api.nim", "src/semicongine/core/api.nim" 115 cpFile "src/vulkan_api/output/api.nim", "src/semicongine/core/api.nim"
144 cpDir "src/vulkan_api/output/platform", "src/semicongine/vulkan/platform" 116 cpDir "src/vulkan_api/output/platform", "src/semicongine/vulkan/platform"
145 117
146 if getCommand() in ["c", "compile", "r", "dump", "check", "idetools"]: 118 if getCommand() in ["c", "compile", "r", "dump", "check", "idetools"]:
147 compilerFlags() 119 --path:src
120 --mm:orc
121 --threads:on
122 if defined(linux):
123 --d:VK_USE_PLATFORM_XLIB_KHR
124 if defined(windows):
125 --d:VK_USE_PLATFORM_WIN32_KHR