diff --git a/crates/jrsonnet-stdlib/Cargo.toml b/crates/jrsonnet-stdlib/Cargo.toml index 910afc5e..8fdba162 100644 --- a/crates/jrsonnet-stdlib/Cargo.toml +++ b/crates/jrsonnet-stdlib/Cargo.toml @@ -16,9 +16,13 @@ exp-preserve-order = ["jrsonnet-evaluator/exp-preserve-order"] # Bigint type exp-bigint = ["dep:num-bigint", "jrsonnet-evaluator/exp-bigint"] -exp-null-coaelse = ["jrsonnet-parser/exp-null-coaelse", "jrsonnet-evaluator/exp-null-coaelse"] +exp-null-coaelse = [ + "jrsonnet-parser/exp-null-coaelse", + "jrsonnet-evaluator/exp-null-coaelse", +] # std.regexMatch and other helpers exp-regex = ["dep:regex", "dep:lru", "dep:rustc-hash"] +yaml = ["dep:serde_yaml_with_quirks"] [dependencies] jrsonnet-evaluator.workspace = true @@ -42,7 +46,7 @@ base64.workspace = true # std.parseJson serde_json.workspace = true # std.parseYaml, custom library fork is used for C++/golang compatibility -serde_yaml_with_quirks.workspace = true +serde_yaml_with_quirks = { workspace = true, optional = true } num-bigint = { workspace = true, optional = true } diff --git a/crates/jrsonnet-stdlib/src/lib.rs b/crates/jrsonnet-stdlib/src/lib.rs index de84777f..0a476d39 100644 --- a/crates/jrsonnet-stdlib/src/lib.rs +++ b/crates/jrsonnet-stdlib/src/lib.rs @@ -176,6 +176,7 @@ pub fn stdlib_uncached(settings: Rc>) -> ObjValue { ("manifestIni", builtin_manifest_ini::INST), // Parse ("parseJson", builtin_parse_json::INST), + #[cfg(feature = "yaml")] ("parseYaml", builtin_parse_yaml::INST), // Strings ("codepoint", builtin_codepoint::INST), diff --git a/crates/jrsonnet-stdlib/src/parse.rs b/crates/jrsonnet-stdlib/src/parse.rs index 0b91ba6f..d200a5cf 100644 --- a/crates/jrsonnet-stdlib/src/parse.rs +++ b/crates/jrsonnet-stdlib/src/parse.rs @@ -1,5 +1,4 @@ use jrsonnet_evaluator::{function::builtin, runtime_error, IStr, Result, Val}; -use serde::Deserialize; #[builtin] pub fn builtin_parse_json(str: IStr) -> Result { @@ -9,8 +8,11 @@ pub fn builtin_parse_json(str: IStr) -> Result { } #[builtin] +#[cfg(feature = "yaml")] pub fn builtin_parse_yaml(str: IStr) -> Result { + use serde::Deserialize; use serde_yaml_with_quirks::DeserializingQuirks; + let value = serde_yaml_with_quirks::Deserializer::from_str_with_quirks( &str, DeserializingQuirks { old_octals: true },