Skip to content

Commit

Permalink
publish: add additional logic handle polars rev metadata
Browse files Browse the repository at this point in the history
- if we're publishing on a release version of Rust Polars, it will have the `-release` suffix
- if QSV_POLARS_REV is not found or set properly, set suffix to `-unknown`
  • Loading branch information
jqnatividad committed Aug 24, 2024
1 parent 8ec07cd commit e60e44f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ local-encoding = { git = "/~https://github.com/slonopotamus/local-encoding-rs", br
# or a specific commit if more revisions have been made since the latest polars/py-polars release.
# BUILD NOTE: Be sure to set QSV_POLARS_REV below to the latest commit short hash or tag
# of polars/py-polars before building qsv. This allows us to show the polars rev/tag in --version.
# if we are using a release version of Rust Polars, leave QSV_POLARS_REV empty
# QSV_POLARS_REV=5cfc1f0
# polars = { git = "/~https://github.com/pola-rs/polars", tag = "py-1.4.1" }
polars = { git = "/~https://github.com/pola-rs/polars", rev = "5cfc1f0" }
Expand Down
32 changes: 17 additions & 15 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,23 @@ fn main() {
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)
let polars_rev = cargo_toml_content.find(QSV_POLARS_REV).map_or_else(
|| "-unknown".to_string(),
|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);
let final_rev = cargo_toml_content[start_index..end_index]
.trim()
.to_string();
if final_rev.is_empty() {
"-release".to_string()
} else {
final_rev
}
},
);
println!("cargo:rustc-env=QSV_POLARS_REV={polars_rev}");
}
}

0 comments on commit e60e44f

Please sign in to comment.