Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move yaml behind feature gate #185

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions crates/jrsonnet-stdlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yaml should be added to default-features,

default = ["yaml"]

But then this feature would need to be forwarded thru jrsonnet-cli/jrsonnet crates, and there is no easy way to opt-out of the features other than default-features=false, making this flag not easily usable.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is your suggestion?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is hard to make proper opt-out features, so I would prefer not to make yaml optional.


[dependencies]
jrsonnet-evaluator.workspace = true
Expand All @@ -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 }

Expand Down
1 change: 1 addition & 0 deletions crates/jrsonnet-stdlib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ pub fn stdlib_uncached(settings: Rc<RefCell<Settings>>) -> 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),
Expand Down
4 changes: 3 additions & 1 deletion crates/jrsonnet-stdlib/src/parse.rs
Original file line number Diff line number Diff line change
@@ -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<Val> {
Expand All @@ -9,8 +8,11 @@ pub fn builtin_parse_json(str: IStr) -> Result<Val> {
}

#[builtin]
#[cfg(feature = "yaml")]
pub fn builtin_parse_yaml(str: IStr) -> Result<Val> {
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 },
Expand Down