Mercurial > crates > nonstick
comparison libpam-sys/libpam-sys-test/build.rs @ 130:80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
This reimplements everything in nonstick on top of the new -sys crate.
We don't yet use libpam-sys's helpers for binary message payloads. Soon.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Tue, 01 Jul 2025 06:11:43 -0400 |
parents | c77846f3a979 |
children | a632a8874131 |
comparison
equal
deleted
inserted
replaced
129:5b2de52dd8b2 | 130:80c07e5ab22f |
---|---|
1 use bindgen::MacroTypeVariation; | 1 use bindgen::MacroTypeVariation; |
2 use libpam_sys_impls::__pam_impl_enum__; | 2 use libpam_sys_impls::__pam_impl_enum__; |
3 use proc_macro2::{Group, TokenStream, TokenTree}; | 3 use proc_macro2::{Group, Ident, TokenStream, TokenTree}; |
4 use quote::{format_ident, ToTokens}; | 4 use quote::{format_ident, ToTokens}; |
5 use std::path::Path; | 5 use std::path::Path; |
6 use std::process::Command; | 6 use std::process::Command; |
7 use std::str::FromStr; | 7 use std::str::FromStr; |
8 use std::{env, fs}; | 8 use std::{env, fs}; |
148 } | 148 } |
149 | 149 |
150 fn remove_consts(file_contents: &str, out_file: impl AsRef<Path>) { | 150 fn remove_consts(file_contents: &str, out_file: impl AsRef<Path>) { |
151 let deconstified = deconstify( | 151 let deconstified = deconstify( |
152 TokenStream::from_str(file_contents).unwrap(), | 152 TokenStream::from_str(file_contents).unwrap(), |
153 &TokenStream::from_str("mut") | 153 &format_ident!("mut"), |
154 .unwrap() | |
155 .into_iter() | |
156 .next() | |
157 .unwrap(), | |
158 ) | 154 ) |
159 .to_string(); | 155 .to_string(); |
160 let out_file = out_file.as_ref(); | 156 let out_file = out_file.as_ref(); |
161 fs::write(out_file, deconstified).unwrap(); | 157 fs::write(out_file, deconstified).unwrap(); |
162 rustfmt(out_file) | 158 rustfmt(out_file) |
168 .status() | 164 .status() |
169 .unwrap(); | 165 .unwrap(); |
170 assert!(status.success(), "rustfmt exited with code {status}"); | 166 assert!(status.success(), "rustfmt exited with code {status}"); |
171 } | 167 } |
172 | 168 |
173 fn deconstify(stream: TokenStream, mut_token: &TokenTree) -> TokenStream { | 169 fn deconstify(stream: TokenStream, mut_token: &Ident) -> TokenStream { |
174 TokenStream::from_iter(stream.into_iter().map(|token| { | 170 TokenStream::from_iter(stream.into_iter().map(|token| { |
175 match token { | 171 match token { |
176 TokenTree::Group(g) => { | 172 TokenTree::Group(g) => { |
177 TokenTree::Group(Group::new(g.delimiter(), deconstify(g.stream(), mut_token))) | 173 TokenTree::Group(Group::new(g.delimiter(), deconstify(g.stream(), mut_token))) |
178 .into_token_stream() | 174 .into_token_stream() |