Mercurial > games > semicongine
annotate semiconginev2/build.nim @ 1257:e9b8d87b9883
fix: super stupid bug in perspective matrix X(
author | sam <sam@basx.dev> |
---|---|
date | Sun, 28 Jul 2024 18:55:46 +0700 |
parents | 56781cc0fc7c |
children |
rev | line source |
---|---|
396 | 1 # this should be used with nimscript |
2 | |
386
31f8ecc6644c
add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff
changeset
|
3 import std/strformat |
31f8ecc6644c
add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff
changeset
|
4 import std/os |
392
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
5 import std/strutils |
386
31f8ecc6644c
add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff
changeset
|
6 |
1190
a3eb305bcac2
start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
1156
diff
changeset
|
7 include ./core/globals |
388 | 8 |
930 | 9 const BLENDER_CONVERT_SCRIPT = currentSourcePath().parentDir().parentDir().joinPath("tools/blender_gltf_converter.py") |
966
a3428760e483
fix: steamcmd not executable, implement steam-upload
sam <sam@basx.dev>
parents:
964
diff
changeset
|
10 const STEAMCMD_ZIP = currentSourcePath().parentDir().parentDir().joinPath("tools/steamcmd.zip") |
973 | 11 const STEAMBUILD_DIR_NAME = "steam" |
12 | |
13 var STEAMLIB: string | |
14 if defined(linux): | |
15 STEAMLIB = currentSourcePath().parentDir().parentDir().joinPath("libs/libsteam_api.so") | |
16 elif defined(windows): | |
17 STEAMLIB = currentSourcePath().parentDir().parentDir().joinPath("libs/steam_api.dll") | |
18 else: | |
19 raise newException(Exception, "Unsupported platform") | |
392
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
20 |
437 | 21 proc semicongine_builddir*(buildname: string, builddir = "./build"): string = |
995
2a1de6cb5282
fix: packaging fails if there are no resources, fix: zip-generation
sam <sam@basx.dev>
parents:
992
diff
changeset
|
22 assert projectName() != "", "Please specify project file as a commandline argument" |
391
68198310770b
add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents:
390
diff
changeset
|
23 var platformDir = "unkown" |
392
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
24 |
391
68198310770b
add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents:
390
diff
changeset
|
25 if defined(linux): |
68198310770b
add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents:
390
diff
changeset
|
26 platformDir = "linux" |
392
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
27 elif defined(windows): |
391
68198310770b
add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents:
390
diff
changeset
|
28 platformDir = "windows" |
975 | 29 else: |
30 raise newException(Exception, "Unsupported platform") | |
391
68198310770b
add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents:
390
diff
changeset
|
31 |
68198310770b
add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents:
390
diff
changeset
|
32 return builddir / buildname / platformDir / projectName() |
68198310770b
add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents:
390
diff
changeset
|
33 |
437 | 34 proc semicongine_build_switches*(buildname: string, builddir = "./build") = |
386
31f8ecc6644c
add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff
changeset
|
35 switch("experimental", "strictEffects") |
31f8ecc6644c
add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff
changeset
|
36 switch("experimental", "strictFuncs") |
31f8ecc6644c
add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff
changeset
|
37 switch("define", "nimPreviewHashRef") |
975 | 38 if defined(linux): |
39 switch("define", "VK_USE_PLATFORM_XLIB_KHR") | |
40 elif defined(windows): | |
400 | 41 switch("define", "VK_USE_PLATFORM_WIN32_KHR") |
42 switch("app", "gui") | |
975 | 43 else: |
44 raise newException(Exception, "Unsupported platform") | |
45 | |
437 | 46 switch("outdir", semicongine_builddir(buildname, builddir = builddir)) |
973 | 47 switch("passL", "-Wl,-rpath,'$ORIGIN'") # adds directory of executable to dynlib search path |
386
31f8ecc6644c
add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff
changeset
|
48 |
973 | 49 proc semicongine_pack*(outdir: string, bundleType: string, resourceRoot: string, withSteam: bool) = |
438 | 50 switch("define", "PACKAGETYPE=" & bundleType) |
386
31f8ecc6644c
add: util to build projects more streamlined
Sam <sam@basx.dev>
parents:
diff
changeset
|
51 |
979 | 52 assert resourceRoot.dirExists, &"Resource root '{resourceRoot}' does not exists" |
53 | |
966
a3428760e483
fix: steamcmd not executable, implement steam-upload
sam <sam@basx.dev>
parents:
964
diff
changeset
|
54 outdir.rmDir() |
a3428760e483
fix: steamcmd not executable, implement steam-upload
sam <sam@basx.dev>
parents:
964
diff
changeset
|
55 outdir.mkDir() |
396 | 56 |
57 echo "BUILD: Packing assets from '" & resourceRoot & "' into directory '" & outdir & "'" | |
58 let outdir_resources = joinPath(outdir, RESOURCEROOT) | |
59 if bundleType == "dir": | |
60 cpDir(resourceRoot, outdir_resources) | |
61 elif bundleType == "zip": | |
966
a3428760e483
fix: steamcmd not executable, implement steam-upload
sam <sam@basx.dev>
parents:
964
diff
changeset
|
62 outdir_resources.mkDir() |
979 | 63 for resourceDir in resourceRoot.listDirs(): |
64 let outputfile = joinPath(outdir_resources, resourceDir.splitPath().tail & ".zip") | |
65 withdir resourceDir: | |
396 | 66 if defined(linux): |
979 | 67 echo &"zip -r {relativePath(outputfile, resourceDir)} ." |
68 exec &"zip -r {relativePath(outputfile, resourceDir)} ." | |
396 | 69 elif defined(windows): |
979 | 70 echo &"powershell Compress-Archive * {relativePath(outputfile, resourceDir)}" |
71 exec &"powershell Compress-Archive * {relativePath(outputfile, resourceDir)}" | |
975 | 72 else: |
73 raise newException(Exception, "Unsupported platform") | |
437 | 74 elif bundleType == "exe": |
75 switch("define", "BUILD_RESOURCEROOT=" & joinPath(getCurrentDir(), resourceRoot)) # required for in-exe packing of resources, must be absolute | |
973 | 76 if withSteam: |
77 STEAMLIB.cpFile(outdir.joinPath(STEAMLIB.extractFilename)) | |
391
68198310770b
add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents:
390
diff
changeset
|
78 |
68198310770b
add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents:
390
diff
changeset
|
79 proc semicongine_zip*(dir: string) = |
68198310770b
add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents:
390
diff
changeset
|
80 withdir dir.parentDir: |
1016 | 81 let zipFile = dir.lastPathPart & ".zip" |
82 if zipFile.fileExists: | |
83 zipFile.rmFile() | |
391
68198310770b
add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents:
390
diff
changeset
|
84 if defined(linux): |
995
2a1de6cb5282
fix: packaging fails if there are no resources, fix: zip-generation
sam <sam@basx.dev>
parents:
992
diff
changeset
|
85 exec &"zip -r {dir.lastPathPart} {dir.lastPathPart}" |
391
68198310770b
add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents:
390
diff
changeset
|
86 elif defined(windows): |
68198310770b
add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents:
390
diff
changeset
|
87 exec &"powershell Compress-Archive * {dir.lastPathPart}" |
975 | 88 else: |
89 raise newException(Exception, "Unsupported platform") | |
391
68198310770b
add: function to zip directories, usefull when creating dists
Sam <sam@basx.dev>
parents:
390
diff
changeset
|
90 |
392
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
91 |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
92 # need this because fileNewer from std/os does not work in Nim VM |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
93 proc fileNewerStatic(file1, file2: string): bool = |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
94 assert file1.fileExists |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
95 assert file2.fileExists |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
96 when defined(linux): |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
97 let command = "/usr/bin/test " & file1 & " -nt " & file2 |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
98 let ex = gorgeEx(command) |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
99 return ex.exitCode == 0 |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
100 elif defined(window): |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
101 {.error "Resource imports not supported on windows for now".} |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
102 |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
103 proc import_meshes*(files: seq[(string, string)]) = |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
104 if files.len == 0: |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
105 return |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
106 |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
107 var args = @["--background", "--python", BLENDER_CONVERT_SCRIPT, "--"] |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
108 for (input, output) in files: |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
109 args.add input |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
110 args.add output |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
111 |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
112 exec("blender " & args.join(" ")) |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
113 |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
114 proc import_audio*(files: seq[(string, string)]) = |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
115 for (input, output) in files: |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
116 let command = "ffmpeg " & ["-y", "-i", input, "-ar", $AUDIO_SAMPLE_RATE, output].join(" ") |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
117 exec(command) |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
118 |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
119 proc semicongine_import_resource_file*(resourceMap: openArray[(string, string)]) = |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
120 when not defined(linux): |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
121 {.warning: "Resource files can only be imported on linux, please make sure that the required files are created by runing the build on a linux machine.".} |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
122 return |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
123 var meshfiles: seq[(string, string)] |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
124 var audiofiles: seq[(string, string)] |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
125 |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
126 for (target_rel, source_rel) in resourceMap: |
967 | 127 let target = thisDir().joinPath(target_rel) |
128 let source = thisDir().joinPath(source_rel) | |
392
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
129 if not source.fileExists: |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
130 raise newException(IOError, &"Not found: {source}") |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
131 if not target.fileExists or source.fileNewerStatic(target): |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
132 echo &"{target} is outdated" |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
133 if source.endsWith("blend"): |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
134 meshfiles.add (source, target) |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
135 elif source.endsWith("mp3") or source.endsWith("ogg") or source.endsWith("wav"): |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
136 audiofiles.add (source, target) |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
137 else: |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
138 raise newException(Exception, &"unkown file type: {source}") |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
139 target.parentDir().mkDir() |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
140 else: |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
141 echo &"{target} is up-to-date" |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
142 import_meshes meshfiles |
ff751cbe66e3
add: build-time code for resouce importing
Sam <sam@basx.dev>
parents:
391
diff
changeset
|
143 import_audio audiofiles |
964
3c17ac18166e
add: initial code for automated steam builds
sam <sam@basx.dev>
parents:
930
diff
changeset
|
144 |
3c17ac18166e
add: initial code for automated steam builds
sam <sam@basx.dev>
parents:
930
diff
changeset
|
145 |
966
a3428760e483
fix: steamcmd not executable, implement steam-upload
sam <sam@basx.dev>
parents:
964
diff
changeset
|
146 # for steam-buildscript docs see https://partner.steamgames.com/doc/sdk/uploading |
a3428760e483
fix: steamcmd not executable, implement steam-upload
sam <sam@basx.dev>
parents:
964
diff
changeset
|
147 proc semicongine_steam_upload*(steamaccount, password, buildscript: string) = |
973 | 148 let steamdir = thisDir().joinPath(STEAMBUILD_DIR_NAME) |
964
3c17ac18166e
add: initial code for automated steam builds
sam <sam@basx.dev>
parents:
930
diff
changeset
|
149 if not dirExists(steamdir): |
966
a3428760e483
fix: steamcmd not executable, implement steam-upload
sam <sam@basx.dev>
parents:
964
diff
changeset
|
150 steamdir.mkDir |
a3428760e483
fix: steamcmd not executable, implement steam-upload
sam <sam@basx.dev>
parents:
964
diff
changeset
|
151 let zipFilename = STEAMCMD_ZIP.extractFilename |
a3428760e483
fix: steamcmd not executable, implement steam-upload
sam <sam@basx.dev>
parents:
964
diff
changeset
|
152 STEAMCMD_ZIP.cpFile(steamdir.joinPath(zipFilename)) |
a3428760e483
fix: steamcmd not executable, implement steam-upload
sam <sam@basx.dev>
parents:
964
diff
changeset
|
153 withDir(steamdir): |
975 | 154 if defined(linux): |
155 exec &"unzip {zipFilename}" | |
156 rmFile zipFilename | |
157 exec "steamcmd/steamcmd.sh +quit" # self-update steamcmd | |
158 elif defined(windows): | |
159 exec &"powershell Expand-Archive -LiteralPath {zipFilename} ." | |
160 rmFile zipFilename | |
161 exec "steamcmd/steamcmd.exe +quit" # self-update steamcmd | |
162 else: | |
163 raise newException(Exception, "Unsupported platform") | |
966
a3428760e483
fix: steamcmd not executable, implement steam-upload
sam <sam@basx.dev>
parents:
964
diff
changeset
|
164 |
975 | 165 var steamcmd: string |
166 if defined(linux): | |
973 | 167 steamcmd = STEAMBUILD_DIR_NAME.joinPath("steamcmd").joinPath("steamcmd.sh") |
975 | 168 elif defined(windows): |
169 steamcmd = STEAMBUILD_DIR_NAME.joinPath("steamcmd").joinPath("steamcmd.exe") | |
170 else: | |
171 raise newException(Exception, "Unsupported platform") | |
172 let scriptPath = "..".joinPath("..").joinPath(buildscript) | |
967 | 173 exec &"./{steamcmd} +login \"{steamaccount}\" \"{password}\" +run_app_build {scriptPath} +quit" |
1017
1953a7ba4161
add: command to sign executables on windows
sam <sam@basx.dev>
parents:
1016
diff
changeset
|
174 |
1953a7ba4161
add: command to sign executables on windows
sam <sam@basx.dev>
parents:
1016
diff
changeset
|
175 proc semicongine_sign_executable*(file: string) = |
1953a7ba4161
add: command to sign executables on windows
sam <sam@basx.dev>
parents:
1016
diff
changeset
|
176 const SIGNTOOL_EXE = "C:/Program Files (x86)/Windows Kits/10/App Certification Kit/signtool.exe" |
1953a7ba4161
add: command to sign executables on windows
sam <sam@basx.dev>
parents:
1016
diff
changeset
|
177 if not SIGNTOOL_EXE.fileExists: |
1953a7ba4161
add: command to sign executables on windows
sam <sam@basx.dev>
parents:
1016
diff
changeset
|
178 raise newException(Exception, &"signtool.exe not found at ({SIGNTOOL_EXE}), please install the Windows SDK") |
1018 | 179 exec &"\"{SIGNTOOL_EXE}\" sign /a /tr http://timestamp.globalsign.com/tsa/r6advanced1 /fd SHA256 /td SHA256 {file}" |