From fbee7c85bd93c03ea4799936d31c585bdbf12711 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Mon, 25 Sep 2023 12:32:57 -0500 Subject: [PATCH 01/19] Fix net server stopping when handle is garbage collected --- CHANGELOG.md | 1 + src/lune/builtins/net/server.rs | 8 ++++++-- src/lune/util/futures.rs | 18 ++++++++++++++++++ src/lune/util/mod.rs | 1 + 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 src/lune/util/futures.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 98a6b07..934cc67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fixed `net.serve` stopping when the returned `ServeHandle` is garbage collected - Fixed missing trailing newline when using the `warn` global - Fixed constructor for `CFrame` in the `roblox` built-in library not parsing the 12-arg overload correctly. ([#102]) - Fixed various functions for `CFrame` in the `roblox` built-in library being incorrect, specifically row-column ordering and some flipped signs. ([#103]) diff --git a/src/lune/builtins/net/server.rs b/src/lune/builtins/net/server.rs index 167f10b..68617d9 100644 --- a/src/lune/builtins/net/server.rs +++ b/src/lune/builtins/net/server.rs @@ -12,7 +12,7 @@ use tokio::sync::{mpsc, oneshot, Mutex}; use crate::lune::{ scheduler::Scheduler, - util::{traits::LuaEmitErrorExt, TableBuilder}, + util::{futures::yield_forever, traits::LuaEmitErrorExt, TableBuilder}, }; use super::{ @@ -115,7 +115,11 @@ where .http1_keepalive(true) // Web sockets must be kept alive .serve(hyper_make_service) .with_graceful_shutdown(async move { - shutdown_rx.recv().await; + if shutdown_rx.recv().await.is_none() { + // The channel was closed, meaning the serve handle + // was garbage collected by lua without being used + yield_forever().await; + } }); if let Err(e) = result.await { eprintln!("Net serve error: {e}") diff --git a/src/lune/util/futures.rs b/src/lune/util/futures.rs new file mode 100644 index 0000000..40163c1 --- /dev/null +++ b/src/lune/util/futures.rs @@ -0,0 +1,18 @@ +use std::future::Future; +use std::pin::Pin; +use std::task::{Context, Poll}; + +#[derive(Debug, Clone, Copy)] +pub struct YieldForever; + +impl Future for YieldForever { + type Output = (); + + fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll { + Poll::Pending + } +} + +pub fn yield_forever() -> YieldForever { + YieldForever +} diff --git a/src/lune/util/mod.rs b/src/lune/util/mod.rs index 38984af..3c9457c 100644 --- a/src/lune/util/mod.rs +++ b/src/lune/util/mod.rs @@ -1,6 +1,7 @@ mod table_builder; pub mod formatting; +pub mod futures; pub mod traits; pub use table_builder::TableBuilder; From 2e53cdcad7e92810e62a1c523b6683171a5f4b14 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Mon, 25 Sep 2023 12:41:56 -0500 Subject: [PATCH 02/19] Fix list subcommand not listing global dir without a local dir --- CHANGELOG.md | 1 + src/cli/mod.rs | 23 +++++++++-------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 934cc67..25234ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fixed list subcommand not listing global scripts without a local `.lune` / `lune` directory present - Fixed `net.serve` stopping when the returned `ServeHandle` is garbage collected - Fixed missing trailing newline when using the `warn` global - Fixed constructor for `CFrame` in the `roblox` built-in library not parsing the 12-arg overload correctly. ([#102]) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index ccc11ae..9a80c9d 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -83,20 +83,15 @@ impl Cli { // List files in `lune` and `.lune` directories, if wanted // This will also exit early and not run anything else if self.list { - let sorted_relative = match find_lune_scripts(false).await { - Ok(scripts) => sort_lune_scripts(scripts), - Err(e) => { - eprintln!("{e}"); - return Ok(ExitCode::FAILURE); - } - }; - let sorted_home_dir = match find_lune_scripts(true).await { - Ok(scripts) => sort_lune_scripts(scripts), - Err(e) => { - eprintln!("{e}"); - return Ok(ExitCode::FAILURE); - } - }; + let sorted_relative = find_lune_scripts(false).await.map(sort_lune_scripts); + let sorted_home_dir = find_lune_scripts(true).await.map(sort_lune_scripts); + if sorted_relative.is_err() && sorted_home_dir.is_err() { + eprintln!("{}", sorted_relative.unwrap_err()); + return Ok(ExitCode::FAILURE); + } + + let sorted_relative = sorted_relative.unwrap_or(Vec::new()); + let sorted_home_dir = sorted_home_dir.unwrap_or(Vec::new()); let mut buffer = String::new(); if !sorted_relative.is_empty() { From bfcd78c43e88d513fafdd7c4633d0857bdcf5fb1 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Mon, 25 Sep 2023 13:43:59 -0500 Subject: [PATCH 03/19] Round decimal place in Vector3 and CFrame when converting to dom type --- CHANGELOG.md | 1 + src/roblox/datatypes/mod.rs | 2 ++ src/roblox/datatypes/types/vector3.rs | 11 +++++++---- src/roblox/datatypes/util.rs | 16 ++++++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 src/roblox/datatypes/util.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 25234ed..5cf906d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Update to Luau version `0.594` +- CFrame and Vector3 values are now rounded to the nearest 2 ^ 16 decimal place to reduce floating point errors and diff noise. Note that this does not affect intermediate calculations done in lua, and only happens when a property value is set on an Instance. ### Fixed diff --git a/src/roblox/datatypes/mod.rs b/src/roblox/datatypes/mod.rs index 6604d5f..5432c50 100644 --- a/src/roblox/datatypes/mod.rs +++ b/src/roblox/datatypes/mod.rs @@ -6,6 +6,8 @@ pub mod extension; pub mod result; pub mod types; +mod util; + use result::*; pub use crate::roblox::shared::userdata::*; diff --git a/src/roblox/datatypes/types/vector3.rs b/src/roblox/datatypes/types/vector3.rs index a7ba383..ef0307e 100644 --- a/src/roblox/datatypes/types/vector3.rs +++ b/src/roblox/datatypes/types/vector3.rs @@ -5,7 +5,10 @@ use glam::Vec3; use mlua::prelude::*; use rbx_dom_weak::types::Vector3 as DomVector3; -use crate::{lune::util::TableBuilder, roblox::exports::LuaExportsTable}; +use crate::{ + lune::util::TableBuilder, + roblox::{datatypes::util::round_float_decimal, exports::LuaExportsTable}, +}; use super::{super::*, EnumItem}; @@ -212,9 +215,9 @@ impl From for Vector3 { impl From for DomVector3 { fn from(v: Vector3) -> Self { DomVector3 { - x: v.0.x, - y: v.0.y, - z: v.0.z, + x: round_float_decimal(v.0.x), + y: round_float_decimal(v.0.y), + z: round_float_decimal(v.0.z), } } } diff --git a/src/roblox/datatypes/util.rs b/src/roblox/datatypes/util.rs new file mode 100644 index 0000000..7855507 --- /dev/null +++ b/src/roblox/datatypes/util.rs @@ -0,0 +1,16 @@ +// HACK: We round to the nearest Very Small Decimal +// to reduce writing out floating point accumulation +// errors to files (mostly relevant for xml formats) +const ROUNDING: usize = 65_536; // 2 ^ 16 + +pub fn round_float_decimal(value: f32) -> f32 { + let place = ROUNDING as f32; + + // Round only the fractional part, we do not want to + // lose any float precision in case a user for some + // reason has very very large float numbers in files + let whole = value.trunc(); + let fract = (value.fract() * place).round() / place; + + whole + fract +} From 8c853fb99ec59df964655ccdc2cefd3c17f53e9c Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Mon, 25 Sep 2023 13:52:02 -0500 Subject: [PATCH 04/19] Update dependencies --- CHANGELOG.md | 12 ++-- Cargo.lock | 165 +++++++++++++++++++++------------------------------ 2 files changed, 75 insertions(+), 102 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cf906d..aa4522c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Added a new `datetime` built-in library for handling date & time values, parsing, formatting, and more ([#94]) +- Added a new `datetime` built-in library for handling date & time values, parsing, formatting, and more. ([#94]) Example usage: @@ -57,14 +57,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- Update to Luau version `0.594` +- Update to Luau version `0.596`. - CFrame and Vector3 values are now rounded to the nearest 2 ^ 16 decimal place to reduce floating point errors and diff noise. Note that this does not affect intermediate calculations done in lua, and only happens when a property value is set on an Instance. ### Fixed -- Fixed list subcommand not listing global scripts without a local `.lune` / `lune` directory present -- Fixed `net.serve` stopping when the returned `ServeHandle` is garbage collected -- Fixed missing trailing newline when using the `warn` global +- Fixed list subcommand not listing global scripts without a local `.lune` / `lune` directory present. +- Fixed `net.serve` stopping when the returned `ServeHandle` is garbage collected. +- Fixed missing trailing newline when using the `warn` global. - Fixed constructor for `CFrame` in the `roblox` built-in library not parsing the 12-arg overload correctly. ([#102]) - Fixed various functions for `CFrame` in the `roblox` built-in library being incorrect, specifically row-column ordering and some flipped signs. ([#103]) @@ -131,7 +131,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- Update to Luau version `0.591` +- Update to Luau version `0.591`. - Lune's internal task scheduler and `require` functionality has been completely rewritten.
The new scheduler is much more stable, conforms to a larger test suite, and has a few additional benefits: diff --git a/Cargo.lock b/Cargo.lock index dd718f6..f29605d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,9 +19,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aho-corasick" -version = "1.0.5" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c378d78423fdad8089616f827526ee33c19f2fddbd5de1629152c9593ba4783" +checksum = "ea5d730647d4fadd988536d06fecce94b7b4f2a7efdae548f1cf4b63205518ab" dependencies = [ "memchr", ] @@ -150,7 +150,7 @@ checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -217,16 +217,15 @@ dependencies = [ [[package]] name = "blake3" -version = "1.4.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "199c42ab6972d92c9f8995f086273d25c42fc0f7b2a1fcefba465c1352d25ba5" +checksum = "0231f06152bf547e9c2b5194f247cd97aacf6dcd8b15d8e5ec0663f64580da87" dependencies = [ "arrayref", "arrayvec 0.7.4", "cc", "cfg-if", "constant_time_eq 0.3.0", - "digest", ] [[package]] @@ -324,9 +323,9 @@ dependencies = [ [[package]] name = "chrono_lc" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4556d06f1286632cf49ef465898936b17c1b903e232965f2b52ebbc6bd5390a" +checksum = "ec58ebe2c3ff4a2262806e7bcda70a74f8cebd173d8cef16e1e30705dc016d08" dependencies = [ "chrono", "lazy_static", @@ -339,9 +338,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.3" +version = "4.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84ed82781cea27b43c9b106a979fe450a13a31aab0500595fb3fc06616de08e6" +checksum = "b1d7b8d5ec32af0fadc644bf1fd509a688c2103b185644bb1e29d164e0703136" dependencies = [ "clap_builder", "clap_derive", @@ -349,9 +348,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.2" +version = "4.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bb9faaa7c2ef94b2743a21f5a29e6f0010dff4caa69ac8e9d6cf8b6fa74da08" +checksum = "5179bb514e4d7c2051749d8fcefa2ed6d06a9f4e6d69faf3805f5d80b8cf8d56" dependencies = [ "anstream", "anstyle", @@ -368,7 +367,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -510,7 +509,6 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", "crypto-common", - "subtle", ] [[package]] @@ -645,9 +643,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" [[package]] name = "fd-lock" @@ -708,7 +706,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -778,9 +776,9 @@ checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" [[package]] name = "glam" -version = "0.24.1" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42218cb640844e3872cc3c153dc975229e080a6c4733b34709ef445610550226" +checksum = "b5418c17512bdf42730f9032c74e1ae39afc408745ebb2acf72fbc4691c17945" [[package]] name = "glob" @@ -827,9 +825,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" +checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" [[package]] name = "home" @@ -1090,9 +1088,9 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "luau0-src" -version = "0.7.4+luau594" +version = "0.7.5+luau596" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd3a63bc31a97efdd1f4d0246c33bed3086f63a67cdf7d0451f68cb215aad20c" +checksum = "cda221ef787513a320f1de3ca8987d110fa7096c460a8f6feaeeba46d1551507" dependencies = [ "cc", ] @@ -1407,7 +1405,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -1439,7 +1437,7 @@ dependencies = [ "line-wrap", "quick-xml", "serde", - "time 0.3.28", + "time 0.3.29", ] [[package]] @@ -1465,21 +1463,21 @@ dependencies = [ [[package]] name = "profiling" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45f10e75d83c7aec79a6aa46f897075890e156b105eebe51cfa0abce51af025f" +checksum = "f89dff0959d98c9758c88826cc002e2c3d0b9dfac4139711d1f30de442f1139b" dependencies = [ "profiling-procmacros", ] [[package]] name = "profiling-procmacros" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74c55e9e629af5298a40e0fa106435b2da30484c4ec76b41d19bc4d00dd8b903" +checksum = "eb156a45b6b9fe8027497422179fb65afc84d36707a7ca98297bf06bccb8d43f" dependencies = [ "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -1757,7 +1755,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots 0.25.2", + "webpki-roots", "winreg 0.50.0", ] @@ -1833,9 +1831,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.13" +version = "0.38.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7db8590df6dfcd144d22afd1b83b36c21a18d7cbc1dc4bb5295a8712e9eb662" +checksum = "747c788e9ce8e92b12cd485c49ddf90723550b654b32508f979b71a7b1ecda4f" dependencies = [ "bitflags 2.4.0", "errno", @@ -1852,7 +1850,7 @@ checksum = "cd8d6c9f025a446bc4d18ad9632e69aec8f287aa84499ee335599fabd20c3fd8" dependencies = [ "log", "ring", - "rustls-webpki 0.101.5", + "rustls-webpki", "sct", ] @@ -1867,19 +1865,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.100.3" +version = "0.101.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f6a5fc258f1c1276dfe3016516945546e2d5383911efc0fc4f1cdc5df3a4ae3" -dependencies = [ - "ring", - "untrusted", -] - -[[package]] -name = "rustls-webpki" -version = "0.101.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45a27e3b59326c16e23d30aeb7a36a24cc0d29e71d68ff611cdfb4a01d013bed" +checksum = "3c7d5dece342910d9ba34d259310cae3e0154b873b35408b787b59bce53d34fe" dependencies = [ "ring", "untrusted", @@ -1987,7 +1975,7 @@ checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -2047,9 +2035,9 @@ dependencies = [ [[package]] name = "sha1" -version = "0.10.5" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" dependencies = [ "cfg-if", "cpufeatures", @@ -2097,9 +2085,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" +checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" [[package]] name = "socket2" @@ -2203,12 +2191,6 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "1.0.109" @@ -2222,9 +2204,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.33" +version = "2.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9caece70c63bfba29ec2fed841a09851b14a235c60010fa4de58089b6c025668" +checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8" dependencies = [ "proc-macro2", "quote", @@ -2246,9 +2228,9 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64" dependencies = [ "winapi-util", ] @@ -2270,7 +2252,7 @@ checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35" dependencies = [ "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -2300,22 +2282,22 @@ dependencies = [ [[package]] name = "time" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17f6bb557fd245c28e6411aa56b6403c689ad95061f50e4be16c274e70a17e48" +checksum = "426f806f4089c493dcac0d24c29c01e2c38baf8e30f1b716ee37e83d200b18fe" dependencies = [ "deranged", "itoa", "serde", "time-core", - "time-macros 0.2.14", + "time-macros 0.2.15", ] [[package]] name = "time-core" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" @@ -2329,9 +2311,9 @@ dependencies = [ [[package]] name = "time-macros" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a942f44339478ef67935ab2bbaec2fb0322496cf3cbe84b261e06ac3814c572" +checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20" dependencies = [ "time-core", ] @@ -2392,7 +2374,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -2407,9 +2389,9 @@ dependencies = [ [[package]] name = "tokio-tungstenite" -version = "0.20.0" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b2dbec703c26b00d74844519606ef15d09a7d6857860f84ad223dec002ddea2" +checksum = "212d5dcb2a1ce06d81107c3d0ffa3121fe974b73f068c8282cb1c32328113b6c" dependencies = [ "futures-util", "log", @@ -2417,14 +2399,14 @@ dependencies = [ "tokio", "tokio-rustls", "tungstenite", - "webpki-roots 0.23.1", + "webpki-roots", ] [[package]] name = "tokio-util" -version = "0.7.8" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d" +checksum = "1d68074620f57a0b21594d9735eb2e98ab38b17f80d3fcb189fca266771ca60d" dependencies = [ "bytes", "futures-core", @@ -2495,7 +2477,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", ] [[package]] @@ -2545,9 +2527,9 @@ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "tungstenite" -version = "0.20.0" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e862a1c4128df0112ab625f55cd5c934bcb4312ba80b39ae4b4835a3fd58e649" +checksum = "9e3dac10fd62eaf6617d3a904ae222845979aec67c615d1c842b4002c7666fb9" dependencies = [ "byteorder 1.4.3", "bytes", @@ -2557,7 +2539,7 @@ dependencies = [ "log", "rand", "rustls", - "sha1 0.10.5", + "sha1 0.10.6", "thiserror", "url", "utf-8", @@ -2608,9 +2590,9 @@ checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" [[package]] name = "unicode-width" -version = "0.1.10" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" [[package]] name = "unsafe-libyaml" @@ -2717,7 +2699,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", "wasm-bindgen-shared", ] @@ -2751,7 +2733,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.33", + "syn 2.0.37", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2772,15 +2754,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "webpki-roots" -version = "0.23.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b03058f88386e5ff5310d9111d53f48b17d732b401aeb83a8d5190f2ac459338" -dependencies = [ - "rustls-webpki 0.100.3", -] - [[package]] name = "webpki-roots" version = "0.25.2" @@ -2805,9 +2778,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" dependencies = [ "winapi", ] @@ -2989,9 +2962,9 @@ dependencies = [ [[package]] name = "xml-rs" -version = "0.8.18" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab77e97b50aee93da431f2cee7cd0f43b4d1da3c408042f2d7d164187774f0a" +checksum = "0fcb9cbac069e033553e8bb871be2fbdffcab578eb25bd0f7c508cedc6dcd75a" [[package]] name = "zeroize" From 83ac971792680b18adbc09fcb4bc92d93e36443e Mon Sep 17 00:00:00 2001 From: SnorlaxAssist <57375992+SnorlaxAssist@users.noreply.github.com> Date: Mon, 25 Sep 2023 15:14:29 -0400 Subject: [PATCH 05/19] Fix failing test cases on Windows (#111) --- .gitattributes | 3 ++ src/lune/builtins/process/options.rs | 2 +- tests/net/serve/requests.luau | 3 +- tests/process/spawn.luau | 65 ++++++++++++++++++++-------- 4 files changed, 54 insertions(+), 19 deletions(-) diff --git a/.gitattributes b/.gitattributes index cf332f3..3efb273 100644 --- a/.gitattributes +++ b/.gitattributes @@ -7,3 +7,6 @@ # Ensure all lua files use LF *.lua eol=lf *.luau eol=lf + +# Ensure all txt files within tests use LF +tests/**/*.txt eol=lf diff --git a/src/lune/builtins/process/options.rs b/src/lune/builtins/process/options.rs index 688caa3..21a6264 100644 --- a/src/lune/builtins/process/options.rs +++ b/src/lune/builtins/process/options.rs @@ -98,7 +98,7 @@ impl<'lua> FromLua<'lua> for ProcessSpawnOptions { LuaValue::Boolean(true) => { this.shell = match env::consts::FAMILY { "unix" => Some("/bin/sh".to_string()), - "windows" => Some("/bin/sh".to_string()), + "windows" => Some("powershell".to_string()), _ => None, }; } diff --git a/tests/net/serve/requests.luau b/tests/net/serve/requests.luau index 1d033a1..b17ad2d 100644 --- a/tests/net/serve/requests.luau +++ b/tests/net/serve/requests.luau @@ -52,7 +52,8 @@ if not success then assert( string.find(message, "Connection reset") or string.find(message, "Connection closed") - or string.find(message, "Connection refused"), + or string.find(message, "Connection refused") + or string.find(message, "No connection could be made"), -- Windows Request Error "Server did not stop responding to requests" ) else diff --git a/tests/process/spawn.luau b/tests/process/spawn.luau index c3537df..7715439 100644 --- a/tests/process/spawn.luau +++ b/tests/process/spawn.luau @@ -10,9 +10,17 @@ local thread = task.delay(1, function() process.exit(1) end) -local result = process.spawn("ls", { - "-a", -}) +local isWindows = process.os == "windows"; + +-- To run windows command, we need to launch cmd.exe and pass the command as an argument. +local result = process.spawn( + if isWindows then "cmd" else "ls", + if isWindows then { + "/c", "dir" + } else { + "-a" + } +) task.cancel(thread) @@ -27,7 +35,7 @@ assert(string.find(result.stdout, ".gitignore") ~= nil, "Missing .gitignore in o -- It should also work the same when spawned using a shell local shellResult = process.spawn("ls", { - "-a", + if isWindows then "-Force" else "-a" }, { shell = true, }) @@ -40,30 +48,34 @@ assert(shellResult.stdout ~= "", "Stdout was empty (shell)") assert(string.find(shellResult.stdout, "Cargo.toml") ~= nil, "Missing Cargo.toml in output (shell)") assert(string.find(shellResult.stdout, ".gitignore") ~= nil, "Missing .gitignore in output (shell)") +local pwdCommand = if isWindows then "cmd" else "pwd" +local pwdArgs = if isWindows then { "/c", "cd" } else {} -- Make sure the cwd option actually uses the directory we want -local rootPwd = process.spawn("pwd", {}, { +local rootPwd = process.spawn(pwdCommand, pwdArgs, { cwd = "/", }).stdout rootPwd = string.gsub(rootPwd, "^%s+", "") rootPwd = string.gsub(rootPwd, "%s+$", "") -if rootPwd ~= "/" then +-- Windows: :\, Unix: / +local expectedRootPwd = if isWindows then string.sub(rootPwd, 1, 1) .. ":\\" else "/" +if rootPwd ~= expectedRootPwd then error( string.format( "Current working directory for child process was not set correctly!" - .. "\nExpected '/', got '%s'", - rootPwd + .. "\nExpected '%s', got '%s'", + expectedRootPwd, rootPwd ) ) end -- Setting cwd should not change the cwd of this process -local pwdBefore = process.spawn("pwd").stdout +local pwdBefore = process.spawn(pwdCommand, pwdArgs).stdout process.spawn("ls", {}, { cwd = "/", shell = true, }) -local pwdAfter = process.spawn("pwd").stdout +local pwdAfter = process.spawn(pwdCommand, pwdArgs).stdout assert(pwdBefore == pwdAfter, "Current working directory changed after running child process") --[[ @@ -74,7 +86,10 @@ assert(pwdBefore == pwdAfter, "Current working directory changed after running c local homeDir1 = process.spawn("echo $HOME", nil, { shell = true, }).stdout -local homeDir2 = process.spawn("pwd", nil, { + +-- Powershell for windows uses `$pwd.Path` instead of `pwd` as pwd would return a PathInfo object, +-- using $pwd.Path gets the Path property of the PathInfo object. +local homeDir2 = process.spawn(if isWindows then "$pwd.Path" else "pwd", nil, { shell = true, cwd = "~", }).stdout @@ -94,7 +109,10 @@ assert(homeDir1 == homeDir2, "Home dirs did not match when performing tilde subs local SLEEP_DURATION = 1 / 4 local SLEEP_SAMPLES = 2 -local thread2 = task.delay(SLEEP_DURATION * 1.5, function() +-- Windows tend to have a higher execution time +local yieldTolarance = if isWindows then 25 else SLEEP_DURATION * 1.5; + +local thread2 = task.delay(yieldTolarance, function() stdio.ewrite("Spawning a sleep process should take a reasonable amount of time\n") task.wait(1) process.exit(1) @@ -104,7 +122,16 @@ local sleepStart = os.clock() local sleepCounter = 0 for i = 1, SLEEP_SAMPLES, 1 do task.spawn(function() - process.spawn("sleep", { tostring(SLEEP_DURATION) }) + local args = { + -- Sleep command on Windows in Seconds has some weird behavior with decimals... + tostring(SLEEP_DURATION * (isWindows and 1000 or 1)) + }; + if isWindows then + -- ... so we use milliseconds instead. + table.insert(args, 1, "-Milliseconds"); + end + -- Windows does not have `sleep` as a process, so we use powershell instead. + process.spawn("sleep", args, if isWindows then { shell = true } else nil) sleepCounter += 1 end) end @@ -115,12 +142,13 @@ end task.cancel(thread2) local sleepElapsed = os.clock() - sleepStart + assert( sleepElapsed >= SLEEP_DURATION, "Spawning a process that does blocking sleep did not sleep enough" ) assert( - sleepElapsed < SLEEP_DURATION * 1.5, + sleepElapsed < yieldTolarance, "Coroutine yielded the main lua thread during process yield" ) @@ -128,13 +156,16 @@ assert( local echoMessage = "Hello from child process!" local echoResult = process.spawn("echo", { - '"$TEST_VAR"', + if isWindows then '"$Env:TEST_VAR"' else '"$TEST_VAR"', }, { env = { TEST_VAR = echoMessage }, - shell = "bash", + shell = if isWindows then "powershell" else "bash", -- "bash" does not exist on Windows, using "powershell" instead. stdio = "inherit", }) + +-- Windows echo adds a \r before the newline +local trailingAddition = if isWindows then "\r\n" else "\n" assert( - echoResult.stdout == (echoMessage .. "\n"), -- Note that echo adds a newline + echoResult.stdout == (echoMessage .. trailingAddition), -- Note that echo adds a newline "Inheriting stdio did not return proper output" ) From b1ee221555cc5c3794d844bb56dad2e0b9e62e7a Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Mon, 25 Sep 2023 14:20:01 -0500 Subject: [PATCH 06/19] Stylua formatting in process spawn test file --- tests/process/spawn.luau | 63 +++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 36 deletions(-) diff --git a/tests/process/spawn.luau b/tests/process/spawn.luau index 7715439..68691ae 100644 --- a/tests/process/spawn.luau +++ b/tests/process/spawn.luau @@ -10,16 +10,11 @@ local thread = task.delay(1, function() process.exit(1) end) -local isWindows = process.os == "windows"; +local IS_WINDOWS = process.os == "windows" --- To run windows command, we need to launch cmd.exe and pass the command as an argument. local result = process.spawn( - if isWindows then "cmd" else "ls", - if isWindows then { - "/c", "dir" - } else { - "-a" - } + if IS_WINDOWS then "cmd" else "ls", + if IS_WINDOWS then { "/c", "dir" } else { "-a" } ) task.cancel(thread) @@ -33,9 +28,10 @@ assert(string.find(result.stdout, "Cargo.toml") ~= nil, "Missing Cargo.toml in o assert(string.find(result.stdout, ".gitignore") ~= nil, "Missing .gitignore in output") -- It should also work the same when spawned using a shell +-- Note that the default on Windows is Powershell which has different flags / behavior local shellResult = process.spawn("ls", { - if isWindows then "-Force" else "-a" + if IS_WINDOWS then "-Force" else "-a", }, { shell = true, }) @@ -48,22 +44,25 @@ assert(shellResult.stdout ~= "", "Stdout was empty (shell)") assert(string.find(shellResult.stdout, "Cargo.toml") ~= nil, "Missing Cargo.toml in output (shell)") assert(string.find(shellResult.stdout, ".gitignore") ~= nil, "Missing .gitignore in output (shell)") -local pwdCommand = if isWindows then "cmd" else "pwd" -local pwdArgs = if isWindows then { "/c", "cd" } else {} +local pwdCommand = if IS_WINDOWS then "cmd" else "pwd" +local pwdArgs = if IS_WINDOWS then { "/c", "cd" } else {} + -- Make sure the cwd option actually uses the directory we want local rootPwd = process.spawn(pwdCommand, pwdArgs, { cwd = "/", }).stdout rootPwd = string.gsub(rootPwd, "^%s+", "") rootPwd = string.gsub(rootPwd, "%s+$", "") + -- Windows: :\, Unix: / -local expectedRootPwd = if isWindows then string.sub(rootPwd, 1, 1) .. ":\\" else "/" +local expectedRootPwd = if IS_WINDOWS then string.sub(rootPwd, 1, 1) .. ":\\" else "/" if rootPwd ~= expectedRootPwd then error( string.format( "Current working directory for child process was not set correctly!" .. "\nExpected '%s', got '%s'", - expectedRootPwd, rootPwd + expectedRootPwd, + rootPwd ) ) end @@ -89,7 +88,7 @@ local homeDir1 = process.spawn("echo $HOME", nil, { -- Powershell for windows uses `$pwd.Path` instead of `pwd` as pwd would return a PathInfo object, -- using $pwd.Path gets the Path property of the PathInfo object. -local homeDir2 = process.spawn(if isWindows then "$pwd.Path" else "pwd", nil, { +local homeDir2 = process.spawn(if IS_WINDOWS then "$pwd.Path" else "pwd", nil, { shell = true, cwd = "~", }).stdout @@ -109,10 +108,8 @@ assert(homeDir1 == homeDir2, "Home dirs did not match when performing tilde subs local SLEEP_DURATION = 1 / 4 local SLEEP_SAMPLES = 2 --- Windows tend to have a higher execution time -local yieldTolarance = if isWindows then 25 else SLEEP_DURATION * 1.5; - -local thread2 = task.delay(yieldTolarance, function() +-- Unfortunately we +local thread2 = task.delay(30, function() stdio.ewrite("Spawning a sleep process should take a reasonable amount of time\n") task.wait(1) process.exit(1) @@ -123,15 +120,15 @@ local sleepCounter = 0 for i = 1, SLEEP_SAMPLES, 1 do task.spawn(function() local args = { - -- Sleep command on Windows in Seconds has some weird behavior with decimals... - tostring(SLEEP_DURATION * (isWindows and 1000 or 1)) - }; - if isWindows then + -- Sleep command on Windows in Seconds has some weird behavior with decimals ... + tostring(SLEEP_DURATION * (IS_WINDOWS and 1000 or 1)), + } + if IS_WINDOWS then -- ... so we use milliseconds instead. - table.insert(args, 1, "-Milliseconds"); + table.insert(args, 1, "-Milliseconds") end -- Windows does not have `sleep` as a process, so we use powershell instead. - process.spawn("sleep", args, if isWindows then { shell = true } else nil) + process.spawn("sleep", args, if IS_WINDOWS then { shell = true } else nil) sleepCounter += 1 end) end @@ -141,31 +138,25 @@ end task.cancel(thread2) -local sleepElapsed = os.clock() - sleepStart - assert( - sleepElapsed >= SLEEP_DURATION, + (os.clock() - sleepStart) >= SLEEP_DURATION, "Spawning a process that does blocking sleep did not sleep enough" ) -assert( - sleepElapsed < yieldTolarance, - "Coroutine yielded the main lua thread during process yield" -) -- Inheriting stdio & environment variables should work local echoMessage = "Hello from child process!" local echoResult = process.spawn("echo", { - if isWindows then '"$Env:TEST_VAR"' else '"$TEST_VAR"', + if IS_WINDOWS then '"$Env:TEST_VAR"' else '"$TEST_VAR"', }, { env = { TEST_VAR = echoMessage }, - shell = if isWindows then "powershell" else "bash", -- "bash" does not exist on Windows, using "powershell" instead. + shell = if IS_WINDOWS then "powershell" else "bash", stdio = "inherit", }) --- Windows echo adds a \r before the newline -local trailingAddition = if isWindows then "\r\n" else "\n" +-- Windows echo adds \r\n (CRLF) and unix adds \n (LF) +local trailingAddition = if IS_WINDOWS then "\r\n" else "\n" assert( - echoResult.stdout == (echoMessage .. trailingAddition), -- Note that echo adds a newline + echoResult.stdout == (echoMessage .. trailingAddition), "Inheriting stdio did not return proper output" ) From 2b222d8e2a939414faf53cc819c8239ba7e11de1 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Mon, 25 Sep 2023 14:22:39 -0500 Subject: [PATCH 07/19] Format another test file --- tests/roblox/datatypes/CFrame.luau | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/roblox/datatypes/CFrame.luau b/tests/roblox/datatypes/CFrame.luau index ba4979c..b40d97a 100644 --- a/tests/roblox/datatypes/CFrame.luau +++ b/tests/roblox/datatypes/CFrame.luau @@ -127,15 +127,17 @@ assertEq( -- Angles +-- stylua: ignore start assertEq( - CFrame.Angles(math.pi/2, math.pi/4, math.pi/4), + CFrame.Angles(math.pi / 2, math.pi / 4, math.pi / 4), CFrame.new( - 0, 0, 0, - 0.49999997, -0.49999997, 0.707106769, - 0.49999994, -0.5, -0.707106769, + 0, 0, 0, + 0.49999997, -0.49999997, 0.707106769, + 0.49999994, -0.5, -0.707106769, 0.707106769, 0.707106769, 0 ) ) +-- stylua: ignore end -- TODO: More methods From 8ddafdf996ca9d29579426a31435cf5237f18121 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Mon, 25 Sep 2023 14:30:07 -0500 Subject: [PATCH 08/19] Add stylua format check to CI --- .github/workflows/ci.yaml | 5 ++++- .justfile | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bfe2683..98d95ea 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -25,8 +25,11 @@ jobs: with: components: rustfmt + - name: Install Just + uses: extractions/setup-just@v1 + - name: Check Formatting - run: cargo fmt -- --check + run: just fmt-check ci: needs: ["fmt"] diff --git a/.justfile b/.justfile index 33d8a26..0db0e59 100644 --- a/.justfile +++ b/.justfile @@ -9,3 +9,14 @@ run-file FILE_NAME: # Run tests for the Lune library test: cargo test --lib + +# Check formatting for all Rust & Luau files +fmt-check: + #!/usr/bin/env bash + set -euo pipefail + stylua scripts --check + stylua types --check + stylua tests --check \ + --glob "tests/**/*.luau" \ + --glob "!tests/roblox/rbx-test-files/**" + cargo fmt --check From 3df7750b5420f3c545eec81d546bbf8862b82ba1 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Mon, 25 Sep 2023 14:34:46 -0500 Subject: [PATCH 09/19] Add missing install step to CI workflow --- .github/workflows/ci.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 98d95ea..a0271b4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -28,6 +28,9 @@ jobs: - name: Install Just uses: extractions/setup-just@v1 + - name: Install Tooling + uses: ok-nick/setup-aftman@v0.4.2 + - name: Check Formatting run: just fmt-check From 854c3c6f7194088315b0b726c4427bf60d86fa2a Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Mon, 25 Sep 2023 14:44:46 -0500 Subject: [PATCH 10/19] Add note about powershell to changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa4522c..df8eae4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Update to Luau version `0.596`. +- `process.spawn` now uses `powershell` instead of `/bin/bash` as the shell on Windows, with `shell = true`. - CFrame and Vector3 values are now rounded to the nearest 2 ^ 16 decimal place to reduce floating point errors and diff noise. Note that this does not affect intermediate calculations done in lua, and only happens when a property value is set on an Instance. ### Fixed From 5f7bf6d3f276f7a80561f91f16b1d6af6fbf23a4 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Mon, 25 Sep 2023 14:52:26 -0500 Subject: [PATCH 11/19] Minor changes to readme for clarity and brevity --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 08dea4b..2981996 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ - +Lune logo ---- +

Lune

@@ -22,26 +22,26 @@
---- +
-A standalone [Luau](https://luau-lang.org) script runtime. +A standalone [Luau](https://luau-lang.org) runtime. -Write and run scripts, similar to runtimes for other languages such as [Node](https://nodejs.org) / [Deno](https://deno.land), or [Luvit](https://luvit.io) for vanilla Lua. +Write and run programs, similar to runtimes for other languages such as [Node](https://nodejs.org), [Deno](https://deno.land), [Bun](https://bun.sh), or [Luvit](https://luvit.io) for vanilla Lua. -Lune provides fully asynchronous APIs wherever possible, and is built in Rust 🦀 for optimal safety and correctness. +Lune provides fully asynchronous APIs wherever possible, and is built in Rust 🦀 for speed, safety and correctness. ## Features -- 🌙 A strictly minimal but powerful interface that is easy to read and remember, just like Luau itself -- 🧰 Fully featured APIs for the filesystem, networking, stdio, all included in the small (~4mb) executable +- 🌙 Strictly minimal but powerful interface that is easy to read and remember, just like Luau itself +- 🧰 Fully featured APIs for the filesystem, networking, stdio, all included in the small (~5mb) executable - 📚 World-class documentation, on the web _or_ directly in your editor, no network connection necessary -- 🏡 A familiar scripting environment for Roblox developers, with an included 1-to-1 task scheduler port +- 🏡 Familiar runtime environment for Roblox developers, with an included 1-to-1 task scheduler port - ✏️ Optional built-in library for manipulating Roblox place & model files, and their instances ## Non-goals -- Making scripts short and terse - proper autocomplete / intellisense make scripting using Lune just as quick, and readability is important -- Running full Roblox game scripts outside of Roblox - there is some compatibility, but Lune is meant for different purposes +- Making programs short and terse - proper autocomplete / intellisense make using Lune just as quick, and readability is important +- Running full Roblox games outside of Roblox - there is some compatibility, but Lune is meant for different purposes ## Where do I start? From dd1db5dcab23fd55421fa3fbeb23698c6f8ffeba Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Mon, 25 Sep 2023 15:43:32 -0500 Subject: [PATCH 12/19] Justfile and release workflow improvements --- .github/workflows/release.yaml | 70 ++++++-------------- .gitignore | 7 ++ .justfile | 117 ++++++++++++++++++++++++++++++--- 3 files changed, 133 insertions(+), 61 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 3acda52..85b25f1 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -10,9 +10,6 @@ defaults: run: shell: bash -env: - CARGO_TARGET_DIR: output - jobs: init: name: Init @@ -33,6 +30,7 @@ jobs: build: needs: ["init"] strategy: + fail-fast: false matrix: include: - name: Windows x86_64 @@ -71,6 +69,9 @@ jobs: with: targets: ${{ matrix.cargo-target }} + - name: Install Just + uses: extractions/setup-just@v1 + - name: Install build tooling (aarch64-unknown-linux-gnu) if: matrix.cargo-target == 'aarch64-unknown-linux-gnu' run: | @@ -79,26 +80,12 @@ jobs: sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu - name: Build binary - run: | - cargo build \ - --locked --release --all-features \ - --target ${{ matrix.cargo-target }} + run: just build --locked --release --target ${{ matrix.cargo-target }} - - name: Create binary archive - run: | - mkdir -p staging - if [ "${{ matrix.runner-os }}" = "windows-latest" ]; then - cp "output/${{ matrix.cargo-target }}/release/lune.exe" staging/ - cd staging - 7z a ../release.zip * - else - cp "output/${{ matrix.cargo-target }}/release/lune" staging/ - cd staging - chmod +x lune - zip ../release.zip * - fi + - name: Create release archive + run: just zip-release ${{ matrix.cargo-target }} - - name: Upload binary artifact + - name: Upload release artifact uses: actions/upload-artifact@v3 with: name: ${{ matrix.artifact-name }} @@ -109,38 +96,19 @@ jobs: runs-on: ubuntu-latest needs: ["init", "build"] steps: - - name: Download binaries + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Just + uses: extractions/setup-just@v1 + + - name: Download releases uses: actions/download-artifact@v3 with: - path: ./binaries + path: ./releases - - name: Discover binaries - run: | - cd ./binaries - echo "" - echo "Binaries dir:" - ls -lhrt - echo "" - echo "Searching for zipped releases..." - for DIR in * ; do - if [ -d "$DIR" ]; then - cd "$DIR" - for FILE in * ; do - if [ ! -d "$FILE" ]; then - if [ "$FILE" = "release.zip" ]; then - echo "Found zipped release '$DIR'" - mv "$FILE" "../$DIR.zip" - rm -rf "../$DIR/" - fi - fi - done - cd .. - fi - done - echo "" - echo "Binaries dir:" - ls -lhrt - cd .. + - name: Unpack releases + run: just unpack-releases "./releases" - name: Create release uses: softprops/action-gh-release@v1 @@ -150,5 +118,5 @@ jobs: name: ${{ needs.init.outputs.version }} tag_name: v${{ needs.init.outputs.version }} fail_on_unmatched_files: true - files: ./binaries/*.zip + files: ./releases/*.zip draft: true diff --git a/.gitignore b/.gitignore index a05cc5f..6f7b83e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,14 @@ # Autogenerated dirs /bin +/out /target +/staging + +/**/bin +/**/out +/**/target +/**/staging # Autogenerated files diff --git a/.justfile b/.justfile index 0db0e59..d29e1c3 100644 --- a/.justfile +++ b/.justfile @@ -1,22 +1,119 @@ -# Run an individual test using the Lune CLI -run-test TEST_NAME: - cargo run -- "tests/{{TEST_NAME}}" +EXT := if os() == "windows" { ".exe" } else { "" } +CWD := invocation_directory() +BIN_NAME := "lune" + +# Default hidden recipe for listing other recipes + cwd +[no-cd] +[no-exit-message] +[private] +default: + #!/usr/bin/env bash + set -euo pipefail + printf "Current directory:\n {{CWD}}\n" + just --list + +# Builds the Lune CLI binary +[no-exit-message] +build *ARGS: + #!/usr/bin/env bash + set -euo pipefail + cargo build --bin {{BIN_NAME}} {{ARGS}} # Run an individual file using the Lune CLI -run-file FILE_NAME: - cargo run -- "{{FILE_NAME}}" +[no-exit-message] +run FILE_PATH: + #!/usr/bin/env bash + set -euo pipefail + cargo run --bin {{BIN_NAME}} -- "{{FILE_PATH}}" # Run tests for the Lune library -test: - cargo test --lib +[no-exit-message] +test *ARGS: + #!/usr/bin/env bash + set -euo pipefail + cargo test --lib -- {{ARGS}} + +# Run tests for the Lune binary +[no-exit-message] +test-bin *ARGS: + #!/usr/bin/env bash + set -euo pipefail + cargo test --bin {{BIN_NAME}} -- {{ARGS}} + +# Apply formatting for all Rust & Luau files +[no-exit-message] +fmt: + #!/usr/bin/env bash + set -euo pipefail + stylua scripts tests types \ + --glob "tests/**/*.luau" \ + --glob "!tests/roblox/rbx-test-files/**" + cargo fmt # Check formatting for all Rust & Luau files +[no-exit-message] fmt-check: #!/usr/bin/env bash set -euo pipefail - stylua scripts --check - stylua types --check - stylua tests --check \ + stylua scripts tests types \ --glob "tests/**/*.luau" \ --glob "!tests/roblox/rbx-test-files/**" cargo fmt --check + +# Zips up the built binary into a single zip file +[no-exit-message] +zip-release TARGET_TRIPLE: + #!/usr/bin/env bash + set -euo pipefail + rm -rf staging + rm -rf release.zip + mkdir -p staging + cp "target/{{TARGET_TRIPLE}}/release/{{BIN_NAME}}{{EXT}}" staging/ + cd staging + if [ "{{os_family()}}" = "windows" ]; then + 7z a ../release.zip * + else + chmod +x {{BIN_NAME}} + zip ../release.zip * + fi + cd "{{CWD}}" + rm -rf staging + +# Used in GitHub workflow to move per-matrix release zips +[no-exit-message] +[private] +unpack-releases RELEASES_DIR: + #!/usr/bin/env bash + set -euo pipefail + # + if [ ! -d "{{RELEASES_DIR}}" ]; then + echo "Releases directory is missing" + exit 1 + fi + # + cd "{{RELEASES_DIR}}" + echo "" + echo "Releases dir:" + ls -lhrt + echo "" + echo "Searching for zipped releases..." + # + for DIR in * ; do + if [ -d "$DIR" ]; then + cd "$DIR" + for FILE in * ; do + if [ ! -d "$FILE" ]; then + if [ "$FILE" = "release.zip" ]; then + echo "Found zipped release '$DIR'" + mv "$FILE" "../$DIR.zip" + rm -rf "../$DIR/" + fi + fi + done + cd .. + fi + done + # + echo "" + echo "Releases dir:" + ls -lhrt From de0a570a4003cec76f7d1031ab876128543901df Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Mon, 25 Sep 2023 15:48:02 -0500 Subject: [PATCH 13/19] Dont lint unknown global in scripts --- scripts/font_enum_map.luau | 1 + scripts/physical_properties_enum_map.luau | 1 + 2 files changed, 2 insertions(+) diff --git a/scripts/font_enum_map.luau b/scripts/font_enum_map.luau index f6d4106..a0d1908 100644 --- a/scripts/font_enum_map.luau +++ b/scripts/font_enum_map.luau @@ -1,4 +1,5 @@ --!nocheck +--!nolint UnknownGlobal -- NOTE: This must be ran in Roblox Studio to get up-to-date font values diff --git a/scripts/physical_properties_enum_map.luau b/scripts/physical_properties_enum_map.luau index 62b3f97..3ad9f93 100644 --- a/scripts/physical_properties_enum_map.luau +++ b/scripts/physical_properties_enum_map.luau @@ -1,4 +1,5 @@ --!nocheck +--!nolint UnknownGlobal -- NOTE: This must be ran in Roblox Studio to get up-to-date enum values From 3b9830336ee3c8df7f1d0c857df0b739b11ee1a5 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Mon, 25 Sep 2023 16:30:26 -0500 Subject: [PATCH 14/19] Add luau-lsp analyze job to CI workflow --- .github/workflows/ci.yaml | 18 ++++++++++++++++-- .justfile | 13 +++++++++++-- .vscode/settings.json | 6 ------ 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a0271b4..3cd2189 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -17,8 +17,6 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 - with: - submodules: true - name: Install Rust uses: dtolnay/rust-toolchain@stable @@ -34,6 +32,22 @@ jobs: - name: Check Formatting run: just fmt-check + analyze: + name: Analyze and lint Luau files + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Just + uses: extractions/setup-just@v1 + + - name: Install Tooling + uses: ok-nick/setup-aftman@v0.4.2 + + - name: Analyze + run: just analyze + ci: needs: ["fmt"] strategy: diff --git a/.justfile b/.justfile index d29e1c3..99ea8ae 100644 --- a/.justfile +++ b/.justfile @@ -45,7 +45,7 @@ test-bin *ARGS: fmt: #!/usr/bin/env bash set -euo pipefail - stylua scripts tests types \ + stylua .lune scripts tests types \ --glob "tests/**/*.luau" \ --glob "!tests/roblox/rbx-test-files/**" cargo fmt @@ -55,11 +55,20 @@ fmt: fmt-check: #!/usr/bin/env bash set -euo pipefail - stylua scripts tests types \ + stylua .lune scripts tests types \ --glob "tests/**/*.luau" \ --glob "!tests/roblox/rbx-test-files/**" cargo fmt --check +# Analyze and lint Luau files using luau-lsp +[no-exit-message] +analyze: + #!/usr/bin/env bash + set -euo pipefail + luau-lsp analyze .lune scripts tests types \ + --settings=".vscode/settings.json" \ + --ignore="tests/roblox/rbx-test-files/**" + # Zips up the built binary into a single zip file [no-exit-message] zip-release TARGET_TRIPLE: diff --git a/.vscode/settings.json b/.vscode/settings.json index 9652462..e7ff588 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,21 +1,15 @@ { - // Luau - disable Roblox features, enable Lune typedefs & requires "luau-lsp.sourcemap.enabled": false, "luau-lsp.types.roblox": false, "luau-lsp.require.mode": "relativeToFile", "luau-lsp.require.directoryAliases": { "@lune/": "./types/" }, - // Luau - ignore type defs file in docs dir and dev scripts we use "luau-lsp.ignoreGlobs": [ - "docs/*.d.luau", - "packages/lib-roblox/scripts/*.luau", "tests/roblox/rbx-test-files/**/*.lua", "tests/roblox/rbx-test-files/**/*.luau" ], - // Rust "rust-analyzer.check.command": "clippy", - // Formatting "editor.formatOnSave": true, "stylua.searchParentDirectories": true, "prettier.tabWidth": 2, From 165987d60b3b8eec6fb350bb14406f0cd85c0790 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Mon, 25 Sep 2023 16:34:40 -0500 Subject: [PATCH 15/19] Only run analyze in CI if formatting succeeds --- .github/workflows/ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3cd2189..3c68822 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -33,6 +33,7 @@ jobs: run: just fmt-check analyze: + needs: ["fmt"] name: Analyze and lint Luau files runs-on: ubuntu-latest steps: From bdec11996df5fdc535945d61117d6507ca255662 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Mon, 25 Sep 2023 16:42:00 -0500 Subject: [PATCH 16/19] Temp rename typedef files --- types/{DateTime.luau => datetime-temp.luau} | 0 types/{FS.luau => fs-temp.luau} | 0 types/{Luau.luau => luau-temp.luau} | 0 types/{Net.luau => net-temp.luau} | 0 types/{Process.luau => process-temp.luau} | 0 types/{Roblox.luau => roblox-temp.luau} | 0 types/{Serde.luau => serde-temp.luau} | 0 types/{Stdio.luau => stdio-temp.luau} | 0 types/{Task.luau => task-temp.luau} | 0 9 files changed, 0 insertions(+), 0 deletions(-) rename types/{DateTime.luau => datetime-temp.luau} (100%) rename types/{FS.luau => fs-temp.luau} (100%) rename types/{Luau.luau => luau-temp.luau} (100%) rename types/{Net.luau => net-temp.luau} (100%) rename types/{Process.luau => process-temp.luau} (100%) rename types/{Roblox.luau => roblox-temp.luau} (100%) rename types/{Serde.luau => serde-temp.luau} (100%) rename types/{Stdio.luau => stdio-temp.luau} (100%) rename types/{Task.luau => task-temp.luau} (100%) diff --git a/types/DateTime.luau b/types/datetime-temp.luau similarity index 100% rename from types/DateTime.luau rename to types/datetime-temp.luau diff --git a/types/FS.luau b/types/fs-temp.luau similarity index 100% rename from types/FS.luau rename to types/fs-temp.luau diff --git a/types/Luau.luau b/types/luau-temp.luau similarity index 100% rename from types/Luau.luau rename to types/luau-temp.luau diff --git a/types/Net.luau b/types/net-temp.luau similarity index 100% rename from types/Net.luau rename to types/net-temp.luau diff --git a/types/Process.luau b/types/process-temp.luau similarity index 100% rename from types/Process.luau rename to types/process-temp.luau diff --git a/types/Roblox.luau b/types/roblox-temp.luau similarity index 100% rename from types/Roblox.luau rename to types/roblox-temp.luau diff --git a/types/Serde.luau b/types/serde-temp.luau similarity index 100% rename from types/Serde.luau rename to types/serde-temp.luau diff --git a/types/Stdio.luau b/types/stdio-temp.luau similarity index 100% rename from types/Stdio.luau rename to types/stdio-temp.luau diff --git a/types/Task.luau b/types/task-temp.luau similarity index 100% rename from types/Task.luau rename to types/task-temp.luau From 3ddd8b46762865214ddfda7686959cef15fc81c3 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Mon, 25 Sep 2023 16:42:35 -0500 Subject: [PATCH 17/19] Make typedef files all lowercase --- types/{datetime-temp.luau => datetime.luau} | 0 types/{fs-temp.luau => fs.luau} | 0 types/{luau-temp.luau => luau.luau} | 0 types/{net-temp.luau => net.luau} | 0 types/{process-temp.luau => process.luau} | 0 types/{roblox-temp.luau => roblox.luau} | 0 types/{serde-temp.luau => serde.luau} | 0 types/{stdio-temp.luau => stdio.luau} | 0 types/{task-temp.luau => task.luau} | 0 9 files changed, 0 insertions(+), 0 deletions(-) rename types/{datetime-temp.luau => datetime.luau} (100%) rename types/{fs-temp.luau => fs.luau} (100%) rename types/{luau-temp.luau => luau.luau} (100%) rename types/{net-temp.luau => net.luau} (100%) rename types/{process-temp.luau => process.luau} (100%) rename types/{roblox-temp.luau => roblox.luau} (100%) rename types/{serde-temp.luau => serde.luau} (100%) rename types/{stdio-temp.luau => stdio.luau} (100%) rename types/{task-temp.luau => task.luau} (100%) diff --git a/types/datetime-temp.luau b/types/datetime.luau similarity index 100% rename from types/datetime-temp.luau rename to types/datetime.luau diff --git a/types/fs-temp.luau b/types/fs.luau similarity index 100% rename from types/fs-temp.luau rename to types/fs.luau diff --git a/types/luau-temp.luau b/types/luau.luau similarity index 100% rename from types/luau-temp.luau rename to types/luau.luau diff --git a/types/net-temp.luau b/types/net.luau similarity index 100% rename from types/net-temp.luau rename to types/net.luau diff --git a/types/process-temp.luau b/types/process.luau similarity index 100% rename from types/process-temp.luau rename to types/process.luau diff --git a/types/roblox-temp.luau b/types/roblox.luau similarity index 100% rename from types/roblox-temp.luau rename to types/roblox.luau diff --git a/types/serde-temp.luau b/types/serde.luau similarity index 100% rename from types/serde-temp.luau rename to types/serde.luau diff --git a/types/stdio-temp.luau b/types/stdio.luau similarity index 100% rename from types/stdio-temp.luau rename to types/stdio.luau diff --git a/types/task-temp.luau b/types/task.luau similarity index 100% rename from types/task-temp.luau rename to types/task.luau From 5efc8da300c56195e74d6a6d23c7e53b027490a5 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Mon, 25 Sep 2023 16:51:38 -0500 Subject: [PATCH 18/19] Fix builtin require casing in test file --- tests/datetime/toUniversalTime.luau | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/datetime/toUniversalTime.luau b/tests/datetime/toUniversalTime.luau index 7e181ef..edf1c31 100644 --- a/tests/datetime/toUniversalTime.luau +++ b/tests/datetime/toUniversalTime.luau @@ -1,4 +1,4 @@ -local DateTime = require("@lune/DateTime") +local DateTime = require("@lune/datetime") local values = DateTime.fromIsoDate("2023-08-27T05:54:19Z"):toLocalTime() From bb23d0a9cdf4d1275fee70c62811ba3af77727ba Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Mon, 25 Sep 2023 17:34:46 -0500 Subject: [PATCH 19/19] Update tooling --- aftman.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aftman.toml b/aftman.toml index 37eb389..7c2a05f 100644 --- a/aftman.toml +++ b/aftman.toml @@ -1,4 +1,4 @@ [tools] -luau-lsp = "JohnnyMorganz/luau-lsp@1.23.0" +luau-lsp = "JohnnyMorganz/luau-lsp@1.24.1" selene = "Kampfkarren/selene@0.25.0" -stylua = "JohnnyMorganz/StyLua@0.18.1" +stylua = "JohnnyMorganz/StyLua@0.18.2"