Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pcsc-sys: add nicer error message when pcsclite is not found on Linux #53

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
ci:
strategy:
matrix:
os: [ubuntu-22.04, windows-2019, macos-12]
os: [ubuntu-22.04, windows-2022, macos-14]
toolchain: [stable]
include:
- {os: ubuntu-22.04, toolchain: '1.38.0'}
Expand All @@ -20,7 +20,7 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install dependencies (Linux)
if: matrix.os == 'ubuntu-22.04'
Expand Down
44 changes: 33 additions & 11 deletions pcsc-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
use std::env;

fn print_pcsclite_error_message(target_os: &str) {
if target_os == "linux" {
eprintln!(
"If you are using Debian (or a derivative), try:

$ sudo apt install pkgconf libpcsclite-dev
"
);
eprintln!(
"If you are using Arch (or a derivative), try:

$ sudo pacman -S pkgconf pcsclite
"
);
eprintln!(
"If you are using Fedora (or a derivative), try:

$ sudo dnf install pkgconf pcsc-lite-devel
"
);
}
}

fn main() {
let target_os = env::var("CARGO_CFG_TARGET_OS")
.expect(r#"The CARGO_CFG_TARGET_OS environment is not set in the build script."#);
Expand All @@ -25,17 +48,16 @@ fn main() {
env::var("PCSC_LIB_NAME").unwrap_or_else(|_| "pcsclite".to_string())
);
} else {
pkg_config::Config::new()
.atleast_version("1")
.probe("libpcsclite")
.unwrap_or_else(|_| {
panic!(
r#"Could not find a PCSC library.
For the target OS `{}`, I tried to use pkg-config to find libpcsclite.
Do you have pkg-config and libpcsclite configured for this target?"#,
target_os
)
});
if let Err(err) = pkg_config::Config::new().atleast_version("1").probe("libpcsclite") {
eprintln!("Could not find a PCSC library.");
eprintln!(
"For the target OS `{}`, I tried to use pkg-config to find libpcsclite.",
target_os
);
eprintln!("The error given is: {}", err);
print_pcsclite_error_message(&target_os);
std::process::exit(1);
}
}
}
};
Expand Down