forked from pgcentralfoundation/pgrx
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.rs
31 lines (30 loc) · 1.42 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
//LICENSE
//LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
//LICENSE
//LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc. <[email protected]>
//LICENSE
//LICENSE All rights reserved.
//LICENSE
//LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
fn main() {
println!("cargo:rerun-if-changed=build.rs");
if let Some(cargo_version) = cargo_version() {
println!("cargo:rustc-env=CARGO_VERSION_DURING_BUILD={cargo_version}");
}
}
/// Gets the current `cargo` version.
///
/// Used to check our toolchain version. `cargo` sets the `CARGO` env var both
/// when running the build script and when running `cargo-pgrx`, so it's easier
/// to check `cargo` than to check `rustc` itself. Also `cargo` will
/// always have the same version as the `rustc` it goes with, so checking the
/// `cargo` version is sufficient.
///
/// [Reference: Environment variables Cargo sets for build
/// scripts](https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts)
fn cargo_version() -> Option<String> {
let cargo = std::env::var_os("CARGO").expect("`CARGO` env var wasn't set!");
let output = std::process::Command::new(cargo).arg("--version").output().ok()?;
std::str::from_utf8(&output.stdout).map(|s| s.trim().to_string()).ok()
}