From d335b5b2b7061274645d2660ec6065fdc8647efe Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Tue, 21 Apr 2026 15:23:21 -0400 Subject: [PATCH 1/2] glean-build: Allow to overwrite venv dir in code --- glean-core/build/src/lib.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/glean-core/build/src/lib.rs b/glean-core/build/src/lib.rs index 451ce1a9ea..e7cf3695c9 100644 --- a/glean-core/build/src/lib.rs +++ b/glean-core/build/src/lib.rs @@ -45,6 +45,7 @@ const GLEAN_PARSER_VERSION: &str = "19.0.0"; pub struct Builder { files: Vec, out_dir: String, + env_dir: Option, } impl Default for Builder { @@ -57,6 +58,7 @@ impl Default for Builder { Self { files: vec![], out_dir, + env_dir: None, } } } @@ -70,6 +72,7 @@ impl Builder { Self { files: vec![], out_dir: out_dir.into(), + env_dir: None, } } @@ -93,6 +96,15 @@ impl Builder { self } + /// Set environment path to use. + pub fn env_dir

(&mut self, path: P) -> &mut Self + where + P: Into, + { + self.env_dir = Some(path.into()); + self + } + /// Generate the Rust bindings. /// /// The consumer must include the generated `glean_metrics.rs` file, e.g.: @@ -111,6 +123,8 @@ impl Builder { eprintln!("got env dir: {env_dir}"); let env_path = PathBuf::from(env_dir); VirtualEnv::with_path(&sh, &env_path)? + } else if let Some(env_dir) = &self.env_dir { + VirtualEnv::with_path(&sh, env_dir)? } else { let venv = VirtualEnv::new(&sh, "py3-glean_parser")?; From d95c829314aaa3094ac52a2010fc2ce2aae7e1bd Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Fri, 17 Apr 2026 13:45:45 -0400 Subject: [PATCH 2/2] glean-build: Allow to change target format --- glean-core/build/src/lib.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/glean-core/build/src/lib.rs b/glean-core/build/src/lib.rs index e7cf3695c9..dab1a7dde0 100644 --- a/glean-core/build/src/lib.rs +++ b/glean-core/build/src/lib.rs @@ -46,6 +46,7 @@ pub struct Builder { files: Vec, out_dir: String, env_dir: Option, + format: String, } impl Default for Builder { @@ -59,6 +60,7 @@ impl Default for Builder { files: vec![], out_dir, env_dir: None, + format: String::from("rust"), } } } @@ -73,6 +75,7 @@ impl Builder { files: vec![], out_dir: out_dir.into(), env_dir: None, + format: String::from("rust"), } } @@ -84,6 +87,12 @@ impl Builder { self } + /// Change output format. Defaults to `rust`. + pub fn format>(&mut self, format: S) -> &mut Self { + self.format = format.into(); + self + } + /// Add multiple definition files, e.g. `metrics.yaml` or `pings.yaml`. pub fn files

(&mut self, files: P) -> &mut Self where @@ -139,7 +148,8 @@ impl Builder { println!("cargo:rerun-if-changed={file}"); } - let mut args = vec!["translate", "--format", "rust", "--output", out_dir]; + let mut args = vec!["translate", "--output", out_dir]; + args.extend(["--format", &self.format]); args.extend(self.files.iter().map(|s| s.as_str())); venv.run_module("glean_parser", &args)?;