Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Marc 'risson' Schmitt <[email protected]>
  • Loading branch information
rissson committed Nov 5, 2024
1 parent 4e95777 commit 942c34d
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ jobs:
env:
CIBW_ARCHS_LINUX: auto aarch64 ppc64le s390x
CIBW_BEFORE_ALL_LINUX: "curl -sSf https://sh.rustup.rs | sh -s -- -y && yum install -y krb5-devel clang-devel"
CIBW_BEFORE_ALL_MACOS: "brew install llvm krb5"
CIBW_BEFORE_ALL_MACOS: "curl -sSf https://sh.rustup.rs | sh -s -- -y && brew install krb5 llvm"
CIBW_ENVIRONMENT_LINUX: "PATH=$HOME/.cargo/bin:$PATH"
CIBW_SKIP: "*-musllinux_i686 *-manylinux_i686"
CIBW_MANYLINUX_X86_64_IMAGE: manylinux_2_28
Expand Down
90 changes: 89 additions & 1 deletion kadmin-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,94 @@
use std::{env, path::PathBuf};
use std::{
env,
path::{Path, PathBuf},
process::Command,
};

fn execute_command_and_get_output(cmd: &str, args: &[&str]) -> Option<String> {
let out = Command::new(cmd).args(args).output();
if let Ok(ref r1) = out {
if r1.status.success() {
let r2 = String::from_utf8(r1.stdout.clone());
if let Ok(r3) = r2 {
return Some(r3.trim().to_string());
}
}
}

None
}

fn resolve_with_wellknown_homebrew_location(dir: &str) -> Option<PathBuf> {
// Check up default aarch 64 Homebrew installation location first
// for quick resolution if possible.
// `pkg-config` on brew doesn't necessarily contain settings for krb5 apparently.
let homebrew = Path::new(dir).join("opt/krb5");
if homebrew.exists() {
return Some(homebrew);
}
// Calling `brew --prefix <package>` command usually slow and
// takes seconds, and will be used only as a last resort.
let output = execute_command_and_get_output("brew", &["--prefix", "krb5"]);
if let Some(ref output) = output {
let homebrew = Path::new(&output);
if homebrew.exists() {
return Some(homebrew.to_path_buf());
}
}

None
}

fn resolve_with_wellknown_location(dir: &str) -> Option<PathBuf> {
let root_dir = Path::new(dir);
let include_krb5 = root_dir.join("include/krb5");
if include_krb5.exists() {
Some(root_dir.to_path_buf())
} else {
None
}
}

fn find_macos(target: &str, host: &str) -> Option<PathBuf> {
if host == target && target.ends_with("-apple-darwin") {
let homebrew_dir = match target {
"aarch64-apple-darwin" => "/opt/homebrew",
_ => "/usr/local",
};

if let Some(dir) = resolve_with_wellknown_homebrew_location(homebrew_dir) {
return Some(dir);
} else if let Some(dir) = resolve_with_wellknown_location("/opt/pkg") {
// pkgsrc
return Some(dir);
} else if let Some(dir) = resolve_with_wellknown_location("/opt/local") {
// MacPorts
return Some(dir);
}
}
None
}

fn main() {
let target = env::var("TARGET").unwrap();
let host = env::var("HOST").unwrap();

if let Some(dir) = find_macos(&target, &host) {
for lib in ["KRB5", "KADM5CLNT", "KADM5SRV"] {
unsafe {
env::set_var(
format!("SYSTEM_DEPS_{lib}_SEARCH_NATIVE"),
format!("{}/lib", dir.display()),
);
env::set_var(
format!("SYSTEM_DEPS_{lib}_SEARCH_FRAMEWORK"),

Check warning on line 84 in kadmin-sys/build.rs

View workflow job for this annotation

GitHub Actions / lint (rustfmt, nightly, rustfmt)

Diff in /home/runner/work/kadmin-rs/kadmin-rs/kadmin-sys/build.rs
format!("{}/lib", dir.display()),
);
env::set_var(format!("SYSTEM_DEPS_{lib}_INCLUDE"), format!("{}/include", dir.display()));
}
}
}

let deps = system_deps::Config::new().probe().unwrap();

let mut builder = bindgen::builder()
Expand Down

0 comments on commit 942c34d

Please sign in to comment.