forked from GDRETools/gdsdecomp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSCsub
More file actions
604 lines (518 loc) · 23.4 KB
/
Copy pathSCsub
File metadata and controls
604 lines (518 loc) · 23.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
#!/usr/bin/env python
import re
from typing import Any, Literal
import gdre_icon_builder
import shutil
from subprocess import Popen, PIPE, check_output
import os
import glob
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from SCons.Environment import Environment
from SCons.Builder import Builder
from SCons import Import
env: Environment = None
env_modules: Environment = None
env_gdsdecomp: Environment = None
Import("env")
Import("env_modules")
MODULE_DIR: str = env.Dir("#modules/gdsdecomp").abspath
BUILD_DIR: str = env.Dir("#bin").abspath
EXTERNAL_STEM: str = "external_install"
EXTERNAL_DIR: str = os.path.join(MODULE_DIR, EXTERNAL_STEM)
etcpak_dir = "#thirdparty/etcpak/"
mmp3thirdparty_dir = "#thirdparty/minimp3/"
liboggthirdparty_dir = "#thirdparty/libogg/"
libvorbisthirdparty_dir = "#thirdparty/libvorbis/"
webpthirdparty_dir = "#thirdparty/libwebp/"
vtracer_dir_include_dir = "#modules/gdsdecomp/external/vtracer/include"
godot_mono_decomp_include_dir = "#modules/gdsdecomp/external/godot-mono-decomp/GodotMonoDecompNativeAOT/include"
# hack to force the minimum macOS version to 10.15; it is currently hard-coded to 10.13 in the macos/detect.py script
# TODO: remove this hack once the minimum macOS version is updated to 10.15
if env["platform"] == "macos" and env["arch"] == "x86_64":
env.Append(CPPFLAGS=["-mmacosx-version-min=10.15"])
env.Append(LINKFLAGS=["-mmacosx-version-min=10.15"])
env.Append(CXXFLAGS=["-mmacosx-version-min=10.15"])
env.Append(ASFLAGS=["-mmacosx-version-min=10.15"])
env_modules.Append(CPPFLAGS=["-mmacosx-version-min=10.15"])
env_modules.Append(LINKFLAGS=["-mmacosx-version-min=10.15"])
env_modules.Append(CXXFLAGS=["-mmacosx-version-min=10.15"])
env_modules.Append(ASFLAGS=["-mmacosx-version-min=10.15"])
env_gdsdecomp = env_modules.Clone()
# Append the include path to include the current directory
# This is a hack for tests, since the test headers get built from tests/test_main.cpp,
# and the headers that our tests pull in are relative to the current directory.
# TODO: Figure out a way to not have to do this
if env["tests"]:
env.Append(CPPPATH=[vtracer_dir_include_dir])
env.Append(CPPPATH=[godot_mono_decomp_include_dir])
env.Append(CPPPATH=["#modules/gdsdecomp/"])
env.Append(CPPPATH=[liboggthirdparty_dir])
env.Append(CPPPATH=[libvorbisthirdparty_dir])
env_gdsdecomp.Append(CPPPATH=[vtracer_dir_include_dir])
env_gdsdecomp.Append(CPPPATH=[godot_mono_decomp_include_dir])
env_gdsdecomp.Append(CPPPATH=["#modules/gdsdecomp/"])
env_gdsdecomp.Append(CPPPATH=["#thirdparty/thorsvg/"])
if env["disable_exceptions"]:
env_gdsdecomp.Append(CPPDEFINES=["DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS"])
env_gdsdecomp["BUILDERS"]["MakeGDREIconsBuilder"] = Builder(
action=env_gdsdecomp.Run(gdre_icon_builder.make_gdre_icons_action),
suffix=".h",
src_suffix=".svg",
)
icon_sources = Glob("icons/*.svg")
env_gdsdecomp.Alias(
"gdre_icons",
[env_gdsdecomp.MakeGDREIconsBuilder("editor/gdre_icons.gen.h", icon_sources)],
)
def doproc(cmd):
# ensure that it doesn't print stderr to the terminal if print_err is False
process = Popen(cmd, stdout=PIPE, stderr=PIPE)
(output, err) = process.communicate()
if not err:
return output.decode("utf-8").strip()
else:
return None
semver_regex = r"^[vV]?(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"
def is_dev_build(env):
return env["dev_build"] if "dev_build" in env else False
def write_version_header():
git = shutil.which("git")
version_info = "unknown"
is_tag = False
if git == None:
print("GDRE WARNING: cannot find git on path, unknown version will be saved in gdre_version.gen.h")
else:
# git describe --abbrev=6
version_info = doproc([git, "describe", "--tags", "--abbrev=6"])
if version_info is None:
print("GDRE WARNING: git failed to run, unknown version will be saved in gdre_version.gen.h")
version_info = "unknown"
else:
# git describe --exact-match --tags HEAD
res = doproc([git, "describe", "--exact-match", "--tags", "HEAD"])
if not res:
splits = version_info.split("-")
build_info = splits[-1]
build_num = splits[-2]
# everything but the last two elements
new_version_info = "-".join(splits[:-2])
semver_regex_match = re.match(semver_regex, new_version_info)
if semver_regex_match:
major = semver_regex_match.group("major")
minor = semver_regex_match.group("minor")
patch = semver_regex_match.group("patch")
prerelease_tag = semver_regex_match.group("prerelease")
build_metadata = semver_regex_match.group("buildmetadata")
else:
print("WARNING: version string does not match semver format")
splits = new_version_info.split(".")
if len(splits) < 3:
print("WARNING: version string is too short")
major = "0"
minor = "0"
patch = "0"
else:
major = splits[0]
minor = splits[1]
patch = splits[2]
prerelease_tag = ""
build_metadata = ""
dev_stuff = f"dev.{build_num}+{build_info}"
if prerelease_tag:
prerelease_name = prerelease_tag.split(".")[0]
prerelease_num = prerelease_tag.split(".")[-1]
if prerelease_num.isdigit():
prerelease_num = str(int(prerelease_num) + 1)
print("prerelease_num", prerelease_num)
prerelease_tag = f"{prerelease_name}.{prerelease_num}"
else:
prerelease_tag += ".1"
new_version_info = f"{major}.{minor}.{patch}-{prerelease_tag}+{dev_stuff.replace('+', '-')}"
else:
patch = str(int(patch) + 1) if patch.isdigit() else 0
new_version_info = f"{major}.{minor}.{patch}-{dev_stuff}"
version_info = new_version_info
else:
version_info = res
f = open("utility/gdre_version.gen.h", "w")
# check if we're not on a tag
process = Popen([git, "status", "--porcelain"], stdout=PIPE)
# define GDRE_VERSION "dev-poc (for Godot 4.0)"
f.write('#define GDRE_VERSION "')
f.write(version_info)
f.write('"\n')
f.close()
write_version_header()
env_gdsdecomp.Prepend(CPPPATH=[etcpak_dir])
if env["builtin_libogg"]:
env_gdsdecomp.Prepend(CPPPATH=[liboggthirdparty_dir])
if env["builtin_libvorbis"]:
env_gdsdecomp.Prepend(CPPPATH=["#thirdparty/libvorbis"])
# Treat minimp3 headers as system headers to avoid raising warnings. Not supported on MSVC.
if not env.msvc:
env_gdsdecomp.Append(CPPFLAGS=["-isystem", Dir(mmp3thirdparty_dir).path])
else:
env_gdsdecomp.Prepend(CPPPATH=[mmp3thirdparty_dir])
if env["builtin_libwebp"]:
env_gdsdecomp.Prepend(CPPPATH=[webpthirdparty_dir, webpthirdparty_dir + "src/"])
def get_sources(rel_path, filters=["*.h", "*.hpp", "*.cpp"], exclude_filters=[]):
abs_path = os.path.join(MODULE_DIR, rel_path)
# check if abs_path exists
if not os.path.exists(abs_path):
raise Exception(
f"Path {abs_path} does not exist, please run `git submodule update --init --recursive` in the patchwork_editor directory"
)
sources = []
for suffix in filters:
globstr = os.path.join(abs_path, "**", suffix)
new_sources = glob.glob(globstr, recursive=True)
sources += [
source
for source in new_sources
if (not exclude_filters or not any(exclude_filter in source for exclude_filter in exclude_filters))
]
print("SOURCES", sources)
return [os.path.relpath(source, MODULE_DIR) for source in sources]
def cmake_builder(external_dir, source_dir, build_dir, libs, config_options=None):
output = bytes()
# get dev_build from env
dev_build = env["dev_build"] if "dev_build" in env else False
build_variant = "Debug" if dev_build else "Release"
print("BUILD VARIANT", build_variant)
Config_cmd = ["cmake", "-S", source_dir, "-B", build_dir, "-DCMAKE_BUILD_TYPE=" + build_variant]
if config_options:
Config_cmd += config_options
try:
# if os.path.exists(build_dir):
# shutil.rmtree(build_dir, ignore_errors=True)
output += check_output(["cmake", "-E", "make_directory", external_dir]) + b"\n"
output += check_output(["cmake", "-E", "make_directory", build_dir]) + b"\n"
output += check_output(Config_cmd) + b"\n"
output += check_output(["cmake", "--build", build_dir]) + b"\n"
# remove the old libs
for lib in libs:
lib_path = os.path.join(external_dir, lib)
if os.path.exists(lib_path):
os.remove(lib_path)
output += check_output(["cmake", "--install", build_dir, "--prefix", external_dir]) + b"\n"
except Exception as e:
# convert output to string
output = output.decode("utf-8")
print(f"Failed to build automerge-c: {e}")
print(f"Output: {output}")
exit(1)
# output = output.decode("utf-8")
# print(output)
def get_rustc_target():
rustc_cmd = shutil.which("rustc")
if not rustc_cmd:
raise Exception("rustc not found")
output = check_output([rustc_cmd, "-vV"])
match = re.search(r"host: ([^ \n]*)", output.decode("utf-8"))
if not match:
raise Exception("Could not determine rustc host target")
return match.group(1)
def get_cargo_target(build_env):
arch_part: str = "x86_64" if build_env["arch"] == "x86_64" else "aarch64"
cargo_target: str = ""
if build_env["platform"] == "macos":
cargo_target = str(f"{arch_part}-apple-darwin")
elif build_env["platform"] == "linuxbsd":
cargo_target = str(f"{arch_part}-unknown-linux-gnu")
elif build_env["platform"] == "windows":
cargo_target = str(f"{arch_part}-pc-windows-")
if build_env.msvc:
cargo_target += "msvc"
else:
cargo_target += "gnu"
elif build_env["platform"] == "web": # use emscripten
cargo_target = str(f"wasm32-unknown-emscripten")
elif build_env["platform"] == "ios":
cargo_target = str(f"{arch_part}-apple-ios")
elif build_env["platform"] == "android":
cargo_target = str(f"{arch_part}-linux-android")
else:
raise Exception(f"Unsupported platform: {build_env['platform']}")
return cargo_target
def cargo_builder(external_dir: str, source_dir: str, build_dir: str, libs: list[str], build_env):
output = bytes()
# get dev_build from env
if build_env is None:
raise Exception("build_env is required")
dev_build = build_env["dev_build"] if "dev_build" in build_env else False
build_variant = "Debug" if dev_build else "Release"
print("BUILD VARIANT", build_variant)
cargo_target = get_cargo_target(build_env)
cbindgen_dir = os.path.join(source_dir, "include", "vtracer")
# rustc_target = get_rustc_target()
arch_flag = str(f"--target={cargo_target}")
cargo_cmd = ["cargo", "build", "--lib", arch_flag]
if not dev_build:
cargo_cmd.append("--release")
cargo_env = os.environ.copy()
cargo_env["CARGO_TARGET_DIR"] = build_dir
# cargo_env["CARGO_INSTALL_ROOT"] = external_dir
cargo_env["CBINDGEN_TARGET_DIR"] = cbindgen_dir
if build_env["platform"] == "web":
# need to include -Ctarget-feature=+atomics,+bulk-memory,+mutable-globals
cargo_env["RUSTFLAGS"] = (
"-Cpanic=abort -Ctarget-feature=+atomics,+bulk-memory,+mutable-globals -Clink-arg=-fno-exceptions -Clink-arg=-sDISABLE_EXCEPTION_THROWING=1 -Clink-arg=-sDISABLE_EXCEPTION_CATCHING=1 -Cllvm-args=-enable-emscripten-cxx-exceptions=0 -Zlink-native-libraries=no"
)
cargo_cmd.append("-Zbuild-std=std,panic_abort")
# need to also set
cargo_cmd.append("-Zbuild-std-features=panic_immediate_abort")
output = check_output(cargo_cmd, cwd=source_dir, env=cargo_env)
print(output.decode("utf-8"))
if env.msvc:
dar = get_vtracer_lib_dir()
for lib in libs:
lib_path = os.path.join(dar, os.path.basename(lib).split(".")[0] + env["LIBSUFFIX"])
if os.path.exists(lib):
# copy lib to lib_path
shutil.copy(lib, lib_path)
def add_libs_to_env(module_obj, libs, sources):
for lib in libs:
env_gdsdecomp.Depends(lib, sources)
if env.msvc:
# ensure the lib ends with .lib
if not lib.endswith(".lib"):
# remove the current extension, add .lib
lib_base = lib.rsplit(".", 1)[0]
lib = lib_base + ".lib"
env.Append(LINKFLAGS=[lib])
continue
# get the basename of the library minus the extension
lib_name = os.path.basename(lib).split(".")[0]
# if env.msvc:
# lib_name = lib + env["LIBSUFFIX"]
print("LIB NAME", lib_name)
env.Append(LIBS=[lib_name])
env.Depends(module_obj, libs)
VTRACER_PREFIX = "external/vtracer"
VTRACER_DIR = os.path.join(MODULE_DIR, VTRACER_PREFIX)
VTRACER_BUILD_DIR = os.path.join(VTRACER_DIR, "target")
VTRACER_LIBS = ["vtracer"]
# Godot Mono Decomp configuration
GODOT_MONO_DECOMP_PARENT = "external/godot-mono-decomp"
GODOT_MONO_DECOMP_PREFIX = "external/godot-mono-decomp/GodotMonoDecompNativeAOT"
GODOT_MONO_DECOMP_DIR = os.path.join(MODULE_DIR, GODOT_MONO_DECOMP_PREFIX)
GODOT_MONO_DECOMP_LIBS = ["GodotMonoDecompNativeAOT"]
def get_vtracer_libs():
lib_prefix: str = "lib" if not env.msvc else ""
lib_suffix: Literal[".a", ".lib"] = ".a" if not env.msvc else ".lib"
return [lib_prefix + lib + lib_suffix for lib in VTRACER_LIBS]
def get_vtracer_lib_dir():
rust_target = get_cargo_target(build_env=env)
debug_build = env["dev_build"]
variant_dir = "debug" if debug_build else "release"
return os.path.join(VTRACER_BUILD_DIR, rust_target, variant_dir)
def get_vtracer_lib_paths() -> list[Any]:
libs = get_vtracer_libs()
lib_paths = []
build_dir = get_vtracer_lib_dir()
for lib in libs:
lib_path = os.path.join(build_dir, lib)
lib_paths.append(lib_path)
print("LIB PATHS", lib_paths)
return lib_paths
env.Append(LIBPATH=[get_vtracer_lib_dir()])
def vtracer_builder(target, source, env):
print("VTRACER BUILD")
print(str(target[0]))
print(source)
# print(env)
cargo_builder(EXTERNAL_DIR, VTRACER_DIR, VTRACER_BUILD_DIR, get_vtracer_lib_paths(), env)
def build_vtracer(module_obj):
SRC_SUFFIXES = ["*.h", "*.cpp", "*.rs", "*.txt"]
lib_suffix: Literal[".a", ".lib"] = ".a" if not env.msvc else ".lib"
env_gdsdecomp["BUILDERS"]["vtracerBuilder"] = Builder(
action=vtracer_builder,
suffix=lib_suffix,
src_suffix=["*.h", "*.cpp", "*.rs", "*.txt"],
)
libs = get_vtracer_lib_paths()
vtracer_sources = get_sources(VTRACER_PREFIX, SRC_SUFFIXES)
env_gdsdecomp.Alias(
"vtracerlib",
[env_gdsdecomp.vtracerBuilder(libs, vtracer_sources)],
)
add_libs_to_env(module_obj, libs, vtracer_sources)
if env.msvc:
env.Append(LINKFLAGS=["userenv.lib"])
pass
def get_godot_mono_decomp_libs(static_lib: bool, _env=env):
if static_lib:
lib_prefix: str = "lib" if not _env.msvc else ""
lib_suffix: str = ".a" if not _env.msvc else ".lib"
else:
lib_prefix: str = "lib" if not _env.msvc else ""
if _env["platform"] == "macos":
lib_suffix = ".dylib"
elif _env.msvc:
# lib_suffix = ".dll"
# we can't link against .dll on windows
lib_suffix = ".lib"
else:
lib_suffix = ".so"
return [lib_prefix + lib + lib_suffix for lib in GODOT_MONO_DECOMP_LIBS]
def get_godot_mono_triplet(platform: str, arch: str):
if platform == "macos":
platform_part = "osx"
arch_part = "arm64" if arch == "arm64" else "x64"
elif platform == "linuxbsd":
platform_part = "linux"
arch_part = "arm64" if arch == "arm64" else "x64"
elif platform == "windows":
platform_part = "win"
arch_part = "arm64" if arch == "arm64" else "x64"
else:
raise Exception(f"Unsupported platform: {platform}")
return f"{platform_part}-{arch_part}"
def get_dotnet_variant_name(dev_build: bool):
return "Debug" if dev_build else "Release"
def get_godot_mono_decomp_lib_dir(platform: str, arch: str, dev_build: bool):
# Determine the platform and architecture for the library path
triplet = get_godot_mono_triplet(platform, arch)
target_framework = "net9.0"
# cat the modules/gdsdecomp/external/godot-mono-decomp/GodotMonoDecompNativeAOT/GodotMonoDecompNativeAOT.csproj file to see what runtime is used
with open(os.path.join(GODOT_MONO_DECOMP_DIR, "GodotMonoDecompNativeAOT.csproj"), "r") as f:
for line in f:
if "TargetFramework" in line:
target_framework = line.split(">")[1].split("<")[0].strip()
print("TARGET FRAMEWORK", target_framework)
break
return os.path.join(
GODOT_MONO_DECOMP_DIR, "bin", get_dotnet_variant_name(dev_build), target_framework, triplet, "publish"
)
def get_godot_mono_decomp_lib_paths(_env=env) -> list[Any]:
libs = get_godot_mono_decomp_libs(False, _env)
lib_paths = []
build_dir = get_godot_mono_decomp_lib_dir(
_env["platform"],
_env["arch"],
is_dev_build(_env),
)
for lib in libs:
lib_path = os.path.join(build_dir, lib)
lib_paths.append(lib_path)
print("GODOT MONO DECOMP LIB PATHS", lib_paths)
return lib_paths
env.Append(LIBPATH=[BUILD_DIR])
env.Append(LIBPATH=[get_godot_mono_decomp_lib_dir(env["platform"], env["arch"], is_dev_build(env))])
def godot_mono_builder(target, source, env: dict[str, Any]):
print("GODOT MONO DECOMP BUILD: ", target)
libs = get_godot_mono_decomp_lib_paths(env)
native_lib_type = "Shared"
dev_build: bool = is_dev_build(env)
build_variant = get_dotnet_variant_name(dev_build)
print("BUILD VARIANT ", build_variant)
BASE_CMD = [
"dotnet",
"publish",
f"/p:NativeLib={native_lib_type}",
"/p:PublishProfile=AOT",
"-c",
build_variant,
]
dotnet_publish_cmd = BASE_CMD + ["-r", get_godot_mono_triplet(env["platform"], env["arch"])]
lib_dir = get_godot_mono_decomp_lib_dir(env["platform"], env["arch"], dev_build)
cwd = GODOT_MONO_DECOMP_DIR
print("DOTNET PUBLISH CMD", dotnet_publish_cmd)
dotnet_publish_output = check_output(dotnet_publish_cmd, cwd=cwd)
# parse utf-8
print("DOTNET PUBLISH OUTPUT", dotnet_publish_output.decode("utf-8"))
other_lib_dir = ""
if env["platform"] == "macos":
# run it again for the opposite architecture
new_arch = "x86_64" if env["arch"] == "arm64" else "arm64"
new_triplet = get_godot_mono_triplet(env["platform"], new_arch)
dotnet_publish_cmd = BASE_CMD + ["-r", new_triplet]
other_lib_dir = get_godot_mono_decomp_lib_dir(env["platform"], new_arch, dev_build)
cwd = GODOT_MONO_DECOMP_DIR
print("DOTNET PUBLISH CMD", dotnet_publish_cmd)
dotnet_publish_output = check_output(dotnet_publish_cmd, cwd=cwd)
print("DOTNET PUBLISH OUTPUT", dotnet_publish_output.decode("utf-8"))
# lipo them together
# if the platform is macos or linux, we need to make a copy with a "lib" prefix
bin_paths = []
# ensure the BUILD_DIR exists
if not os.path.exists(BUILD_DIR):
os.makedirs(BUILD_DIR)
for lib in libs:
# copy it to the godot build directory
if env.msvc:
lib = lib.replace(".lib", ".dll")
copy_path: str = os.path.abspath(os.path.join(BUILD_DIR, os.path.basename(lib)))
print("LIB PATH", lib)
print("COPY PATH", copy_path)
if env["platform"] == "macos":
# lipo them together
lipo_cmd = [
"lipo",
"-create",
lib,
os.path.join(other_lib_dir, os.path.basename(lib)),
"-output",
copy_path,
]
print("LIPOING LIB TO ", copy_path)
lipo_output = check_output(lipo_cmd, cwd=lib_dir)
else:
shutil.copy(lib, copy_path)
# if env.msvc:
# shutil.copy(lib.replace(".lib", ".dll"), copy_path.replace(".lib", ".dll"))
def build_godot_mono_decomp(module_obj):
# For pre-built .NET NativeAOT libraries, we just need to link them
libs = get_godot_mono_decomp_lib_paths()
# Create empty sources list since we're linking pre-built libraries
godot_mono_decomp_sources = glob.glob(os.path.join(GODOT_MONO_DECOMP_DIR, "**", "*.cs"), recursive=True)
# add the get_godot_mono_decomp_lib_dir() to the LIBPATH
lib_suffix = ".so"
if env.msvc:
lib_suffix = ".lib" # not .dll
elif env["platform"] == "macos":
lib_suffix = ".dylib"
src_suffixes = ["*.h", "*.cs", "*.csproj", "*.props", "*.targets", "*.pubxml"]
env_gdsdecomp["BUILDERS"]["godotMonoDecompBuilder"] = Builder(
action=godot_mono_builder,
suffix=lib_suffix,
src_suffix=src_suffixes,
)
depends_libs = []
# if the library doesn't exist in BUILD_DIR, remove the libs from disk to force a rebuild
for lib in libs:
new_lib = os.path.join(BUILD_DIR, os.path.basename(lib))
if env.msvc:
new_lib = new_lib.replace(".lib", ".dll")
depends_libs.append(new_lib)
all_libs = libs + depends_libs
godot_mono_decomp_sources = get_sources(GODOT_MONO_DECOMP_PARENT, src_suffixes, ["obj/", "bin/", "obj\\", "bin\\"])
env_gdsdecomp.Alias(
"godotMonoDecomp",
[env_gdsdecomp.godotMonoDecompBuilder(all_libs, godot_mono_decomp_sources)],
)
add_libs_to_env(module_obj, libs, godot_mono_decomp_sources)
env.Depends(module_obj, depends_libs)
if env["platform"] == "linuxbsd":
# add -Wl,-rpath,'$ORIGIN'
# env.Append(LINKFLAGS=["-Wl,-rpath,'$ORIGIN'"])
env.Append( LINKFLAGS = Split('-z origin') )
env.Append( RPATH = env.Literal('\\$$ORIGIN'))
# env.Append(LIBPATH=[get_godot_mono_decomp_lib_dir()])
# link against external/libvtracer.a and godot-mono-decomp libraries
module_obj = []
env_gdsdecomp.add_source_files(module_obj, "*.cpp")
env_gdsdecomp.add_source_files(module_obj, "bytecode/*.cpp")
env_gdsdecomp.add_source_files(module_obj, "compat/*.cpp")
if env["target"] == "editor":
env_gdsdecomp.add_source_files(module_obj, "editor/*.cpp")
env_gdsdecomp.add_source_files(module_obj, "exporters/*.cpp")
env_gdsdecomp.add_source_files(module_obj, "utility/*.cpp")
env_gdsdecomp.add_source_files(module_obj, "external/tga/*.cpp")
env_gdsdecomp.add_source_files(module_obj, "external/etcpak-decompress/*.cpp")
env_gdsdecomp.add_source_files(module_obj, "external/tinygltf/tiny_gltf.cc")
env_gdsdecomp.add_source_files(module_obj, "module_etc_decompress/*.cpp")
build_vtracer(module_obj)
build_godot_mono_decomp(module_obj)
env.modules_sources += module_obj