Mercurial > games > semicongine
annotate config.nims @ 1033:3c2056353ee2
did: cleanup nimble definition
author | sam <sam@basx.dev> |
---|---|
date | Thu, 21 Mar 2024 15:55:57 +0700 |
parents | 1ab09f8cc68d |
children | fe48b091e83f |
rev | line source |
---|---|
33
94c38e4b5782
did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents:
24
diff
changeset
|
1 import std/strformat |
94c38e4b5782
did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents:
24
diff
changeset
|
2 import std/strutils |
94c38e4b5782
did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents:
24
diff
changeset
|
3 import std/os |
18 | 4 |
33
94c38e4b5782
did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents:
24
diff
changeset
|
5 const BUILDBASE = "build" |
94c38e4b5782
did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents:
24
diff
changeset
|
6 const DEBUG = "debug" |
94c38e4b5782
did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents:
24
diff
changeset
|
7 const RELEASE = "release" |
94c38e4b5782
did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents:
24
diff
changeset
|
8 const LINUX = "linux" |
94c38e4b5782
did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents:
24
diff
changeset
|
9 const WINDOWS = "windows" |
18 | 10 |
438 | 11 const PACKAGETYPE* {.strdefine.}: string = "dir" # dir, zip, exe |
213
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
12 const RESOURCEROOT* {.strdefine.}: string = "resources" |
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
13 |
383 | 14 switch("d", "nimPreviewHashRef") |
15 switch("experimental", "strictEffects") | |
16 switch("experimental", "strictFuncs") | |
17 switch("nimblePath", "nimbledeps/pkgs2") | |
18 | |
213
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
19 task build, "build": |
438 | 20 switch("d", "PACKAGETYPE=" & PACKAGETYPE) |
273
93becb68cb7a
fix: change due to build-configuration change
Sam <sam@basx.dev>
parents:
252
diff
changeset
|
21 switch("d", "RESOURCEROOT=" & RESOURCEROOT) |
213
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
22 var buildType = DEBUG |
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
23 var platformDir = "" |
83
5e19aead2b61
add: new vulkan api wrapper, not done yet
Sam <sam@basx.dev>
parents:
82
diff
changeset
|
24 if defined(linux): |
5e19aead2b61
add: new vulkan api wrapper, not done yet
Sam <sam@basx.dev>
parents:
82
diff
changeset
|
25 switch("define", "VK_USE_PLATFORM_XLIB_KHR") |
213
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
26 platformDir = LINUX |
83
5e19aead2b61
add: new vulkan api wrapper, not done yet
Sam <sam@basx.dev>
parents:
82
diff
changeset
|
27 if defined(windows): |
5e19aead2b61
add: new vulkan api wrapper, not done yet
Sam <sam@basx.dev>
parents:
82
diff
changeset
|
28 switch("define", "VK_USE_PLATFORM_WIN32_KHR") |
213
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
29 platformDir = WINDOWS |
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
30 if defined(release): |
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
31 switch("app", "gui") |
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
32 buildType = RELEASE |
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
33 else: |
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
34 switch("debugger", "native") |
33
94c38e4b5782
did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents:
24
diff
changeset
|
35 |
213
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
36 var outdir = getCurrentDir() / BUILDBASE / buildType / platformDir / projectName() |
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
37 switch("outdir", outdir) |
18 | 38 setCommand "c" |
213
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
39 rmDir(outdir) |
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
40 mkDir(outdir) |
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
41 let resourcedir = joinPath(projectDir(), RESOURCEROOT) |
316
b145a05c2459
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
273
diff
changeset
|
42 if dirExists(resourcedir): |
213
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
43 let outdir_resources = joinPath(outdir, RESOURCEROOT) |
438 | 44 if PACKAGETYPE == "dir": |
213
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
45 cpDir(resourcedir, outdir_resources) |
438 | 46 elif PACKAGETYPE == "zip": |
213
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
47 mkDir(outdir_resources) |
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
48 for resource in listDirs(resourcedir): |
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
49 let |
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
50 oldcwd = getCurrentDir() |
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
51 outputfile = joinPath(outdir_resources, resource.splitPath().tail & ".zip") |
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
52 inputfile = resource.splitPath().tail |
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
53 cd(resource) |
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
54 if defined(linux): |
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
55 exec &"zip -r {outputfile} ." |
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
56 elif defined(windows): |
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
57 # TODO: test this |
214 | 58 exec &"powershell Compress-Archive * {outputfile}" |
213
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
59 cd(oldcwd) |
18 | 60 |
213
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
61 task build_all_debug, "build all examples for debug": |
33
94c38e4b5782
did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents:
24
diff
changeset
|
62 for file in listFiles("examples"): |
94c38e4b5782
did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents:
24
diff
changeset
|
63 if file.endsWith(".nim"): |
213
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
64 exec(&"nim build {file}") |
33
94c38e4b5782
did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents:
24
diff
changeset
|
65 |
213
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
66 task build_all_release, "build all examples for release": |
33
94c38e4b5782
did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents:
24
diff
changeset
|
67 for file in listFiles("examples"): |
94c38e4b5782
did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents:
24
diff
changeset
|
68 if file.endsWith(".nim"): |
213
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
69 exec(&"nim build -d:release {file}") |
33
94c38e4b5782
did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents:
24
diff
changeset
|
70 |
316
b145a05c2459
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
273
diff
changeset
|
71 task test_all, "Run all test programs": |
b145a05c2459
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
273
diff
changeset
|
72 for file in listFiles("tests"): |
438 | 73 if file.endsWith(".nim") and not file.endsWith("test_resources.nim"): |
316
b145a05c2459
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
273
diff
changeset
|
74 exec(&"nim build --run {file}") |
b145a05c2459
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
273
diff
changeset
|
75 |
438 | 76 exec("nim build -d:BUILD_RESOURCEROOT=tests/resources -d:PACKAGETYPE=dir --run tests/test_resources.nim") |
77 exec("nim build -d:BUILD_RESOURCEROOT=tests/resources -d:PACKAGETYPE=zip --run tests/test_resources.nim") | |
78 exec("nim build -d:BUILD_RESOURCEROOT=tests/resources -d:PACKAGETYPE=exe --run tests/test_resources.nim") | |
79 | |
33
94c38e4b5782
did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents:
24
diff
changeset
|
80 task clean, "remove all build files": |
94c38e4b5782
did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents:
24
diff
changeset
|
81 exec(&"rm -rf {BUILDBASE}") |
94c38e4b5782
did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents:
24
diff
changeset
|
82 |
94c38e4b5782
did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents:
24
diff
changeset
|
83 task publish, "publish all build": |
248 | 84 for file in listDirs("build/debug/linux"): |
252 | 85 exec(&"scp -r {file} sam@mail.basx.dev:/var/www/public.basx.dev/semicongine/debug/linux/") |
86 for file in listDirs("build/release/linux"): | |
87 exec(&"scp -r {file} sam@mail.basx.dev:/var/www/public.basx.dev/semicongine/release/linux/") | |
88 for file in listDirs("build/debug/windows"): | |
89 exec(&"scp -r {file} sam@mail.basx.dev:/var/www/public.basx.dev/semicongine/debug/windows/") | |
90 for file in listDirs("build/release/windows"): | |
91 exec(&"scp -r {file} sam@mail.basx.dev:/var/www/public.basx.dev/semicongine/release/windows/") | |
53 | 92 |
36 | 93 task glslangValidator, "Download glslangValidator (required for linux compilation)": |
62
7153eadb07eb
fix: some formatting, bug when opening on windows.
Sam <sam@basx.dev>
parents:
55
diff
changeset
|
94 let dirname = "/tmp/glslang_download" |
36 | 95 exec &"mkdir -p {dirname}" |
96 exec &"cd {dirname} && wget https://github.com/KhronosGroup/glslang/releases/download/master-tot/glslang-master-linux-Release.zip" | |
97 exec &"cd {dirname} && unzip *.zip" | |
98 exec &"mv {dirname}/bin/glslangValidator examples/" | |
99 exec &"rm -rf {dirname}" | |
100 | |
101 task glslangValidator_exe, "Download glslangValidator.exe (required for windows compilation)": | |
213
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
102 # TODO: make this work on windows |
62
7153eadb07eb
fix: some formatting, bug when opening on windows.
Sam <sam@basx.dev>
parents:
55
diff
changeset
|
103 let dirname = "/tmp/glslang_download" |
36 | 104 exec &"mkdir -p {dirname}" |
105 exec &"cd {dirname} && wget https://github.com/KhronosGroup/glslang/releases/download/master-tot/glslang-master-windows-x64-Release.zip" | |
106 exec &"cd {dirname} && unzip *.zip" | |
107 exec &"mv {dirname}/bin/glslangValidator.exe examples/" | |
108 exec &"rm -rf {dirname}" | |
33
94c38e4b5782
did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents:
24
diff
changeset
|
109 |
62
7153eadb07eb
fix: some formatting, bug when opening on windows.
Sam <sam@basx.dev>
parents:
55
diff
changeset
|
110 task run_all, "Run all binaries": |
39 | 111 for file in listFiles("build/debug/linux"): |
112 exec file | |
113 for file in listFiles("build/release/linux"): | |
114 exec file | |
115 for file in listFiles("build/debug/windows"): | |
116 exec &"wine {file}" | |
117 for file in listFiles("build/release/windows"): | |
118 exec &"wine {file}" | |
46
9e81f06a5c57
add: some changes to build on windows host
Sam <sam@basx.dev>
parents:
44
diff
changeset
|
119 |
78
f67496a189cb
add: vulkan api generator, not finished yet
Sam <sam@basx.dev>
parents:
62
diff
changeset
|
120 task get_vulkan_wrapper, "Download vulkan wrapper": |
f67496a189cb
add: vulkan api generator, not finished yet
Sam <sam@basx.dev>
parents:
62
diff
changeset
|
121 exec &"curl https://raw.githubusercontent.com/nimgl/nimgl/master/src/nimgl/vulkan.nim > src/semicongine/vulkan/c_api.nim" |
f67496a189cb
add: vulkan api generator, not finished yet
Sam <sam@basx.dev>
parents:
62
diff
changeset
|
122 |
f67496a189cb
add: vulkan api generator, not finished yet
Sam <sam@basx.dev>
parents:
62
diff
changeset
|
123 task generate_vulkan_api, "Generate Vulkan API": |
194
93f661a20f74
did: a bit of cleanup with the config, also add some documentation
Sam <sam@basx.dev>
parents:
83
diff
changeset
|
124 selfExec &"c -d:ssl --run src/vulkan_api/vulkan_api_generator.nim" |
82
9e7937b7bcc8
did: complete vulkan api generator pipeline for now
Sam <sam@basx.dev>
parents:
78
diff
changeset
|
125 mkDir "src/semicongine/vulkan/" |
207
81fab407a479
add: some adjustment to the last refactoring :P
Sam <sam@basx.dev>
parents:
194
diff
changeset
|
126 mkDir "src/semicongine/core/" |
81fab407a479
add: some adjustment to the last refactoring :P
Sam <sam@basx.dev>
parents:
194
diff
changeset
|
127 cpFile "src/vulkan_api/output/api.nim", "src/semicongine/core/api.nim" |
82
9e7937b7bcc8
did: complete vulkan api generator pipeline for now
Sam <sam@basx.dev>
parents:
78
diff
changeset
|
128 cpDir "src/vulkan_api/output/platform", "src/semicongine/vulkan/platform" |
78
f67496a189cb
add: vulkan api generator, not finished yet
Sam <sam@basx.dev>
parents:
62
diff
changeset
|
129 |
46
9e81f06a5c57
add: some changes to build on windows host
Sam <sam@basx.dev>
parents:
44
diff
changeset
|
130 if getCommand() in ["c", "compile", "r", "dump", "check", "idetools"]: |
213
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
131 if defined(linux): |
438 | 132 --d: VK_USE_PLATFORM_XLIB_KHR |
213
b5d9410a8184
add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents:
207
diff
changeset
|
133 if defined(windows): |
438 | 134 --d: VK_USE_PLATFORM_WIN32_KHR |