From 94b64b461917ad17c2137a01ad0ce2b09700f152 Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Wed, 10 Jul 2024 18:40:52 +0200 Subject: [PATCH 1/2] Update zip --- Cargo.lock | 42 ++++++++++++++++++++++++++++++++---------- Cargo.toml | 2 +- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2df8581..faad8f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -640,9 +640,9 @@ checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" [[package]] name = "crc32fast" -version = "1.4.0" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" dependencies = [ "cfg-if", ] @@ -658,9 +658,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.19" +version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" [[package]] name = "crypto-common" @@ -2011,6 +2011,12 @@ version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" +[[package]] +name = "lockfree-object-pool" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9374ef4228402d4b7e403e5838cb880d9ee663314b0a900d5a6aabf0c213552e" + [[package]] name = "log" version = "0.4.21" @@ -3435,18 +3441,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.60" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18" +checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.60" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" +checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", @@ -4426,9 +4432,9 @@ checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" [[package]] name = "zip" -version = "1.3.0" +version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1f4a27345eb6f7aa7bd015ba7eb4175fa4e1b462a29874b779e0bbcf96c6ac7" +checksum = "775a2b471036342aa69bc5a602bc889cb0a06cda00477d0c69566757d5553d39" dependencies = [ "arbitrary", "bzip2", @@ -4437,11 +4443,27 @@ dependencies = [ "displaydoc", "flate2", "indexmap", + "memchr", "thiserror", "time", + "zopfli", "zstd", ] +[[package]] +name = "zopfli" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5019f391bac5cf252e93bbcc53d039ffd62c7bfb7c150414d61369afe57e946" +dependencies = [ + "bumpalo", + "crc32fast", + "lockfree-object-pool", + "log", + "once_cell", + "simd-adler32", +] + [[package]] name = "zstd" version = "0.13.1" diff --git a/Cargo.toml b/Cargo.toml index 8c0e7c5..f38ac22 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ members = [ exclude = ["lib/color-eyre"] [workspace.dependencies] -zip = { version = "1.3.0", default-features = false, features = ["deflate", "bzip2", "zstd", "time"] } +zip = { version = "2.1.3", default-features = false, features = ["deflate", "bzip2", "zstd", "time"] } [patch.crates-io] color-eyre = { path = "lib/color-eyre" } From 0f14834e2d162fe6b734407ce6359cbc49127e91 Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Wed, 10 Jul 2024 18:41:38 +0200 Subject: [PATCH 2/2] Remove string_template Use minijinja for all templates --- Cargo.lock | 1 - crates/dtmm/Cargo.toml | 1 - .../assets/{mod_main.lua => mod_main.lua.j2} | 4 +++- crates/dtmm/src/controller/deploy.rs | 24 ++++++++++++------- 4 files changed, 18 insertions(+), 12 deletions(-) rename crates/dtmm/assets/{mod_main.lua => mod_main.lua.j2} (98%) diff --git a/Cargo.lock b/Cargo.lock index faad8f6..55cdf0d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -910,7 +910,6 @@ dependencies = [ "sdk", "serde", "serde_sjson", - "string_template", "strip-ansi-escapes", "time", "tokio", diff --git a/crates/dtmm/Cargo.toml b/crates/dtmm/Cargo.toml index f57d0c8..661eb17 100644 --- a/crates/dtmm/Cargo.toml +++ b/crates/dtmm/Cargo.toml @@ -29,7 +29,6 @@ path-slash = "0.2.1" sdk = { path = "../../lib/sdk", version = "*" } serde = { version = "1.0.152", features = ["derive", "rc"] } serde_sjson = { path = "../../lib/serde_sjson", version = "*" } -string_template = "0.2.1" strip-ansi-escapes = "0.2.0" time = { version = "0.3.20", features = ["serde", "serde-well-known", "local-offset"] } tokio = { version = "1.23.0", features = ["rt", "fs", "tracing", "sync"] } diff --git a/crates/dtmm/assets/mod_main.lua b/crates/dtmm/assets/mod_main.lua.j2 similarity index 98% rename from crates/dtmm/assets/mod_main.lua rename to crates/dtmm/assets/mod_main.lua.j2 index e4006f6..c1131be 100644 --- a/crates/dtmm/assets/mod_main.lua +++ b/crates/dtmm/assets/mod_main.lua.j2 @@ -17,7 +17,7 @@ local require_store = {} -- This token is treated as a string template and filled by DTMM during deployment. -- This allows hiding unsafe I/O functions behind a setting. --- It's also a valid table definition, thereby degrading gracefully when not replaced. +-- When not replaced, it's also a valid table definition, thereby degrading gracefully. local is_io_enabled = {{ is_io_enabled }} -- luacheck: ignore 113 local lua_libs = { debug = debug, @@ -207,3 +207,5 @@ function init() Main:init() end + +-- vim: ft=lua diff --git a/crates/dtmm/src/controller/deploy.rs b/crates/dtmm/src/controller/deploy.rs index 4d5f831..a59a1fe 100644 --- a/crates/dtmm/src/controller/deploy.rs +++ b/crates/dtmm/src/controller/deploy.rs @@ -1,4 +1,3 @@ -use std::collections::HashMap; use std::io::{Cursor, ErrorKind}; use std::path::{Path, PathBuf}; use std::str::FromStr; @@ -16,7 +15,6 @@ use sdk::{ Bundle, BundleDatabase, BundleFile, BundleFileType, BundleFileVariant, FromBinary, ToBinary, }; use serde::{Deserialize, Serialize}; -use string_template::Template; use time::OffsetDateTime; use tokio::fs::{self, DirEntry}; use tokio::io::AsyncWriteExt; @@ -572,12 +570,17 @@ async fn patch_boot_bundle(state: Arc) -> Result> { let span = tracing::debug_span!("Importing mod main script"); let _enter = span.enter(); - let is_io_enabled = format!("{}", state.is_io_enabled); - let mut data = HashMap::new(); - data.insert("is_io_enabled", is_io_enabled.as_str()); + let mut env = Environment::new(); + env.add_template("mod_main.lua", include_str!("../../assets/mod_main.lua.j2")) + .wrap_err("Failed to compile template for `mod_main.lua`")?; + let tmpl = env + .get_template("mod_main.lua") + .wrap_err("Failed to get template `mod_main.lua`")?; + + let lua = tmpl + .render(minijinja::context!(is_io_enabled => if state.is_io_enabled { "true" } else {"false"})) + .wrap_err("Failed to render template `mod_main.lua`")?; - let tmpl = include_str!("../../assets/mod_main.lua"); - let lua = Template::new(tmpl).render(&data); tracing::trace!("Main script rendered:\n===========\n{}\n=============", lua); let file = lua::compile(MOD_BOOT_SCRIPT, lua).wrap_err("Failed to compile mod main Lua file")?; @@ -707,7 +710,7 @@ pub(crate) async fn deploy_mods(state: ActionState) -> Result<()> { }, async { let path = state.game_dir.join(DEPLOYMENT_DATA_PATH); - match read_sjson_file::<_, DeploymentData>(path).await { + match read_sjson_file::<_, DeploymentData>(&path).await { Ok(data) => Ok(Some(data)), Err(err) => { if let Some(err) = err.downcast_ref::() @@ -715,7 +718,10 @@ pub(crate) async fn deploy_mods(state: ActionState) -> Result<()> { { Ok(None) } else { - Err(err).wrap_err("Failed to read deployment data") + Err(err).wrap_err(format!( + "Failed to read deployment data from: {}", + path.display() + )) } } }