Skip to content

Commit ca098c6

Browse files
committed
Improve sentry-native build process
Fix script
1 parent d913819 commit ca098c6

File tree

2 files changed

+122
-81
lines changed

2 files changed

+122
-81
lines changed

SConstruct

Lines changed: 75 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ BIN_DIR = "{project_dir}/addons/{extension_name}/bin".format(
1414
project_dir=PROJECT_DIR,
1515
extension_name=EXTENSION_NAME)
1616

17+
1718
# *** Generate version header.
1819

1920
print("Generating SDK version header...")
@@ -38,112 +39,107 @@ version_header_content = """/* DO NOT EDIT - generated by SConstruct */
3839
with open("src/sdk_version.gen.h", "w") as f:
3940
f.write(version_header_content)
4041

42+
4143
# *** Build godot-cpp.
4244

4345
print("Reading godot-cpp build configuration...")
4446
env = SConscript("modules/godot-cpp/SConstruct")
4547

48+
4649
# *** Build sentry-native.
4750

48-
# TODO: macOS needs to use a different SDK.
49-
if env["platform"] in ["linux", "macos"]:
51+
if env["platform"] in ["linux", "macos", "windows"]:
52+
env.Append(CPPDEFINES=["SENTRY_BUILD_STATIC", "NATIVE_SDK"])
53+
env.Append(CPPPATH=["modules/sentry-native/include"])
54+
env.Append(LIBPATH=["modules/sentry-native/install/lib/"])
5055

51-
def build_sentry_native(target, source, env):
52-
result = subprocess.run(
53-
["sh", "scripts/build-sentry-native.sh"],
54-
check=True,
56+
sentry_targets = []
57+
sentry_sources = ["modules/sentry-native/src/"]
58+
59+
def add_target(lib_name):
60+
env.Append(LIBS=[lib_name])
61+
if env["platform"] == "windows":
62+
sentry_targets.append("modules/sentry-native/install/lib/" + lib_name + ".lib")
63+
sentry_targets.append("modules/sentry-native/install/lib/" + lib_name + ".pdb")
64+
else:
65+
sentry_targets.append("modules/sentry-native/install/lib/lib" + lib_name + ".a")
66+
67+
add_target("sentry")
68+
add_target("crashpad_client")
69+
add_target("crashpad_handler_lib")
70+
add_target("crashpad_minidump")
71+
add_target("crashpad_snapshot")
72+
add_target("crashpad_tools")
73+
add_target("crashpad_util")
74+
add_target("mini_chromium")
75+
76+
# Include additional platform-specific libs.
77+
if env["platform"] == "windows":
78+
add_target("crashpad_compat")
79+
env.Append(
80+
LIBS=[
81+
"winhttp",
82+
"advapi32",
83+
"DbgHelp",
84+
"Version",
85+
]
5586
)
56-
return result.returncode
87+
elif env["platform"] == "linux":
88+
add_target("crashpad_compat")
89+
env.Append(
90+
LIBS=[
91+
"curl",
92+
]
93+
)
94+
elif env["platform"] == "macos":
95+
env.Append(
96+
LIBS=[
97+
"curl",
98+
]
99+
)
100+
101+
# TODO: macOS needs to use a different SDK.
102+
if env["platform"] == "windows":
103+
crashpad_handler_bin = "crashpad_handler.exe"
104+
build_command = ["powershell", "scripts/build-sentry-native.ps1"]
105+
else:
106+
crashpad_handler_bin = "crashpad_handler"
107+
build_command = ["sh", "scripts/build-sentry-native.sh"]
57108

58-
crashpad_handler_target = "{bin}/{platform}/crashpad_handler".format(
109+
crashpad_handler_target = "{bin}/{platform}/{handler_bin}".format(
59110
bin=BIN_DIR,
60-
platform=env["platform"]
111+
platform=env["platform"],
112+
handler_bin=crashpad_handler_bin,
61113
)
62-
sentry_native = env.Command(
63-
[
64-
"modules/sentry-native/install/lib/libsentry.a",
65-
crashpad_handler_target,
66-
],
67-
["modules/sentry-native/src"],
68-
[
69-
build_sentry_native,
70-
Copy(
71-
crashpad_handler_target,
72-
"modules/sentry-native/install/bin/crashpad_handler",
73-
),
74-
],
75-
)
76-
elif env["platform"] == "windows":
114+
crashpad_handler_source = "modules/sentry-native/install/bin/" + crashpad_handler_bin
115+
sentry_targets.append(crashpad_handler_target)
77116

78117
def build_sentry_native(target, source, env):
79118
result = subprocess.run(
80-
["powershell", "scripts/build-sentry-native.ps1"],
119+
build_command,
81120
check=True,
82121
)
83122
return result.returncode
84123

85124
sentry_native = env.Command(
86-
["modules/sentry-native/install/lib/sentry.lib", BIN_DIR + "/windows/crashpad_handler.exe"],
87-
["modules/sentry-native/src/"],
125+
sentry_targets,
126+
sentry_sources,
88127
[
89128
build_sentry_native,
90-
Copy(
91-
BIN_DIR + "/windows/crashpad_handler.exe",
92-
"modules/sentry-native/install/bin/crashpad_handler.exe",
93-
),
129+
Copy(crashpad_handler_target, crashpad_handler_source),
94130
],
95131
)
96-
Depends(sentry_native, "modules/godot-cpp") # Force sentry-native to be built sequential to godot-cpp (not in parallel)
97-
Default(sentry_native)
98-
Clean(sentry_native, ["modules/sentry-native/build", "modules/sentry-native/install"])
99132

100-
# Include relative to project source root.
101-
env.Append(CPPPATH=["src/"])
133+
Depends(sentry_native, "modules/godot-cpp") # Force sentry-native to be built sequential to godot-cpp (not in parallel)
134+
Default(sentry_native)
135+
Clean(sentry_native, ["modules/sentry-native/build", "modules/sentry-native/install"])
102136

103-
# Include sentry-native libs (static).
104-
if env["platform"] in ["linux", "macos", "windows"]:
105-
env.Append(CPPDEFINES=["SENTRY_BUILD_STATIC", "NATIVE_SDK"])
106-
env.Append(CPPPATH=["modules/sentry-native/include"])
107-
env.Append(LIBPATH=["modules/sentry-native/install/lib/"])
108-
env.Append(
109-
LIBS=[
110-
"sentry",
111-
"crashpad_client",
112-
"crashpad_handler_lib",
113-
"crashpad_minidump",
114-
"crashpad_snapshot",
115-
"crashpad_tools",
116-
"crashpad_util",
117-
"mini_chromium",
118-
]
119-
)
120-
# Include additional platform-specific libs.
121-
if env["platform"] == "windows":
122-
env.Append(
123-
LIBS=[
124-
"crashpad_compat",
125-
"winhttp",
126-
"advapi32",
127-
"DbgHelp",
128-
"Version",
129-
]
130-
)
131-
elif env["platform"] == "linux":
132-
env.Append(
133-
LIBS=[
134-
"crashpad_compat",
135-
"curl",
136-
]
137-
)
138-
elif env["platform"] == "macos":
139-
env.Append(
140-
LIBS=[
141-
"curl",
142-
]
143-
)
144137

145138
# *** Build GDExtension library.
146139

140+
# Include relative to project source root.
141+
env.Append(CPPPATH=["src/"])
142+
147143
# Source files to compile.
148144
sources = Glob("src/*.cpp")
149145
sources += Glob("src/sentry/*.cpp")
@@ -178,6 +174,7 @@ else:
178174

179175
Default(library)
180176

177+
181178
# *** Deploy extension manifest.
182179

183180
manifest = env.Substfile(
@@ -194,6 +191,7 @@ manifest = env.Substfile(
194191

195192
Default(manifest)
196193

194+
197195
# *** Create symbolic link from project addons dir to gdUnit4 testing framework submodule.
198196

199197
def symlink(target, source, env):

scripts/build-sentry-native.ps1

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,49 @@
11
Push-Location modules\sentry-native
2-
cmake -B build -DSENTRY_BUILD_SHARED_LIBS=OFF -DSENTRY_BUILD_RUNTIMESTATIC=ON -DSENTRY_BACKEND=crashpad -DSENTRY_SDK_NAME="sentry.native.godot" -DCMAKE_BUILD_TYPE=RelWithDebInfo
3-
cmake --build build --target sentry --parallel --config RelWithDebInfo
4-
cmake --build build --target crashpad_handler --parallel --config RelWithDebInfo
5-
cmake --install build --prefix install --config RelWithDebInfo
2+
3+
$curDir = Get-Location
4+
$buildDir = Join-Path -Path $curDir -ChildPath "build"
5+
$installDir = Join-Path -Path $curDir -ChildPath "install"
6+
$pdbBuildDir = Join-Path -Path $buildDir -ChildPath "pdb"
7+
$pdbSourceDir = Join-Path -Path $pdbBuildDir -ChildPath "RelWithDebInfo"
8+
$libInstallDir = Join-Path -Path $installDir -ChildPath "lib"
9+
10+
cmake -B $buildDir -DSENTRY_BUILD_SHARED_LIBS=OFF -DSENTRY_BUILD_RUNTIMESTATIC=ON -DSENTRY_BACKEND=crashpad -DSENTRY_SDK_NAME="sentry.native.godot" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY="$pdbBuildDir"
11+
cmake --build $buildDir --target sentry --parallel --config RelWithDebInfo
12+
cmake --build $buildDir --target crashpad_handler --parallel --config RelWithDebInfo
13+
cmake --install $buildDir --prefix $installDir --config RelWithDebInfo
14+
15+
# *** Install PDB files
16+
17+
Write-Host "Installing PDB files"
18+
19+
if (!(Test-Path -Path $libInstallDir)) {
20+
Throw "Directory $libInstallDir does not exist."
21+
exit
22+
}
23+
if (!(Test-Path -Path $buildDir)) {
24+
Throw "Directory $buildDir does not exist."
25+
exit
26+
}
27+
28+
Get-ChildItem -Path $pdbSourceDir -Filter "*.pdb" -Recurse | ForEach-Object {
29+
$pdbFile = $_.Name
30+
$pdbSource = $_.FullName
31+
$pdbTarget = Join-Path -Path $libInstallDir -ChildPath $pdbFile
32+
$libBase = [System.IO.Path]::GetFileNameWithoutExtension($pdbFile)
33+
$libPath = Join-Path -Path $libInstallDir -ChildPath "$libBase.lib"
34+
35+
if (Test-Path -Path $libPath) {
36+
if (Test-Path -Path $pdbTarget) {
37+
$sourceHash = Get-FileHash -Path $pdbSource -Algorithm SHA256
38+
$targetHash = Get-FileHash -Path $pdbTarget -Algorithm SHA256
39+
if ($sourceHash.Hash -eq $targetHash.Hash) {
40+
Write-Host "-- Up-to-date: $pdbTarget."
41+
return
42+
}
43+
}
44+
Write-Host "-- Installing: $pdbFile to $libInstallDir"
45+
Copy-Item -Path $pdbSource -Destination $pdbTarget -Force
46+
}
47+
}
48+
649
Pop-Location

0 commit comments

Comments
 (0)