Skip to content

Commit 509a86a

Browse files
hellaismmaker
authored andcommitted
Get build to work on macOS
1 parent 5669d55 commit 509a86a

3 files changed

Lines changed: 30 additions & 45 deletions

File tree

Cargo.lock

Lines changed: 14 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ooniauth-py/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ bincode = {workspace = true}
1818
serde = {workspace = true}
1919
thiserror = {workspace = true}
2020
base64 = "0.22.1"
21+
22+
[build-dependencies]
23+
pyo3-build-config = "0.28.3"

ooniauth-py/build.rs

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,19 @@
11
// Build helper for plain Cargo workflows.
2-
// Maturin usually sets Python link flags; this script queries `python3-config`
3-
// and emits equivalent linker directives so `cargo build/test` can link PyO3.
4-
// This is needed because Cargo does not automatically inherit Maturin's linker setup.
5-
use std::process::Command;
6-
72
fn main() {
3+
pyo3_build_config::add_extension_module_link_args();
4+
85
println!("cargo:rerun-if-env-changed=PYO3_PYTHON");
96
println!("cargo:rerun-if-env-changed=PYTHON_SYS_EXECUTABLE");
107

11-
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
12-
if target_os != "macos" {
13-
return;
14-
}
15-
16-
let flags = python3_config_ldflags();
17-
if let Some(flags) = flags {
18-
emit_link_flags(&flags);
19-
}
20-
}
21-
22-
fn python3_config_ldflags() -> Option<String> {
23-
run_python3_config(&["--embed", "--ldflags"]).or_else(|| run_python3_config(&["--ldflags"]))
24-
}
25-
26-
fn run_python3_config(args: &[&str]) -> Option<String> {
27-
let output = Command::new("python3-config").args(args).output().ok()?;
28-
if !output.status.success() {
29-
return None;
30-
}
31-
String::from_utf8(output.stdout).ok()
32-
}
33-
34-
fn emit_link_flags(flags: &str) {
35-
let mut iter = flags.split_whitespace().peekable();
36-
while let Some(flag) = iter.next() {
37-
if let Some(path) = flag.strip_prefix("-L") {
38-
println!("cargo:rustc-link-search=native={path}");
39-
} else if let Some(lib) = flag.strip_prefix("-l") {
40-
println!("cargo:rustc-link-lib={lib}");
41-
} else if flag == "-framework" {
42-
if let Some(name) = iter.next() {
43-
println!("cargo:rustc-link-lib=framework={name}");
44-
}
45-
}
46-
}
8+
println!("cargo:rerun-if-changed=build.rs");
9+
println!("cargo:rerun-if-env-changed=CC");
10+
println!("cargo:rerun-if-env-changed=CFLAGS");
11+
println!("cargo:rerun-if-env-changed=LDFLAGS");
12+
println!("cargo:rerun-if-env-changed=RUSTFLAGS");
13+
println!("cargo:rustc-check-cfg=cfg(Py_3_10)");
14+
println!("cargo:rustc-check-cfg=cfg(Py_3_11)");
15+
println!("cargo:rustc-check-cfg=cfg(Py_3_12)");
16+
println!("cargo:rustc-check-cfg=cfg(Py_3_13)");
17+
println!("cargo:rustc-check-cfg=cfg(Py_3_14)");
18+
println!("cargo:rustc-check-cfg=cfg(Py_3_15)");
4719
}

0 commit comments

Comments
 (0)