Skip to content

Commit

Permalink
Rename the pam binding files as requested
Browse files Browse the repository at this point in the history
Also fix the Makefile to generate the bindings.
  • Loading branch information
bjorn3 committed Oct 23, 2024
1 parent 54ba749 commit 2674b00
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
15 changes: 10 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@ PAM_SRC_DIR = src/pam

BINDGEN_CMD = bindgen --allowlist-function '^pam_.*$$' --allowlist-var '^PAM_.*$$' --opaque-type pam_handle_t --blocklist-function pam_vsyslog --blocklist-function pam_vprompt --blocklist-function pam_vinfo --blocklist-function pam_verror --blocklist-type '.*va_list.*' --ctypes-prefix libc --no-layout-tests --sort-semantically

PAM_VARIANT = $$(./get-pam-variant.bash)

.PHONY: all clean pam-sys pam-sys-diff

pam-sys-diff:
@$(BINDGEN_CMD) $< | diff --color=auto $(PAM_SRC_DIR)/sys.rs - || (echo run \'make -B pam-sys\' to apply these changes && false)
@echo $(PAM_SRC_DIR)/sys.rs does not need to be re-generated
@$(BINDGEN_CMD) $(PAM_SRC_DIR)/wrapper.h | \
sed 's/rust-bindgen [0-9]*\.[0-9]*\.[0-9]*/&, minified by cargo-minify/' | \
diff --color=auto $(PAM_SRC_DIR)/sys_$(PAM_VARIANT).rs - \
|| (echo run \'make -B pam-sys\' to apply these changes && false)
@echo $(PAM_SRC_DIR)/sys_$(PAM_VARIANT).rs does not need to be re-generated

# use 'make pam-sys' to re-generate the sys.rs file for your local platform
pam-sys:
$(BINDGEN_CMD) $(PAM_SRC_DIR)/wrapper.h --output $(PAM_SRC_DIR)/sys_$$(uname | tr 'A-Z' 'a-z').rs
$(BINDGEN_CMD) $(PAM_SRC_DIR)/wrapper.h --output $(PAM_SRC_DIR)/sys_$(PAM_VARIANT).rs
cargo minify --apply --allow-dirty
sed -i.bak 's/rust-bindgen [0-9]*\.[0-9]*\.[0-9]*/&, minified by cargo-minify/' $(PAM_SRC_DIR)/sys_$$(uname | tr 'A-Z' 'a-z').rs
rm $(PAM_SRC_DIR)/sys_$$(uname | tr 'A-Z' 'a-z').rs.bak
sed -i.bak 's/rust-bindgen [0-9]*\.[0-9]*\.[0-9]*/&, minified by cargo-minify/' $(PAM_SRC_DIR)/sys_$(PAM_VARIANT).rs
rm $(PAM_SRC_DIR)/sys_$(PAM_VARIANT).rs.bak

clean:
rm $(PAM_SRC_DIR)/sys.rs
15 changes: 15 additions & 0 deletions get-pam-variant.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

# FIXME read headers to find the actually used variant
case $(uname) in
Linux)
echo linuxpam
;;
FreeBSD)
echo openpam
;;
*)
echo "Unsupported platform"
exit 1
;;
esac
4 changes: 2 additions & 2 deletions src/pam/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ mod error;
mod rpassword;
mod securemem;

#[cfg_attr(target_os = "linux", path = "sys_linux.rs")]
#[cfg_attr(target_os = "freebsd", path = "sys_freebsd.rs")]
#[cfg_attr(target_os = "linux", path = "sys_linuxpam.rs")]
#[cfg_attr(target_os = "freebsd", path = "sys_openpam.rs")]
#[allow(nonstandard_style)]
pub mod sys;

Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 2674b00

Please sign in to comment.