()
| 44 | } |
| 45 | |
| 46 | fn main() { |
| 47 | // libgit2 1.8 (libgit2-sys 0.17.0+1.8.1) references Advapi32 symbols |
| 48 | // (GetNamedSecurityInfoW, RegOpenKeyExW, RegQueryValueExW, RegCloseKey) |
| 49 | // but its build script never links Advapi32 on MSVC. Emitted from this |
| 50 | // crate's own build script so every binary and test binary of this |
| 51 | // crate resolves them (a wrapper crate's flags are dropped from the |
| 52 | // link graph when nothing references it). |
| 53 | if std::env::var_os("CARGO_CFG_WINDOWS").is_some() { |
| 54 | println!("cargo:rustc-link-lib=advapi32"); |
| 55 | } |
| 56 | |
| 57 | println!("cargo:rerun-if-changed=build.rs"); |
| 58 | println!("cargo:rerun-if-env-changed=ATOMIC_BUILD_CHANNEL"); |
| 59 | println!("cargo:rerun-if-env-changed=ATOMIC_BUILD_COMMIT"); |
| 60 | |
| 61 | let version = env::var("CARGO_PKG_VERSION").expect("Cargo supplies the package version"); |
| 62 | let channel = env::var("ATOMIC_BUILD_CHANNEL").unwrap_or_else(|_| "dev".to_string()); |
| 63 | match channel.as_str() { |
| 64 | "release" => { |
| 65 | println!("cargo:rustc-env=ATOMIC_CLI_VERSION={version}"); |
| 66 | return; |
| 67 | } |
| 68 | "dev" => {} |
| 69 | _ => panic!("ATOMIC_BUILD_CHANNEL must be 'dev' or 'release'"), |
| 70 | } |
| 71 | |
| 72 | let manifest_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap()); |
| 73 | let root = git(&manifest_dir, &["rev-parse", "--show-toplevel"]) |
| 74 | .map(|path| PathBuf::from(path.trim())); |
| 75 | let mut dirty = false; |
| 76 | if let Some(root) = &root { |
| 77 | watch_repository(root); |
| 78 | dirty = git(root, &["status", "--porcelain", "--untracked-files=no"]) |
| 79 | .is_some_and(|status| !status.trim().is_empty()); |
| 80 | } |
| 81 | |
| 82 | let commit = match env::var("ATOMIC_BUILD_COMMIT") { |
| 83 | Ok(commit) => { |
| 84 | let short = short_commit(&commit) |
| 85 | .expect("ATOMIC_BUILD_COMMIT must contain a 12 to 64 character hexadecimal commit"); |
| 86 | short.to_string() |
| 87 | } |
| 88 | Err(_) => root |
| 89 | .as_deref() |
| 90 | .and_then(|root| git(root, &["rev-parse", "--verify", "HEAD"])) |
| 91 | .and_then(|commit| short_commit(&commit).map(str::to_owned)) |
| 92 | .unwrap_or_else(|| "unknown".to_string()), |
| 93 | }; |
| 94 | let dirty = if dirty { "-dirty" } else { "" }; |
| 95 | println!("cargo:rustc-env=ATOMIC_CLI_VERSION={version} (dev {commit}{dirty})"); |
| 96 | } |
nothing calls this directly
no test coverage detected