Skip to content

Commit

Permalink
fix(GH-160): serialized-stdlib feature
Browse files Browse the repository at this point in the history
  • Loading branch information
JarvisCraft committed May 10, 2024
1 parent d2cbc43 commit 3a03ca5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 6 additions & 2 deletions crates/jrsonnet-stdlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ workspace = true

[features]
default = ["codegenerated-stdlib"]
# Speed-up initialization by generating code for parsed stdlib, instead
# of invoking parser for it
# Speed-up initialization by generating code for parsed stdlib,
# instead of invoking parser for it.
# This is mutually exclusive with `serialized-stdlib`.
codegenerated-stdlib = ["jrsonnet-parser/structdump"]
# Use the embedded serialized stdlib.
# This is mutually exclusive with `codegenerated-stdlib`.
serialized-stdlib = []
# Enables legacy `std.thisFile` support, at the cost of worse caching
legacy-this-file = []
# Add order preservation flag to some functions
Expand Down
10 changes: 7 additions & 3 deletions crates/jrsonnet-stdlib/src/expr.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use jrsonnet_parser::LocExpr;

pub fn stdlib_expr() -> LocExpr {
#[cfg(feature = "serialized-stdlib")]
#[cfg(all(feature = "serialized-stdlib", feature = "codegenerated-stdlib"))]
compile_error!(
"features `serialized-stdlib` and `codegenerated-stdlib` are mutually exclusive"
);
#[cfg(all(feature = "serialized-stdlib", not(feature = "codegenerated-stdlib")))]
{
use bincode::{BincodeRead, DefaultOptions, Options};
use serde::{Deserialize, Deserializer};
Expand Down Expand Up @@ -77,7 +81,7 @@ pub fn stdlib_expr() -> LocExpr {
LocExpr::deserialize(&mut deserializer).unwrap()
}

#[cfg(feature = "codegenerated-stdlib")]
#[cfg(all(feature = "codegenerated-stdlib", not(feature = "serialized-stdlib")))]
{
mod structdump_import {
pub(super) use std::{option::Option, rc::Rc, vec};
Expand All @@ -88,7 +92,7 @@ pub fn stdlib_expr() -> LocExpr {
include!(concat!(env!("OUT_DIR"), "/stdlib.rs"))
}

#[cfg(not(feature = "codegenerated-stdlib"))]
#[cfg(not(any(feature = "serialized-stdlib", feature = "codegenerated-stdlib")))]
{
use jrsonnet_parser::Source;

Expand Down

0 comments on commit 3a03ca5

Please sign in to comment.