diff --git a/Cargo.lock b/Cargo.lock index a7c9884b..efe1f951 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1575,7 +1575,7 @@ dependencies = [ [[package]] name = "rust-g" -version = "0.4.5-P" +version = "0.4.5-P2" dependencies = [ "chrono", "crypto-hash", diff --git a/Cargo.toml b/Cargo.toml index d8fe71ce..44d04c41 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rust-g" edition = "2018" -version = "0.4.5-P" +version = "0.4.5-P2" authors = ["Bjorn Neergaard "] repository = "https://github.com/ParadiseSS13/rust-g" license-file = "LICENSE" diff --git a/build.rs b/build.rs index 42c9e75c..e9ece6e9 100644 --- a/build.rs +++ b/build.rs @@ -14,46 +14,15 @@ fn main() { // header write!( f, - r#"// rust_g.dm - DM API for rust_g extension library -// -// To configure, create a `rust_g.config.dm` and set what you care about from -// the following options: -// -// #define RUST_G "path/to/rust_g" -// Override the .dll/.so detection logic with a fixed path or with detection -// logic of your own. -// -// #define RUSTG_OVERRIDE_BUILTINS -// Enable replacement rust-g functions for certain builtins. Off by default. - -#ifndef RUST_G -// Default automatic RUST_G detection. -// On Windows, looks in the standard places for `rust_g.dll`. -// On Linux, looks in `.`, `$LD_LIBRARY_PATH`, and `~/.byond/bin` for either of -// `librust_g.so` (preferred) or `rust_g` (old). - -/* This comment bypasses grep checks */ /var/__rust_g - -/proc/__detect_rust_g() - if (world.system_type == UNIX) - if (fexists("./librust_g.so")) - // No need for LD_LIBRARY_PATH badness. - return __rust_g = "./librust_g.so" - else if (fexists("./rust_g")) - // Old dumb filename. - return __rust_g = "./rust_g" - else if (fexists("[world.GetConfig("env", "HOME")]/.byond/bin/rust_g")) - // Old dumb filename in `~/.byond/bin`. - return __rust_g = "rust_g" - else - // It's not in the current directory, so try others - return __rust_g = "librust_g.so" - else - return __rust_g = "rust_g" - -#define RUST_G (__rust_g || __detect_rust_g()) + r#"#ifndef RUST_G +/// Locator for the RUSTG DLL or SO depending on system type. Override if needed. +#define RUST_G (world.system_type == UNIX ? "./librust_g.so" : "./rust_g.dll") #endif +// Gets the version of RUSTG +/proc/rustg_get_version() return call(RUST_G, "get_version")() + +// Defines for internal job subsystem // #define RUSTG_JOB_NO_RESULTS_YET "NO RESULTS YET" #define RUSTG_JOB_NO_SUCH_JOB "NO SUCH JOB" #define RUSTG_JOB_ERROR "JOB PANICKED" @@ -64,6 +33,7 @@ fn main() { // module: dmi if enabled!("DMI") { write!(f, r#" +// DMI related operations // #define rustg_dmi_strip_metadata(fname) call(RUST_G, "dmi_strip_metadata")(fname) #define rustg_dmi_create_png(path, width, height, data) call(RUST_G, "dmi_create_png")(path, width, height, data) "#).unwrap(); @@ -72,6 +42,7 @@ fn main() { // module: noise if enabled!("NOISE") { write!(f, r#" +// Noise related operations // #define rustg_noise_get_at_coordinates(seed, x, y) call(RUST_G, "noise_get_at_coordinates")(seed, x, y) "#).unwrap() } @@ -81,6 +52,7 @@ fn main() { write!( f, r#" +// File related operations // #define rustg_file_read(fname) call(RUST_G, "file_read")(fname) #define rustg_file_write(text, fname) call(RUST_G, "file_write")(text, fname) #define rustg_file_append(text, fname) call(RUST_G, "file_append")(text, fname) @@ -99,6 +71,7 @@ fn main() { write!( f, r#" +// Git related operations // #define rustg_git_revparse(rev) call(RUST_G, "rg_git_revparse")(rev) #define rustg_git_commit_date(rev) call(RUST_G, "rg_git_commit_date")(rev) "# @@ -109,6 +82,7 @@ fn main() { // module: hash if enabled!("HASH") { write!(f, r#" +// Hash related operations // #define rustg_hash_string(algorithm, text) call(RUST_G, "hash_string")(algorithm, text) #define rustg_hash_file(algorithm, fname) call(RUST_G, "hash_file")(algorithm, fname) @@ -128,7 +102,8 @@ fn main() { write!( f, r#" -#define rustg_log_write(fname, text, format) call(RUST_G, "log_write")(fname, text, format) +// Logging stuff // +#define rustg_log_write(fname, text) call(RUST_G, "log_write")(fname, text) /proc/rustg_log_close_all() return call(RUST_G, "log_close_all")() "# ) @@ -140,6 +115,7 @@ fn main() { write!( f, r#" +// URL encoding stuff #define rustg_url_encode(text) call(RUST_G, "url_encode")(text) #define rustg_url_decode(text) call(RUST_G, "url_decode")(text) @@ -155,6 +131,7 @@ fn main() { // module: http if enabled!("HTTP") { write!(f, r#" +// HTTP library stuff // #define RUSTG_HTTP_METHOD_GET "get" #define RUSTG_HTTP_METHOD_PUT "put" #define RUSTG_HTTP_METHOD_DELETE "delete" @@ -172,6 +149,7 @@ fn main() { // module: sql if enabled!("SQL") { write!(f, r#" +// SQL stuff // #define rustg_sql_connect_pool(options) call(RUST_G, "sql_connect_pool")(options) #define rustg_sql_query_async(handle, query, params) call(RUST_G, "sql_query_async")(handle, query, params) #define rustg_sql_query_blocking(handle, query, params) call(RUST_G, "sql_query_blocking")(handle, query, params) @@ -180,4 +158,10 @@ fn main() { #define rustg_sql_check_query(job_id) call(RUST_G, "sql_check_query")("[job_id]") "#).unwrap(); } + + // Version footer + write!(f, " +// RUSTG Version // +#define RUST_G_VERSION \"{}\"" +, env!("CARGO_PKG_VERSION")).unwrap(); } diff --git a/src/byond.rs b/src/byond.rs index 379386b8..012c165a 100644 --- a/src/byond.rs +++ b/src/byond.rs @@ -75,3 +75,8 @@ macro_rules! byond_fn { } }; } + +// Easy version checker. Its in this file so its included no matter what +byond_fn! { get_version() { + Some(env!("CARGO_PKG_VERSION")) +} } \ No newline at end of file