Skip to content

Commit 1e10934

Browse files
committed
prepare for srcwrtimer_sample_extension repo to use this
1 parent 99a9600 commit 1e10934

File tree

22 files changed

+79
-333
lines changed

22 files changed

+79
-333
lines changed

Cargo.lock

Lines changed: 0 additions & 55 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
1-
[workspace]
1+
# https://doc.rust-lang.org/cargo/reference/workspaces.html
22

3-
resolver = "2" # shrug
3+
[workspace]
4+
resolver = "2"
45

56
members = [
6-
"closestpos",
7-
#"closestpos-rs",
8-
"extshared",
9-
"extshared_build_helper",
7+
"closestpos*",
8+
"extshared*",
109
"smbz2",
11-
#"srcwrf64",
12-
"srcwrhttp",
13-
"srcwrjson",
14-
#"srcwrreplayman",
15-
"srcwrsample",
16-
#"srcwrsyncer",
17-
"srcwrutil",
10+
"srcwr*",
1811
]
19-
# Don't build these by default... (because they're just crates for extensions)
2012
exclude = [
21-
"extshared",
22-
"extshared_build_helper",
13+
# The SourceMod codez and folder structure...
14+
"srcwrtimer",
15+
16+
# Crates that are not finished (or they're broken) so ignore them...
17+
"closestpos-rs", # broken
18+
"srcwrf64", # lol nothing implemented
19+
"srcwrreplayman", # very wip lol
20+
"srcwrsyncer", # not using right now
2321
]
2422

2523
[workspace.package]
2624
version = "1.0.0"
27-
edition = "2021"
25+
edition = "2024"
2826
# TODO: Setup homepage url to go to each extension's folder / README?
2927
homepage = "https://github.com/srcwr/srcwrtimer"
3028
repository = "https://github.com/srcwr/srcwrtimer"
3129

30+
[workspace.dependencies]
31+
extshared_build_helper = { path = "extshared_build_helper" }
32+
extshared = { path = "extshared" }
33+
3234
[profile.release]
3335
lto = true
3436
incremental = false
@@ -37,5 +39,3 @@ incremental = false
3739
#git2-curl = { path = "../git2-rs/git2-curl" }
3840
#git2 = { path = "../git2-rs" }
3941

40-
#bzip2 = { path = "../bzip2-rs" }
41-

Makefile.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ dependencies = [
7777

7878
[env]
7979
HOSTOSPLAIN = { source = "${OS}", default_value = "linux", mapping = {"Windows_NT" = "windows"} }
80-
EXTERNALDIR="${CARGO_MAKE_WORKING_DIRECTORY}/_external"
80+
SRCWRTIMER_ROOT_DIR="${CARGO_MAKE_WORKING_DIRECTORY}"
81+
EXTERNALDIR="${SRCWRTIMER_ROOT_DIR}/_external"
8182
PACKAGEDIR="${CARGO_MAKE_WORKING_DIRECTORY}/_package"
8283

8384
# Problem with master (as of 2024-09-30):

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ TODO: investigate https://github.com/rust-cross/cargo-xwin for msvc builds from
4747
- A better JSON extension for plugins to use. The `natives_json.rs` code is a mess lol. Minimally tested.
4848
- srcwrreplayman
4949
- An incomplete/placeholder extension to provide more efficient and performant replay storage and access. Expect something similar to [bhoptimer_helper_minimal](https://github.com/srcwr/bhoptimer_helper_minimal).
50-
- srcwrsample
51-
- A sample/test extension that I use for random things. If you want an extension to copy & paste to base a new extension off of then you could try this, srcwrutil, or smbz2.
5250
- srcwrsql
5351
- Was going to be a SQL extension that runs queries parallel to each other. SourceMod's SQL extension runs each query one-after-another, with a sleep after each query, so it's not very performant. TODO one day...
5452
- srcwrsyncer

closestpos-rs/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ repository.workspace = true
1212
crate-type = ["cdylib"]
1313

1414
[build-dependencies]
15-
extshared_build_helper = { path = "../extshared_build_helper" }
15+
extshared_build_helper.workspace = true
1616

1717
[dependencies]
18-
extshared = { path = "../extshared" }
18+
extshared.workspace = true
1919
kiddo = "4"

closestpos/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ repository.workspace = true
1212
crate-type = ["cdylib"]
1313

1414
[build-dependencies]
15-
extshared_build_helper = { path = "../extshared_build_helper" }
15+
extshared_build_helper.workspace = true
1616

1717
[dependencies]
18-
extshared = { path = "../extshared" }
18+
extshared.workspace = true

extshared/src/smext_conf_boilerplate.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ macro_rules! smext_conf_boilerplate_extension_info {
1010
() => {
1111
use std::io::Write;
1212

13-
#[no_mangle]
13+
#[unsafe(no_mangle)]
1414
pub extern "C" fn rust_conf_name() -> *const u8 {
1515
concat!(env!("CARGO_PKG_NAME"), "\0").as_ptr()
1616
}
17-
#[no_mangle]
17+
#[unsafe(no_mangle)]
1818
pub extern "C" fn rust_conf_description() -> *const u8 {
1919
concat!(env!("CARGO_PKG_DESCRIPTION"), "\0").as_ptr()
2020
}
21-
#[no_mangle]
21+
#[unsafe(no_mangle)]
2222
pub extern "C" fn rust_conf_version() -> *const u8 {
2323
static VER: std::sync::LazyLock<String> = std::sync::LazyLock::new(|| {
2424
let dirty = if env!("VERGEN_GIT_DIRTY") == "true" {
@@ -37,11 +37,11 @@ macro_rules! smext_conf_boilerplate_extension_info {
3737
//concat!(env!("CARGO_PKG_VERSION"), "\0").as_ptr()
3838
VER.as_ptr()
3939
}
40-
#[no_mangle]
40+
#[unsafe(no_mangle)]
4141
pub extern "C" fn rust_conf_author() -> *const u8 {
4242
concat!(env!("CARGO_PKG_AUTHORS"), "\0").as_ptr()
4343
}
44-
#[no_mangle]
44+
#[unsafe(no_mangle)]
4545
pub extern "C" fn rust_conf_url() -> *const u8 {
4646
concat!(
4747
env!("CARGO_PKG_HOMEPAGE"),
@@ -51,16 +51,16 @@ macro_rules! smext_conf_boilerplate_extension_info {
5151
)
5252
.as_ptr()
5353
}
54-
#[no_mangle]
54+
#[unsafe(no_mangle)]
5555
pub extern "C" fn rust_conf_logtag() -> *const u8 {
5656
concat!(env!("CARGO_PKG_NAME"), "\0").as_ptr()
5757
}
58-
#[no_mangle]
58+
#[unsafe(no_mangle)]
5959
pub extern "C" fn rust_conf_license() -> *const u8 {
6060
concat!(env!("CARGO_PKG_LICENSE"), "\0").as_ptr()
6161
}
6262

63-
#[no_mangle]
63+
#[unsafe(no_mangle)]
6464
#[allow(clippy::not_unsafe_ptr_arg_deref)]
6565
pub extern "C" fn rust_sdk_on_load_wrapper(
6666
error: *mut u8,
@@ -85,26 +85,26 @@ macro_rules! smext_conf_boilerplate_extension_info {
8585
macro_rules! smext_conf_boilerplate_load_funcs {
8686
() => {
8787
// perhaps an anyhow::Result<()> would be better...
88-
#[no_mangle]
88+
#[unsafe(no_mangle)]
8989
pub fn rust_sdk_on_load(_late: bool) -> Result<(), Box<dyn std::error::Error>> {
9090
Ok(())
9191
}
9292

93-
#[no_mangle]
93+
#[unsafe(no_mangle)]
9494
pub extern "C" fn rust_sdk_on_unload() {}
9595

96-
#[no_mangle]
96+
#[unsafe(no_mangle)]
9797
pub extern "C" fn rust_sdk_on_all_loaded() {}
9898

99-
#[no_mangle]
99+
#[unsafe(no_mangle)]
100100
pub extern "C" fn rust_on_core_map_start(
101101
_edict_list: *mut core::ffi::c_void,
102102
_edict_count: i32,
103103
_client_max: i32,
104104
) {
105105
}
106106

107-
#[no_mangle]
107+
#[unsafe(no_mangle)]
108108
pub extern "C" fn rust_on_core_map_end() {}
109109
};
110110
}

extshared_build_helper/src/lib.rs

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ use vergen_gitcl::BuildBuilder;
2020
use vergen_gitcl::Emitter;
2121
use vergen_gitcl::GitclBuilder;
2222

23+
static SRCWRTIMER_ROOT_DIR: std::sync::LazyLock<String> = std::sync::LazyLock::new(|| {
24+
std::env::var("SRCWRTIMER_ROOT_DIR").unwrap()
25+
});
26+
2327
pub fn generate_inc_defines_and_enums(outdir: &str, incfile: &str, name: &str) {
2428
println!("cargo:rerun-if-changed={}", incfile);
2529
let content = std::fs::read_to_string(incfile).unwrap();
@@ -53,29 +57,23 @@ pub {}\n",
5357
std::fs::write(format!("{}/{}_DEFINES.rs", outdir, name), defines).unwrap();
5458
}
5559

56-
pub fn use_atcprintf(build: &mut cc::Build) -> &mut cc::Build {
57-
println!("cargo:rerun-if-changed=../extshared/src/sprintf.cpp");
58-
build.file("../extshared/src/sprintf.cpp")
60+
pub fn use_atcprintf(build: &mut cc::Build) {
61+
slurp_single_file(build, &format!("{}/extshared/src/sprintf.cpp", *SRCWRTIMER_ROOT_DIR));
5962
}
6063

61-
pub fn use_cellarray(build: &mut cc::Build) -> &mut cc::Build {
62-
println!("cargo:rerun-if-changed=../extshared/src/ICellArray.cpp");
63-
build
64-
.define("HANDLE_CELLARRAY", None)
65-
.file("../extshared/src/ICellArray.cpp")
64+
pub fn use_cellarray(build: &mut cc::Build) {
65+
build.define("HANDLE_CELLARRAY", None);
66+
slurp_single_file(build, &format!("{}/extshared/src/ICellArray.cpp", *SRCWRTIMER_ROOT_DIR));
6667
}
6768

68-
pub fn use_fileobject(build: &mut cc::Build) -> &mut cc::Build {
69-
println!("cargo:rerun-if-changed=../extshared/src/IFileObject.cpp");
70-
println!("cargo:rerun-if-changed=../extshared/src/IFileObject.hpp");
71-
build
72-
.define("HANDLE_FILEOBJECT", None)
73-
.file("../extshared/src/IFileObject.cpp")
69+
pub fn use_fileobject(build: &mut cc::Build) {
70+
build.define("HANDLE_FILEOBJECT", None);
71+
slurp_single_file(build, &format!("{}/extshared/src/IFileObject.cpp", *SRCWRTIMER_ROOT_DIR));
72+
slurp_single_file(build, &format!("{}/extshared/src/IFileObject.hpp", *SRCWRTIMER_ROOT_DIR));
7473
}
7574

76-
pub fn use_valvefs(build: &mut cc::Build) -> &mut cc::Build {
77-
println!("cargo:rerun-if-changed=../extshared/src/valvefs.cpp");
78-
build.file("../extshared/src/valvefs.cpp")
75+
pub fn use_valvefs(build: &mut cc::Build) {
76+
slurp_single_file(build, &format!("{}/extshared/src/valvefs.cpp", *SRCWRTIMER_ROOT_DIR));
7977
}
8078

8179
pub fn compile_lib(build: cc::Build, name: &str) {
@@ -142,7 +140,7 @@ pub fn smext_tf2(build: &mut cc::Build) {
142140
// https://github.com/alliedmodders/sourcemod/blob/master/public/sample_ext/AMBuildScript
143141
pub fn smext_hl2sdk_for_good_games(build: &mut cc::Build, sdk_name: &str, sdk_id: usize) {
144142
let sdk_path = std::env::var("HL2SDK")
145-
.unwrap_or(format!("../_external/alliedmodders/hl2sdk-{}", sdk_name));
143+
.unwrap_or(format!("{}/_external/alliedmodders/hl2sdk-{}", *SRCWRTIMER_ROOT_DIR, sdk_name));
146144

147145
let like_msvc = build.get_compiler().is_like_msvc();
148146
let target_windows = std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows";
@@ -196,7 +194,7 @@ pub fn smext_hl2sdk_for_good_games(build: &mut cc::Build, sdk_name: &str, sdk_id
196194
// This is necessary because the CC compiler (zig cc) throws errors about using C++ standards via .std() when compiling C files.... frick....
197195
pub fn link_sm_detours(mainbuild: &mut cc::Build) {
198196
let sm =
199-
std::env::var("SOURCEMOD").unwrap_or("../_external/alliedmodders/sourcemod".to_string());
197+
std::env::var("SOURCEMOD").unwrap_or(format!("{}/_external/alliedmodders/sourcemod", *SRCWRTIMER_ROOT_DIR));
200198
//let target_windows = std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows";
201199
let like_msvc = mainbuild.get_compiler().is_like_msvc();
202200

@@ -259,16 +257,16 @@ pub fn smext_build() -> cc::Build {
259257
.unwrap();
260258

261259
let sm =
262-
std::env::var("SOURCEMOD").unwrap_or("../_external/alliedmodders/sourcemod".to_string());
263-
let mm = std::env::var("METAMOD").unwrap_or("../_external/alliedmodders/mmsource".to_string());
260+
std::env::var("SOURCEMOD").unwrap_or(format!("{}/_external/alliedmodders/sourcemod", *SRCWRTIMER_ROOT_DIR));
261+
let mm = std::env::var("METAMOD").unwrap_or(format!("{}/_external/alliedmodders/mmsource", *SRCWRTIMER_ROOT_DIR));
264262

265-
println!("cargo:rerun-if-changed=../extshared/src/coreident.cpp");
266-
println!("cargo:rerun-if-changed=../extshared/src/coreident.hpp");
267-
println!("cargo:rerun-if-changed=../extshared/src/extension.cpp");
268-
println!("cargo:rerun-if-changed=../extshared/src/extension.h");
269-
println!("cargo:rerun-if-changed=../extshared/src/rust_exports.h");
270-
println!("cargo:rerun-if-changed=../extshared/src/smsdk_config.h");
271-
//rerun_on_dir_cc_files_changed("../extshared/src");
263+
println!("cargo:rerun-if-changed={}/extshared/src/coreident.cpp", *SRCWRTIMER_ROOT_DIR);
264+
println!("cargo:rerun-if-changed={}/extshared/src/coreident.hpp", *SRCWRTIMER_ROOT_DIR);
265+
println!("cargo:rerun-if-changed={}/extshared/src/extension.cpp", *SRCWRTIMER_ROOT_DIR);
266+
println!("cargo:rerun-if-changed={}/extshared/src/extension.h", *SRCWRTIMER_ROOT_DIR);
267+
println!("cargo:rerun-if-changed={}/extshared/src/rust_exports.h", *SRCWRTIMER_ROOT_DIR);
268+
println!("cargo:rerun-if-changed={}/extshared/src/smsdk_config.h", *SRCWRTIMER_ROOT_DIR);
269+
//rerun_on_dir_cc_files_changed("{}/extshared/src", *SRCWRTIMER_ROOT_DIR);
272270

273271
let mut build = cc::Build::new();
274272
let like_msvc = build.get_compiler().is_like_msvc();
@@ -284,9 +282,9 @@ pub fn smext_build() -> cc::Build {
284282
.include(format!("{}/public/amtl", sm))
285283
.include(format!("{}/core", mm))
286284
.include(format!("{}/core/sourcehook", mm))
287-
.include("../extshared/src")
288-
.file("../extshared/src/coreident.cpp")
289-
.file("../extshared/src/extension.cpp")
285+
.include(format!("{}/extshared/src", *SRCWRTIMER_ROOT_DIR))
286+
.file(format!("{}/extshared/src/coreident.cpp", *SRCWRTIMER_ROOT_DIR))
287+
.file(format!("{}/extshared/src/extension.cpp", *SRCWRTIMER_ROOT_DIR))
290288
.file(format!("{}/public/smsdk_ext.cpp", sm))
291289
.cpp(true)
292290
.static_crt(true);

smbz2/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ repository.workspace = true
1212
crate-type = ["cdylib"]
1313

1414
[build-dependencies]
15-
extshared_build_helper = { path = "../extshared_build_helper" }
15+
extshared_build_helper.workspace = true
1616

1717
[dependencies]
18-
extshared = { path = "../extshared" }
18+
extshared.workspace = true
1919
#bzip2 = { git = "https://github.com/srcwr/bzip2-rs.git", rev = "bd66f7c", features=["static"] }
2020
bzip2 = { version = "0.5", default-features = false, features = ["libbz2-rs-sys"] }

srcwrf64/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ repository.workspace = true
1212
crate-type = ["cdylib"]
1313

1414
[build-dependencies]
15-
extshared_build_helper = { path = "../extshared_build_helper" }
15+
extshared_build_helper.workspace = true
1616

1717
[dependencies]
18-
extshared = { path = "../extshared" }
18+
extshared.workspace = true
1919
ryu = "1.0"

0 commit comments

Comments
 (0)