Skip to content

Commit

Permalink
Emit warnings on windows when an incompatible GnuPG is detected.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnschug committed Nov 19, 2024
1 parent a3107ea commit 4f24ed4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Continuous Integration
name: CI
on: [push, pull_request]
env:
CARGO_TERM_COLOR: always
jobs:
test:
basic-tests:
name: Test Suite (${{ matrix.os }}, rust-${{ matrix.rust }})
runs-on: ${{ matrix.os }}
strategy:
Expand Down Expand Up @@ -31,15 +31,17 @@ jobs:
run: brew install gpgme

- name: Install rust
run: rustup default ${{ matrix.rust }}
run: rustup toolchain install --no-self-update --profile minimal ${{ matrix.rust }}

- run: rustup default ${{ matrix.rust }}

- name: Build
run: cargo build --verbose

- name: Run tests
run: cargo test --verbose --no-fail-fast

docker-static:
docker-static-test:
name: Test Suite (linux, docker, musl)
runs-on: ubuntu-latest
steps:
Expand All @@ -52,7 +54,7 @@ jobs:
- name: Run tests in container
run: docker run test-build

docker-windows:
docker-windows-test:
name: Test Suite (windows, docker)
runs-on: windows-2022
continue-on-error: true
Expand Down
52 changes: 27 additions & 25 deletions gpgme-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
if build::cargo_cfg_windows() && build::cargo_feature("windows_raw_dylib") {
return Ok(()); // neccessary linker args set in lib.rs
}
build::rerun_if_changed("build.rs");

#[cfg(windows)]
if try_registry() {
if build::cargo_cfg_windows() && (build::cargo_feature("windows_raw_dylib") || try_registry()) {
return Ok(());
}

system_deps::Config::new().probe()?;
Ok(())
}

#[cfg(not(windows))]
fn try_registry() -> bool {
false
}

#[cfg(windows)]
fn try_registry() -> bool {
use std::{ffi::OsString, path::PathBuf};
Expand All @@ -27,35 +29,35 @@ fn try_registry() -> bool {
KEY_WOW64_32KEY
};
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
let Ok(key) = hklm
.open_subkey_with_flags(path, flags | KEY_READ)
.inspect_err(|e| eprintln!("unable to retrieve install location: {e}"))
else {
let Ok(key) = hklm.open_subkey_with_flags(path, KEY_READ | flags) else {
return false;
};
let Ok(root) = key
.get_value::<OsString, _>("Install Directory")
.map(PathBuf::from)
.inspect_err(|e| eprintln!("unable to retrieve install location: {e}"))
else {
return false;
};

println!("detected install via registry: {}", root.display());
build::rustc_link_search(root.join("lib"));
build::rustc_link_lib("dylib:+verbatim=libgpgme.imp");
true
}
if !build::cargo_cfg_windows() {
eprintln!("cross compiling. disabling registry detection.");
return false;
match (build::cargo_cfg_pointer_width(), wide) {
(64, true) | (32, false) => {
println!("detected install via registry: {}", root.display());
build::rustc_link_search(root.join("lib"));
build::rustc_link_lib("dylib:+verbatim=libgpgme.imp");
true
}
_ => {
eprintln!(
"An incompatible installation of GnuPG was detected: {}\n\
Try switching the target from 64-bit to 32-bit or 32-bit to 64-bit.\n",
root.display()
);
false
}
}
}

[r"SOFTWARE\Gpg4win", r"SOFTWARE\GnuPG"].iter().any(|s| {
if build::cargo_cfg_pointer_width() == 64 {
try_key(s, true)
} else {
try_key(s, false)
}
})
[r"SOFTWARE\Gpg4win", r"SOFTWARE\GnuPG"]
.iter()
.any(|s| try_key(s, true) || try_key(s, false))
}

0 comments on commit 4f24ed4

Please sign in to comment.