Skip to content

Commit

Permalink
Merge upstream into current-bee
Browse files Browse the repository at this point in the history
  • Loading branch information
Crossedfall committed Mar 7, 2021
2 parents 07dcb14 + 48ed995 commit 61624c0
Show file tree
Hide file tree
Showing 22 changed files with 253 additions and 67 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.dm]
indent_style = tab
58 changes: 49 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 17 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "rust-g"
edition = "2018"
version = "0.4.6"
version = "0.4.7"
authors = ["Bjorn Neergaard <[email protected]>"]
repository = "https://github.com/tgstation/rust-g"
license-file = "LICENSE"
Expand All @@ -20,6 +20,8 @@ thiserror = "1.0"
flume = { version = "0.9", optional = true }
chrono = { version = "0.4", optional = true }
md-5 = { version = "0.9", optional = true }
twox-hash = { version = "1.6.0", optional = true }
const-random = { version = "0.1.13", optional = true }
sha-1 = { version = "0.9", optional = true }
sha2 = { version = "0.9", optional = true }
hex = { version = "0.4", optional = true }
Expand All @@ -37,18 +39,26 @@ once_cell = { version = "1.4", optional = true }
mysql = { version = "20.0", optional = true }
dashmap = { version = "3.11", optional = true }
zip = { version = "0.5.8", optional = true }
rand = {version = "0.7", optional = true}


[features]
default = ["dmi", "log", "git", "http", "json", "sql", "noise"]
default = ["cellularnoise", "dmi", "file", "git", "http", "json", "log", "noise", "sql"]

# default features
cellularnoise = ["rand"]
dmi = ["png", "image"]
file = []
hash = ["md-5", "sha-1", "sha2", "hex"]
json = ["serde", "serde_json"]
log = ["chrono"]
url = ["url-dep", "percent-encoding"]
git = ["git2", "chrono"]
http = ["reqwest", "serde", "serde_json", "once_cell", "jobs"]
json = ["serde", "serde_json"]
log = ["chrono"]
sql = ["mysql", "serde", "serde_json", "once_cell", "dashmap", "jobs"]
jobs = ["flume"]

# non-default features
hash = ["md-5", "sha-1", "sha2", "hex", "twox-hash", "const-random"]
url = ["url-dep", "percent-encoding"]
unzip = ["zip", "jobs"]

# internal feature-like things
jobs = ["flume"]
42 changes: 19 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,49 +52,46 @@ System libraries:
sudo apt-get install zlib1g-dev:i386 libssl-dev:i386 pkg-config:i386
```

* Other distributions install the appropriate **32-bit development** and **32-bit runtime** packages.
* Other Linux distributions install the appropriate **32-bit development** and **32-bit runtime** packages.

## Compiling

The [cargo] tool handles compilation, as well as automatically downloading and
The [Cargo] tool handles compilation, as well as automatically downloading and
compiling all Rust dependencies. The default configuration is suitable for
use with the [tgstation] codebase, but not [beestation]. To compile in release mode:

Linux:
```sh
# Linux
cargo build --release --target=i686-unknown-linux-gnu
# Windows
cargo build --release --target=i686-pc-windows-msvc
export PKG_CONFIG_ALLOW_CROSS=1
cargo build --release --target i686-unknown-linux-gnu
# output: target/i686-unknown-linux-gnu/release/librust_g.so
```

On Linux, the output will be `target/release/librust_g.so`.

On Windows, the output will be `target/release/rust_g.dll`.

For more advanced configuration, a list of modules may be passed:
Windows:

```sh
export PKG_CONFIG_ALLOW_CROSS=1
# Linux
cargo build --release --target=i686-unknown-linux-gnu --features dmi,file,log,url,http,noise,json
# Windows
cargo build --release --target=i686-pc-windows-msvc --features dmi,file,log,url,http,noise,json
cargo build --release --target i686-pc-windows-msvc
# output: target/i686-pc-windows-msvc/release/rust_g.dll
```

To get additional features, pass a list to `--features`, for example `--features hash,url`. To get all features, pass `--all-features`. To disable the default features, pass `--no-default-features`.

The default features are:
* log: Faster log output.
* cellularnoise: Function to generate cellular automata-based noise.
* dmi: DMI manipulations which are impossible from within BYOND.
Used by the asset cache subsystem to improve load times.
* file: Faster replacements for `file2text` and `text2file`, as well as reading or checking if files exist.
* git: Functions for robustly checking the current git revision.
* http: Asynchronous HTTP(s) client supporting most standard methods.
* json: Function to check JSON validity.
* log: Faster log output.
* sql: Asynchronous MySQL/MariaDB client library.
* noise: 2d Perlin noise.
* json: Function to check JSON validity.

Additional features are:
* url: Faster replacements for `url_encode` and `url_decode`.
* file: Faster replacements for `file2text` and `text2file`, as well as reading or checking if files exist.
* hash: Faster replacement for `md5`, support for SHA-1, SHA-256, and SHA-512. Requires OpenSSL on Linux.
* url: Faster replacements for `url_encode` and `url_decode`.
* unzip: Function to download a .zip from a URL and unzip it to a directory.

## Installing

Expand All @@ -112,7 +109,6 @@ at the top of `rust_g.dm` for details.

You must build a 32-bit version of the library for it to be compatible with
BYOND. Attempting to build a 64-bit version will fail with an explanatory error.
Use the `rustup override add` command described above or build with `--target`.

### Linux

Expand Down Expand Up @@ -169,9 +165,9 @@ If you're still having problems, ask in the [Coderbus Discord]'s
`#tooling-questions` channel.

[tgstation]: https://github.com/tgstation/tgstation
[ beestation ]: https://github.com/beestation/beestation-hornet
[beestation]: https://github.com/beestation/beestation-hornet
[Rust]: https://rust-lang.org
[cargo]: https://doc.rust-lang.org/cargo/
[Cargo]: https://doc.rust-lang.org/cargo/
[rustup]: https://rustup.rs/
[msvc]: https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools&rel=15
[Coderbus Discord]: https://discord.gg/Vh8TJp9
Expand Down
15 changes: 15 additions & 0 deletions dmsrc/cellularnoise.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* This proc generates a cellular automata noise grid which can be used in procedural generation methods.
*
* Returns a single string that goes row by row, with values of 1 representing an alive cell, and a value of 0 representing a dead cell.
*
* Arguments:
* * percentage: The chance of a turf starting closed
* * smoothing_iterations: The amount of iterations the cellular automata simulates before returning the results
* * birth_limit: If the number of neighboring cells is higher than this amount, a cell is born
* * death_limit: If the number of neighboring cells is lower than this amount, a cell dies
* * width: The width of the grid.
* * height: The height of the grid.
*/
#define rustg_cnoise_generate(percentage, smoothing_iterations, birth_limit, death_limit, width, height) \
call(RUST_G, "cnoise_generate")(percentage, smoothing_iterations, birth_limit, death_limit, width, height)
6 changes: 3 additions & 3 deletions dmsrc/dmi.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#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)
#define rustg_dmi_resize_png(path, width, height, resizetype) call(RUST_G, "dmi_resize_png")(path, width, height, resizetype)
#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)
#define rustg_dmi_resize_png(path, width, height, resizetype) call(RUST_G, "dmi_resize_png")(path, width, height, resizetype)
6 changes: 3 additions & 3 deletions dmsrc/file.dm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
#define rustg_file_append(text, fname) call(RUST_G, "file_append")(text, fname)

#ifdef RUSTG_OVERRIDE_BUILTINS
#define file2text(fname) rustg_file_read("[fname]")
#define text2file(text, fname) rustg_file_append(text, "[fname]")
#endif
#define file2text(fname) rustg_file_read("[fname]")
#define text2file(text, fname) rustg_file_append(text, "[fname]")
#endif
4 changes: 2 additions & 2 deletions dmsrc/git.dm
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#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)
#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)
5 changes: 3 additions & 2 deletions dmsrc/hash.dm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#define RUSTG_HASH_SHA1 "sha1"
#define RUSTG_HASH_SHA256 "sha256"
#define RUSTG_HASH_SHA512 "sha512"
#define RUSTG_HASH_XXH64 "xxh64"

#ifdef RUSTG_OVERRIDE_BUILTINS
#define md5(thing) (isfile(thing) ? rustg_hash_file(RUSTG_HASH_MD5, "[thing]") : rustg_hash_string(RUSTG_HASH_MD5, thing))
#endif
#define md5(thing) (isfile(thing) ? rustg_hash_file(RUSTG_HASH_MD5, "[thing]") : rustg_hash_string(RUSTG_HASH_MD5, thing))
#endif
6 changes: 3 additions & 3 deletions dmsrc/http.dm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
#define RUSTG_HTTP_METHOD_PATCH "patch"
#define RUSTG_HTTP_METHOD_HEAD "head"
#define RUSTG_HTTP_METHOD_POST "post"
#define rustg_http_request_blocking(method, url, body, headers) call(RUST_G, "http_request_blocking")(method, url, body, headers)
#define rustg_http_request_async(method, url, body, headers) call(RUST_G, "http_request_async")(method, url, body, headers)
#define rustg_http_check_request(req_id) call(RUST_G, "http_check_request")(req_id)
#define rustg_http_request_blocking(method, url, body, headers, options) call(RUST_G, "http_request_blocking")(method, url, body, headers, options)
#define rustg_http_request_async(method, url, body, headers, options) call(RUST_G, "http_request_async")(method, url, body, headers, options)
#define rustg_http_check_request(req_id) call(RUST_G, "http_check_request")(req_id)
6 changes: 3 additions & 3 deletions dmsrc/jobs.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#define RUSTG_JOB_NO_RESULTS_YET "NO RESULTS YET"
#define RUSTG_JOB_NO_SUCH_JOB "NO SUCH JOB"
#define RUSTG_JOB_ERROR "JOB PANICKED"
#define RUSTG_JOB_NO_RESULTS_YET "NO RESULTS YET"
#define RUSTG_JOB_NO_SUCH_JOB "NO SUCH JOB"
#define RUSTG_JOB_ERROR "JOB PANICKED"
2 changes: 1 addition & 1 deletion dmsrc/json.dm
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define rustg_json_is_valid(text) (call(RUST_G, "json_is_valid")(text) == "true")
#define rustg_json_is_valid(text) (call(RUST_G, "json_is_valid")(text) == "true")
4 changes: 2 additions & 2 deletions dmsrc/log.dm
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define rustg_log_write(fname, text, format) call(RUST_G, "log_write")(fname, text, format)
/proc/rustg_log_close_all() return call(RUST_G, "log_close_all")()
#define rustg_log_write(fname, text, format) call(RUST_G, "log_write")(fname, text, format)
/proc/rustg_log_close_all() return call(RUST_G, "log_close_all")()
2 changes: 1 addition & 1 deletion dmsrc/main.dm
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
return __rust_g = "rust_g"

#define RUST_G (__rust_g || __detect_rust_g())
#endif
#endif
2 changes: 1 addition & 1 deletion dmsrc/noise.dm
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define rustg_noise_get_at_coordinates(seed, x, y) call(RUST_G, "noise_get_at_coordinates")(seed, x, y)
#define rustg_noise_get_at_coordinates(seed, x, y) call(RUST_G, "noise_get_at_coordinates")(seed, x, y)
2 changes: 1 addition & 1 deletion dmsrc/sql.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
#define rustg_sql_query_blocking(handle, query, params) call(RUST_G, "sql_query_blocking")(handle, query, params)
#define rustg_sql_connected(handle) call(RUST_G, "sql_connected")(handle)
#define rustg_sql_disconnect_pool(handle) call(RUST_G, "sql_disconnect_pool")(handle)
#define rustg_sql_check_query(job_id) call(RUST_G, "sql_check_query")("[job_id]")
#define rustg_sql_check_query(job_id) call(RUST_G, "sql_check_query")("[job_id]")
2 changes: 1 addition & 1 deletion dmsrc/unzip.dm
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define rustg_unzip_download_async(url, unzip_directory) call(RUST_G, "unzip_download_async")(url, unzip_directory)
#define rustg_unzip_check(job_id) call(RUST_G, "unzip_check")("[job_id]")
#define rustg_unzip_check(job_id) call(RUST_G, "unzip_check")("[job_id]")
Loading

0 comments on commit 61624c0

Please sign in to comment.