From 607eb0e9c5cd5469ed1f5713d4356ee8ab73f402 Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Wed, 21 Aug 2024 05:37:19 -0400 Subject: [PATCH] `build`: only set polars version metadata when building with polars feature --- build.rs | 54 +++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/build.rs b/build.rs index dd9e48d45..e64d5dfa0 100644 --- a/build.rs +++ b/build.rs @@ -1,8 +1,3 @@ -use std::{fs, path::Path}; - -// This is the string that is searched for in Cargo.toml to find the Polars revision -const QSV_POLARS_REV: &str = "# QSV_POLARS_REV="; - fn main() { // we use TARGET in --version and user-agent strings println!( @@ -16,24 +11,33 @@ fn main() { std::env::var("QSV_KIND").unwrap_or_else(|_| "compiled".to_string()) ); - // QSV_POLARS_REV contains either the commit id short hash or the git tag - // of the Polars version qsv was built against - let cargo_toml_path = Path::new("Cargo.toml"); - let cargo_toml_content = - fs::read_to_string(cargo_toml_path).expect("Failed to read Cargo.toml"); - let polars_rev = cargo_toml_content - .find(QSV_POLARS_REV) - .map_or_else(String::new, |index| { - let start_index = index + QSV_POLARS_REV.len(); - let end_index = cargo_toml_content[start_index..] - .find('\n') - .map_or(cargo_toml_content.len(), |i| start_index + i); - cargo_toml_content[start_index..end_index] - .trim() - .to_string() - }); - println!( - "cargo:rustc-env=QSV_POLARS_REV={}", - std::env::var("QSV_POLARS_REV").unwrap_or(polars_rev) - ); + #[cfg(feature = "polars")] + { + use std::{fs, path::Path}; + + // This is the string that is searched for in Cargo.toml to find the Polars revision + const QSV_POLARS_REV: &str = "# QSV_POLARS_REV="; + + // QSV_POLARS_REV contains either the commit id short hash or the git tag + // of the Polars version qsv was built against + let cargo_toml_path = Path::new("Cargo.toml"); + let cargo_toml_content = + fs::read_to_string(cargo_toml_path).expect("Failed to read Cargo.toml"); + let polars_rev = + cargo_toml_content + .find(QSV_POLARS_REV) + .map_or_else(String::new, |index| { + let start_index = index + QSV_POLARS_REV.len(); + let end_index = cargo_toml_content[start_index..] + .find('\n') + .map_or(cargo_toml_content.len(), |i| start_index + i); + cargo_toml_content[start_index..end_index] + .trim() + .to_string() + }); + println!( + "cargo:rustc-env=QSV_POLARS_REV={}", + std::env::var("QSV_POLARS_REV").unwrap_or(polars_rev) + ); + } }