diff --git a/Cargo.lock b/Cargo.lock index 8b10ef885..500a8ce3a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1271,6 +1271,7 @@ dependencies = [ "limbo_ext", "limbo_macros", "limbo_percentile", + "limbo_regexp", "limbo_uuid", "log", "miette", diff --git a/core/Cargo.toml b/core/Cargo.toml index 81f3b454c..694617ec3 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -14,7 +14,7 @@ name = "limbo_core" path = "lib.rs" [features] -default = ["fs", "json", "uuid", "io_uring", "percentile"] +default = ["fs", "json", "uuid", "io_uring"] fs = [] json = [ "dep:jsonb", @@ -24,6 +24,7 @@ json = [ uuid = ["limbo_uuid/static"] io_uring = ["dep:io-uring", "rustix/io_uring"] percentile = ["limbo_percentile/static"] +regexp = ["limbo_regexp/static"] [target.'cfg(target_os = "linux")'.dependencies] io-uring = { version = "0.6.1", optional = true } @@ -60,6 +61,7 @@ rand = "0.8.5" bumpalo = { version = "3.16.0", features = ["collections", "boxed"] } limbo_macros = { path = "../macros" } limbo_uuid = { path = "../extensions/uuid", optional = true, features = ["static"] } +limbo_regexp = { path = "../extensions/regexp", optional = true, features = ["static"] } limbo_percentile = { path = "../extensions/percentile", optional = true, features = ["static"] } miette = "7.4.0" diff --git a/core/ext/mod.rs b/core/ext/mod.rs index 377853769..cbd2fa258 100644 --- a/core/ext/mod.rs +++ b/core/ext/mod.rs @@ -75,28 +75,19 @@ impl Database { } pub fn register_builtins(&self) -> Result<(), String> { + let ext_api = self.build_limbo_ext(); #[cfg(feature = "uuid")] - self.register_uuid()?; - #[cfg(feature = "percentile")] - self.register_percentile()?; - Ok(()) - } - - #[cfg(feature = "uuid")] - pub fn register_uuid(&self) -> Result<(), String> { - let ext_api = Box::new(self.build_limbo_ext()); if unsafe { !limbo_uuid::register_extension_static(&ext_api).is_ok() } { return Err("Failed to register uuid extension".to_string()); } - Ok(()) - } - - #[cfg(feature = "percentile")] - pub fn register_percentile(&self) -> Result<(), String> { - let ext_api = self.build_limbo_ext(); + #[cfg(feature = "percentile")] if unsafe { !limbo_percentile::register_extension_static(&ext_api).is_ok() } { return Err("Failed to register percentile extension".to_string()); } + #[cfg(feature = "regexp")] + if unsafe { !limbo_regexp::register_extension_static(&ext_api).is_ok() } { + return Err("Failed to register regexp extension".to_string()); + } Ok(()) } } diff --git a/extensions/regexp/Cargo.toml b/extensions/regexp/Cargo.toml index dc2f87c3b..9ca5c222f 100644 --- a/extensions/regexp/Cargo.toml +++ b/extensions/regexp/Cargo.toml @@ -6,11 +6,14 @@ edition.workspace = true license.workspace = true repository.workspace = true +[features] +static = ["limbo_ext/static"] + [lib] crate-type = ["cdylib", "lib"] [dependencies] -limbo_ext = { path = "../core"} +limbo_ext = { path = "../core", features = ["static"] } regex = "1.11.1" log = "0.4.20" diff --git a/testing/extensions.py b/testing/extensions.py index 915465e9b..74755a012 100755 --- a/testing/extensions.py +++ b/testing/extensions.py @@ -133,7 +133,6 @@ def assert_specific_time(result): def test_uuid(pipe): specific_time = "01945ca0-3189-76c0-9a8f-caf310fc8b8e" - # these are built into the binary, so we just test they work run_test( pipe, @@ -210,7 +209,20 @@ def validate_percentile_disc(res): def test_aggregates(pipe): - # also built-in + extension_path = "./target/debug/liblimbo_percentile.so" + # assert no function before extension loads + run_test( + pipe, + "SELECT median(1);", + returns_error, + "median agg function returns null when ext not loaded", + ) + run_test( + pipe, + f".load {extension_path}", + returns_null, + "load extension command works properly", + ) run_test( pipe, "select median(value) from numbers;", @@ -260,4 +272,3 @@ def main(): if __name__ == "__main__": main() -