Skip to content

Commit 2b1cb35

Browse files
committed
make extshared_build_helper handle x32 and x64
1 parent de7167d commit 2b1cb35

File tree

1 file changed

+40
-10
lines changed
  • extshared_build_helper/src

1 file changed

+40
-10
lines changed

extshared_build_helper/src/lib.rs

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ use vergen_gitcl::GitclBuilder;
2222

2323
static SRCWRTIMER_ROOT_DIR: std::sync::LazyLock<String> =
2424
std::sync::LazyLock::new(|| std::env::var("SRCWRTIMER_ROOT_DIR").unwrap());
25+
static IS_X64: std::sync::LazyLock<bool> =
26+
std::sync::LazyLock::new(|| std::env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap() == "64");
2527

2628
pub fn generate_inc_defines_and_enums(outdir: &str, incfile: &str, name: &str) {
2729
println!("cargo:rerun-if-changed={}", incfile);
@@ -158,18 +160,32 @@ pub fn smext_hl2sdk_for_good_games(build: &mut cc::Build, sdk_name: &str, sdk_id
158160
}
159161

160162
if like_msvc {
161-
build.define("COMPILER_MSVC", "1").define("COMPILER_MSVC64", "1");
163+
if *IS_X64 {
164+
build.define("COMPILER_MSVC64", "1");
165+
} else {
166+
build.define("COMPILER_MSVC32", "1");
167+
}
168+
build.define("COMPILER_MSVC", "1");
162169
} else {
163170
build.define("COMPILER_GCC", "1");
164171
}
165172

166173
let (lib_folder, links) = if target_windows {
167-
(format!("{sdk_path}/lib/public/x64"), vec![
168-
"tier0", "tier1", "vstdlib", "mathlib",
169-
])
174+
(
175+
if *IS_X64 {
176+
format!("{sdk_path}/lib/public/x64")
177+
} else {
178+
format!("{sdk_path}/lib/public/x86")
179+
},
180+
vec!["tier0", "tier1", "vstdlib", "mathlib"],
181+
)
170182
} else {
171183
(
172-
format!("{sdk_path}/lib/public/linux64"),
184+
if *IS_X64 {
185+
format!("{sdk_path}/lib/public/linux64")
186+
} else {
187+
format!("{sdk_path}/lib/public/linux")
188+
},
173189
// vec!["tier1_i486", "mathlib_i486"] // ??????
174190
vec![],
175191
)
@@ -212,9 +228,13 @@ pub fn link_sm_detours(mainbuild: &mut cc::Build) {
212228
slurp_folder(&mut detours, &format!("{}/public/safetyhook/src", sm));
213229

214230
if like_msvc {
231+
if *IS_X64 {
232+
detours.define("COMPILER_MSVC64", "1");
233+
} else {
234+
detours.define("COMPILER_MSVC32", "1");
235+
}
215236
detours
216237
.define("COMPILER_MSVC", "1")
217-
.define("COMPILER_MSVC64", "1")
218238
.flag("/std:c++latest") // /std:c++23 doesn't exist yet!! crazy! TODO: periodically check this https://learn.microsoft.com/en-us/cpp/build/reference/std-specify-language-standard-version
219239
.flag("/permissive-")
220240
// C++ stack unwinding & extern "C" don't throw...
@@ -289,25 +309,35 @@ pub fn smext_build() -> cc::Build {
289309
// Same with .dll file name...
290310
// println!("cargo::rustc-link-arg=/OUT:_build\\i686-pc-windows-msvc\\release\\{}.ext.dll", std::env::var("CARGO_PKG_NAME").unwrap());
291311

312+
if *IS_X64 {
313+
build
314+
.flag("/d2archSSE42") // sse4.2!
315+
.define("COMPILER_MSVC64", "1");
316+
} else {
317+
build.define("COMPILER_MSVC32", "1");
318+
}
319+
292320
build
293321
.define("COMPILER_MSVC", "1")
294-
.define("COMPILER_MSVC64", "1")
295322
.flag("/std:c++latest") // /std:c++23 doesn't exist yet!! crazy! TODO: periodically check this https://learn.microsoft.com/en-us/cpp/build/reference/std-specify-language-standard-version
296323
// We also set /Zi and /FS in .cargo/config.toml with some cc-crate target-specific environment variables
297-
.flag("/d2archSSE42") // sse4.2!
298324
.flag("/Zi") // debug info things https://learn.microsoft.com/en-us/cpp/build/reference/z7-zi-zi-debug-information-format
299325
.flag("/FS") // force synchronous pdb writes https://learn.microsoft.com/en-us/cpp/build/reference/fs-force-synchronous-pdb-writes
300326
.flag("/wd4100") // disable warning C4100: unreferenced formal parameter
301327
.flag("/EHsc") // https://learn.microsoft.com/en-us/cpp/build/reference/eh-exception-handling-model
302328
// "This needs to be after our optimization flags which could otherwise disable it."
303-
// "Don't omit the frame pointer.""
329+
// "Don't omit the frame pointer." (this doesn't do anything in x64)
304330
.flag("/Oy-");
305331
} else {
332+
if *IS_X64 {
333+
build.flag("-mcpu=x86_64_v2");
334+
} else {
335+
build.flag("-msse").flag("-m32");
336+
}
306337
build
307338
.define("HAVE_STDINT_H", None)
308339
.define("GNUC", None)
309340
.define("COMPILER_GCC", "1")
310-
.flag("-mcpu=x86_64_v2")
311341
.flag("-std=c++23")
312342
.flag("-Wno-unknown-pragmas")
313343
.flag("-Wno-dangling-else")

0 commit comments

Comments
 (0)