Skip to content

Commit

Permalink
build: only set polars version metadata when building with polars f…
Browse files Browse the repository at this point in the history
…eature
  • Loading branch information
jqnatividad committed Aug 21, 2024
1 parent f2866ab commit 607eb0e
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions build.rs
Original file line number Diff line number Diff line change
@@ -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!(
Expand All @@ -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)
);
}
}

0 comments on commit 607eb0e

Please sign in to comment.