Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DNM] The most unholy solution to 515 and 516 rustlibs #28590

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 3 additions & 12 deletions .github/workflows/build_rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion _build_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions code/__DEFINES/rust.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions rust/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
target = "i686-pc-windows-msvc"
27 changes: 15 additions & 12 deletions rust/Cargo.lock

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

7 changes: 6 additions & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"]
16 changes: 16 additions & 0 deletions rust/README.MD
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 8 additions & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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."
);
18 changes: 16 additions & 2 deletions rust/src/milla/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ByondValue> {
fn milla_load_turfs(
data_property: ByondValue,
low_corner: ByondValue,
high_corner: ByondValue,
) -> eyre::Result<ByondValue> {
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(
Expand Down
Binary file renamed rustlibs.dll → rustlibs_515.dll
Binary file not shown.
Binary file renamed rustlibs_prod.dll → rustlibs_515_prod.dll
Binary file not shown.
Binary file added rustlibs_516.dll
Binary file not shown.
Binary file added rustlibs_516_prod.dll
Binary file not shown.
37 changes: 37 additions & 0 deletions tools/ci/build_all_rustlibs.sh
Original file line number Diff line number Diff line change
@@ -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
Binary file removed tools/ci/librustlibs_ci.so
Binary file not shown.
Binary file added tools/ci/librustlibs_ci_515.so
Binary file not shown.
Binary file added tools/ci/librustlibs_ci_516.so
Binary file not shown.