diff --git a/bapi.dll b/bapi.dll new file mode 100644 index 00000000000..2e781de7658 Binary files /dev/null and b/bapi.dll differ diff --git a/code/__DEFINES/rust_bapi.dm b/code/__DEFINES/rust_bapi.dm index 0c8bfe9b753..a5fc6e8d55c 100644 --- a/code/__DEFINES/rust_bapi.dm +++ b/code/__DEFINES/rust_bapi.dm @@ -1,9 +1,10 @@ -// Default automatic .dll/.so detection. -// Look for it in the build location first, then in `.`, then in standard places. +// ------------------------------------------- .dll/.so detection +/// Global var set to bapi .dll/.so location. /* This comment bypasses grep checks */ /var/__bapi +/// Look for .dll/.so in the build location first, then in `.`, then in standard places. /proc/__detect_bapi() if(world.system_type == UNIX) #ifdef CIBUILDING @@ -12,17 +13,20 @@ return __bapi = "tools/ci/libbapi_ci.so" #endif // First check if it's built in the usual place. - if(fexists("./bapi/target/i686-unknown-linux-gnu/release/libbapi.so")) - return __bapi = "./bapi/target/i686-unknown-linux-gnu/release/libbapi.so" + if(fexists("./rust/bapi/target/i686-unknown-linux-gnu/release/libbapi.so")) + return __bapi = "./rust/bapi/target/i686-unknown-linux-gnu/release/libbapi.so" // Then check in the current directory. if(fexists("./libbapi.so")) return __bapi = "./libbapi.so" // And elsewhere. return __bapi = "libbapi.so" else - // First check if it's built in the usual place. + // First check if it's built in the usual place when working on it locally. if(fexists("./rust/bapi/target/i686-pc-windows-msvc/release/bapi.dll")) return __bapi = "./rust/bapi/target/i686-pc-windows-msvc/release/bapi.dll" + // Also check the debug location if compiled without optimizations. + if(fexists("./rust/bapi/target/i686-pc-windows-msvc/debug/bapi.dll")) + return __bapi = "./rust/bapi/target/i686-pc-windows-msvc/debug/bapi.dll" // Then check in the current directory. if(fexists("./bapi.dll")) return __bapi = "./bapi.dll" @@ -31,9 +35,11 @@ #define BAPI (__bapi || __detect_bapi()) -#define BAPI_CALL(func, args...) call_ext(BAPI, "byond:[#func]_ffi")(args) +#define BAPI_CALL(func, args...) call_ext(BAPI, "byond:[#func]")(args) -// ----------------------------------------------------------------------- -// ----------------------------------------------------------------------- +// ------------------------------------------- bapi functions callable from dm +// Should only call functions ending with `_ffi`. -#define bapi_hello_world(arg) BAPI_CALL(hello_world, arg) +#define bapi_read_dmm_file(arg) BAPI_CALL(read_dmm_file_ffi, arg) + +// ------------------------------------------- fin diff --git a/code/__HELPERS/stack_trace.dm b/code/__HELPERS/stack_trace.dm index 5c220d7a74a..6dc9bbd5598 100644 --- a/code/__HELPERS/stack_trace.dm +++ b/code/__HELPERS/stack_trace.dm @@ -1,4 +1,5 @@ -/// gives us the stack trace from CRASH() without ending the current proc. +/// Gives us the stack trace from CRASH() without ending the current proc. /// Do not call directly, use the [stack_trace] macro instead. +/// May also be used by other tooling like from rust. /proc/_stack_trace(message, file, line) CRASH("[message] ([file]:[line])") diff --git a/code/modules/maps/reader.dm b/code/modules/maps/reader.dm index 247b49dcc79..faa66bf4e16 100644 --- a/code/modules/maps/reader.dm +++ b/code/modules/maps/reader.dm @@ -50,7 +50,8 @@ GLOBAL_DATUM_INIT(_preloader, /dmm_suite/preloader, new) /dmm_suite/proc/load_map_impl(dmm_file, x_offset, y_offset, z_offset, cropMap, measureOnly, no_changeturf, x_lower = -INFINITY, x_upper = INFINITY, y_lower = -INFINITY, y_upper = INFINITY) var/tfile = dmm_file//the map file we're creating if(isfile(tfile)) - tfile = file2text(tfile) + // tfile = file2text(tfile) + tfile = bapi_read_dmm_file("[tfile]") // `tfile` is of type `File`, this makes it into just a string of its path if(!x_offset) x_offset = 1 diff --git a/html/changelogs/DreamySkrell-bapi-spacemandmm-reading.yml b/html/changelogs/DreamySkrell-bapi-spacemandmm-reading.yml new file mode 100644 index 00000000000..0047aa41b38 --- /dev/null +++ b/html/changelogs/DreamySkrell-bapi-spacemandmm-reading.yml @@ -0,0 +1,13 @@ + +author: DreamySkrell + +# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again. +delete-after: True + +# Any changes you've made. See valid prefix list above. +# INDENT WITH TWO SPACES. NOT TABS. SPACES. +# SCREW THIS UP AND IT WON'T WORK. +# Also, this gets changed to [] after reading. Just remove the brackets when you add new shit. +# Please surround your changes in double quotes ("). It works without them, but if you use certain characters it screws up compiling. The quotes will not show up in the changelog. +changes: + - rscadd: "BAPI - spacemandmm dmm reading." diff --git a/rust/bapi/Cargo.lock b/rust/bapi/Cargo.lock index e0d494d88f1..b471b35fd13 100644 --- a/rust/bapi/Cargo.lock +++ b/rust/bapi/Cargo.lock @@ -2,6 +2,31 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "adler32" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "aho-corasick" version = "1.1.3" @@ -11,11 +36,46 @@ dependencies = [ "memchr", ] +[[package]] +name = "attribute-derive" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c124f12ade4e670107b132722d0ad1a5c9790bcbc1b265336369ea05626b4498" +dependencies = [ + "attribute-derive-macro", + "proc-macro2", + "quote", + "syn 2.0.60", +] + +[[package]] +name = "attribute-derive-macro" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b217a07446e0fb086f83401a98297e2d81492122f5874db5391bd270a185f88" +dependencies = [ + "collection_literals", + "interpolator", + "proc-macro-error", + "proc-macro-utils", + "proc-macro2", + "quote", + "quote-use", + "syn 2.0.60", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + [[package]] name = "bapi" version = "1.0.0" dependencies = [ "byondapi", + "dmm-tools", "eyre", ] @@ -25,7 +85,7 @@ version = "0.69.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" dependencies = [ - "bitflags", + "bitflags 2.5.0", "cexpr", "clang-sys", "itertools", @@ -38,20 +98,42 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn", + "syn 2.0.60", "which", ] +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bitflags" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +[[package]] +name = "builtins-proc-macro" +version = "0.0.0" +source = "git+https://github.com/SpaceManiac/SpacemanDMM?rev=6c5a751516ae0e8add4b2aa4388a1e84e96e7082#6c5a751516ae0e8add4b2aa4388a1e84e96e7082" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + [[package]] name = "byondapi" version = "0.4.4" -source = "git+https://github.com/spacestation13/byondapi-rs.git#5afdd9863a0fc1d8d1d42dd2128c9978f54e12ca" +source = "git+https://github.com/spacestation13/byondapi-rs?rev=5afdd9863a0fc1d8d1d42dd2128c9978f54e12ca#5afdd9863a0fc1d8d1d42dd2128c9978f54e12ca" dependencies = [ "byondapi-macros", "byondapi-sys", @@ -65,17 +147,17 @@ dependencies = [ [[package]] name = "byondapi-macros" version = "0.1.2" -source = "git+https://github.com/spacestation13/byondapi-rs.git#5afdd9863a0fc1d8d1d42dd2128c9978f54e12ca" +source = "git+https://github.com/spacestation13/byondapi-rs?rev=5afdd9863a0fc1d8d1d42dd2128c9978f54e12ca#5afdd9863a0fc1d8d1d42dd2128c9978f54e12ca" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.60", ] [[package]] name = "byondapi-sys" version = "0.11.1" -source = "git+https://github.com/spacestation13/byondapi-rs.git#5afdd9863a0fc1d8d1d42dd2128c9978f54e12ca" +source = "git+https://github.com/spacestation13/byondapi-rs?rev=5afdd9863a0fc1d8d1d42dd2128c9978f54e12ca#5afdd9863a0fc1d8d1d42dd2128c9978f54e12ca" dependencies = [ "bindgen", "doxygen-rs", @@ -84,6 +166,26 @@ dependencies = [ "walkdir", ] +[[package]] +name = "bytemuck" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15" +dependencies = [ + "bytemuck_derive", +] + +[[package]] +name = "bytemuck_derive" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4da9a32f3fed317401fa3c862968128267c3106685286e15d5aaa3d7389c2f60" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.60", +] + [[package]] name = "cexpr" version = "0.6.0" @@ -110,6 +212,66 @@ dependencies = [ "libloading", ] +[[package]] +name = "collection_literals" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "186dce98367766de751c42c4f03970fc60fc012296e706ccbb9d5df9b6c1e271" + +[[package]] +name = "color_space" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3776b2bcc4e914db501bb9be9572dd706e344b9eb8f882894f3daa651d281381" + +[[package]] +name = "crc32fast" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "derive-where" +version = "1.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62d671cc41a825ebabc75757b62d3d168c577f9149b2d49ece1dad1f72119d25" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.60", +] + +[[package]] +name = "dmm-tools" +version = "0.1.0" +source = "git+https://github.com/SpaceManiac/SpacemanDMM?rev=6c5a751516ae0e8add4b2aa4388a1e84e96e7082#6c5a751516ae0e8add4b2aa4388a1e84e96e7082" +dependencies = [ + "ahash", + "bumpalo", + "bytemuck", + "dreammaker", + "either", + "indexmap 1.9.3", + "inflate", + "lodepng", + "ndarray", + "rand", +] + [[package]] name = "doxygen-rs" version = "0.4.2" @@ -119,6 +281,29 @@ dependencies = [ "phf", ] +[[package]] +name = "dreammaker" +version = "0.1.0" +source = "git+https://github.com/SpaceManiac/SpacemanDMM?rev=6c5a751516ae0e8add4b2aa4388a1e84e96e7082#6c5a751516ae0e8add4b2aa4388a1e84e96e7082" +dependencies = [ + "ahash", + "bitflags 1.3.2", + "builtins-proc-macro", + "color_space", + "derivative", + "get-size", + "get-size-derive", + "indexmap 1.9.3", + "interval-tree", + "lodepng", + "ordered-float", + "phf", + "serde", + "serde_derive", + "termcolor", + "toml", +] + [[package]] name = "either" version = "1.11.0" @@ -151,12 +336,74 @@ dependencies = [ "once_cell", ] +[[package]] +name = "fallible_collections" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a88c69768c0a15262df21899142bc6df9b9b823546d4b4b9a7bc2d6c448ec6fd" +dependencies = [ + "hashbrown 0.13.2", +] + +[[package]] +name = "flate2" +version = "1.0.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "get-size" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b61e2dab7eedce93a83ab3468b919873ff16bac5a3e704011ff836d22b2120" + +[[package]] +name = "get-size-derive" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13a1bcfb855c1f340d5913ab542e36f25a1c56f57de79022928297632435dec2" +dependencies = [ + "attribute-derive", + "quote", + "syn 2.0.60", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "glob" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" +dependencies = [ + "ahash", +] + [[package]] name = "hashbrown" version = "0.14.5" @@ -178,6 +425,16 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", +] + [[package]] name = "indexmap" version = "2.2.6" @@ -185,9 +442,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.14.5", ] +[[package]] +name = "inflate" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cdb29978cc5797bd8dcc8e5bf7de604891df2a8dc576973d71a281e916db2ff" +dependencies = [ + "adler32", +] + +[[package]] +name = "interpolator" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71dd52191aae121e8611f1e8dc3e324dd0dd1dee1e6dd91d10ee07a3cfb4d9d8" + +[[package]] +name = "interval-tree" +version = "0.8.0" +source = "git+https://github.com/SpaceManiac/SpacemanDMM?rev=6c5a751516ae0e8add4b2aa4388a1e84e96e7082#6c5a751516ae0e8add4b2aa4388a1e84e96e7082" + [[package]] name = "inventory" version = "0.3.15" @@ -237,12 +514,35 @@ version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" +[[package]] +name = "lodepng" +version = "3.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a42d298694b14401847de29abd44adf278b42e989e516deac7b72018400002d8" +dependencies = [ + "crc32fast", + "fallible_collections", + "flate2", + "libc", + "rgb", +] + [[package]] name = "log" version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +[[package]] +name = "matrixmultiply" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7574c1cf36da4798ab73da5b215bbf444f50718207754cb522201d78d1cd0ff2" +dependencies = [ + "autocfg", + "rawpointer", +] + [[package]] name = "memchr" version = "2.7.2" @@ -255,6 +555,28 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "ndarray" +version = "0.15.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb12d4e967ec485a5f71c6311fe28158e9d6f4bc4a447b474184d0f91a8fa32" +dependencies = [ + "matrixmultiply", + "num-complex", + "num-integer", + "num-traits", + "rawpointer", +] + [[package]] name = "nom" version = "7.1.3" @@ -265,6 +587,33 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "num-complex" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23c6602fda94a57c990fe0df199a035d83576b496aa29f4e634a8ac6004e68a6" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + [[package]] name = "num_enum" version = "0.7.2" @@ -283,7 +632,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn", + "syn 2.0.60", ] [[package]] @@ -292,6 +641,15 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "ordered-float" +version = "3.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1e1c390732d15f1d48471625cd92d154e66db2c56645e29a9cd26f4699f72dc" +dependencies = [ + "num-traits", +] + [[package]] name = "phf" version = "0.11.2" @@ -322,7 +680,7 @@ dependencies = [ "phf_shared", "proc-macro2", "quote", - "syn", + "syn 2.0.60", ] [[package]] @@ -334,6 +692,12 @@ dependencies = [ "siphasher", ] +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + [[package]] name = "prettyplease" version = "0.2.19" @@ -341,7 +705,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ac2cf0f2e4f42b49f5ffd07dae8d746508ef7526c13940e5f524012ae6c6550" dependencies = [ "proc-macro2", - "syn", + "syn 2.0.60", ] [[package]] @@ -353,6 +717,41 @@ dependencies = [ "toml_edit", ] +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro-utils" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f59e109e2f795a5070e69578c4dc101068139f74616778025ae1011d4cd41a8" +dependencies = [ + "proc-macro2", + "quote", + "smallvec", +] + [[package]] name = "proc-macro2" version = "1.0.81" @@ -371,12 +770,47 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "quote-use" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7b5abe3fe82fdeeb93f44d66a7b444dedf2e4827defb0a8e69c437b2de2ef94" +dependencies = [ + "quote", + "quote-use-macros", + "syn 2.0.60", +] + +[[package]] +name = "quote-use-macros" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97ea44c7e20f16017a76a245bb42188517e13d16dcb1aa18044bc406cdc3f4af" +dependencies = [ + "derive-where", + "proc-macro2", + "quote", + "syn 2.0.60", +] + [[package]] name = "rand" version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", "rand_core", ] @@ -385,6 +819,15 @@ name = "rand_core" version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rawpointer" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" [[package]] name = "regex" @@ -415,6 +858,15 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +[[package]] +name = "rgb" +version = "0.8.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05aaa8004b64fd573fc9d002f4e632d51ad4f026c2b5ba95fcb6c2f32c2c47d8" +dependencies = [ + "bytemuck", +] + [[package]] name = "rustc-hash" version = "1.1.0" @@ -436,7 +888,7 @@ version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ - "bitflags", + "bitflags 2.5.0", "errno", "libc", "linux-raw-sys", @@ -458,6 +910,26 @@ version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" +[[package]] +name = "serde" +version = "1.0.200" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddc6f9cc94d67c0e21aaf7eda3a010fd3af78ebf6e096aa6e2e13c79749cce4f" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.200" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "856f046b9400cee3c8c94ed572ecdb752444c24528c035cd35882aad6f492bcb" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.60", +] + [[package]] name = "shlex" version = "1.3.0" @@ -470,6 +942,23 @@ version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.60" @@ -481,6 +970,24 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + [[package]] name = "toml_datetime" version = "0.6.5" @@ -493,7 +1000,7 @@ version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" dependencies = [ - "indexmap", + "indexmap 2.2.6", "toml_datetime", "winnow", ] @@ -504,6 +1011,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + [[package]] name = "walkdir" version = "2.5.0" @@ -514,6 +1027,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + [[package]] name = "which" version = "4.4.2" @@ -616,3 +1135,23 @@ checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" dependencies = [ "memchr", ] + +[[package]] +name = "zerocopy" +version = "0.7.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.60", +] diff --git a/rust/bapi/Cargo.toml b/rust/bapi/Cargo.toml index 58ca38434b3..24e60549bcb 100644 --- a/rust/bapi/Cargo.toml +++ b/rust/bapi/Cargo.toml @@ -8,6 +8,12 @@ edition = "2021" [lib] crate-type = ["cdylib"] +# ------------------------------------------------------- + [dependencies] -byondapi = { git = "https://github.com/spacestation13/byondapi-rs.git", version = "0.4.4" } +# byondapi +byondapi = { git = "https://github.com/spacestation13/byondapi-rs", rev = "5afdd9863a0fc1d8d1d42dd2128c9978f54e12ca" } +# error-handling eyre = "0.6.12" +# spacemandmm, also used by strongmandmm +dmmtools = { git = "https://github.com/SpaceManiac/SpacemanDMM", rev = "6c5a751516ae0e8add4b2aa4388a1e84e96e7082", package = "dmm-tools" } diff --git a/rust/bapi/README.md b/rust/bapi/README.md index e9d138a7c71..61de6a99370 100644 --- a/rust/bapi/README.md +++ b/rust/bapi/README.md @@ -1 +1,37 @@ -`cargo build --release --all-features --target=i686-pc-windows-msvc ; copy target\i686-pc-windows-msvc\release\bapi.dll ../..` +# What is this + +todo + +# What is this `_ffi` stuff + +FFI means "foreign function interface". Basically, different programming languages have very different features and mechanisms, +and if we want them to communicate, like here DM and Rust, in a way, we need to go to the lowest level possible, that being C, +as that is what basically every language can understand. + +Rust functions callable from DM should end with `_ffi`, and have a very "raw" form, and do the least things possible to just call the actual Rust functions. + +Rust functions that do actual things should not end with `_ffi`, and can be nice, idiomatic, Rust-like, and most importantly, safe. + +# On safety + +I recommend reading up on these topics related to Rust: safety, `unsafe {}`, error-handling, panics. + +Safety related stuff: +- Generally, try to call stack trace dm proc on error or panic, so it fails tests and stops debugging (may need to turn on breakpoints on runtime errors). +- Panics (like `foo().unwrap();`) are caught with a panic handler that calls stack trace proc, and writes to a file. + Panics are unrecoverable, so this is the best we can do in this case. + Panics should not really happen though, except in a "fatal error and literally cannot proceed further" situation. +- Unhandled errors (like `foo()?;`) call stack trace proc and return null from the function. +- Some unsafety may be required, like to parse args in `_ffi` functions, but should not be present any where else. + And if for whatever reason it is needed, it should be documented well. +- All rust code (generally, outside of `_ffi`) should be nice, safe, and idiomatic. + +# Other stuff + +Command to compile bapi. The resulting `.dll` should be in `./rust/bapi/target/i686-pc-windows-msvc/release/...`. +The server should try to find and use the `.dll` in that location, otherwise use `./bapi.dll` in main dir. +Building either in release mode (with optimizations) or in debug (without, the default) is fine, but release `.dll` takes priority. +``` +cargo build --target=i686-pc-windows-msvc +cargo build --release --target=i686-pc-windows-msvc +``` diff --git a/rust/bapi/src/lib.rs b/rust/bapi/src/lib.rs index 1b9f7314607..27616b573ca 100644 --- a/rust/bapi/src/lib.rs +++ b/rust/bapi/src/lib.rs @@ -1,14 +1,68 @@ -use byondapi::{byond_string, prelude::*, Error}; +use byondapi::prelude::*; -// Panic handler that dumps info out to a text file (overwriting) if we crash. +/// Call stack trace dm method with message. +fn dm_call_stack_trace(msg: String) { + let msg = byondapi::value::ByondValue::try_from(msg).unwrap(); + byondapi::global_call::call_global_id( + { + static STRING_ID: std::sync::OnceLock = std::sync::OnceLock::new(); + *STRING_ID.get_or_init(|| byondapi::byond_string::str_id_of("_stack_trace").unwrap()) + }, + &[msg], + ) + .unwrap(); +} + +/// Panic handler, called on unhandled errors. +/// Writes panic info to a text file, and calls dm stack trace proc as well. fn setup_panic_handler() { std::panic::set_hook(Box::new(|info| { - std::fs::write("./bapi_panic.txt", format!("Panic {:#?}", info)).unwrap(); + let msg = format!("RUST BAPI PANIC \n {:#?}", info); + let _ = std::fs::write("./bapi_panic.txt", msg.clone()); + crate::dm_call_stack_trace(msg); })) } -#[byondapi::bind] -fn hello_world(_arg: ByondValue) { - setup_panic_handler(); - Ok(ByondValue::new_str("Hello from byondapi!").unwrap()) +/// Turns spacemandmm map object to string. +pub fn map_to_string(map: &dmmtools::dmm::Map) -> eyre::Result { + let mut v = vec![]; + map.to_writer(&mut v)?; + let s = String::from_utf8(v)?; + Ok(s) +} + +/// +#[no_mangle] +pub unsafe extern "C" fn read_dmm_file_ffi( + argc: byondapi::sys::u4c, + argv: *mut byondapi::value::ByondValue, +) -> byondapi::value::ByondValue { + let args = unsafe { ::byondapi::parse_args(argc, argv) }; + match read_dmm_file(args.get(0).map(ByondValue::clone).unwrap_or_default()) { + Ok(val) => val, + Err(info) => { + crate::dm_call_stack_trace(format!("RUST BAPI ERROR \n {:#?}", info)); + ByondValue::null() + } + } +} + +/// +fn read_dmm_file(path: ByondValue) -> eyre::Result { + setup_panic_handler(); + + let path: String = path.get_string()?; + let path: std::path::PathBuf = path.try_into()?; + + // some checks, just return null if path is bad for whatever reason + if !path.is_file() || !path.exists() { + return Ok(ByondValue::null()); + } + + // read file and parse with spacemandmm + let dmm = dmmtools::dmm::Map::from_file(&path)?; + + // return the map converted to string + let str = map_to_string(&dmm)?; + Ok(ByondValue::new_str(str)?) } diff --git a/tools/ci/libbapi_ci.so b/tools/ci/libbapi_ci.so new file mode 100644 index 00000000000..22e2115dcef Binary files /dev/null and b/tools/ci/libbapi_ci.so differ