From 58e35be8e6f4fb25d8112a151117d23f89c9719f Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Sat, 08 Apr 2023 19:46:46 +0000 Subject: [PATCH] fix: build without codegenerated-stdlib feature --- --- a/crates/jrsonnet-stdlib/build.rs +++ b/crates/jrsonnet-stdlib/build.rs @@ -1,30 +1,34 @@ -use std::{env, fs::File, io::Write, path::Path}; +fn main() { + #[cfg(feature = "codegenerated-stdlib")] + { + use std::{env, fs::File, io::Write, path::Path}; -use jrsonnet_parser::{parse, ParserSettings, Source}; -use structdump::CodegenResult; + use jrsonnet_parser::{parse, ParserSettings, Source}; + use structdump::CodegenResult; -fn main() { - let parsed = parse( - include_str!("./src/std.jsonnet"), - &ParserSettings { - source: Source::new_virtual("".into(), include_str!("./src/std.jsonnet").into()), - }, - ) - .expect("parse"); + let parsed = parse( + include_str!("./src/std.jsonnet"), + &ParserSettings { + source: Source::new_virtual( + "".into(), + include_str!("./src/std.jsonnet").into(), + ), + }, + ) + .expect("parse"); - let mut out = CodegenResult::default(); + let mut out = CodegenResult::default(); - let v = out.codegen(&parsed, true); + let v = out.codegen(&parsed, true); - { - let out_dir = env::var("OUT_DIR").unwrap(); - let dest_path = Path::new(&out_dir).join("stdlib.rs"); - let mut f = File::create(dest_path).unwrap(); - f.write_all( - ("#[allow(clippy::redundant_clone)]".to_owned() + &v.to_string()) - .replace(';', ";\n") - .as_bytes(), - ) - .unwrap(); + { + let out_dir = env::var("OUT_DIR").unwrap(); + let dest_path = Path::new(&out_dir).join("stdlib.rs"); + let mut f = File::create(dest_path).unwrap(); + f.write_all( + ("#[allow(clippy::redundant_clone)]".to_owned() + &v.to_string()).as_bytes(), + ) + .unwrap(); + } } } --- a/crates/jrsonnet-stdlib/src/expr.rs +++ b/crates/jrsonnet-stdlib/src/expr.rs @@ -1,11 +1,5 @@ use jrsonnet_parser::LocExpr; -mod structdump_import { - pub(super) use std::{option::Option, rc::Rc, vec}; - - pub(super) use jrsonnet_parser::*; -} - pub fn stdlib_expr() -> LocExpr { #[cfg(feature = "serialized-stdlib")] { @@ -85,15 +79,25 @@ #[cfg(feature = "codegenerated-stdlib")] { + mod structdump_import { + pub(super) use std::{option::Option, rc::Rc, vec}; + + pub(super) use jrsonnet_parser::*; + }; + include!(concat!(env!("OUT_DIR"), "/stdlib.rs")) } #[cfg(not(feature = "codegenerated-stdlib"))] { + use jrsonnet_parser::Source; + + const STDLIB_STR: &str = include_str!("./std.jsonnet"); + jrsonnet_parser::parse( STDLIB_STR, - &ParserSettings { - file_name: Source::new_virtual(Cow::Borrowed(""), STDLIB_STR.into()), + &jrsonnet_parser::ParserSettings { + source: Source::new_virtual("".into(), STDLIB_STR.into()), }, ) .unwrap() -- gitstuff