diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index c66e5c20b99ca..95135294ccd48 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -27,6 +27,11 @@ rustlibs.dll @AffectedArc07 rustlibs_prod.dll @AffectedArc07 rust_g.dll @AffectedArc07 +# temp executables because life is pain +rustlibs_515.dll @AffectedArc07 +rustlibs_516.dll @AffectedArc07 +rustlibs_515_prod.dll @AffectedArc07 +rustlibs_516_prod.dll @AffectedArc07 ### S34NW # TGUI stuff diff --git a/.github/workflows/build_rust.yml b/.github/workflows/build_rust.yml index de2c3208b0f83..3f8c690054ef9 100644 --- a/.github/workflows/build_rust.yml +++ b/.github/workflows/build_rust.yml @@ -65,7 +65,6 @@ jobs: git pull origin "$PR_BRANCH" --depth=$((ahead_by + 1)) git remote add upstream "https://github.com/$BASE_REPOSITORY.git" git fetch upstream "$BASE_BRANCH" --depth=$((behind_by + 1)) - cd rust # Get dependencies. rustup target add i686-unknown-linux-gnu @@ -74,18 +73,10 @@ jobs: sudo apt-get update sudo apt-get install zlib1g-dev:i386 lib32gcc-13-dev mingw-w64 mingw-w64-i686-dev - # Build it. - cargo build --release --target i686-unknown-linux-gnu - cargo build --release --target i686-pc-windows-gnu - - # Copy the built targets to their checked-in locations. - cp target/i686-unknown-linux-gnu/release/librustlibs.so ../tools/ci/librustlibs_ci.so - cp target/i686-pc-windows-gnu/release/rustlibs.dll ../rustlibs.dll - - # Build the para-specific version - RUSTFLAGS='-C target-cpu=znver5' cargo build --release --target=i686-pc-windows-gnu - cp target/i686-pc-windows-gnu/release/rustlibs.dll ../rustlibs_prod.dll + # Run the build + tools/ci/build_all_rustlibs.sh + # And commit git commit -a -m "Build Rust library" --allow-empty git push origin diff --git a/_build_dependencies.sh b/_build_dependencies.sh index 7d1eb5a143724..79b52e1303ed0 100644 --- a/_build_dependencies.sh +++ b/_build_dependencies.sh @@ -10,7 +10,7 @@ export STABLE_BYOND_MINOR=1633 # Beta Byond Major - Uncomment and update if beta cycle active export BETA_BYOND_MAJOR=516 # Beta Byond Minor - Uncomment and update if beta cycle active -export BETA_BYOND_MINOR=1648 +export BETA_BYOND_MINOR=1657 # Python version for mapmerge and other tools export PYTHON_VERSION=3.11.6 # RUSTG version diff --git a/code/__DEFINES/rust.dm b/code/__DEFINES/rust.dm index a78d48c341f2b..7d0e52c8fa4cc 100644 --- a/code/__DEFINES/rust.dm +++ b/code/__DEFINES/rust.dm @@ -18,13 +18,18 @@ #endif /proc/__detect_rustlib() + var/version_suffix = "515" + if(world.byond_build >= 1651) + version_suffix = "516" + if(world.system_type == UNIX) #ifdef CIBUILDING // CI override, use librustlibs_ci.so if possible. - if(fexists("./tools/ci/librustlibs_ci.so")) - return __rustlib = "tools/ci/librustlibs_ci.so" + if(fexists("./tools/ci/librustlibs_ci_[version_suffix].so")) + return __rustlib = "tools/ci/librustlibs_ci_[version_suffix].so" #endif // First check if it's built in the usual place. + // Linx doesnt get the version suffix because if youre using linux you can figure out what server version youre running for if(fexists("./rust/target/i686-unknown-linux-gnu/release/librustlibs[RUSTLIBS_SUFFIX].so")) return __rustlib = "./rust/target/i686-unknown-linux-gnu/release/librustlibs[RUSTLIBS_SUFFIX].so" // Then check in the current directory. @@ -34,14 +39,14 @@ return __rustlib = "librustlibs[RUSTLIBS_SUFFIX].so" else // First check if it's built in the usual place. - if(fexists("./rust/target/i686-pc-windows-msvc/release/rustlibs[RUSTLIBS_SUFFIX].dll")) - return __rustlib = "./rust/target/i686-pc-windows-msvc/release/rustlibs[RUSTLIBS_SUFFIX].dll" + if(fexists("./rust/target/i686-pc-windows-msvc/release/rustlibs.dll")) + return __rustlib = "./rust/target/i686-pc-windows-msvc/release/rustlibs.dll" // Then check in the current directory. - if(fexists("./rustlibs[RUSTLIBS_SUFFIX].dll")) - return __rustlib = "./rustlibs[RUSTLIBS_SUFFIX].dll" + if(fexists("./rustlibs_[version_suffix][RUSTLIBS_SUFFIX].dll")) + return __rustlib = "./rustlibs_[version_suffix][RUSTLIBS_SUFFIX].dll" // And elsewhere. - var/assignment_confirmed = (__rustlib = "rustlibs[RUSTLIBS_SUFFIX].dll") + var/assignment_confirmed = (__rustlib = "rustlibs_[version_suffix][RUSTLIBS_SUFFIX].dll") // This being spanned over multiple lines is kinda scuffed, but its needed because of https://www.byond.com/forum/post/2072419 return assignment_confirmed diff --git a/rust/.cargo/config.toml b/rust/.cargo/config.toml new file mode 100644 index 0000000000000..93801863ce650 --- /dev/null +++ b/rust/.cargo/config.toml @@ -0,0 +1,2 @@ +[build] +target = "i686-pc-windows-msvc" diff --git a/rust/Cargo.lock b/rust/Cargo.lock index ffbbc755eface..e3df62388fa9d 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -93,9 +93,9 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bindgen" -version = "0.70.1" +version = "0.71.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f49d8fed880d473ea71efb9bf597651e77201bdd4893efe54c9e5d65ae04ce6f" +checksum = "5f58bf3d7db68cfbac37cfc485a8d711e87e064c3d0fe0435b92f7a407f9d6b3" dependencies = [ "bitflags 2.5.0", "cexpr", @@ -141,8 +141,8 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "byondapi" -version = "0.4.11" -source = "git+https://github.com/spacestation13/byondapi-rs.git#c3b15e8574eca87865c640616029e6ea72da4cd1" +version = "0.5.14" +source = "git+https://github.com/spacestation13/byondapi-rs.git#299384dd1f7ceadd9759fe205de02a629193bf79" dependencies = [ "byondapi-macros", "byondapi-sys", @@ -153,8 +153,8 @@ dependencies = [ [[package]] name = "byondapi-macros" -version = "0.1.3" -source = "git+https://github.com/spacestation13/byondapi-rs.git#c3b15e8574eca87865c640616029e6ea72da4cd1" +version = "0.2.3" +source = "git+https://github.com/spacestation13/byondapi-rs.git#299384dd1f7ceadd9759fe205de02a629193bf79" dependencies = [ "proc-macro2", "quote", @@ -163,8 +163,8 @@ dependencies = [ [[package]] name = "byondapi-sys" -version = "0.11.2" -source = "git+https://github.com/spacestation13/byondapi-rs.git#c3b15e8574eca87865c640616029e6ea72da4cd1" +version = "0.12.3" +source = "git+https://github.com/spacestation13/byondapi-rs.git#299384dd1f7ceadd9759fe205de02a629193bf79" dependencies = [ "bindgen", "doxygen-rs", @@ -517,9 +517,12 @@ source = "git+https://github.com/SpaceManiac/SpacemanDMM?rev=6c5a751516ae0e8add4 [[package]] name = "inventory" -version = "0.3.15" +version = "0.3.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f958d3d68f4167080a18141e10381e7634563984a537f2a49a30fd8e53ac5767" +checksum = "ab08d7cd2c5897f2c949e5383ea7c7db03fb19130ffcfbf7eda795137ae3cb83" +dependencies = [ + "rustversion", +] [[package]] name = "itertools" @@ -930,9 +933,9 @@ dependencies = [ [[package]] name = "rustc-hash" -version = "1.1.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" [[package]] name = "rustlibs" diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 77be2902dbb9d..5ab9f163e6aa7 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -11,7 +11,7 @@ crate-type = ["cdylib"] [dependencies] atomic_float = "1.0.0" bitflags = "2.5.0" -byondapi = { git = "https://github.com/spacestation13/byondapi-rs.git", version = "0.4.7" } +byondapi = { git = "https://github.com/spacestation13/byondapi-rs.git", version = "0.5.14", default-features = false } eyre = "0.6.12" rand = { version = "0.8.5", features = ["small_rng"] } scc = "2.1.1" @@ -35,3 +35,8 @@ walkdir = "2.5.0" regex = "1.10.5" png = "0.17.16" chrono = "0.4.39" + +[features] +default = ["byond-515"] +byond-515 = ["byondapi/byond-515-1621"] +byond-516 = ["byondapi/byond-516-1651"] diff --git a/rust/README.MD b/rust/README.MD new file mode 100644 index 0000000000000..c3a5c733b77f0 --- /dev/null +++ b/rust/README.MD @@ -0,0 +1,16 @@ +# Paradise Rust Libraries + +## Info + +These libraries allow rust code for things that are incredibly slow or outright impossible in DM. +Think of it like a ParadiseSS13 specifiy version of [rust-g](https://github.com/tgstation/rust-g). + +It currently handles: + +- Atmospherics (`milla`) +- DMM manipulation stuff (`mapmanip`) + +## Building + +BYOND 516.1651 introduced breaking changes to ByondAPI, the interop system to get data other than strings in and out of DLLs. +Because of this, you need to specify the `--no-default-features --features byond-516` to build the 516 compliant lib. Not specifying a feature will build for versions `515.1621` to `516.1650`. Specifying `byond-516` will build for `516.1651` and up. diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 66ed4b0b1bbb4..aad7a1b1b2b0a 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -1,3 +1,11 @@ mod logging; mod mapmanip; mod milla; + +#[cfg(all(not(feature = "byond-515"), not(feature = "byond-516")))] +compile_error!("Please specify byond-515 or byond-516 as a feature to specify BYOND version."); + +#[cfg(all(feature = "byond-515", feature = "byond-516"))] +compile_error!( + "Please specify ONLY byond-515 or bypnd-516 as a feature to specify BYOND version, not all features." +); diff --git a/rust/src/milla/api.rs b/rust/src/milla/api.rs index a92b648732eb4..cfd7eb5d8f427 100644 --- a/rust/src/milla/api.rs +++ b/rust/src/milla/api.rs @@ -100,15 +100,29 @@ pub(crate) fn internal_create_environment( /// BYOND API for loading a block of turfs into MILLA with their default air. #[byondapi::bind] -fn milla_load_turfs(data_property: ByondValue, low_corner: ByondValue, high_corner: ByondValue) -> eyre::Result { +fn milla_load_turfs( + data_property: ByondValue, + low_corner: ByondValue, + high_corner: ByondValue, +) -> eyre::Result { let property_ref = data_property.get_strid()?; for turf in byond_block(byond_xyz(&low_corner)?, byond_xyz(&high_corner)?)? { let (x, y, z) = byond_xyz(&turf)?.coordinates(); let mut property = turf.read_var_id(property_ref)?; let data = property.get_list_values()?; + + #[cfg(feature = "byond-516")] + property.decrement_tempref(); + + #[cfg(feature = "byond-515")] property.decrement_ref(); + if data.len() != 17 { - return Err(eyre!("data property has the wrong length: {} vs {}", data.len(), 17)); + return Err(eyre!( + "data property has the wrong length: {} vs {}", + data.len(), + 17 + )); } internal_set_tile( diff --git a/rustlibs.dll b/rustlibs_515.dll similarity index 50% rename from rustlibs.dll rename to rustlibs_515.dll index 02988d613277f..2c65bedafeb2d 100644 Binary files a/rustlibs.dll and b/rustlibs_515.dll differ diff --git a/rustlibs_prod.dll b/rustlibs_515_prod.dll similarity index 50% rename from rustlibs_prod.dll rename to rustlibs_515_prod.dll index c48f9c15bf8ae..3b855a32789e4 100644 Binary files a/rustlibs_prod.dll and b/rustlibs_515_prod.dll differ diff --git a/rustlibs_516.dll b/rustlibs_516.dll new file mode 100644 index 0000000000000..aa2deb2a58d9c Binary files /dev/null and b/rustlibs_516.dll differ diff --git a/rustlibs_516_prod.dll b/rustlibs_516_prod.dll new file mode 100644 index 0000000000000..c04c533f9e920 Binary files /dev/null and b/rustlibs_516_prod.dll differ diff --git a/tools/ci/build_all_rustlibs.sh b/tools/ci/build_all_rustlibs.sh new file mode 100755 index 0000000000000..de533ea46c73d --- /dev/null +++ b/tools/ci/build_all_rustlibs.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# Make is fail early if theres a problem +set -euo pipefail + +# Get to our folder first +cd rust + +WINDOWS_TARGET="i686-pc-windows-gnu" +LINUX_TARGET="i686-unknown-linux-gnu" + +# Handle building on windows +if [[ "$OSTYPE" == "msys" ]]; then + WINDOWS_TARGET="i686-pc-windows-msvc" +fi + +# Build it for CI +cargo build --release --target $LINUX_TARGET +cp target/$LINUX_TARGET/release/librustlibs.so ../tools/ci/librustlibs_ci_515.so +cargo clean +cargo build --release --target $LINUX_TARGET --no-default-features --features byond-516 +cp target/$LINUX_TARGET/release/librustlibs.so ../tools/ci/librustlibs_ci_516.so + +# Build it for Windows +cargo build --release --target $WINDOWS_TARGET +cp target/$WINDOWS_TARGET/release/rustlibs.dll ../rustlibs_515.dll +cargo clean +cargo build --release --target $WINDOWS_TARGET --no-default-features --features byond-516 +cp target/$WINDOWS_TARGET/release/rustlibs.dll ../rustlibs_516.dll + +# Build the para-specific version +export RUSTFLAGS='-C target-cpu=znver5' +cargo build --release --target=$WINDOWS_TARGET +cp target/$WINDOWS_TARGET/release/rustlibs.dll ../rustlibs_515_prod.dll +cargo clean +cargo build --release --target=$WINDOWS_TARGET --no-default-features --features byond-516 +cp target/$WINDOWS_TARGET/release/rustlibs.dll ../rustlibs_516_prod.dll diff --git a/tools/ci/librustlibs_ci.so b/tools/ci/librustlibs_ci.so deleted file mode 100644 index 53ebaa7bc58ea..0000000000000 Binary files a/tools/ci/librustlibs_ci.so and /dev/null differ diff --git a/tools/ci/librustlibs_ci_515.so b/tools/ci/librustlibs_ci_515.so new file mode 100644 index 0000000000000..b7b4069ac3363 Binary files /dev/null and b/tools/ci/librustlibs_ci_515.so differ diff --git a/tools/ci/librustlibs_ci_516.so b/tools/ci/librustlibs_ci_516.so new file mode 100644 index 0000000000000..ccab9f88c2790 Binary files /dev/null and b/tools/ci/librustlibs_ci_516.so differ