git.delta.rocks / jrsonnet / refs/commits / 58e35be8e6f4

difftreelog

fix build without codegenerated-stdlib feature

Yaroslav Bolyukin2023-04-08parent: #759cfac.patch.diff
in: master

2 files changed

modifiedcrates/jrsonnet-stdlib/build.rsdiffbeforeafterboth
--- 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("<std>".into(), include_str!("./src/std.jsonnet").into()),
-		},
-	)
-	.expect("parse");
+		let parsed = parse(
+			include_str!("./src/std.jsonnet"),
+			&ParserSettings {
+				source: Source::new_virtual(
+					"<std>".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();
+		}
 	}
 }
modifiedcrates/jrsonnet-stdlib/src/expr.rsdiffbeforeafterboth
1use jrsonnet_parser::LocExpr;1use jrsonnet_parser::LocExpr;
2
3mod structdump_import {
4 pub(super) use std::{option::Option, rc::Rc, vec};
5
6 pub(super) use jrsonnet_parser::*;
7}
82
9pub fn stdlib_expr() -> LocExpr {3pub fn stdlib_expr() -> LocExpr {
10 #[cfg(feature = "serialized-stdlib")]4 #[cfg(feature = "serialized-stdlib")]
8579
86 #[cfg(feature = "codegenerated-stdlib")]80 #[cfg(feature = "codegenerated-stdlib")]
87 {81 {
82 mod structdump_import {
83 pub(super) use std::{option::Option, rc::Rc, vec};
84
85 pub(super) use jrsonnet_parser::*;
86 };
87
88 include!(concat!(env!("OUT_DIR"), "/stdlib.rs"))88 include!(concat!(env!("OUT_DIR"), "/stdlib.rs"))
89 }89 }
9090
91 #[cfg(not(feature = "codegenerated-stdlib"))]91 #[cfg(not(feature = "codegenerated-stdlib"))]
92 {92 {
93 use jrsonnet_parser::Source;
94
95 const STDLIB_STR: &str = include_str!("./std.jsonnet");
96
93 jrsonnet_parser::parse(97 jrsonnet_parser::parse(
94 STDLIB_STR,98 STDLIB_STR,
95 &ParserSettings {99 &jrsonnet_parser::ParserSettings {
96 file_name: Source::new_virtual(Cow::Borrowed("<std>"), STDLIB_STR.into()),100 source: Source::new_virtual("<std>".into(), STDLIB_STR.into()),
97 },101 },
98 )102 )
99 .unwrap()103 .unwrap()