annotate config.nims @ 905:a9d71d2c2461

did: same for panels
author Sam <sam@basx.dev>
date Sat, 24 Feb 2024 15:35:52 +0700
parents ad961543994b
children fe48b091e83f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
494
0c18638c7217 did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents: 485
diff changeset
1 import std/strformat
0c18638c7217 did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents: 485
diff changeset
2 import std/strutils
0c18638c7217 did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents: 485
diff changeset
3 import std/os
479
16842d15319a add: basic vertex buffer functionality
Sam <sam@basx.dev>
parents: 474
diff changeset
4
494
0c18638c7217 did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents: 485
diff changeset
5 const BUILDBASE = "build"
0c18638c7217 did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents: 485
diff changeset
6 const DEBUG = "debug"
0c18638c7217 did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents: 485
diff changeset
7 const RELEASE = "release"
0c18638c7217 did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents: 485
diff changeset
8 const LINUX = "linux"
0c18638c7217 did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents: 485
diff changeset
9 const WINDOWS = "windows"
479
16842d15319a add: basic vertex buffer functionality
Sam <sam@basx.dev>
parents: 474
diff changeset
10
899
ad961543994b did: refactor and improve packaging API
Sam <sam@basx.dev>
parents: 844
diff changeset
11 const PACKAGETYPE* {.strdefine.}: string = "dir" # dir, zip, exe
674
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
12 const RESOURCEROOT* {.strdefine.}: string = "resources"
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
13
844
094342d38c69 fix: old settings
Sam <sam@basx.dev>
parents: 835
diff changeset
14 switch("d", "nimPreviewHashRef")
094342d38c69 fix: old settings
Sam <sam@basx.dev>
parents: 835
diff changeset
15 switch("experimental", "strictEffects")
094342d38c69 fix: old settings
Sam <sam@basx.dev>
parents: 835
diff changeset
16 switch("experimental", "strictFuncs")
094342d38c69 fix: old settings
Sam <sam@basx.dev>
parents: 835
diff changeset
17 switch("nimblePath", "nimbledeps/pkgs2")
094342d38c69 fix: old settings
Sam <sam@basx.dev>
parents: 835
diff changeset
18
674
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
19 task build, "build":
899
ad961543994b did: refactor and improve packaging API
Sam <sam@basx.dev>
parents: 844
diff changeset
20 switch("d", "PACKAGETYPE=" & PACKAGETYPE)
734
a432a4a99110 fix: change due to build-configuration change
Sam <sam@basx.dev>
parents: 713
diff changeset
21 switch("d", "RESOURCEROOT=" & RESOURCEROOT)
674
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
22 var buildType = DEBUG
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
23 var platformDir = ""
544
c3c772512e7c add: new vulkan api wrapper, not done yet
Sam <sam@basx.dev>
parents: 543
diff changeset
24 if defined(linux):
c3c772512e7c add: new vulkan api wrapper, not done yet
Sam <sam@basx.dev>
parents: 543
diff changeset
25 switch("define", "VK_USE_PLATFORM_XLIB_KHR")
674
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
26 platformDir = LINUX
544
c3c772512e7c add: new vulkan api wrapper, not done yet
Sam <sam@basx.dev>
parents: 543
diff changeset
27 if defined(windows):
c3c772512e7c add: new vulkan api wrapper, not done yet
Sam <sam@basx.dev>
parents: 543
diff changeset
28 switch("define", "VK_USE_PLATFORM_WIN32_KHR")
674
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
29 platformDir = WINDOWS
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
30 if defined(release):
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
31 switch("app", "gui")
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
32 buildType = RELEASE
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
33 else:
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
34 switch("debugger", "native")
494
0c18638c7217 did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents: 485
diff changeset
35
674
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
36 var outdir = getCurrentDir() / BUILDBASE / buildType / platformDir / projectName()
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
37 switch("outdir", outdir)
479
16842d15319a add: basic vertex buffer functionality
Sam <sam@basx.dev>
parents: 474
diff changeset
38 setCommand "c"
674
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
39 rmDir(outdir)
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
40 mkDir(outdir)
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
41 let resourcedir = joinPath(projectDir(), RESOURCEROOT)
777
754835bf175e add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents: 734
diff changeset
42 if dirExists(resourcedir):
674
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
43 let outdir_resources = joinPath(outdir, RESOURCEROOT)
899
ad961543994b did: refactor and improve packaging API
Sam <sam@basx.dev>
parents: 844
diff changeset
44 if PACKAGETYPE == "dir":
674
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
45 cpDir(resourcedir, outdir_resources)
899
ad961543994b did: refactor and improve packaging API
Sam <sam@basx.dev>
parents: 844
diff changeset
46 elif PACKAGETYPE == "zip":
674
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
47 mkDir(outdir_resources)
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
48 for resource in listDirs(resourcedir):
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
49 let
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
50 oldcwd = getCurrentDir()
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
51 outputfile = joinPath(outdir_resources, resource.splitPath().tail & ".zip")
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
52 inputfile = resource.splitPath().tail
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
53 cd(resource)
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
54 if defined(linux):
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
55 exec &"zip -r {outputfile} ."
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
56 elif defined(windows):
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
57 # TODO: test this
675
cba4bebaf9d0 fix: resources on windows
Sam <sam@basx.dev>
parents: 674
diff changeset
58 exec &"powershell Compress-Archive * {outputfile}"
674
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
59 cd(oldcwd)
479
16842d15319a add: basic vertex buffer functionality
Sam <sam@basx.dev>
parents: 474
diff changeset
60
674
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
61 task build_all_debug, "build all examples for debug":
494
0c18638c7217 did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents: 485
diff changeset
62 for file in listFiles("examples"):
0c18638c7217 did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents: 485
diff changeset
63 if file.endsWith(".nim"):
674
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
64 exec(&"nim build {file}")
494
0c18638c7217 did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents: 485
diff changeset
65
674
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
66 task build_all_release, "build all examples for release":
494
0c18638c7217 did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents: 485
diff changeset
67 for file in listFiles("examples"):
0c18638c7217 did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents: 485
diff changeset
68 if file.endsWith(".nim"):
674
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
69 exec(&"nim build -d:release {file}")
494
0c18638c7217 did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents: 485
diff changeset
70
777
754835bf175e add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents: 734
diff changeset
71 task test_all, "Run all test programs":
754835bf175e add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents: 734
diff changeset
72 for file in listFiles("tests"):
899
ad961543994b did: refactor and improve packaging API
Sam <sam@basx.dev>
parents: 844
diff changeset
73 if file.endsWith(".nim") and not file.endsWith("test_resources.nim"):
777
754835bf175e add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents: 734
diff changeset
74 exec(&"nim build --run {file}")
754835bf175e add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents: 734
diff changeset
75
899
ad961543994b did: refactor and improve packaging API
Sam <sam@basx.dev>
parents: 844
diff changeset
76 exec("nim build -d:BUILD_RESOURCEROOT=tests/resources -d:PACKAGETYPE=dir --run tests/test_resources.nim")
ad961543994b did: refactor and improve packaging API
Sam <sam@basx.dev>
parents: 844
diff changeset
77 exec("nim build -d:BUILD_RESOURCEROOT=tests/resources -d:PACKAGETYPE=zip --run tests/test_resources.nim")
ad961543994b did: refactor and improve packaging API
Sam <sam@basx.dev>
parents: 844
diff changeset
78 exec("nim build -d:BUILD_RESOURCEROOT=tests/resources -d:PACKAGETYPE=exe --run tests/test_resources.nim")
ad961543994b did: refactor and improve packaging API
Sam <sam@basx.dev>
parents: 844
diff changeset
79
494
0c18638c7217 did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents: 485
diff changeset
80 task clean, "remove all build files":
0c18638c7217 did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents: 485
diff changeset
81 exec(&"rm -rf {BUILDBASE}")
0c18638c7217 did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents: 485
diff changeset
82
0c18638c7217 did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents: 485
diff changeset
83 task publish, "publish all build":
709
3b00747b2451 did: few fixes
Sam <sam@basx.dev>
parents: 696
diff changeset
84 for file in listDirs("build/debug/linux"):
713
cdb3ff9b0047 did: update configs
sam <sam@basx.dev>
parents: 709
diff changeset
85 exec(&"scp -r {file} sam@mail.basx.dev:/var/www/public.basx.dev/semicongine/debug/linux/")
cdb3ff9b0047 did: update configs
sam <sam@basx.dev>
parents: 709
diff changeset
86 for file in listDirs("build/release/linux"):
cdb3ff9b0047 did: update configs
sam <sam@basx.dev>
parents: 709
diff changeset
87 exec(&"scp -r {file} sam@mail.basx.dev:/var/www/public.basx.dev/semicongine/release/linux/")
cdb3ff9b0047 did: update configs
sam <sam@basx.dev>
parents: 709
diff changeset
88 for file in listDirs("build/debug/windows"):
cdb3ff9b0047 did: update configs
sam <sam@basx.dev>
parents: 709
diff changeset
89 exec(&"scp -r {file} sam@mail.basx.dev:/var/www/public.basx.dev/semicongine/debug/windows/")
cdb3ff9b0047 did: update configs
sam <sam@basx.dev>
parents: 709
diff changeset
90 for file in listDirs("build/release/windows"):
cdb3ff9b0047 did: update configs
sam <sam@basx.dev>
parents: 709
diff changeset
91 exec(&"scp -r {file} sam@mail.basx.dev:/var/www/public.basx.dev/semicongine/release/windows/")
514
86629e31543e add: improve build on windows
Sam <sam@basx.dev>
parents: 507
diff changeset
92
497
797f6f9c9d73 did: migrate rest of make functionality
Sam <sam@basx.dev>
parents: 496
diff changeset
93 task glslangValidator, "Download glslangValidator (required for linux compilation)":
523
311ee4e58032 fix: some formatting, bug when opening on windows.
Sam <sam@basx.dev>
parents: 516
diff changeset
94 let dirname = "/tmp/glslang_download"
497
797f6f9c9d73 did: migrate rest of make functionality
Sam <sam@basx.dev>
parents: 496
diff changeset
95 exec &"mkdir -p {dirname}"
797f6f9c9d73 did: migrate rest of make functionality
Sam <sam@basx.dev>
parents: 496
diff changeset
96 exec &"cd {dirname} && wget https://github.com/KhronosGroup/glslang/releases/download/master-tot/glslang-master-linux-Release.zip"
797f6f9c9d73 did: migrate rest of make functionality
Sam <sam@basx.dev>
parents: 496
diff changeset
97 exec &"cd {dirname} && unzip *.zip"
797f6f9c9d73 did: migrate rest of make functionality
Sam <sam@basx.dev>
parents: 496
diff changeset
98 exec &"mv {dirname}/bin/glslangValidator examples/"
797f6f9c9d73 did: migrate rest of make functionality
Sam <sam@basx.dev>
parents: 496
diff changeset
99 exec &"rm -rf {dirname}"
797f6f9c9d73 did: migrate rest of make functionality
Sam <sam@basx.dev>
parents: 496
diff changeset
100
797f6f9c9d73 did: migrate rest of make functionality
Sam <sam@basx.dev>
parents: 496
diff changeset
101 task glslangValidator_exe, "Download glslangValidator.exe (required for windows compilation)":
674
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
102 # TODO: make this work on windows
523
311ee4e58032 fix: some formatting, bug when opening on windows.
Sam <sam@basx.dev>
parents: 516
diff changeset
103 let dirname = "/tmp/glslang_download"
497
797f6f9c9d73 did: migrate rest of make functionality
Sam <sam@basx.dev>
parents: 496
diff changeset
104 exec &"mkdir -p {dirname}"
797f6f9c9d73 did: migrate rest of make functionality
Sam <sam@basx.dev>
parents: 496
diff changeset
105 exec &"cd {dirname} && wget https://github.com/KhronosGroup/glslang/releases/download/master-tot/glslang-master-windows-x64-Release.zip"
797f6f9c9d73 did: migrate rest of make functionality
Sam <sam@basx.dev>
parents: 496
diff changeset
106 exec &"cd {dirname} && unzip *.zip"
797f6f9c9d73 did: migrate rest of make functionality
Sam <sam@basx.dev>
parents: 496
diff changeset
107 exec &"mv {dirname}/bin/glslangValidator.exe examples/"
797f6f9c9d73 did: migrate rest of make functionality
Sam <sam@basx.dev>
parents: 496
diff changeset
108 exec &"rm -rf {dirname}"
494
0c18638c7217 did: refactoring, move more from make to nimscript
Sam <sam@basx.dev>
parents: 485
diff changeset
109
523
311ee4e58032 fix: some formatting, bug when opening on windows.
Sam <sam@basx.dev>
parents: 516
diff changeset
110 task run_all, "Run all binaries":
500
8025ab67d931 fix: hello cube, add: run_all command
Sam <sam@basx.dev>
parents: 499
diff changeset
111 for file in listFiles("build/debug/linux"):
8025ab67d931 fix: hello cube, add: run_all command
Sam <sam@basx.dev>
parents: 499
diff changeset
112 exec file
8025ab67d931 fix: hello cube, add: run_all command
Sam <sam@basx.dev>
parents: 499
diff changeset
113 for file in listFiles("build/release/linux"):
8025ab67d931 fix: hello cube, add: run_all command
Sam <sam@basx.dev>
parents: 499
diff changeset
114 exec file
8025ab67d931 fix: hello cube, add: run_all command
Sam <sam@basx.dev>
parents: 499
diff changeset
115 for file in listFiles("build/debug/windows"):
8025ab67d931 fix: hello cube, add: run_all command
Sam <sam@basx.dev>
parents: 499
diff changeset
116 exec &"wine {file}"
8025ab67d931 fix: hello cube, add: run_all command
Sam <sam@basx.dev>
parents: 499
diff changeset
117 for file in listFiles("build/release/windows"):
8025ab67d931 fix: hello cube, add: run_all command
Sam <sam@basx.dev>
parents: 499
diff changeset
118 exec &"wine {file}"
507
15e78601b390 add: some changes to build on windows host
Sam <sam@basx.dev>
parents: 505
diff changeset
119
539
9400c1cf26a5 add: vulkan api generator, not finished yet
Sam <sam@basx.dev>
parents: 523
diff changeset
120 task get_vulkan_wrapper, "Download vulkan wrapper":
9400c1cf26a5 add: vulkan api generator, not finished yet
Sam <sam@basx.dev>
parents: 523
diff changeset
121 exec &"curl https://raw.githubusercontent.com/nimgl/nimgl/master/src/nimgl/vulkan.nim > src/semicongine/vulkan/c_api.nim"
9400c1cf26a5 add: vulkan api generator, not finished yet
Sam <sam@basx.dev>
parents: 523
diff changeset
122
9400c1cf26a5 add: vulkan api generator, not finished yet
Sam <sam@basx.dev>
parents: 523
diff changeset
123 task generate_vulkan_api, "Generate Vulkan API":
655
53e08e6c5ae6 did: a bit of cleanup with the config, also add some documentation
Sam <sam@basx.dev>
parents: 544
diff changeset
124 selfExec &"c -d:ssl --run src/vulkan_api/vulkan_api_generator.nim"
543
1822bea7de34 did: complete vulkan api generator pipeline for now
Sam <sam@basx.dev>
parents: 539
diff changeset
125 mkDir "src/semicongine/vulkan/"
668
a02d503ffa53 add: some adjustment to the last refactoring :P
Sam <sam@basx.dev>
parents: 655
diff changeset
126 mkDir "src/semicongine/core/"
a02d503ffa53 add: some adjustment to the last refactoring :P
Sam <sam@basx.dev>
parents: 655
diff changeset
127 cpFile "src/vulkan_api/output/api.nim", "src/semicongine/core/api.nim"
543
1822bea7de34 did: complete vulkan api generator pipeline for now
Sam <sam@basx.dev>
parents: 539
diff changeset
128 cpDir "src/vulkan_api/output/platform", "src/semicongine/vulkan/platform"
539
9400c1cf26a5 add: vulkan api generator, not finished yet
Sam <sam@basx.dev>
parents: 523
diff changeset
129
507
15e78601b390 add: some changes to build on windows host
Sam <sam@basx.dev>
parents: 505
diff changeset
130 if getCommand() in ["c", "compile", "r", "dump", "check", "idetools"]:
674
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
131 if defined(linux):
899
ad961543994b did: refactor and improve packaging API
Sam <sam@basx.dev>
parents: 844
diff changeset
132 --d: VK_USE_PLATFORM_XLIB_KHR
674
496b328faa43 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 668
diff changeset
133 if defined(windows):
899
ad961543994b did: refactor and improve packaging API
Sam <sam@basx.dev>
parents: 844
diff changeset
134 --d: VK_USE_PLATFORM_WIN32_KHR